Geant4 Quickstart Guide
Step 4: Compile the Application
The easiest way to compile a Geant4 application is to use CMake. If you have not already done so, download
and install CMake from www.cmake.org.
CMake is designed to help you set up the build-environment for your software project independently of the plattform
and compiler you are using (CMake is short for Cross-Plattform Make). On Linux, this means it will generate Make-file
for you, which you can use to compile your project. On Windows machines, this means CMake can create a Visual Studio
Project file for you, with all library and include paths configured for your project.
In order to tell CMake what to do, you must provide a CMake script, which specifies your source and include paths and
any libraries you want to link against.
Assuming that the main file of your project is called "basicApplication.cc", the script below will allow CMake to
setup your Geant4 project. Just copy this script into a file with the name "CMakeLists.txt" and put this file into
the same directory as your source code file.
#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(basicProject)
find_package(Geant4 REQUIRED ui_all vis_all)
find_package(Geant4 REQUIRED)
include(${Geant4_USE_FILE})
#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(basicApplication basicApplication.cc ${sources} ${headers})
target_link_libraries(basicApplication ${Geant4_LIBRARIES})
add_custom_target(basicProject DEPENDS basicApplication)
#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
install(TARGETS basicApplication DESTINATION bin)
The below description of how to use CMake is quite short, since it is assumed you are already familiar with CMake from
the Installation Guide.
Now run CMake. If you are using a Windows system, run the GUI. Under "Where is the source code", browse to the directory containing your source code. Under "Where to build the binaries", select the directory in which you want your Visual Studio project files to be created. Now hit "Configure". CMake will give you a couple of options, one of which is "CMAKE_INSTALL_PREFIX". This is the directory in which Visual Studio will attempt to build the executable.
You may have to change this directory, since often Visual Studio will not have writing privileges to the default
directory.
After configuring, hit "generate". Now CMake will build the Visual Studio project in the path you specified under
"where is the source code". You can open this project by double-clicking the *.prj file in that directory. You are
now ready to compile your application using Visal Studio. In the Solution Explorer, right click "Install" and
select "Build".
Congratulations! You have just compiled your first Geant4 Application.
page 1 / page 2 / page 3 / page 4
|