1 # - Find ROOT instalation
2 # This module tries to find the ROOT installation on your system.
3 # It tries to find the root-config script which gives you all the needed information.
4 # If the system variable ROOTSYS is set this is straight forward.
5 # If not the module uses the pathes given in ROOT_CONFIG_SEARCHPATH.
6 # If you need an other path you should add this path to this varaible.
7 # The root-config script is then used to detect basically everything else.
8 # This module defines a number of key variables and macros.
11 MESSAGE("Looking for Root...")
12 MESSAGE(STATUS "Looking for Root...")
14 SET(ROOT_CONFIG_SEARCHPATH
15 ${SIMPATH}/tools/root/bin
19 SET(ROOT_DEFINITIONS "")
21 SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)
23 SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)
25 FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS
26 ${ROOT_CONFIG_SEARCHPATH}
27 NO_SYSTEM_ENVIRONMENT_PATH)
29 IF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
30 MESSAGE( FATAL_ERROR "ROOT not installed in the searchpath and ROOTSYS is not set. Please
31 set ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the
32 subdirectory cmake/modules.")
33 ELSE (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
34 MESSAGE("root-config found")
35 STRING(REGEX REPLACE "(^.*)/bin/root-config" "\\1" test ${ROOT_CONFIG_EXECUTABLE})
36 SET( ENV{ROOTSYS} ${test})
38 ENDIF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
41 IF (ROOT_CONFIG_EXECUTABLE)
45 EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION)
47 MESSAGE(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
48 MESSAGE(STATUS "Looking for Root... - version ${ROOTVERSION} ")
50 MESSAGE( "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
51 MESSAGE( "Looking for Root... - version ${ROOTVERSION} ")
53 # we need at least version 5.00/00
54 IF (NOT ROOT_MIN_VERSION)
55 SET(ROOT_MIN_VERSION "5.00/00")
56 ENDIF (NOT ROOT_MIN_VERSION)
58 # now parse the parts of the user given version string into variables
59 STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}")
60 STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}")
61 STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}")
63 # and now the version string given by qmake
64 STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}")
65 STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}")
66 STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}")
68 IF (found_root_major_vers LESS 5)
69 MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"")
70 ENDIF (found_root_major_vers LESS 5)
72 # compute an overall version number which can be compared at once
73 MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}")
74 MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}")
76 IF (found_vers LESS req_vers)
78 SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
79 ELSE (found_vers LESS req_vers)
81 ENDIF (found_vers LESS req_vers)
83 ENDIF (ROOT_CONFIG_EXECUTABLE)
85 #MESSAGE("root found = "${ROOT_FOUND})
89 # ask root-config for the library dir
90 # Set ROOT_LIBRARY_DIR
92 EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
94 OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )
96 IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
97 SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} )
98 ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
99 MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,")
100 MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.")
101 ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
103 # ask root-config for the binary dir
104 EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE}
106 OUTPUT_VARIABLE root_bins )
107 SET(ROOT_BINARY_DIR ${root_bins})
109 # ask root-config for the include dir
110 EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
112 OUTPUT_VARIABLE root_headers )
113 SET(ROOT_INCLUDE_DIR ${root_headers})
116 # ask root-config for the library varaibles
117 EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
118 # ARGS "--noldflags --noauxlibs --libs"
120 OUTPUT_VARIABLE root_flags )
122 # STRING(REGEX MATCHALL "([^ ])+" root_libs_all ${root_flags})
123 # STRING(REGEX MATCHALL "-L([^ ])+" root_library ${root_flags})
124 # REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}")
126 SET(ROOT_LIBRARIES ${root_flags})
128 # Make variables changeble to the advanced user
129 MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)
132 SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})
134 SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})
136 #######################################
138 # Check the executables of ROOT
141 #######################################
143 FIND_PROGRAM(ROOT_CINT_EXECUTABLE
145 PATHS ${ROOT_BINARY_DIR}
154 ###########################################
156 # Macros for building ROOT dictionary
158 ###########################################
160 MACRO (ROOT_GENERATE_DICTIONARY_OLD )
164 foreach (_current_FILE ${ARGN})
166 IF (${_current_FILE} MATCHES "^.*\\.h$")
167 IF (${_current_FILE} MATCHES "^.*Link.*$")
168 set(LINKDEF_FILE ${_current_FILE})
169 ELSE (${_current_FILE} MATCHES "^.*Link.*$")
170 set(INFILES ${INFILES} ${_current_FILE})
171 ENDIF (${_current_FILE} MATCHES "^.*Link.*$")
172 ELSE (${_current_FILE} MATCHES "^.*\\.h$")
173 IF (${_current_FILE} MATCHES "^.*\\.cxx$")
174 set(OUTFILE ${_current_FILE})
175 ELSE (${_current_FILE} MATCHES "^.*\\.cxx$")
176 set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
177 ENDIF (${_current_FILE} MATCHES "^.*\\.cxx$")
178 ENDIF (${_current_FILE} MATCHES "^.*\\.h$")
180 endforeach (_current_FILE ${ARGN})
182 # MESSAGE("INFILES: ${INFILES}")
183 # MESSAGE("OutFILE: ${OUTFILE}")
184 # MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
185 # MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
187 STRING(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}")
188 # MESSAGE("BLA: ${bla}")
189 SET (OUTFILES ${OUTFILE} ${bla})
191 ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
192 COMMAND ${ROOT_CINT_EXECUTABLE}
193 ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
195 # MESSAGE("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}")
197 ENDMACRO (ROOT_GENERATE_DICTIONARY_OLD)
199 ###########################################
201 # Macros for building ROOT dictionary
203 ###########################################
205 MACRO (ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
209 foreach (_current_FILE ${INCLUDE_DIRS_IN})
210 set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
211 endforeach (_current_FILE ${INCLUDE_DIRS_IN})
214 # MESSAGE("INFILES: ${INFILES}")
215 # MESSAGE("OutFILE: ${OUTFILE}")
216 # MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
217 # MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
219 STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}")
220 # MESSAGE("BLA: ${bla}")
221 SET (OUTFILES ${OUTFILE} ${bla})
223 ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
224 COMMAND ${ROOT_CINT_EXECUTABLE}
225 ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
227 ENDMACRO (ROOT_GENERATE_DICTIONARY)