Literature
Africa |
CmakeVsMakeGeant4: cmake vs. make1. makeAdvantages
To use make, you need to source the geant4make.sh file, for example put the following in your .bash_profile: Then, just go to the source directory and run make. Variables can be set in you environment. For instance, if you run (or put in your bash_profile) it should compile using Root histograms (assuming your Geant4 code supports this). 2. cmakeAdvantages
To use make, you need to source the geant4.sh file, for example put the following in your .bash_profile: Then, if you want to compile, first tweak your CMakeLists.txt file (see below for example). Then make a separate, blank build directory, and run a command like the following: in my case this could be for example: To create an Xcode project: It can be useful to create an alias and put it in your .bash_profile file: then you only need to run The cmake command generates makefiles, so if you are not using an IDE, then you still need to run make in your build folder to create an executable, for example: Example of CmakeLists.txt fileThe following file generates the rdecay02 example, with added linking to visualisation libraries and the ROOT framework. It assumes a FindROOT.cmake file is present within a folder called cmake in the project source directory. The easiest way to get this is to copy from the Geant4 source: e.g. copy the contents geant4.9.5.p02/cmake/Modules into your cmake/ folder. cmake_minimum_required(VERSION 2.6 FATAL_ERROR) set(name rdecay02) project(${name}) option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON) if(WITH_GEANT4_UIVIS) find_package(Geant4 REQUIRED ui_all vis_all) else() find_package(Geant4 REQUIRED) endif() include(${Geant4_USE_FILE}) #---------------------------------------------------------------------------- # Find ROOT (optional package) # set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) find_package(ROOT QUIET) if(ROOT_FOUND) message(STATUS "ROOT found. --> compiling with ROOT enabled.") # Uncomment this line if suitable (some customization may be needed) add_definitions(-DG4ANALYSIS_USE_ROOT) else() message(STATUS "G4 ROOT NOT found. --> ROOT disabled.") endif() #---------------------------------------------------------------------------- # Locate sources and headers for this project # include_directories(${PROJECT_SOURCE_DIR}/include ${Geant4_INCLUDE_DIR} ${ROOT_INCLUDE_DIR}) file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc) # the following line makes the headers visible in IDEs, for example Xcode file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh) add_executable(${name} EXCLUDE_FROM_ALL ${name}.cc ${sources} ${headers}) target_link_libraries(${name} ${Geant4_LIBRARIES} ${ROOT_LIBRARIES}) |