|
6 | 6 |
|
7 | 7 | #---Check for installed packages depending on the build options/components enabled -- |
8 | 8 | include(CheckCXXSourceCompiles) |
| 9 | +include(CheckIncludeFileCXX) |
9 | 10 | include(ExternalProject) |
10 | 11 | include(FindPackageHandleStandardArgs) |
11 | 12 |
|
@@ -80,6 +81,29 @@ if(NOT builtin_nlohmannjson) |
80 | 81 | message(STATUS "nlohmann/json.hpp not found. Switching on builtin_nlohmannjson option") |
81 | 82 | set(builtin_nlohmannjson ON CACHE BOOL "Enabled because nlohmann/json.hpp not found" FORCE) |
82 | 83 | endif() |
| 84 | + |
| 85 | + # If we found an external nlohmann_json with a version greater than 3.11, |
| 86 | + # check that it has the json_fwd.hpp header. |
| 87 | + if(nlohmann_json_FOUND AND nlohmann_json_VERSION VERSION_GREATER_EQUAL 3.11) |
| 88 | + set(_old_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) |
| 89 | + set(_old_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET}) |
| 90 | + |
| 91 | + set(CMAKE_REQUIRED_LIBRARIES nlohmann_json::nlohmann_json) |
| 92 | + set(CMAKE_REQUIRED_QUIET TRUE) |
| 93 | + check_include_file_cxx("nlohmann/json_fwd.hpp" _nlohmann_json_fwd_hpp) |
| 94 | + if(NOT _nlohmann_json_fwd_hpp) |
| 95 | + set(_msg "Could not find nlohmann/json_fwd.hpp, which is required for versions greater than 3.11.") |
| 96 | + if(nlohmann_json_VERSION VERSION_LESS 3.11.2) |
| 97 | + set(_msg "${_msg} Please upgrade to at least version 3.11.2.") |
| 98 | + else() |
| 99 | + set(_msg "${_msg} It is installed by default, so your installation is incomplete!") |
| 100 | + endif() |
| 101 | + message(FATAL_ERROR "${_msg}") |
| 102 | + endif() |
| 103 | + |
| 104 | + set(CMAKE_REQUIRED_LIBRARIES ${_old_CMAKE_REQUIRED_LIBRARIES}) |
| 105 | + set(CMAKE_REQUIRED_QUIET ${_old_CMAKE_REQUIRED_QUIET}) |
| 106 | + endif() |
83 | 107 | endif() |
84 | 108 | endif() |
85 | 109 |
|
|
0 commit comments