From 07923c22b6f0aa20b80b20b7b595c282fffdef7c Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 18 Sep 2025 14:02:57 +0500 Subject: [PATCH] cmake - support find_package for json --- cmake/CMakeLists.txt | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 81a63615ba..10f361ec44 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -251,15 +251,26 @@ endif() if(GLTF_SUPPORT OR CITYJSON_SUPPORT) UNIFY_ENVVARS_AND_CACHE(JSON_INCLUDE_DIR) - clear_wasm_sysroot() - find_path(json_header_path "nlohmann/json.hpp" HINTS ${JSON_INCLUDE_DIR}) - restore_wasm_sysroot() - 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, aborting") + 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) + clear_wasm_sysroot() + find_path(json_header_path "nlohmann/json.hpp" HINTS ${JSON_INCLUDE_DIR}) + restore_wasm_sysroot() + 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() add_definitions(-DWITH_GLTF)