1 # - Try to find nlohmann_json
3 # The following variables are optionally searched for defaults
4 # nlohmann_json_ROOT_DIR: Base directory where all GLOG components are found
6 # The following are set after configuration is done:
8 # nlohmann_json_INCLUDE_DIRS
9 # nlohmann_json_LIBRARIES
11 include(FindPackageHandleStandardArgs)
13 # only look in default directories
14 set(nlohmann_json_INCLUDE_NAME "nlohmann/json.hpp")
16 find_path(nlohmann_json_INCLUDE_DIR
19 PATHS /usr/local/include
22 if (NOT nlohmann_json_INCLUDE_DIR)
23 set(nlohmann_json_INCLUDE_NAME "json.hpp")
25 nlohmann_json_INCLUDE_DIR
26 NAMES "${nlohmann_json_INCLUDE_NAME}"
31 # Version detection. Unfortunately the header doesn't expose a proper version
33 if (nlohmann_json_INCLUDE_DIR AND nlohmann_json_INCLUDE_NAME)
34 file(READ "${nlohmann_json_INCLUDE_DIR}/${nlohmann_json_INCLUDE_NAME}" NL_HDR_TXT LIMIT 1000)
35 if (NL_HDR_TXT MATCHES "version ([0-9]+\.[0-9]+\.[0-9]+)")
36 set(nlohmann_json_VERSION "${CMAKE_MATCH_1}")
40 set(nlohmann_json_VERSION "${nlohmann_json_VERSION}" CACHE STRING "nlohmann header version")
42 # handle the QUIETLY and REQUIRED arguments and set nlohmann_json_FOUND to TRUE
43 # if all listed variables are TRUE, hide their existence from configuration view
44 include(FindPackageHandleStandardArgs)
45 find_package_handle_standard_args(
47 REQUIRED_VARS nlohmann_json_INCLUDE_DIR nlohmann_json_INCLUDE_NAME
48 VERSION_VAR nlohmann_json_VERSION)
50 if(nlohmann_json_FOUND AND NOT (TARGET nlohmann_json))
51 add_library(nlohmann_json SHARED IMPORTED)
52 set_target_properties(nlohmann_json PROPERTIES
53 INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_INCLUDE_DIR}"