1 # - Find ROOT instalation # This module tries to find the ROOT installation on your system.
2 # It tries to find the root-config script which gives you all the needed information.
3 # If the system variable ROOTSYS is set this is straight forward.
4 # If not the module uses the pathes given in ROOT_CONFIG_SEARCHPATH.
5 # If you need an other path you should add this path to this varaible.
6 # The root-config script is then used to detect basically everything else.
7 # This module defines a number of key variables and macros.
10 MESSAGE(STATUS "Looking for Root...")
12 SET(ROOT_CONFIG_SEARCHPATH
16 SET(ROOT_DEFINITIONS "")
18 SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)
20 SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)
22 FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS
23 ${ROOT_CONFIG_SEARCHPATH}
24 NO_SYSTEM_ENVIRONMENT_PATH)
26 FIND_FILE( RVERSION_H NAMES RVersion.h PATHS $ENV{ROOTSYS}/include )
29 FILE( READ ${RVERSION_H} RVERS_CONTENT )
30 STRING( REGEX MATCH "#define ROOT_RELEASE \"[^\n]+\"\n" _line "${RVERS_CONTENT}" )
31 STRING( REGEX REPLACE "#define ROOT_RELEASE \"([^\n]+)\"\n" "\\1" _match "${_line}")
33 SET( ROOTVERSION ${_match})
42 MESSAGE(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
43 MESSAGE(STATUS "Looking for Root... - version ${ROOTVERSION} ")
45 # we need at least version 5.00/00
46 IF (NOT ROOT_MIN_VERSION)
47 SET(ROOT_MIN_VERSION "5.00/00")
48 ENDIF (NOT ROOT_MIN_VERSION)
50 # now parse the parts of the user given version string into variables
51 STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}")
52 STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}")
53 STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}")
55 # and now the version string given by qmake
56 STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}")
57 STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}")
58 STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}")
60 IF (found_root_major_vers LESS 5)
61 MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"")
62 ENDIF (found_root_major_vers LESS 5)
64 # compute an overall version number which can be compared at once
65 MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}")
66 MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}")
68 IF (found_vers LESS req_vers)
70 SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
71 ELSE (found_vers LESS req_vers)
73 ENDIF (found_vers LESS req_vers)
80 # ask root-config for the library dir
81 # Set ROOT_LIBRARY_DIR
83 SET( ROOT_LIBRARY_DIR $ENV{ROOTSYS}/lib )
84 SET( ROOT_INCLUDE_DIR $ENV{ROOTSYS}/include )
85 SET( ROOT_BINARY_DIR $ENV{ROOTSYS}/bin )
89 EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
91 OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )
93 IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
94 SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} )
95 ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
96 MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,")
97 MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.")
98 ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
100 # ask root-config for the binary dir
101 EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE}
103 OUTPUT_VARIABLE root_bins )
104 SET(ROOT_BINARY_DIR ${root_bins})
106 # ask root-config for the include dir
107 EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
109 OUTPUT_VARIABLE root_headers )
110 SET(ROOT_INCLUDE_DIR ${root_headers})
113 # ask root-config for the library varaibles
114 EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
115 ARGS "--noldflags --noauxlibs --libs"
116 OUTPUT_VARIABLE root_flags )
118 # STRING(REGEX MATCHALL "([^ ])+" root_libs_all ${root_flags})
119 # STRING(REGEX MATCHALL "-L([^ ])+" root_library ${root_flags})
120 # REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}")
122 SET(ROOT_LIBRARIES ${root_flags})
126 # Make variables changeble to the advanced user
127 MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)
130 SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})
132 SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})
134 #######################################
136 # Check the executables of ROOT
139 #######################################
141 FIND_PROGRAM(ROOT_CINT_EXECUTABLE
143 PATHS ${ROOT_BINARY_DIR}
151 ###########################################
153 # Macros for building ROOT dictionary
155 ###########################################
157 MACRO (ROOT_GENERATE_DICTIONARY_OLD )
161 foreach (_current_FILE ${ARGN})
163 IF (${_current_FILE} MATCHES "^.*\\.h$")
164 IF (${_current_FILE} MATCHES "^.*Link.*$")
165 set(LINKDEF_FILE ${_current_FILE})
166 ELSE (${_current_FILE} MATCHES "^.*Link.*$")
167 set(INFILES ${INFILES} ${_current_FILE})
168 ENDIF (${_current_FILE} MATCHES "^.*Link.*$")
169 ELSE (${_current_FILE} MATCHES "^.*\\.h$")
170 IF (${_current_FILE} MATCHES "^.*\\.cxx$")
171 set(OUTFILE ${_current_FILE})
172 ELSE (${_current_FILE} MATCHES "^.*\\.cxx$")
173 set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
174 ENDIF (${_current_FILE} MATCHES "^.*\\.cxx$")
175 ENDIF (${_current_FILE} MATCHES "^.*\\.h$")
177 endforeach (_current_FILE ${ARGN})
179 # MESSAGE("INFILES: ${INFILES}")
180 # MESSAGE("OutFILE: ${OUTFILE}")
181 # MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
182 # MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
184 STRING(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}")
185 # MESSAGE("BLA: ${bla}")
186 SET (OUTFILES ${OUTFILE} ${bla})
188 ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
189 COMMAND ${ROOT_CINT_EXECUTABLE}
190 ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
192 # MESSAGE("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}")
194 ENDMACRO (ROOT_GENERATE_DICTIONARY_OLD)
196 ###########################################
198 # Macros for building ROOT dictionary
200 ###########################################
202 MACRO (ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
206 foreach (_current_FILE ${INCLUDE_DIRS_IN})
207 set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
208 endforeach (_current_FILE ${INCLUDE_DIRS_IN})
211 # MESSAGE("INFILES: ${INFILES}")
212 # MESSAGE("OutFILE: ${OUTFILE}")
213 # MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
214 # MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
216 STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}")
217 # MESSAGE("BLA: ${bla}")
218 SET (OUTFILES ${OUTFILE} ${bla})
220 ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
221 COMMAND ${ROOT_CINT_EXECUTABLE}
222 ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
224 ENDMACRO (ROOT_GENERATE_DICTIONARY)