Skip to content

Commit

Permalink
Find nlohmann_json downstream if EDM4hep has support (#379)
Browse files Browse the repository at this point in the history
* Find nlohmann_json downstream if EDM4hep has support

* Add an EDM4HEP_WITH_JSON cmake option to be explicit

* Make nlohmman_json version a single point of configuration

---------

Co-authored-by: Andre Sailer <[email protected]>
  • Loading branch information
tmadlener and andresailer authored Oct 23, 2024
1 parent 22e85d7 commit 18799da
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ 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)
set(EDM4HEP_NLOHMANN_JSON_VERSION 3.10.5)
find_package(nlohmann_json ${EDM4HEP_NLOHMANN_JSON_VERSION} REQUIRED)
endif()

include(cmake/Key4hepConfig.cmake)

#--- Define basic build settings -----------------------------------------------
Expand Down Expand Up @@ -63,7 +69,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)
Expand Down
5 changes: 5 additions & 0 deletions cmake/EDM4HEPConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 @EDM4HEP_WITH_JSON@)
if (EDM4HEP_WITH_JSON)
find_dependency(nlohmann_json @EDM4HEP_NLOHMANN_JSON_VERSION@ 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")
Expand Down
2 changes: 1 addition & 1 deletion edm4hep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 18799da

Please sign in to comment.