diff --git a/FSL/CMakeLists.txt b/FSL/CMakeLists.txt index 0d17544ef573139bc3aea76999da060aa0c86bc2..f68a8fafec4e0d508480ddbfe909f5c145808806 100644 --- a/FSL/CMakeLists.txt +++ b/FSL/CMakeLists.txt @@ -20,9 +20,7 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) "Framework finding behaviour on macOS" ) # Set up how the project handle some of its dependenices. Either by picking them # up from the environment, or building them itself. - if( NOT TARGET JSONExt ) - include( SetupJSON ) - endif() + include( SetupJSON ) # Set a flag to steer the of the subpackages set( ${PROJECT_NAME}_INDIVIDUAL_BUILD ON ) find_package (FullSimLight REQUIRED) @@ -80,18 +78,7 @@ set(PROJECT_SOURCES ${sources} ${headers} ${uis} ) add_executable(fsl ${PROJECT_SOURCES} ) - - -target_link_libraries(fsl PRIVATE Qt5::Widgets) - -if( GEOMODEL_USE_BUILTIN_JSON ) - add_dependencies(fsl JSONExt ) -endif() - -if( nlohmann_json_FOUND ) - target_link_libraries( fsl PRIVATE nlohmann_json::nlohmann_json ) -endif() - +target_link_libraries(fsl PRIVATE Qt5::Widgets nlohmann_json::nlohmann_json) # Install the executable. install( TARGETS fsl diff --git a/FullSimLight/CMakeLists.txt b/FullSimLight/CMakeLists.txt index bdbd4c747eabf7ef39c680e6b40b48a60546458a..e15a966bb8c9bc71a5abcffc1121882569e53966 100644 --- a/FullSimLight/CMakeLists.txt +++ b/FullSimLight/CMakeLists.txt @@ -27,9 +27,7 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) "Framework finding behaviour on macOS" ) # Set up how the project handle some of its dependenices. Either by picking them # up from the environment, or building them itself. - if( NOT TARGET JSONExt ) - include( SetupJSON ) - endif() + include( SetupJSON ) if( NOT TARGET XercesCBuiltIn ) include( SetupXercesC ) endif() @@ -138,19 +136,6 @@ add_executable(gm2gdml geoModel2GDML.cc ${sources} ${headers}) #---------------------------------------------------------------------------- # Add extra 'include' directories # -# If the in-house build of the nlohmann_json library is used, add explicit dependency -if( GEOMODEL_USE_BUILTIN_JSON ) - add_dependencies( fullSimLight JSONExt ) - add_dependencies( gmclash JSONExt ) - add_dependencies( gmmasscalc JSONExt ) - add_dependencies( fillHistogramExample JSONExt ) - add_dependencies( gmgeantino JSONExt ) - add_dependencies( gm2gdml JSONExt ) - # Acquire Installation Directory of JSONExt - ExternalProject_Get_Property (JSONExt install_dir) - # Include the installed 'include' PATH - include_directories (${install_dir}/include) -endif() # If the in-house build of the Xerces-C library is used, add explicit dependency: for Geant4 if( GEOMODEL_USE_BUILTIN_XERCESC ) add_dependencies( fullSimLight XercesCBuiltIn ) @@ -196,20 +181,11 @@ else() # if built as a part of GeoModel endif() # targets that need 'nlohmann_json' -# NOTE: 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', ...) -if( nlohmann_json_FOUND ) - target_link_libraries( gmclash PRIVATE nlohmann_json::nlohmann_json ) - target_link_libraries( gmmasscalc PRIVATE nlohmann_json::nlohmann_json ) - target_link_libraries( fullSimLight PRIVATE nlohmann_json::nlohmann_json ) - target_link_libraries( gmgeantino PRIVATE nlohmann_json::nlohmann_json ) - target_link_libraries( gm2gdml PRIVATE nlohmann_json::nlohmann_json ) -else() - message(STATUS "WARNING - 'nlohmann_json' not found by CMake!! Anyway, if you installed the single header file in a standard system include dir, I will be able to use it.") -endif() +target_link_libraries( gmclash PRIVATE nlohmann_json::nlohmann_json ) +target_link_libraries( gmmasscalc PRIVATE nlohmann_json::nlohmann_json ) +target_link_libraries( fullSimLight PRIVATE nlohmann_json::nlohmann_json ) +target_link_libraries( gmgeantino PRIVATE nlohmann_json::nlohmann_json ) +target_link_libraries( gm2gdml PRIVATE nlohmann_json::nlohmann_json ) #---------------------------------------------------------------------------- # Add profiling test targets diff --git a/GeoModelTools/CMakeLists.txt b/GeoModelTools/CMakeLists.txt index 7e8ccdcd0125f7d7c632c4a3f0b5774e282c4e95..9fd5840b4561a3cf08e3462914b48c7ef7818941 100644 --- a/GeoModelTools/CMakeLists.txt +++ b/GeoModelTools/CMakeLists.txt @@ -27,9 +27,7 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) "Framework finding behaviour on macOS" ) # Set up how the project handle some of its dependenices. Either by picking them # up from the environment, or building them itself. - if( NOT TARGET JSONExt ) - include( SetupJSON ) - endif() + include( SetupJSON ) if( NOT TARGET XercesCBuiltIn ) include( SetupXercesC ) endif() diff --git a/GeoModelTools/GeoModelJSONParser/CMakeLists.txt b/GeoModelTools/GeoModelJSONParser/CMakeLists.txt index 28eb7d0f8adfd8dc1e1e61d739ba9c8134d1ec6b..2e3f980ab55cfab57ad98d5eb2ed18ccb248d144 100644 --- a/GeoModelTools/GeoModelJSONParser/CMakeLists.txt +++ b/GeoModelTools/GeoModelJSONParser/CMakeLists.txt @@ -6,20 +6,7 @@ file( GLOB HEADERS GeoModelJSONParser/*.h ) # Create the library. add_library( GeoModelJSONParser SHARED ${HEADERS} ${SOURCES} ) - -# If the in-house build of the nlohmann_json library is used, add explicit dependency -if( GEOMODEL_USE_BUILTIN_JSON ) - add_dependencies( GeoModelJSONParser JSONExt ) -endif() - -# 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', ...) -if ( nlohmann_json_FOUND ) - target_link_libraries( GeoModelJSONParser PUBLIC nlohmann_json::nlohmann_json ) -endif() +target_link_libraries( GeoModelJSONParser PUBLIC nlohmann_json::nlohmann_json ) target_include_directories( GeoModelJSONParser PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> diff --git a/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt b/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt index 6984a09c9c5eea3dd845cbf35e2d53f0c52ccd13..662b24a95cbe16967c12c98f8e282b6359e74c13 100644 --- a/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt +++ b/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt @@ -21,9 +21,6 @@ set_target_properties( GXClashPointSystems PROPERTIES if( GEOMODEL_USE_BUILTIN_COIN3D ) add_dependencies( GXClashPointSystems Coin3DBuiltIn ) endif() -if( GEOMODEL_USE_BUILTIN_JSON ) - add_dependencies( GXClashPointSystems JSONExt ) -endif() # Set up an alias with the same name that you would get by "finding" a pre-built # version of the library. diff --git a/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt b/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt index fb3e73d64870e9b3c24110ddd20600ce518daf32..cdbaa073c9f8ea56c3f1cb43e4dcb3c8940945f3 100644 --- a/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt +++ b/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt @@ -26,9 +26,6 @@ set_target_properties( GXGeometrySystems PROPERTIES if( GEOMODEL_USE_BUILTIN_COIN3D ) add_dependencies( GXGeometrySystems Coin3DBuiltIn ) endif() -if( GEOMODEL_USE_BUILTIN_JSON ) - add_dependencies( GXGeometrySystems JSONExt ) -endif() # Set up an alias with the same name that you would get by "finding" a pre-built # version of the library. diff --git a/cmake/SetupJSON.cmake b/cmake/SetupJSON.cmake index a516cde54638058bee2aec199d00a2df564f0acd..6eb203ecf9a84b77d2f1138a5cf7b6c7197e485c 100644 --- a/cmake/SetupJSON.cmake +++ b/cmake/SetupJSON.cmake @@ -6,75 +6,54 @@ # # Make sure that this file is only included once. -get_property( _jsonSetUp GLOBAL PROPERTY GEOMODEL_JSON_SET_UP SET ) -if( _jsonSetUp ) - unset( _jsonSetUp ) - return() -endif() -set_property( GLOBAL PROPERTY GEOMODEL_JSON_SET_UP TRUE ) +include_guard(GLOBAL) # Configuration option for how "nlohmann_json" should be used. -option( GEOMODEL_USE_BUILTIN_JSON -"Download and compile a version of nlohmann_json during the build" FALSE ) +option(GEOMODEL_USE_BUILTIN_JSON "Download and compile a version of nlohmann_json during the build" OFF) # Now do what was requested. -if( GEOMODEL_USE_BUILTIN_JSON ) - +if(GEOMODEL_USE_BUILTIN_JSON) # Tell the user what's happening. message( STATUS "${BoldMagenta}'GEOMODEL_USE_BUILTIN_JSON' was set to 'true' ==> Building nlohmann_json as part of the project${ColourReset}" ) # The include directory and library that will be produced. - set( nlohmann_json_INCLUDE_DIR - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall/${CMAKE_INSTALL_INCLUDEDIR}" ) - set( nlohmann_json_INCLUDE_DIRS "${nlohmann_json_INCLUDE_DIR}" ) - set( nlohmann_json_VERSION "3.6.1" ) - set( nlohmann_json_FOUND TRUE ) + set(nlohmann_json_INCLUDE_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall/${CMAKE_INSTALL_INCLUDEDIR}" ) + set(nlohmann_json_INCLUDE_DIRS "${nlohmann_json_INCLUDE_DIR}" ) + set(nlohmann_json_VERSION "3.6.1" ) + set(nlohmann_json_FOUND TRUE ) message(STATUS "Installing the built-in 'nlohmann_json' in: ${nlohmann_json_INCLUDE_DIR}") # Create the include directory already, otherwise CMake refuses to # create the imported target. - file( MAKE_DIRECTORY "${nlohmann_json_INCLUDE_DIR}" ) + file(MAKE_DIRECTORY "${nlohmann_json_INCLUDE_DIR}") # Build/install nlohmann_json using ExternalProject_Add(...). include( ExternalProject ) - ExternalProject_Add( JSONExt - PREFIX ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONBuild - INSTALL_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall - URL "https://cern.ch/lcgpackages/tarFiles/sources/json-${nlohmann_json_VERSION}.tar.gz" - URL_MD5 "c53592d55e7fec787cf0a406d36098a3" - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} - -DJSON_BuildTests:BOOL=OFF -DJSON_MultipleHeaders:BOOL=ON - BUILD_BYPRODUCTS "${nlohmann_json_INCLUDE_DIR}" ) - install( DIRECTORY - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall/ - DESTINATION . - COMPONENT Development - USE_SOURCE_PERMISSIONS ) + ExternalProject_Add(JSONExt + PREFIX ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONBuild + INSTALL_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall + URL "https://cern.ch/lcgpackages/tarFiles/sources/json-${nlohmann_json_VERSION}.tar.gz" + URL_MD5 "c53592d55e7fec787cf0a406d36098a3" + CMAKE_CACHE_ARGS + -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} + -DJSON_BuildTests:BOOL=OFF + -DJSON_MultipleHeaders:BOOL=ON + BUILD_BYPRODUCTS "${nlohmann_json_INCLUDE_DIR}" ) + install(DIRECTORY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall/ + DESTINATION . + COMPONENT Development + USE_SOURCE_PERMISSIONS) # Set up nlohmann_json's imported target. - add_library( nlohmann_json::nlohmann_json INTERFACE IMPORTED ) - set_target_properties( nlohmann_json::nlohmann_json PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_INCLUDE_DIR}" ) + add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED) + set_property(TARGET nlohmann_json::nlohmann_json PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_INCLUDE_DIR}") + + # Auto handle dependency + add_dependencies(nlohmann_json::nlohmann_json JSONExt) else() - # Find an existing installation of nlohmann_json. - find_package( nlohmann_json QUIET ) - if( nlohmann_json_FOUND ) - # If it was found, tell the user about it. - get_target_property( _incPaths nlohmann_json::nlohmann_json - INTERFACE_INCLUDE_DIRECTORIES ) - list( GET _incPaths 0 _incPath ) - message( STATUS "Found nlohmann_json: ${_incPath}" ) - unset( _incPaths ) - unset( _incPath ) - else() - # If it was not found, it may still be that the necessary header is - # available on the build system. So just set up a dummy library that would - # allow the configuration to succeed. - message( WARNING "Creating a dummy nlohmann_json::nlohmann_json target " - "in case the headers are avalable in some public place..." ) - add_library( nlohmann_json::nlohmann_json INTERFACE IMPORTED ) - endif() + # Find an existing installation of nlohmann_json. + find_package(nlohmann_json REQUIRED) endif()