From 0b6838b94d73daa2f5aff5cbda10f25e4ac5fd5c Mon Sep 17 00:00:00 2001 From: Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch> Date: Fri, 24 Apr 2020 12:21:53 +0200 Subject: [PATCH] Fix build when nlohmann_json is not CMake-installed When nlohmann_json is installed in other ways rather than by using the CMake setup included within the package, no CMake config file is installed for nlohmann_json; and so, it is not possible to use find_package( nlohmann_json ) in the CMake setup of our package. This commit fixes the build for the case, for example, when nohmann_json is installed by simply copying the single-header file into a system include folder as '/usr/local/include'. --- GeoModelJSONParser/CMakeLists.txt | 7 ++++++- cmake/SetupJSON.cmake | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/GeoModelJSONParser/CMakeLists.txt b/GeoModelJSONParser/CMakeLists.txt index 03f7a90..595d0ca 100644 --- a/GeoModelJSONParser/CMakeLists.txt +++ b/GeoModelJSONParser/CMakeLists.txt @@ -6,7 +6,12 @@ file( GLOB HEADERS GeoModelJSONParser/*.h ) # Create the library. add_library( GeoModelJSONParser SHARED ${HEADERS} ${SOURCES} ) -target_link_libraries( GeoModelJSONParser PUBLIC nlohmann_json::nlohmann_json ) +if (nlohmann_json_FOUND) + # we link to nlohmann_json only if we use a version of nlohmann_json installed through CMake; + # this is not needed if the single-header library is installed in a regular + # system include folder (e.g., '/usr/local/include') + target_link_libraries( GeoModelJSONParser PUBLIC nlohmann_json::nlohmann_json ) +endif() target_include_directories( GeoModelJSONParser PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) diff --git a/cmake/SetupJSON.cmake b/cmake/SetupJSON.cmake index 3bd3539..6e77d8a 100644 --- a/cmake/SetupJSON.cmake +++ b/cmake/SetupJSON.cmake @@ -13,7 +13,7 @@ option( GEOMODEL_USE_BUILTIN_JSON if( GEOMODEL_USE_BUILTIN_JSON ) # Tell the user what's happening. - message( STATUS "Building nlohmann_json as part of the project" ) + message( STATUS "'GEOMODEL_USE_BUILTIN_JSON' was set to 'true' ==> Building nlohmann_json as part of the project" ) # The include directory and library that will be produced. set( nlohmann_json_INCLUDE_DIR @@ -50,6 +50,9 @@ if( GEOMODEL_USE_BUILTIN_JSON ) else() # Just find an existing installation of nlohmann_json. - find_package( nlohmann_json ) + find_package( nlohmann_json QUIET) + if( NOT nlohmann_json_FOUND ) + message(STATUS "WARNING! 'nlohmann_json' was not found by CMake!! However, if you installed this single-header library in a standard system include dir (e.g., '/usr/local/include'), I will be able to use it.") + endif() endif() -- GitLab