Integrating ROOT Using CMake

I intend to use the curve fitting algorithms of the ROOT library, as they proved useful and reliable before. However, so far I have only used the ROOT macro interpreter and never compiled a full program myself.

I have a standing C++ program into which I would like to import the ROOT library. I found this article as a starting point. I downloaded the tar-ball, untared it, set up the environment variables using /path/to/root/bin/ (using bash) and ran cmake in the provided folder.

The contents of the CMakeLists.txt file is:

# CMakeLists.txt for event package. It creates a library with dictionary and a main program
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

# You need to tell CMake where to find the ROOT installation. This can be done in a number of ways:
#   - ROOT built with classic configure/make use the provided $ROOTSYS/etc/cmake/FindROOT.cmake
#   - ROOT built with CMake. Add in CMAKE_PREFIX_PATH the installation prefix for ROOT

#---Locate the ROOT package and defines a number of variables (e.g. ROOT_INCLUDE_DIRS)
find_package(ROOT REQUIRED COMPONENTS MathCore RIO Hist Tree Net)

#---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)

include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS})


#---Create a shared library with geneated dictionary
add_library(Event SHARED Event.cxx G__Event.cxx)
target_link_libraries(Event ${ROOT_LIBRARIES})

#---Create  a main program using the library
add_executable(Main MainEvent.cxx)
target_link_libraries(Main Event)

I get the following error when executing cmake:

[code]-- The C compiler identification is GNU 4.9.2
– The CXX compiler identification is GNU 4.9.2
– Check for working C compiler: /usr/bin/cc
– Check for working C compiler: /usr/bin/cc – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working CXX compiler: /usr/bin/c++
– Check for working CXX compiler: /usr/bin/c++ – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:11 (find_package):
By not providing “FindROOT.cmake” in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by “ROOT”, but
CMake did not find one.

Could not find a package configuration file provided by “ROOT” with any of
the following names:

Add the installation prefix of “ROOT” to CMAKE_PREFIX_PATH or set
“ROOT_DIR” to a directory containing one of the above files. If “ROOT”
provides a separate development package or SDK, be sure it has been

I also tried to add the file


to the working directory and add


to the CMakeLists.txt file. This results into this error:

CMake Error at FindROOT.cmake:52 (list):
  list sub-command REMOVE_DUPLICATES requires list to be present.
Call Stack (most recent call first):
  CMakeLists.txt:13 (find_package)

CMake Error at /usr/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:136 (message):
Call Stack (most recent call first):
  /usr/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:343 (_FPHSA_FAILURE_MESSAGE)
  FindROOT.cmake:74 (find_package_handle_standard_args)
  CMakeLists.txt:13 (find_package)

I’d be really helpful if someone could help me getting at least the example code working. I think, I will be able to work it into the cmake setup of my own program afterwards.

Philipp Verpoort

Hi Philipp,

In your last attempt did you have ROOTSYS still set? If yes, could you try setting CMAKE_PREFIX_PATH to the location of ROOT?

The build of ROOT you use - was it done with configure/make or cmake? Does it contain ${ROOTSYS}/cmake/ROOTConfig.cmake? If yes, please set CMAKE_PREFIX_PATH to point to this directory. Then you don’t need FindROOT.cmake


Dear Benedikt,

thank you so much for your help.

Yes, I had ROOTSYS set at all times.

I think, in the case of ‘yes’, the following command, which is already included, should do the job, or am I wrong?

Er… good point. I was using configure/make.

Now, I’m using cmake and I produced a builddir and included this one into CMAKE_PREFIX_PATH:

The output looks better but there is still something missing. Do you know what is wrong this time?

philipp@pc:/path/to/event/build$ cmake ..
CMake Error at /path/to/root/builddir/ROOTConfig.cmake:141 (message):
  ROOT component MathCore not found
Call Stack (most recent call first):
  CMakeLists.txt:13 (find_package)

-- Configuring incomplete, errors occurred!

Thanks again,

I fixed it. It seems the cmake procedure for ROOT didn’t run through completely the first time. Thanks for the help!

Just for completeness this the HowTo for Integrating ROOT with CMake

Here is the event.tar.gz file. Download it.
Go to build folder.
event$cd build
/event/build/$cmake …/ If you get error add this line to the CMakeList.txt file at Ln-8. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} $ENV{ROOTSYS}/etc/cmake)

then make

$ cmake …/
– Found ROOT: /home/rama/root-6.12.06/bin/root-config
– Configuring done
– Generating done
– Build files have been written to: /home/rama/Documents/cpp/ROOT_MACRO/CMake/event/build

[ 16%] Generating G__Event.cxx
Scanning dependencies of target Event
[ 33%] Building CXX object CMakeFiles/Event.dir/Event.cxx.o
[ 50%] Building CXX object CMakeFiles/Event.dir/G__Event.cxx.o
[ 66%] Linking CXX shared library
[ 66%] Built target Event
Scanning dependencies of target Main
[ 83%] Building CXX object CMakeFiles/Main.dir/MainEvent.cxx.o
[100%] Linking CXX executable Main
[100%] Built target Main

Run the executable ./Main