From 1ad1883f0ea67fce4a29a0f7020710e6acedd3cd Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 5 Dec 2025 15:26:48 +0500 Subject: [PATCH] Findnlohmann_json.cmake --- cmake/CMakeLists.txt | 26 +++-------------- cmake/Findnlohmann_json.cmake | 28 +++++++++++++++++++ src/ifcconvert/CMakeLists.txt | 2 +- src/serializers/CMakeLists.txt | 2 +- .../schema_dependent/CMakeLists.txt | 7 ++--- 5 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 cmake/Findnlohmann_json.cmake diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 8402c4b956..31d771f081 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -213,28 +213,10 @@ if(BUILD_IFCGEOM AND WITH_OPENCASCADE) list(APPEND GEOMETRY_KERNELS opencascade) endif() +set(GLTF_LIBRARIES "") if(GLTF_SUPPORT) - UNIFY_ENVVARS_AND_CACHE(JSON_INCLUDE_DIR) - if(NOT JSON_INCLUDE_DIR) - find_package(nlohmann_json CONFIG) - if(nlohmann_json_DIR) - link_libraries(nlohmann_json::nlohmann_json) - else() - message(STATUS "Unable to find nlohmann_json package, trying to find it as a header-only library.") - endif() - endif() - - if(NOT nlohmann_json_DIR) - find_path(json_header_path "nlohmann/json.hpp" HINTS ${JSON_INCLUDE_DIR}) - set(JSON_INCLUDE_DIR ${json_header_path}) - - if(json_header_path) - message(STATUS "JSON for Modern C++ header file found in '${JSON_INCLUDE_DIR}'.") - else() - message(FATAL_ERROR "Unable to find JSON for Modern C++ header file / package, aborting") - endif() - endif() - + find_package(nlohmann_json REQUIRED) + set(GLTF_LIBRARIES nlohmann_json::nlohmann_json) add_definitions(-DWITH_GLTF) set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_GLTF) endif() @@ -449,7 +431,7 @@ else() endif(MSVC) include_directories(${OPENCOLLADA_INCLUDE_DIRS} - ${Boost_INCLUDE_DIRS} ${JSON_INCLUDE_DIR} ${HDF5_INCLUDE_DIR} + ${Boost_INCLUDE_DIRS} ${HDF5_INCLUDE_DIR} ${USD_INCLUDE_DIR} ${TBB_INCLUDE_DIR} ) diff --git a/cmake/Findnlohmann_json.cmake b/cmake/Findnlohmann_json.cmake new file mode 100644 index 0000000000..5f26414102 --- /dev/null +++ b/cmake/Findnlohmann_json.cmake @@ -0,0 +1,28 @@ +# +# Input variables: +# - `JSON_INCLUDE_DIR` +# If input variables are not specified, try to find nlohmann_json config. +# Input variables could also be provided as environment variables. +# +# Output targets: +# - `nlohmann_json::nlohmann_json` + +UNIFY_ENVVARS_AND_CACHE(JSON_INCLUDE_DIR) + +if(NOT JSON_INCLUDE_DIR) + find_package(nlohmann_json CONFIG) + if(nlohmann_json_DIR) + return() + endif() +endif() + +find_path(json_header_path "nlohmann/json.hpp" HINTS "${JSON_INCLUDE_DIR}") + +if(json_header_path) + message(STATUS "JSON for Modern C++ header file found in '${json_header_path}'.") + add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED) + target_include_directories(nlohmann_json::nlohmann_json INTERFACE ${json_header_path}) + return() +endif() + +message(FATAL_ERROR "Unable to find JSON for Modern C++ header file / package, aborting") diff --git a/src/ifcconvert/CMakeLists.txt b/src/ifcconvert/CMakeLists.txt index 85b6d16e30..dd6a0040a2 100644 --- a/src/ifcconvert/CMakeLists.txt +++ b/src/ifcconvert/CMakeLists.txt @@ -13,7 +13,7 @@ target_link_libraries(IfcConvert PRIVATE IfcGeom IfcParse Serializers ${OpenCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${HDF5_LIBRARIES} ${USD_LIBRARIES} - ${CGAL_LIBRARIES} + ${CGAL_LIBRARIES} ${GLTF_LIBRARIES} ) install(TARGETS IfcConvert) diff --git a/src/serializers/CMakeLists.txt b/src/serializers/CMakeLists.txt index c575958a70..c1d9c761f1 100644 --- a/src/serializers/CMakeLists.txt +++ b/src/serializers/CMakeLists.txt @@ -19,7 +19,7 @@ endif() target_link_libraries(Serializers PRIVATE - ${SERIALIZER_SCHEMA_LIBRARIES} ${OPENCOLLADA_LIBRARIES} ${USD_LIBRARIES} + ${SERIALIZER_SCHEMA_LIBRARIES} ${OPENCOLLADA_LIBRARIES} ${USD_LIBRARIES} ${GLTF_LIBRARIES} IfcGeom ${OpenCASCADE_LIBRARIES} ${kernel_libraries} IfcParse ) diff --git a/src/serializers/schema_dependent/CMakeLists.txt b/src/serializers/schema_dependent/CMakeLists.txt index e1d22f262f..6fdcc8e482 100644 --- a/src/serializers/schema_dependent/CMakeLists.txt +++ b/src/serializers/schema_dependent/CMakeLists.txt @@ -6,10 +6,9 @@ foreach(schema ${SCHEMA_VERSIONS}) add_library(Serializers_ifc${schema} OBJECT ${SERIALIZERS_S_FILES}) set(SERIALIZER_SCHEMA_LIBRARIES ${SERIALIZER_SCHEMA_LIBRARIES} Serializers_ifc${schema}) set_target_properties(Serializers_ifc${schema} PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS -DIfcSchema=Ifc${schema}") - if(WASM_BUILD) - target_link_libraries(Serializers_ifc${schema} ${HDF5_LIBRARIES}) - else() - target_link_libraries(Serializers_ifc${schema} IfcGeom ${OpenCASCADE_LIBRARIES} ${HDF5_LIBRARIES}) + target_link_libraries(Serializers_ifc${schema} ${HDF5_LIBRARIES} ${GLTF_LIBRARIES}) + if(NOT WASM_BUILD) + target_link_libraries(Serializers_ifc${schema} IfcGeom ${OpenCASCADE_LIBRARIES}) endif() endforeach()