From 3a4ef70a7fb97b051a4be93e27c8e465217b3263 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Wed, 23 Oct 2024 15:13:06 +0200 Subject: [PATCH 1/3] Find nlohmann_json downstream if EDM4hep has support --- cmake/EDM4HEPConfig.cmake.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/EDM4HEPConfig.cmake.in b/cmake/EDM4HEPConfig.cmake.in index 7bf6d54f2..2a68686e2 100644 --- a/cmake/EDM4HEPConfig.cmake.in +++ b/cmake/EDM4HEPConfig.cmake.in @@ -14,6 +14,11 @@ set_and_check(EDM4HEP_DATA_DIR "@PACKAGE_CMAKE_INSTALL_DATADIR@/edm4hep") include(CMakeFindDependencyMacro) find_dependency(podio REQUIRED) +set(EDM4HEP_WITH_JSON @nlohmann_json_FOUND@) +if (EDM4HEP_WITH_JSON) + find_dependency(nlohmann_json 3.10.5 REQUIRED) +endif() + # - Include the targets file to create the imported targets that a client can # link to (libraries) or execute (programs) include("${CMAKE_CURRENT_LIST_DIR}/EDM4HEPTargets.cmake") From 5bb65d20a79ee16eef0466760050a6944aec7f69 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Wed, 23 Oct 2024 16:22:59 +0200 Subject: [PATCH 2/3] Add an EDM4HEP_WITH_JSON cmake option to be explicit --- CMakeLists.txt | 6 +++++- cmake/EDM4HEPConfig.cmake.in | 2 +- edm4hep/CMakeLists.txt | 2 +- tools/CMakeLists.txt | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bff3b3311..5ae17155f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,11 @@ SET( ${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME find_package(podio 1.1 REQUIRED HINTS $ENV{PODIO}) find_package(ROOT REQUIRED COMPONENTS RIO Tree Physics) +option(EDM4HEP_WITH_JSON "Whether or not to build EDM4HEP with JSON support (and edm4hep2json)" ON) +if (EDM4HEP_WITH_JSON) + find_package(nlohmann_json 3.10.5 REQUIRED) +endif() + include(cmake/Key4hepConfig.cmake) #--- Define basic build settings ----------------------------------------------- @@ -63,7 +68,6 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/NOTICE DESTINATION ${CMAKE_INSTALL_DOCDIR}) -find_package(nlohmann_json 3.10.5) add_subdirectory(edm4hep) add_subdirectory(utils) diff --git a/cmake/EDM4HEPConfig.cmake.in b/cmake/EDM4HEPConfig.cmake.in index 2a68686e2..032d275e3 100644 --- a/cmake/EDM4HEPConfig.cmake.in +++ b/cmake/EDM4HEPConfig.cmake.in @@ -14,7 +14,7 @@ set_and_check(EDM4HEP_DATA_DIR "@PACKAGE_CMAKE_INSTALL_DATADIR@/edm4hep") include(CMakeFindDependencyMacro) find_dependency(podio REQUIRED) -set(EDM4HEP_WITH_JSON @nlohmann_json_FOUND@) +set(EDM4HEP_WITH_JSON @EDM4HEP_WITH_JSON@) if (EDM4HEP_WITH_JSON) find_dependency(nlohmann_json 3.10.5 REQUIRED) endif() diff --git a/edm4hep/CMakeLists.txt b/edm4hep/CMakeLists.txt index 8c2d6b5a4..229f04805 100644 --- a/edm4hep/CMakeLists.txt +++ b/edm4hep/CMakeLists.txt @@ -19,7 +19,7 @@ add_library(EDM4HEP::edm4hep ALIAS edm4hep) file(GLOB_RECURSE top_headers ${PROJECT_SOURCE_DIR}/include/*.h) target_sources(edm4hep PUBLIC FILE_SET headers TYPE HEADERS BASE_DIRS ${PROJECT_SOURCE_DIR}/include FILES ${top_headers}) -if (nlohmann_json_FOUND) +if (EDM4HEP_WITH_JSON) target_compile_definitions(edm4hep PUBLIC PODIO_JSON_OUTPUT) target_link_libraries(edm4hep PUBLIC nlohmann_json::nlohmann_json) endif() diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 0f79fbe32..f7959c12b 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,6 +1,6 @@ list( APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" ) -if (nlohmann_json_FOUND) +if (EDM4HEP_WITH_JSON) add_executable(edm4hep2json src/edm4hep2json.cxx) set(EDM4HEP_SET_RPATH TRUE) From 2b9f9710503d951ba02fd78fb0564aed27fd7927 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Wed, 23 Oct 2024 16:32:19 +0200 Subject: [PATCH 3/3] Make nlohmman_json version a single point of configuration Co-authored-by: Andre Sailer --- CMakeLists.txt | 3 ++- cmake/EDM4HEPConfig.cmake.in | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ae17155f..5b17974d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,8 @@ find_package(ROOT REQUIRED COMPONENTS RIO Tree Physics) option(EDM4HEP_WITH_JSON "Whether or not to build EDM4HEP with JSON support (and edm4hep2json)" ON) if (EDM4HEP_WITH_JSON) - find_package(nlohmann_json 3.10.5 REQUIRED) + set(EDM4HEP_NLOHMANN_JSON_VERSION 3.10.5) + find_package(nlohmann_json ${EDM4HEP_NLOHMANN_JSON_VERSION} REQUIRED) endif() include(cmake/Key4hepConfig.cmake) diff --git a/cmake/EDM4HEPConfig.cmake.in b/cmake/EDM4HEPConfig.cmake.in index 032d275e3..7046fc542 100644 --- a/cmake/EDM4HEPConfig.cmake.in +++ b/cmake/EDM4HEPConfig.cmake.in @@ -16,7 +16,7 @@ find_dependency(podio REQUIRED) set(EDM4HEP_WITH_JSON @EDM4HEP_WITH_JSON@) if (EDM4HEP_WITH_JSON) - find_dependency(nlohmann_json 3.10.5 REQUIRED) + find_dependency(nlohmann_json @EDM4HEP_NLOHMANN_JSON_VERSION@ REQUIRED) endif() # - Include the targets file to create the imported targets that a client can