Skip to content

Commit 8802628

Browse files
authored
Merge pull request #125 from drbenmorgan/support-older-g4tm
Check for G4VTrackingManager support via compilation
2 parents 3a14091 + 8bda7a5 commit 8802628

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ if(G4HepEm_GEANT4_BUILD)
144144
endif()
145145

146146
set(CMAKE_CXX_STANDARD ${Geant4_CXX_STANDARD}) # use value from Geant4Config.cmake
147+
148+
# Check if Geant4 is supports G4VTrackingManager
149+
# Always available from v11.0, but experiments may backport it to earlier versions
150+
# so we do a compile check.
151+
include(CheckCXXSourceCompiles)
152+
set(CMAKE_REQUIRED_LIBRARIES ${Geant4_LIBRARIES})
153+
check_cxx_source_compiles("
154+
#include \"G4VTrackingManager.hh\"
155+
class testtm_ : public G4VTrackingManager {
156+
public:
157+
void HandOverOneTrack(G4Track*) {}
158+
};
159+
int main() { testtm_ model; return 0; }" G4HepEm_HAS_G4VTRACKINGMANAGER)
147160
else()
148161
# Need workaround for G4VERSION_NUM G4HepEmRun...
149162
# ... done in that component for now.

G4HepEm/G4HepEm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set(G4HEPEM_Geant4_LIBRARIES
1414
Geant4::G4track
1515
)
1616

17-
if(Geant4_VERSION VERSION_GREATER_EQUAL 11.0)
17+
if(G4HepEm_HAS_G4VTRACKINGMANAGER)
1818
set(G4HEPEM_headers ${G4HEPEM_headers}
1919
include/G4EmTrackingManager.hh
2020
include/G4HepEmConfig.hh

apps/examples/TestEm3/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ set(sources
4444
src/SteppingVerbose.cc
4545
src/TrackingAction.cc
4646
)
47-
if(Geant4_VERSION VERSION_GREATER_EQUAL 11.0)
47+
if(G4HepEm_HAS_G4VTRACKINGMANAGER)
4848
set(sources ${sources}
4949
src/PhysListG4EmTracking.cc
5050
src/PhysListHepEmTracking.cc
@@ -55,4 +55,5 @@ endif()
5555
# Add the executable, and link it to the Geant4 libraries
5656
#
5757
add_executable(TestEm3 ${PROJECT_SOURCE_DIR}/TestEm3.cc ${sources})
58+
target_compile_definitions(TestEm3 PRIVATE $<$<BOOL:${G4HepEm_HAS_G4VTRACKINGMANAGER}>:G4HepEm_HAS_G4VTRACKINGMANAGER>)
5859
target_link_libraries(TestEm3 ${Geant4_LIBRARIES} ${G4HepEm_LIBRARIES})

apps/examples/TestEm3/src/PhysicsList.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ PhysicsList::PhysicsList() : G4VModularPhysicsList(),
8686
fMessenger = new PhysicsListMessenger(this);
8787
verboseLevel = 0;
8888

89-
#if G4VERSION_NUMBER >= 1100
90-
// make the `G4HepEmTrackingManager` the default whenever it's available (g4>=11.0)
89+
#if G4HepEm_HAS_G4VTRACKINGMANAGER
90+
// make the `G4HepEmTrackingManager` the default whenever it's available
9191
fEmName = G4String("HepEmTracking");
9292
fEmPhysicsList = new PhysListHepEmTracking(fEmName);
9393
#else

cmake/G4HepEmConfig.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# - Project properties
88
set_and_check(G4HepEm_INCLUDE_DIR "@PACKAGE_G4HEPEM_EXPORTED_INCLUDE_DIR@")
99

10+
# Record whether we support G4VTrackingManager.
11+
# Note that this implies the re-found Geant4 below is the exact same as we
12+
# were built with, especially if G4VTrackingManager has been backported to < 11.0
13+
set(G4HepEm_trackingmanager_FOUND @G4HepEm_HAS_G4VTRACKINGMANAGER@)
1014

1115
# - Project dependencies
1216
include(CMakeFindDependencyMacro)

0 commit comments

Comments
 (0)