Geant4 Cross Reference |
1 #---------------------------------------------------------------------------- 2 # Setup the project 3 cmake_minimum_required(VERSION 3.16...3.27) 4 project(HepMCEx02) 5 6 #---------------------------------------------------------------------------- 7 # Find Geant4 package, activating all available UI and Vis drivers by default 8 # You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui 9 # to build a batch mode only executable 10 # 11 option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON) 12 if(WITH_GEANT4_UIVIS) 13 find_package(Geant4 REQUIRED ui_all vis_all) 14 else() 15 find_package(Geant4 REQUIRED) 16 endif() 17 18 #---------------------------------------------------------------------------- 19 # Setup Geant4 include directories and compile definitions 20 # 21 include(${Geant4_USE_FILE}) 22 23 #---------------------------------------------------------------------------- 24 # Find HepMC (required package) 25 # 26 find_package(HepMC REQUIRED) 27 28 #---------------------------------------------------------------------------- 29 # Find Pythia6 (optional package) 30 # 31 find_package(Pythia6 QUIET) 32 if(Pythia6_FOUND) 33 message(STATUS "G4 Examples: Pythia6 found. --> HepMCEx02 example with Pythia6 enabled.") 34 endif() 35 36 #---------------------------------------------------------------------------- 37 # Locate sources and headers for this project 38 # 39 include_directories(${PROJECT_SOURCE_DIR}/include 40 ${Geant4_INCLUDE_DIR} 41 ${HEPMC_INCLUDE_DIR}) 42 file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc) 43 file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh) 44 45 #---------------------------------------------------------------------------- 46 # Add the executable, and link it to the Geant4 libraries 47 # 48 add_executable(HepMCEx02 HepMCEx02.cc ${sources} ${headers}) 49 target_compile_definitions(example_MyPythia PRIVATE $<$<BOOL:${Pythia6_FOUND}>:G4LIB_USE_PYTHIA>) 50 #target_link_libraries(HepMCEx02 ${Geant4_LIBRARIES} 51 # ${HEPMC_LIBRARIES} ${HEPMC_FIO_LIBRARIES} 52 # $<$<BOOL:${Pythia6_FOUND}>:Pythia6::Pythia6> 53 # gfortran) 54 target_link_libraries(HepMCEx02 ${Geant4_LIBRARIES} 55 ${HEPMC_LIBRARIES} ${HEPMC_FIO_LIBRARIES} 56 $<$<BOOL:${Pythia6_FOUND}>:Pythia6::Pythia6>) 57 58 # if pythia is compiled with g77, link with -lg2c instead. 59 #target_link_libraries(HepMCEx02 ${Geant4_LIBRARIES} 60 # ${HEPMC_LIBRARIES} ${HEPMC_FIO_LIBRARIES} 61 # $<$<BOOL:${Pythia6_FOUND}>:Pythia6::Pythia6> 62 # g2c) 63 64 #---------------------------------------------------------------------------- 65 # Copy all scripts to the build directory, i.e. the directory in which we 66 # build HepMCEx02. This is so that we can run the executable directly because it 67 # relies on these scripts being in the current working directory. 68 # 69 set(HepMCEx02_SCRIPTS 70 hepmc_ascii.in hepmc_ascii.out hepmc_pygen.in hepmc_pygen.out pyh4mu.mac pyset.mac vis.mac 71 data/example_MyPythia.dat 72 ) 73 74 foreach(_script ${HepMCEx02_SCRIPTS}) 75 configure_file( 76 ${PROJECT_SOURCE_DIR}/${_script} 77 ${PROJECT_BINARY_DIR}/${_script} 78 COPYONLY 79 ) 80 endforeach() 81 82 #---------------------------------------------------------------------------- 83 # Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX 84 # 85 install(TARGETS HepMCEx02 DESTINATION bin) 86