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/thisroot.sh
(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)
project(event)
# 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
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
#---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(${ROOT_USE_FILE})
include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS})
add_definitions(${ROOT_CXX_FLAGS})
ROOT_GENERATE_DICTIONARY(G__Event Event.h LINKDEF EventLinkDef.h)
#---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:
ROOTConfig.cmake
root-config.cmake
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
installed.
[/code]
I also tried to add the file
/path/to/root/etc/cmake/FindROOT.cmake
to the working directory and add
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
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):
Could NOT find ROOT (missing: ROOT_CONFIG_EXECUTABLE ROOTSYS ROOT_VERSION
ROOT_INCLUDE_DIR ROOT_LIBRARIES ROOT_LIBRARY_DIR)
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.
Best,
Philipp Verpoort