Skip to content

Commit

Permalink
build: Fix potential interaction with GeoModel's bundled json (acts-p…
Browse files Browse the repository at this point in the history
…roject#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.
  • Loading branch information
paulgessinger authored and Ragansu committed Mar 7, 2024
1 parent 52f809c commit e0bd2a3
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 9 deletions.
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
From dec8e912948cac74e5362ebc3b89f34e07ecd8e8 Mon Sep 17 00:00:00 2001
From: Paul Gessinger <hello@paulgessinger.com>
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=<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_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=<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_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)
7 changes: 6 additions & 1 deletion thirdparty/GeoModel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ 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" )
set( ACTS_GEOMODEL_GIT_TAG "${GEOMODEL_VERSION}" CACHE STRING "Version of GeoModel to build" )
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 )
3 changes: 3 additions & 0 deletions thirdparty/nlohmann_json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down

0 comments on commit e0bd2a3

Please sign in to comment.