From ef4341ba4ad9466253851978ba069f4731516896 Mon Sep 17 00:00:00 2001 From: Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch> Date: Tue, 30 Jun 2020 10:13:20 +0200 Subject: [PATCH] Fix farther installation case of nlohmann for Visualization --- GeoModelTools/CMakeLists.txt | 2 +- .../GXClashPointSystems/CMakeLists.txt | 19 ++++++++++++++----- .../VP1GeometrySystems/CMakeLists.txt | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/GeoModelTools/CMakeLists.txt b/GeoModelTools/CMakeLists.txt index b54f5613a..99ce7fba3 100644 --- a/GeoModelTools/CMakeLists.txt +++ b/GeoModelTools/CMakeLists.txt @@ -9,7 +9,7 @@ set( CMAKE_BUILD_TYPE "Release" CACHE STRING "CMake build mode to use" ) set( CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard used for the build" ) set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)allow using GNU extensions" ) -# # Make the module directory visible to CMake. +# Make the module directory visible to CMake. list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) # # # Use the GNU install directory names. diff --git a/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt b/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt index 60c014722..cf1ddf5d3 100644 --- a/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt +++ b/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt @@ -66,11 +66,20 @@ endif() target_link_libraries (GXClashPointSystems PRIVATE SoQt::SoQt Coin::Coin ${Qt5Core_LIBRARIES} GXGui GXBase GXHEPVis ${SoQt_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5PrintSupport_LIBRARIES} ) - -# 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') -if( nlohmann_json_FOUND ) +# We link to `nlohmann_json` only if we use a version of nlohmann_json +# that provides a CMake config file (i.e., either built from source, or also +# installed with Homebrew on macOS). +# This is not needed if the single-header library is installed in a regular +# system include folder (e.g., '/usr/local/include', '/usr/include', ...) +# Also, note that nlohmann_json has been found (or not) at the root level already, +# but apparently it needs to be "found" here again, +# otherwise the nlohmann_json CMake config file is not found properly. +# Thus, in case SetupJSON.cmake finds it at root level, the variable +# SetupJSON_nlohmann_json_FOUND is set to true, and here we "find" nlohmann_json +# again. (TODO: to be investigated if we can simplify all that: ideally, +# finding it at root level inside SetupJSON.cmake should be enough.) +if ( nlohmann_json_FOUND OR SetupJSON_nlohmann_json_FOUND ) + find_package(nlohmann_json QUIET) target_link_libraries( GXClashPointSystems PUBLIC nlohmann_json::nlohmann_json ) endif() diff --git a/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt b/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt index 5235058f8..4873890c3 100644 --- a/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt +++ b/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt @@ -62,10 +62,20 @@ include_directories(${SoQt_INCLUDE_DIRS} ) include_directories(${VP1HEPVis_INCLUDE_DIRS} ) -# 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') -if( nlohmann_json_FOUND ) +# We link to `nlohmann_json` only if we use a version of nlohmann_json +# that provides a CMake config file (i.e., either built from source, or also +# installed with Homebrew on macOS). +# This is not needed if the single-header library is installed in a regular +# system include folder (e.g., '/usr/local/include', '/usr/include', ...) +# Also, note that nlohmann_json has been found (or not) at the root level already, +# but apparently it needs to be "found" here again, +# otherwise the nlohmann_json CMake config file is not found properly. +# Thus, in case SetupJSON.cmake finds it at root level, the variable +# SetupJSON_nlohmann_json_FOUND is set to true, and here we "find" nlohmann_json +# again. (TODO: to be investigated if we can simplify all that: ideally, +# finding it at root level inside SetupJSON.cmake should be enough.) +if ( nlohmann_json_FOUND OR SetupJSON_nlohmann_json_FOUND ) + find_package(nlohmann_json QUIET) target_link_libraries( GXGeometrySystems nlohmann_json::nlohmann_json ) endif() -- GitLab