I’ve created the IDE projects from the Root example “event” with the original CMakeLists.txt (see below).
I succeeded to build and run the example. But the Preprocessor is not able to resolve the Root variables.
Thanks a lot for any help.
Massimo Trifoglio
_ROOT Version: 6.16/00 installed from binaries
_Platform: CentoS 7.6
_Compiler: gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
_Eclipse IDE for C/C++ Developers
Version: Oxygen.1a Release (4.7.1a) Build id: 20171005-1200
CMakelists.txt
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)