Files
IfcOpenShell/cmake/Findnlohmann_json.cmake
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.9 KiB
CMake
Raw Normal View History

2025-12-05 15:26:48 +05:00
#
# 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)
2026-09-16 13:56:45 +05:00
find_package(nlohmann_json ${nlohmann_json_FIND_VERSION} CONFIG)
mark_as_advanced(nlohmann_json)
2025-12-05 15:26:48 +05:00
if(nlohmann_json_DIR)
return()
endif()
endif()
find_path(json_header_path "nlohmann/json.hpp" HINTS "${JSON_INCLUDE_DIR}")
mark_as_advanced(json_header_path)
2025-12-05 15:26:48 +05:00
if(json_header_path)
2026-09-16 13:56:45 +05:00
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
)
2025-12-05 15:26:48 +05:00
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")