Chapter 4.  CMake and Build Tools For Geant4 Developers

Geant4 developers can make use of several powerful features of CMake to help with their work. The key concept and working practice is the separation of the source directory, which is where the sources you edit reside, and the build directory, where the buildscripts and compiled products reside.

4.1.  Developing Geant4 using Make, Xcode, Visual Studio and Eclipse

CMake is a buildsystem that generates scripts for buildtools including Make, Xcode, Visual Studio and Eclipse, among others. The resulting scripts can then be used within the build tool to perform the actual build, install and packaging.

Whilst we only support Make and Visual Studio for Unix and Windows user builds respectively, Geant4 developers are welcome, and encouraged, to use their build tool of choice. Buildscripts for Geant4 using these other buildtools can be generated by choosing the CMake generator when running CMake for the first time.

On the command line, one can select the tool using the -G argument of CMake. For example, to generate an Xcode project for Geant4 using the example from Section 2.1:

    $ mkdir -p /path/to/geant4.9.5-build-xcode
    $ cd /path/to/geant4.9.5-build-xcode
    $ cmake -G Xcode -DCMAKE_INSTALL_PREFIX=/path/to/geant4.9.5-install /path/to/geant4.9.5
  

The resulting /path/to/geant4.9.5-build-xcode/Geant4.xcodeproj project may be opened with Xcode.

In the CMake GUI, the generator will be asked for the first time you click on Configure button (see Section 2.2), where it can be selected from a drop down list.

Note that in all cases, you can only have one buildtool configuration in a given build directory (e.g. you cannot have Unix Makefiles and an Xcode project).

Support for these buildtools is still preliminary, so feedback is welcome, whether bug reports, guides or general comments.