
The goal of this post is to get you to the same point as quickly as possible. I spent a long time editing CMake scripts without really understanding the language, as the documentation is quite scattered, but eventually, things clicked. CMake scripts have a lot of flexibility.Įvery time you integrate an external library, and often when adding support for another platform, you’ll need to edit the script. This script defines targets, but it can also do a lot of other things, such as finding third-party libraries or generating C++ header files. See also the An Introduction to Modern CMake Guide by Henry Schreiner for more information on building your ROOT project with modern CMake.As explained in my previous post, every CMake-based project must contain a script named CMakeLists.txt. add_executable (Main MainEvent.cxx ) target_link_libraries (Main Event ) add_library (Event SHARED Event.cxx ) target_link_libraries (Event PUBLIC ROOT::RIO ROOT::Net ) # Create the main program using the library. # Note: To ensure compatibility with Cling, targets *must* be compiled using the # same C++ standard as ROOT was compiled with. find_package (ROOT REQUIRED COMPONENTS RIO Net ) include_directories ( $) ensures that properties such as required # include directories and C++ standard are propagated to our libraries or executables. cmake_minimum_required (VERSION 3.0 FATAL_ERROR ) project (event ) # Locate the ROOT package and define a number of useful targets and variables. # Otherwise, you must tell the build system where to look for ROOT, # for example by passing `-DROOT_DIR="/path/to/root/installation` at CMake configuration time. # Sourcing `thisroot.sh` already sets the required environment variables. # If ROOT is not installed in a default system location you need to tell CMake where to find it. # CMakeLists.txt for the "event" package. The following is an example of a project that creates a library and an executable file.

However, prefer passing libraries as CMake targets whenever possible (see theįull example below). (the name of the component is the name of the library without any library prefix or suffix). For example, to add the RooStats library, you can specify it as an extra component You can force additional ROOT libraries in the ROOT_LIBRARIES variable using theĬommand. Adding additional libraries to ROOT_LIBRARIES The C++ standard used for ROOT appears for example among the flags listed by To ensure compatibility between ROOT’s C++ interpreter, Cling, and compiled code, yourĪpplication must be compiled with the same C++ standard with which ROOT was compiled. One CMake target per ROOT library is also available, e.g. Path to a CMake module, which makes use of the previous variables and loads modules with useful macros or functions such as ROOT_GENERATE_DICTIONARY. The actual list of libraries is composed using the COMPONENTS listed in the find_package(…) command.įull path for each of the ROOT libraries listed in COMPONENTS.įull path for each ROOT executable (rootcling, root, hadd, etc.). Include directories for the ROOT installation. The main interface is the CMake command find_package(…).Ĭalling find_package(ROOT) makes the following variables available: Variable You can integrate ROOT into a CMake based project. Adding additional libraries to ROOT_LIBRARIES.
