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(STATUS "Looking for Root...")
13 SET(ROOT_CONFIG_SEARCHPATH
14 ${SIMPATH}/tools/root/bin
18 SET(ROOT_DEFINITIONS "")
20 SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)
22 SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)
24 FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS
25 ${ROOT_CONFIG_SEARCHPATH}
26 NO_SYSTEM_ENVIRONMENT_PATH)
28 IF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
29 MESSAGE( FATAL_ERROR "ROOT not installed in the searchpath and ROOTSYS is not set. Please
30 set ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the
31 subdirectory cmake/modules.")
32 ELSE (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
33 STRING(REGEX REPLACE "(^.*)/bin/root-config" "\\1" test ${ROOT_CONFIG_EXECUTABLE})
34 SET( ENV{ROOTSYS} ${test})
36 ENDIF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
39 IF (ROOT_CONFIG_EXECUTABLE)
43 EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION)
45 MESSAGE(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
46 MESSAGE(STATUS "Looking for Root... - version ${ROOTVERSION} ")
48 # we need at least version 5.00/00
49 IF (NOT ROOT_MIN_VERSION)
50 SET(ROOT_MIN_VERSION "5.00/00")
51 ENDIF (NOT ROOT_MIN_VERSION)
53 # now parse the parts of the user given version string into variables
54 STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}")
55 STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}")
56 STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}")
58 # and now the version string given by qmake
59 STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}")
60 STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}")
61 STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}")
63 IF (found_root_major_vers LESS 5)
64 MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"")
65 ENDIF (found_root_major_vers LESS 5)
67 # compute an overall version number which can be compared at once
68 MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}")
69 MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}")
71 IF (found_vers LESS req_vers)
73 SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
74 ELSE (found_vers LESS req_vers)
76 ENDIF (found_vers LESS req_vers)
78 ENDIF (ROOT_CONFIG_EXECUTABLE)
83 # ask root-config for the library dir
84 # Set ROOT_LIBRARY_DIR
86 EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
88 OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )
90 IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
91 SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} )
92 ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
93 MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,")
94 MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.")
95 ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
97 # ask root-config for the binary dir
98 EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE}
100 OUTPUT_VARIABLE root_bins )
101 SET(ROOT_BINARY_DIR ${root_bins})
103 # ask root-config for the include dir
104 EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
106 OUTPUT_VARIABLE root_headers )
107 SET(ROOT_INCLUDE_DIR ${root_headers})
110 # ask root-config for the library varaibles
111 EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
112 # ARGS "--noldflags --noauxlibs --libs"
114 OUTPUT_VARIABLE root_flags )
116 # STRING(REGEX MATCHALL "([^ ])+" root_libs_all ${root_flags})
117 # STRING(REGEX MATCHALL "-L([^ ])+" root_library ${root_flags})
118 # REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}")
120 SET(ROOT_LIBRARIES ${root_flags})
122 # Make variables changeble to the advanced user
123 MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)
126 SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})
128 SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})
130 #######################################
132 # Check the executables of ROOT
135 #######################################
137 FIND_PROGRAM(ROOT_CINT_EXECUTABLE
139 PATHS ${ROOT_BINARY_DIR}
147 ###########################################
149 # Macros for building ROOT dictionary
151 ###########################################
153 MACRO (ROOT_GENERATE_DICTIONARY_OLD )
157 foreach (_current_FILE ${ARGN})
159 IF (${_current_FILE} MATCHES "^.*\\.h$")
160 IF (${_current_FILE} MATCHES "^.*Link.*$")
161 set(LINKDEF_FILE ${_current_FILE})
162 ELSE (${_current_FILE} MATCHES "^.*Link.*$")
163 set(INFILES ${INFILES} ${_current_FILE})
164 ENDIF (${_current_FILE} MATCHES "^.*Link.*$")
165 ELSE (${_current_FILE} MATCHES "^.*\\.h$")
166 IF (${_current_FILE} MATCHES "^.*\\.cxx$")
167 set(OUTFILE ${_current_FILE})
168 ELSE (${_current_FILE} MATCHES "^.*\\.cxx$")
169 set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
170 ENDIF (${_current_FILE} MATCHES "^.*\\.cxx$")
171 ENDIF (${_current_FILE} MATCHES "^.*\\.h$")
173 endforeach (_current_FILE ${ARGN})
175 # MESSAGE("INFILES: ${INFILES}")
176 # MESSAGE("OutFILE: ${OUTFILE}")
177 # MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
178 # MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
180 STRING(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}")
181 # MESSAGE("BLA: ${bla}")
182 SET (OUTFILES ${OUTFILE} ${bla})
184 ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
185 COMMAND ${ROOT_CINT_EXECUTABLE}
186 ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
188 # MESSAGE("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}")
190 ENDMACRO (ROOT_GENERATE_DICTIONARY_OLD)
192 ###########################################
194 # Macros for building ROOT dictionary
196 ###########################################
198 MACRO (ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
202 foreach (_current_FILE ${INCLUDE_DIRS_IN})
203 set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
204 endforeach (_current_FILE ${INCLUDE_DIRS_IN})
207 # MESSAGE("INFILES: ${INFILES}")
208 # MESSAGE("OutFILE: ${OUTFILE}")
209 # MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
210 # MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
212 STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}")
213 # MESSAGE("BLA: ${bla}")
214 SET (OUTFILES ${OUTFILE} ${bla})
216 ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
217 COMMAND ${ROOT_CINT_EXECUTABLE}
218 ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
220 ENDMACRO (ROOT_GENERATE_DICTIONARY)