From fd9c99efa6e3936cece711b4a1e94037394ea88e Mon Sep 17 00:00:00 2001 From: SeverinDiederichs Date: Fri, 27 Mar 2026 11:21:51 +0100 Subject: [PATCH] require Geant4 for AdePT --- CMakeLists.txt | 100 ++++++++---------- examples/Example1/CMakeLists.txt | 17 ++- .../regression/IntegrationTest/CMakeLists.txt | 17 ++- test/unit/testField/CMakeLists.txt | 9 +- 4 files changed, 61 insertions(+), 82 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00626f47..e6f5ed7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,29 +291,25 @@ else() endif() # Find Geant4, optional for now -find_package(Geant4 QUIET) -if(Geant4_FOUND) - message(STATUS "Using Geant4 version ${Cyan}${Geant4_VERSION}${ColorReset} from ${Geant4_INCLUDE_DIRS}") - set(CMAKE_REQUIRED_INCLUDES ${Geant4_INCLUDE_DIRS}) - set(CMAKE_REQUIRED_LIBRARIES ${Geant4_LIBRARIES}) - # Check if Geant4 is supports G4VTrackingManager - # Always available from v11.0, but experiments may backport it to earlier versions - # so we do a compile check. - check_cxx_source_compiles(" - #include \"G4VTrackingManager.hh\" - #include \"G4Track.hh\" - - struct testtm_ : G4VTrackingManager { - void HandOverOneTrack(G4Track*) override {} - }; - - int main() { - testtm_ t; - return 0; - }" AdePT_HAS_G4VTRACKINGMANAGER) -else() - message(STATUS "Did not find Geant4") -endif() +find_package(Geant4 REQUIRED) +message(STATUS "Using Geant4 version ${Cyan}${Geant4_VERSION}${ColorReset} from ${Geant4_INCLUDE_DIRS}") +set(CMAKE_REQUIRED_INCLUDES ${Geant4_INCLUDE_DIRS}) +set(CMAKE_REQUIRED_LIBRARIES ${Geant4_LIBRARIES}) +# Check if Geant4 is supports G4VTrackingManager +# Always available from v11.0, but experiments may backport it to earlier versions +# so we do a compile check. +check_cxx_source_compiles(" + #include \"G4VTrackingManager.hh\" + #include \"G4Track.hh\" + + struct testtm_ : G4VTrackingManager { + void HandOverOneTrack(G4Track*) override {} + }; + + int main() { + testtm_ t; + return 0; + }" AdePT_HAS_G4VTRACKINGMANAGER) # Find HepMC3, used by integration examples to load realistic events find_package(HepMC3 QUIET) @@ -322,36 +318,34 @@ if(HepMC3_FOUND) add_compile_definitions(HEPMC3_FOUND) endif() -# Find G4VG, optional as requires Geant4 -if(Geant4_FOUND) - # Default to use FetchContent'd G4VG for current ease of use and until CI - # includes an install. Also allows easy testing of upstream patches until - # fully stable across projects. - # NB: Though the option can be switched in a given build directory after the initial - # build, if you have an install of G4VG that could/would be picked up, you may get - # CMake-generate time warnings about safe runtime paths. Generally, you should - # pick one way to pickup G4VG and stick with that throughout the lifetime of - # the build directory. - # The eventual fix for this will be to move to require an external G4VG only - option(ADEPT_USE_BUILTIN_G4VG "Fetch and build G4VG as part of AdePT" ON) - if(ADEPT_USE_BUILTIN_G4VG) - # Fetch it locally - include(FetchContent) - FetchContent_Declare( - g4vg - GIT_REPOSITORY https://github.com/celeritas-project/g4vg - GIT_TAG f4308d392a502b7bd7468938f8d9a63198d3d866 # v1.0.3 - ) - # G4VG builds static by default, so change this to shared to match current - # way AdePT is built. - # could also configure for PIC mode static. - set(BUILD_SHARED_LIBS ON) - FetchContent_MakeAvailable(g4vg) - message(STATUS "Using FetchContent to build G4VG as part of AdePT") - else() - find_package(G4VG 1.0.3 REQUIRED) - message(STATUS "Found G4VG: ${G4VG_DIR}") - endif() +# Find G4VG +# Default to use FetchContent'd G4VG for current ease of use and until CI +# includes an install. Also allows easy testing of upstream patches until +# fully stable across projects. +# NB: Though the option can be switched in a given build directory after the initial +# build, if you have an install of G4VG that could/would be picked up, you may get +# CMake-generate time warnings about safe runtime paths. Generally, you should +# pick one way to pickup G4VG and stick with that throughout the lifetime of +# the build directory. +# The eventual fix for this will be to move to require an external G4VG only +option(ADEPT_USE_BUILTIN_G4VG "Fetch and build G4VG as part of AdePT" ON) +if(ADEPT_USE_BUILTIN_G4VG) + # Fetch it locally + include(FetchContent) + FetchContent_Declare( + g4vg + GIT_REPOSITORY https://github.com/celeritas-project/g4vg + GIT_TAG f4308d392a502b7bd7468938f8d9a63198d3d866 # v1.0.3 + ) + # G4VG builds static by default, so change this to shared to match current + # way AdePT is built. + # could also configure for PIC mode static. + set(BUILD_SHARED_LIBS ON) + FetchContent_MakeAvailable(g4vg) + message(STATUS "Using FetchContent to build G4VG as part of AdePT") +else() + find_package(G4VG 1.0.3 REQUIRED) + message(STATUS "Found G4VG: ${G4VG_DIR}") endif() # Find covfie to load external fields from file. diff --git a/examples/Example1/CMakeLists.txt b/examples/Example1/CMakeLists.txt index dffdba73..b6779b0b 100644 --- a/examples/Example1/CMakeLists.txt +++ b/examples/Example1/CMakeLists.txt @@ -8,17 +8,12 @@ if(NOT TARGET G4HepEm::g4HepEm) return() endif() -if(Geant4_FOUND) - if(NOT Geant4_gdml_FOUND) - message(STATUS "Disabling example1 (needs Geant4 with GDML support)") - return() - endif() - if(NOT AdePT_HAS_G4VTRACKINGMANAGER) - message(STATUS "Disabling example1 (needs G4VTrackingManger interface available starting with geant4-11-00)") - return() - endif() -else() - message(STATUS "Disabling example1 (needs Geant4)") +if(NOT Geant4_gdml_FOUND) + message(STATUS "Disabling example1 (needs Geant4 with GDML support)") + return() +endif() +if(NOT AdePT_HAS_G4VTRACKINGMANAGER) + message(STATUS "Disabling example1 (needs G4VTrackingManger interface available starting with geant4-11-00)") return() endif() diff --git a/test/regression/IntegrationTest/CMakeLists.txt b/test/regression/IntegrationTest/CMakeLists.txt index 7bb0966e..72f1791a 100644 --- a/test/regression/IntegrationTest/CMakeLists.txt +++ b/test/regression/IntegrationTest/CMakeLists.txt @@ -8,17 +8,12 @@ if(NOT TARGET G4HepEm::g4HepEm) return() endif() -if(Geant4_FOUND) - if(NOT Geant4_gdml_FOUND) - message(STATUS "Disabling integrationTest (needs Geant4 with GDML support)") - return() - endif() - if(NOT AdePT_HAS_G4VTRACKINGMANAGER) - message(STATUS "Disabling integrationTest (needs G4VTrackingManger interface available starting with geant4-11-00)") - return() - endif() -else() - message(STATUS "Disabling integrationTest (needs Geant4)") +if(NOT Geant4_gdml_FOUND) + message(STATUS "Disabling integrationTest (needs Geant4 with GDML support)") + return() +endif() +if(NOT AdePT_HAS_G4VTRACKINGMANAGER) + message(STATUS "Disabling integrationTest (needs G4VTrackingManger interface available starting with geant4-11-00)") return() endif() diff --git a/test/unit/testField/CMakeLists.txt b/test/unit/testField/CMakeLists.txt index 41ec46fe..e4f9dfa7 100644 --- a/test/unit/testField/CMakeLists.txt +++ b/test/unit/testField/CMakeLists.txt @@ -8,13 +8,8 @@ if(NOT TARGET G4HepEm::g4HepEm) return() endif() -if(Geant4_FOUND) - if(NOT Geant4_gdml_FOUND) - message(STATUS "Disabling testField (needs Geant4 with GDML support)") - return() - endif() -else() - message(STATUS "Disabling testField (needs Geant4)") +if(NOT Geant4_gdml_FOUND) + message(STATUS "Disabling testField (needs Geant4 with GDML support)") return() endif()