From 3d9653511b3747644ed054a29e6844eb8dfd32bf Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Fri, 1 Mar 2024 13:31:20 +0100 Subject: [PATCH] build: Fix potential interaction with GeoModel's bundled json (#2995) GeoModel also bundles JSON. This adds a patch to our bundled GeoModel that allows us to instruct them to not build their own JSON. This should be upstreamed to GeoModel at some point. --- CMakeLists.txt | 16 +-- ...n-to-skip-setting-up-json-completely.patch | 117 ++++++++++++++++++ thirdparty/GeoModel/CMakeLists.txt | 7 +- thirdparty/nlohmann_json/CMakeLists.txt | 3 + 4 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 thirdparty/GeoModel/0001-Add-option-to-skip-setting-up-json-completely.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index 80b8987ccae..d9f4044258e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,6 +290,14 @@ if(ACTS_BUILD_PLUGIN_DD4HEP) find_package(Python 3.8 REQUIRED COMPONENTS Interpreter) find_package(DD4hep ${_acts_dd4hep_version} REQUIRED CONFIG COMPONENTS DDCore DDDetectors) endif() +if(ACTS_BUILD_PLUGIN_JSON) + if(ACTS_USE_SYSTEM_NLOHMANN_JSON) + message(STATUS "Using system installation of nlohmann::json") + find_package(nlohmann_json ${_acts_nlohmanjson_version} REQUIRED CONFIG) + else() + add_subdirectory(thirdparty/nlohmann_json) + endif() +endif() if(ACTS_BUILD_PLUGIN_GEOMODEL) if(ACTS_USE_SYSTEM_GEOMODEL) message(STATUS "Using system installation of GeoModel") @@ -299,14 +307,6 @@ if(ACTS_BUILD_PLUGIN_GEOMODEL) endif() endif() -if(ACTS_BUILD_PLUGIN_JSON) - if(ACTS_USE_SYSTEM_NLOHMANN_JSON) - message(STATUS "Using system installation of nlohmann::json") - find_package(nlohmann_json ${_acts_nlohmanjson_version} REQUIRED CONFIG) - else() - add_subdirectory(thirdparty/nlohmann_json) - endif() -endif() if(ACTS_BUILD_PLUGIN_SYCL) find_package(SYCL REQUIRED) endif() diff --git a/thirdparty/GeoModel/0001-Add-option-to-skip-setting-up-json-completely.patch b/thirdparty/GeoModel/0001-Add-option-to-skip-setting-up-json-completely.patch new file mode 100644 index 00000000000..791243e8ccc --- /dev/null +++ b/thirdparty/GeoModel/0001-Add-option-to-skip-setting-up-json-completely.patch @@ -0,0 +1,117 @@ +From dec8e912948cac74e5362ebc3b89f34e07ecd8e8 Mon Sep 17 00:00:00 2001 +From: Paul Gessinger +Date: Wed, 28 Feb 2024 11:17:47 +0100 +Subject: [PATCH] Add option to skip setting up json completely + +--- + cmake/SetupJSON.cmake | 94 +++++++++++++++++++++++-------------------- + 1 file changed, 51 insertions(+), 43 deletions(-) + +diff --git a/cmake/SetupJSON.cmake b/cmake/SetupJSON.cmake +index 6eb203ec..41e4a1ed 100644 +--- a/cmake/SetupJSON.cmake ++++ b/cmake/SetupJSON.cmake +@@ -10,50 +10,58 @@ 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" OFF) ++option(GEOMODEL_SETUP_JSON "Whether to set up nlohmann_json at all, or expect the target to be present" ON) + +-# Now do what was requested. +-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 ) +- 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}") +- +- # 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= +- -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_property(TARGET nlohmann_json::nlohmann_json PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_INCLUDE_DIR}") +- +- # Auto handle dependency +- add_dependencies(nlohmann_json::nlohmann_json JSONExt) ++if(GEOMODEL_SETUP_JSON) ++ message( STATUS "${BoldMagenta}'GEOMODEL_SETUP_JSON' was set to 'true' ==> Explicitly setting up nlohmann_json${ColourReset}" ) ++ # Now do what was requested. ++ 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 ) ++ 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}") ++ ++ # 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= ++ -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_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 REQUIRED) ++ endif() + else() +- # Find an existing installation of nlohmann_json. +- find_package(nlohmann_json REQUIRED) ++ if(NOT TARGET nlohmann_json::nlohmann_json) ++ message(FATAL_ERROR "The 'nlohmann_json' target was not found, and 'GEOMODEL_SETUP_JSON' was set to 'false'") ++ endif() + endif() +-- +2.39.3 (Apple Git-145) diff --git a/thirdparty/GeoModel/CMakeLists.txt b/thirdparty/GeoModel/CMakeLists.txt index 87726a3ce12..dfd85283977 100644 --- a/thirdparty/GeoModel/CMakeLists.txt +++ b/thirdparty/GeoModel/CMakeLists.txt @@ -15,6 +15,9 @@ message( STATUS "Building GeoModel as part of the ACTS project" ) set( GEOMODEL_VERSION "${_acts_geomodel_version}") +set( GEOMODEL_SETUP_JSON OFF CACHE BOOL "Skip setting up json completely" ) + + # Declare where to get VecMem from. set( ACTS_GEOMODEL_GIT_REPOSITORY "https://gitlab.cern.ch/GeoModelDev/GeoModel" CACHE STRING "Git repository to take GeoModel from" ) @@ -22,7 +25,9 @@ set( ACTS_GEOMODEL_GIT_TAG "${GEOMODEL_VERSION}" CACHE STRING "Version of GeoMod mark_as_advanced( ACTS_GEOMODEL_GIT_REPOSITORY ACTS_GEOMODEL_GIT_TAG ) FetchContent_Declare( geomodel GIT_REPOSITORY "${ACTS_GEOMODEL_GIT_REPOSITORY}" - GIT_TAG "${ACTS_GEOMODEL_GIT_TAG}" ) + GIT_TAG "${ACTS_GEOMODEL_GIT_TAG}" + PATCH_COMMAND git am ${CMAKE_CURRENT_SOURCE_DIR}/0001-Add-option-to-skip-setting-up-json-completely.patch +) # Now set up its build. FetchContent_MakeAvailable( geomodel ) diff --git a/thirdparty/nlohmann_json/CMakeLists.txt b/thirdparty/nlohmann_json/CMakeLists.txt index 781e9ebbee2..52851da85f9 100644 --- a/thirdparty/nlohmann_json/CMakeLists.txt +++ b/thirdparty/nlohmann_json/CMakeLists.txt @@ -4,6 +4,9 @@ include( FetchContent ) # Tell the user what's happening. message( STATUS "Building nlohmann_json as part of the ACTS project" ) +if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif() # Declare where to get VecMem from. set( ACTS_NLOHMANN_JSON_GIT_TAG "v3.10.5" CACHE STRING "Version of nlohmann_json to build" )