Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ option(SOFA_BUILD_RELEASE_PACKAGE "Run package specific configure" OFF)
# Option to allow some dependencies such as cxxopts to be fetched by cmake if
# the package is not found
option(SOFA_ALLOW_FETCH_DEPENDENCIES "Allow compatible dependencies to be fetched if the package is not found by cmake.
List of dependencies that can be fetched: cxxopts, gtest, metis, CImg" ON)
List of dependencies that can be fetched: cxxopts, gtest, metis, CImg, nlohmann json" ON)

# Option to accelerate the compilation
# see https://cmake.org/cmake/help/v3.16/command/target_precompile_headers.html
Expand Down
86 changes: 0 additions & 86 deletions Sofa/framework/Config/cmake/Modules/FindJson.cmake

This file was deleted.

17 changes: 17 additions & 0 deletions Sofa/framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
cmake_minimum_required(VERSION 3.22)
project(Sofa.Core LANGUAGES CXX)

find_package(nlohmann_json QUIET)

if(NOT TARGET nlohmann_json AND SOFA_ALLOW_FETCH_DEPENDENCIES)
message("Sofa.Core: DEPENDENCY nlohmann_json NOT FOUND. SOFA_ALLOW_FETCH_DEPENDENCIES is ON, fetching nlohmann_json...")

set(JSON_BuildTests OFF CACHE INTERNAL "")

sofa_fetch_dependency(nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.12.0
)
elseif(NOT TARGET nlohmann_json)
message(FATAL_ERROR "Sofa.Core: DEPENDENCY nlohmann_json NOT FOUND. SOFA_ALLOW_FETCH_DEPENDENCIES is OFF and thus cannot be fetched. Install nlohmann_json (version>=3.9.1), or enable SOFA_ALLOW_FETCH_DEPENDENCIES to fix this issue.")
endif()

set(SRC_ROOT "src/sofa/core")

set(HEADER_FILES
Expand Down Expand Up @@ -352,6 +367,8 @@ add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})

target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Helper Sofa.Topology Sofa.DefaultType)

target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json)

if(SOFA_BUILD_WITH_PCH_ENABLED)
message("Adding precompiled header for Sofa.Core")
target_precompile_headers(${PROJECT_NAME} PUBLIC ${SRC_ROOT}/objectmodel/BaseObject.h ${SRC_ROOT}/objectmodel/Data.h)
Expand Down
2 changes: 1 addition & 1 deletion Sofa/framework/Core/src/sofa/core/ObjectFactoryJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
******************************************************************************/
#include <sofa/core/ObjectFactoryJson.h>
#include <sofa/core/ObjectFactory.h>
#include <json.h>
#include <nlohmann/json.hpp>
#include <sofa/core/CategoryLibrary.h>


Expand Down
19 changes: 17 additions & 2 deletions Sofa/framework/Helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,23 @@ project(Sofa.Helper LANGUAGES CXX)

# Eigen (header only)
sofa_find_package(Eigen3 REQUIRED)

# Json (header only) needed by AdvancedTimer
sofa_find_package(Json 3.1.2 REQUIRED)
find_package(nlohmann_json QUIET)

if(NOT TARGET nlohmann_json AND SOFA_ALLOW_FETCH_DEPENDENCIES)
message("Sofa.GUI.Common: DEPENDENCY nlohmann_json NOT FOUND. SOFA_ALLOW_FETCH_DEPENDENCIES is ON, fetching nlohmann_json...")

set(JSON_BuildTests OFF CACHE INTERNAL "")

sofa_fetch_dependency(nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.12.0
)
elseif(NOT TARGET nlohmann_json)
message(FATAL_ERROR "Sofa.GUI.Common: DEPENDENCY nlohmann_json NOT FOUND. SOFA_ALLOW_FETCH_DEPENDENCIES is OFF and thus cannot be fetched. Install nlohmann_json (version>=3.9.1), or enable SOFA_ALLOW_FETCH_DEPENDENCIES to fix this issue.")
endif()

# STB (header only)
sofa_find_package(STB REQUIRED)
# DiffLib (header only)
Expand Down Expand Up @@ -249,7 +264,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
endif()

# Json (header only) needed by AdvancedTimer
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${JSON_INCLUDE_DIR}>")
target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json)

# STB (header only) for Image
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${STB_INCLUDE_DIR}>")
Expand Down
4 changes: 2 additions & 2 deletions Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <sofa/helper/logging/Messaging.h>
#include <sofa/helper/AdvancedTimer.h>
#include <sofa/type/vector.h>
#include <json.h>
#include <nlohmann/json.hpp>

#include <iomanip>
#include <cmath>
Expand All @@ -37,7 +37,7 @@

#define DEFAULT_INTERVAL 100

using json = sofa::helper::json;
using json = nlohmann::json;


namespace sofa::helper
Expand Down
2 changes: 0 additions & 2 deletions extlibs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.22)

############# extlibs ##############

# Nlohmann JSON (header-only)
set(json_ROOT "${CMAKE_CURRENT_LIST_DIR}/json" CACHE PATH "Nlohmann JSON directory")
# STB (header-only)
set(STB_ROOT "${CMAKE_CURRENT_LIST_DIR}/stb" CACHE PATH "STB directory")
# DiffLib
Expand Down
21 changes: 0 additions & 21 deletions extlibs/json/LICENSE.MIT

This file was deleted.

13 changes: 0 additions & 13 deletions extlibs/json/json.h

This file was deleted.

Loading