From a5dec547193060c52c61591eb7d67099388260f4 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 16 Sep 2026 13:56:45 +0500 Subject: [PATCH] cmake: add minimum required json version --- cmake/CMakeLists.txt | 4 +++- cmake/Findnlohmann_json.cmake | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index a269f5f0bc..ef6c3ac671 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -298,7 +298,9 @@ if(BUILD_IFCGEOM) endif() if(GLTF_SUPPORT) - find_package(nlohmann_json REQUIRED) + # 3.6.1 is the version currently used on the Windows build. + # 3.10.5 is the version shipped with Ubuntu 22.04. + find_package(nlohmann_json 3.6.1 REQUIRED) endif() # Add USD support to serializers diff --git a/cmake/Findnlohmann_json.cmake b/cmake/Findnlohmann_json.cmake index 172cb4a4f5..b3ac6d5b63 100644 --- a/cmake/Findnlohmann_json.cmake +++ b/cmake/Findnlohmann_json.cmake @@ -10,7 +10,7 @@ UNIFY_ENVVARS_AND_CACHE(JSON_INCLUDE_DIR) if(NOT JSON_INCLUDE_DIR) - find_package(nlohmann_json CONFIG) + find_package(nlohmann_json ${nlohmann_json_FIND_VERSION} CONFIG) mark_as_advanced(nlohmann_json) if(nlohmann_json_DIR) return() @@ -21,7 +21,20 @@ find_path(json_header_path "nlohmann/json.hpp" HINTS "${JSON_INCLUDE_DIR}") mark_as_advanced(json_header_path) if(json_header_path) - message(STATUS "JSON for Modern C++ header file found in '${json_header_path}'.") + file(STRINGS "${json_header_path}/nlohmann/json.hpp" json_version_major_line REGEX "^#define NLOHMANN_JSON_VERSION_MAJOR") + file(STRINGS "${json_header_path}/nlohmann/json.hpp" json_version_minor_line REGEX "^#define NLOHMANN_JSON_VERSION_MINOR") + file(STRINGS "${json_header_path}/nlohmann/json.hpp" json_version_patch_line REGEX "^#define NLOHMANN_JSON_VERSION_PATCH") + string(REGEX REPLACE "^#define NLOHMANN_JSON_VERSION_MAJOR ([0-9]+)$" "\\1" json_version_major "${json_version_major_line}") + string(REGEX REPLACE "^#define NLOHMANN_JSON_VERSION_MINOR ([0-9]+)$" "\\1" json_version_minor "${json_version_minor_line}") + string(REGEX REPLACE "^#define NLOHMANN_JSON_VERSION_PATCH ([0-9]+)$" "\\1" json_version_patch "${json_version_patch_line}") + set(nlohmann_json_VERSION "${json_version_major}.${json_version_minor}.${json_version_patch}") + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(nlohmann_json + REQUIRED_VARS json_header_path + VERSION_VAR nlohmann_json_VERSION + ) + add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED) target_include_directories(nlohmann_json::nlohmann_json INTERFACE ${json_header_path}) return()