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_DEFINITIONS "")
15 set(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)
17 set(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)
19 find_program(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS)
21 if(${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
22 message( FATAL_ERROR "ROOT not installed in the searchpath and ROOTSYS is not set. Please
23 set ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the
24 subdirectory cmake/modules.")
25 else(${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
26 message(STATUS "root-config found")
27 string(REGEX REPLACE "(^.*)/bin/root-config" "\\1" test ${ROOT_CONFIG_EXECUTABLE})
28 set( ENV{ROOTSYS} ${test})
30 endif(${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
33 if(ROOT_CONFIG_EXECUTABLE)
37 exec_program(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION)
39 message(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
40 message(STATUS "Looking for Root... - version ${ROOTVERSION} ")
42 # we need at least version 5.00/00
43 if(NOT ROOT_MIN_VERSION)
44 set(ROOT_MIN_VERSION "5.00/00")
45 endif(NOT ROOT_MIN_VERSION)
47 # now parse the parts of the user given version string into variables
48 string(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}")
49 string(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}")
50 string(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}")
52 # and now the version string given by qmake
53 string(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}")
54 string(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}")
55 string(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}")
57 if(found_root_major_vers LESS 5)
58 message( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"")
59 endif(found_root_major_vers LESS 5)
61 # compute an overall version number which can be compared at once
62 math(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}")
63 math(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}")
65 if(found_vers LESS req_vers)
67 set(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
68 else(found_vers LESS req_vers)
70 endif(found_vers LESS req_vers)
72 endif(ROOT_CONFIG_EXECUTABLE)
74 #message("root found = "${ROOT_FOUND})
78 # ask root-config for the library dir
79 # Set ROOT_LIBRARY_DIR
81 exec_program( ${ROOT_CONFIG_EXECUTABLE}
83 OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )
85 if(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
86 set(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} )
87 else(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
88 message("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,")
89 message("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.")
90 endif(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
92 # ask root-config for the binary dir
93 exec_program(${ROOT_CONFIG_EXECUTABLE}
95 OUTPUT_VARIABLE root_bins )
96 set(ROOT_BINARY_DIR ${root_bins})
98 # ask root-config for the include dir
99 exec_program( ${ROOT_CONFIG_EXECUTABLE}
101 OUTPUT_VARIABLE root_headers )
102 set(ROOT_INCLUDE_DIR ${root_headers})
105 # ask root-config for the library varaibles
106 exec_program( ${ROOT_CONFIG_EXECUTABLE}
107 # ARGS "--noldflags --noauxlibs --libs"
109 OUTPUT_VARIABLE root_flags )
111 # string(REGEX MATCHALL "([^ ])+" root_libs_all ${root_flags})
112 # string(REGEX MATCHALL "-L([^ ])+" root_library ${root_flags})
113 # REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}")
115 set(ROOT_LIBRARIES ${root_flags})
117 # Make variables changeble to the advanced user
118 mark_as_advanced( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)
121 set( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})
123 set(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})
125 #######################################
127 # Check the executables of ROOT
130 #######################################
132 find_program(ROOT_CINT_EXECUTABLE
134 PATHS ${ROOT_BINARY_DIR}
143 ###########################################
145 # Macros for building ROOT dictionary
147 ###########################################
149 macro(ROOT_GENERATE_DICTIONARY_OLD )
153 foreach (_current_FILE ${ARGN})
155 if(${_current_FILE} MATCHES "^.*\\.h$")
156 if(${_current_FILE} MATCHES "^.*Link.*$")
157 set(LINKDEF_FILE ${_current_FILE})
158 else(${_current_FILE} MATCHES "^.*Link.*$")
159 set(INFILES ${INFILES} ${_current_FILE})
160 endif(${_current_FILE} MATCHES "^.*Link.*$")
161 else(${_current_FILE} MATCHES "^.*\\.h$")
162 if(${_current_FILE} MATCHES "^.*\\.cxx$")
163 set(OUTFILE ${_current_FILE})
164 else(${_current_FILE} MATCHES "^.*\\.cxx$")
165 set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
166 endif(${_current_FILE} MATCHES "^.*\\.cxx$")
167 endif(${_current_FILE} MATCHES "^.*\\.h$")
169 endforeach (_current_FILE ${ARGN})
171 # message("INFILES: ${INFILES}")
172 # message("OutFILE: ${OUTFILE}")
173 # message("LINKDEF_FILE: ${LINKDEF_FILE}")
174 # message("INCLUDE_DIRS: ${INCLUDE_DIRS}")
176 string(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}")
177 # message("BLA: ${bla}")
178 set(OUTFILES ${OUTFILE} ${bla})
180 add_custom_command(OUTPUT ${OUTFILES}
181 COMMAND ${ROOT_CINT_EXECUTABLE}
182 ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
184 # message("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}")
186 endmacro(ROOT_GENERATE_DICTIONARY_OLD)
188 ###########################################
190 # Macros for building ROOT dictionary
192 ###########################################
194 macro(ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
198 foreach (_current_FILE ${INCLUDE_DIRS_IN})
199 set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
200 endforeach (_current_FILE ${INCLUDE_DIRS_IN})
203 # message("INFILES: ${INFILES}")
204 # message("OutFILE: ${OUTFILE}")
205 # message("LINKDEF_FILE: ${LINKDEF_FILE}")
206 # message("INCLUDE_DIRS: ${INCLUDE_DIRS}")
208 string(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}")
209 # message("BLA: ${bla}")
210 set(OUTFILES ${OUTFILE} ${bla})
212 add_custom_command(OUTPUT ${OUTFILES}
213 COMMAND ${ROOT_CINT_EXECUTABLE}
214 ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
216 endmacro(ROOT_GENERATE_DICTIONARY)