]> Creatis software - clitk.git/blob - cmake/FindROOT.cmake
The lower and upper options can be tuned for all type of region growing algorithm
[clitk.git] / cmake / FindROOT.cmake
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.
9
10
11 message(STATUS "Looking for Root...")
12
13 set(ROOT_DEFINITIONS "")
14
15 set(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)
16
17 set(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)
18
19 find_program(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS)
20
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})
29   set( ROOTSYS ${test})
30 endif(${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
31
32
33 if(ROOT_CONFIG_EXECUTABLE)
34
35   set(ROOT_FOUND FALSE)
36
37   exec_program(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION)
38
39   message(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
40   message(STATUS "Looking for Root... - version ${ROOTVERSION} ")
41
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)
46
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}")
51
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}")
56
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)
60
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}")
64
65   if(found_vers LESS req_vers)
66     set(ROOT_FOUND FALSE)
67     set(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
68   else(found_vers LESS req_vers)
69     set(ROOT_FOUND TRUE)
70   endif(found_vers LESS req_vers)
71
72 endif(ROOT_CONFIG_EXECUTABLE)
73
74 #message("root found = "${ROOT_FOUND})
75
76 if(ROOT_FOUND)
77
78   # ask root-config for the library dir
79   # Set ROOT_LIBRARY_DIR
80
81   exec_program( ${ROOT_CONFIG_EXECUTABLE}
82     ARGS "--libdir"
83     OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )
84
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}")
91
92   # ask root-config for the binary dir
93   exec_program(${ROOT_CONFIG_EXECUTABLE}
94     ARGS "--bindir"
95     OUTPUT_VARIABLE root_bins )
96   set(ROOT_BINARY_DIR ${root_bins})
97
98   # ask root-config for the include dir
99   exec_program( ${ROOT_CONFIG_EXECUTABLE}
100     ARGS "--incdir"
101     OUTPUT_VARIABLE root_headers )
102   set(ROOT_INCLUDE_DIR ${root_headers})
103       # CACHE INTERNAL "")
104
105   # ask root-config for the library varaibles
106   exec_program( ${ROOT_CONFIG_EXECUTABLE}
107 #    ARGS "--noldflags --noauxlibs --libs"
108     ARGS "--glibs"
109     OUTPUT_VARIABLE root_flags )
110
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}")
114
115   set(ROOT_LIBRARIES ${root_flags})
116
117   # Make variables changeble to the advanced user
118   mark_as_advanced( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)
119
120   # Set ROOT_INCLUDES
121   set( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})
122
123   set(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})
124
125   #######################################
126   #
127   #       Check the executables of ROOT
128   #          ( rootcint )
129   #
130   #######################################
131
132   find_program(ROOT_CINT_EXECUTABLE
133     NAMES rootcint
134     PATHS ${ROOT_BINARY_DIR}
135     NO_DEFAULT_PATH
136     )
137
138 endif(ROOT_FOUND)
139
140
141 #message("icici")
142
143   ###########################################
144   #
145   #       Macros for building ROOT dictionary
146   #
147   ###########################################
148
149 macro(ROOT_GENERATE_DICTIONARY_OLD )
150
151    set(INFILES "")
152
153    foreach (_current_FILE ${ARGN})
154
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$")
168
169    endforeach (_current_FILE ${ARGN})
170
171 #  message("INFILES: ${INFILES}")
172 #  message("OutFILE: ${OUTFILE}")
173 #  message("LINKDEF_FILE: ${LINKDEF_FILE}")
174 #  message("INCLUDE_DIRS: ${INCLUDE_DIRS}")
175
176    string(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}")
177 #   message("BLA: ${bla}")
178    set(OUTFILES ${OUTFILE} ${bla})
179
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})
183
184 #   message("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}")
185
186 endmacro(ROOT_GENERATE_DICTIONARY_OLD)
187
188   ###########################################
189   #
190   #       Macros for building ROOT dictionary
191   #
192   ###########################################
193
194 macro(ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
195
196   set(INCLUDE_DIRS)
197
198   foreach (_current_FILE ${INCLUDE_DIRS_IN})
199     set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
200   endforeach (_current_FILE ${INCLUDE_DIRS_IN})
201
202
203 #  message("INFILES: ${INFILES}")
204 #  message("OutFILE: ${OUTFILE}")
205 #  message("LINKDEF_FILE: ${LINKDEF_FILE}")
206 #  message("INCLUDE_DIRS: ${INCLUDE_DIRS}")
207
208   string(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}")
209 #  message("BLA: ${bla}")
210   set(OUTFILES ${OUTFILE} ${bla})
211
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})
215
216 endmacro(ROOT_GENERATE_DICTIONARY)
217
218 #message("la")