Skip to content

Commit ee52a8b

Browse files
committed
[cmake] Check for json_fwd.hpp in versions > 3.11
Our forward declaration in REveElement.hxx breaks with the versioned namespaces in 3.11, so we require the json_fwd.hpp header.
1 parent ed56a35 commit ee52a8b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cmake/modules/SearchInstalledSoftware.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#---Check for installed packages depending on the build options/components enabled --
88
include(CheckCXXSourceCompiles)
9+
include(CheckIncludeFileCXX)
910
include(ExternalProject)
1011
include(FindPackageHandleStandardArgs)
1112

@@ -80,6 +81,29 @@ if(NOT builtin_nlohmannjson)
8081
message(STATUS "nlohmann/json.hpp not found. Switching on builtin_nlohmannjson option")
8182
set(builtin_nlohmannjson ON CACHE BOOL "Enabled because nlohmann/json.hpp not found" FORCE)
8283
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()
83107
endif()
84108
endif()
85109

0 commit comments

Comments
 (0)