CMake: Find ApMon used for the Shuttle
[u/mrichter/AliRoot.git] / cmake / FindROOT.cmake
CommitLineData
fffaf6a5 1# **************************************************************************
2# * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
3# * *
4# * Author: The ALICE Off-line Project. *
5# * Contributors are mentioned in the code where appropriate. *
6# * *
7# * Permission to use, copy, modify and distribute this software and its *
8# * documentation strictly for non-commercial purposes is hereby granted *
9# * without fee, provided that the above copyright notice appears in all *
10# * copies and that both the copyright notice and this permission notice *
11# * appear in the supporting documentation. The authors make no claims *
12# * about the suitability of this software for any purpose. It is *
13# * provided "as is" without express or implied warranty. *
14# **************************************************************************
15
16# Checking for a proper ROOT installation based on the ROOTSYS variable
17# received during configuration
18# If proper root installation it is setting the following variables
19# - ROOT_VERSION - ROOT version as reported by root-config
20# - ROOT_VERSION_MAJOR
21# - ROOT_VERSIOM_MINOR
22# - ROOT_VERSION_PATCH
23# - ROOT_CONFIG - path to root-config script
24# - ROOT_CINT - path to rootcint executable
0224bae4 25# - ROOT_LIBMAP - path to rlibmap executable
fffaf6a5 26# - ROOT_FEATURES - list of build features for ROOT
27# - ROOT_LIBDIR - full path to ROOT library folder
209fc56a 28# - ROOT_ETCDIR - full path to the ROOT's configuration directory
fffaf6a5 29# - ROOT_LIBRARIES - libraries needed for the package to be used
a0f34e87 30# - ROOT_GLIBRARIES - regular + GUI ROOT libraries + path to be used during linking
aff16a25 31# - ROOT_INCLUDE_DIR - full path to ROOT include folder
20fa67b6 32# - ROOT_CXX_FLAGS - flags used by the C++ compiler for building ROOT
33# - ROOT_HAS_LIBCXX - TRUE if ROOT was built against libc++ (as opposed to libstdc++)
34# - ROOT_HAS_CXX11 - TRUE if ROOT was built with C++11 support
fffaf6a5 35# - ROOT_HASALIEN - ROOT was built with AliEn support
aac9c09b 36# - ROOT_HASOPENGL - ROOT was built with OpenGL support
fffaf6a5 37# - ROOT_HASXML - ROOT was built with XML support
1c5dc89d 38# - ROOT_HASMONALISA - ROOT was built with MonAlisa support - needed by SHUTTLE
1dbe1076 39# - ROOT_FORTRAN - fortran compiler
fffaf6a5 40
36799128 41set(ROOT_FOUND FALSE)
42
fffaf6a5 43if(ROOTSYS)
44 message(STATUS "Checking for a proper ROOT installation in ${ROOTSYS}.")
45
aff16a25 46 # Setting defaults
fffaf6a5 47 set(ROOT_LIBDIR ${ROOTSYS}/lib)
aff16a25 48 set(ROOT_INCLUDE_DIR ${ROOTSYS}/include)
fffaf6a5 49
50 # Check for root-config scripts
51 find_program(ROOT_CONFIG NAMES root-config PATHS ${ROOTSYS}/bin NO_DEFAULT_PATH)
52
36799128 53 if(NOT ROOT_CONFIG)
fffaf6a5 54 message(FATAL_ERROR "Could not find root-config script.")
36799128 55 endif(NOT ROOT_CONFIG)
9f4ff23c 56 mark_as_advanced(ROOT_CONFIG)
3c517eb8 57
0224bae4 58 # Check for rlibmap
8e186b29 59 find_program(ROOT_LIBMAP NAMES rlibmap rootcling PATHS ${ROOTSYS}/bin NO_DEFAULT_PATH)
0224bae4 60 if(ROOT_LIBMAP)
61 message(STATUS "Found ${ROOT_LIBMAP}")
62 else()
63 message(FATAL_ERROR "Could not find rlibmap executable.")
64 endif(ROOT_LIBMAP)
9f4ff23c 65 mark_as_advanced(ROOT_LIBMAP)
0224bae4 66
fffaf6a5 67 # Check for rootcint
68 find_program(ROOT_CINT NAMES rootcint PATHS ${ROOTSYS}/bin NO_DEFAULT_PATH)
69 if(ROOT_CINT)
70 message(STATUS "Found ${ROOT_CINT}")
71 else()
72 message(FATAL_ERROR "Could not find rootcint executable.")
73 endif(ROOT_CINT)
9f4ff23c 74 mark_as_advanced(ROOT_CINT)
fffaf6a5 75
76 # Checking ROOT version
77 execute_process(COMMAND ${ROOT_CONFIG} --version OUTPUT_VARIABLE ROOT_VERSION ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
78 if(error)
79 message(FATAL_ERROR "Error retrieving ROOT version : ${error}")
80 endif(error)
6646d571 81 string(STRIP "${ROOT_VERSION}" ROOT_VERSION)
3c517eb8 82
fffaf6a5 83 # Extract major, minor, and patch versions from
84 string(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" ROOT_VERSION_MAJOR "${ROOT_VERSION}")
85 string(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" ROOT_VERSION_MINOR "${ROOT_VERSION}")
86 string(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" ROOT_VERSION_PATCH "${ROOT_VERSION}")
87 message(STATUS "Found ROOT version ${ROOT_VERSION_MAJOR}.${ROOT_VERSION_MINOR}.${ROOT_VERSION_PATCH}")
88
89 # Print ROOT features
90 execute_process(COMMAND ${ROOT_CONFIG} --features OUTPUT_VARIABLE ROOT_FEATURES ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
91 if(error)
92 message(FATAL_ERROR "Error retrieving ROOT features : ${error}")
93 else()
7345d84f 94 message(STATUS "ROOT was built with the following features: ${ROOT_FEATURES}")
fffaf6a5 95 endif(error)
6646d571 96 string(STRIP "${ROOT_FEATURES}" ROOT_FEATURES)
3c517eb8 97
fffaf6a5 98 # Checking for ROOT libdir
99 execute_process(COMMAND ${ROOT_CONFIG} --libdir OUTPUT_VARIABLE ROOT_LIBDIR ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
100 if(error)
101 message(FATAL_ERROR "Error retrieving ROOT libdir: ${error}")
102 endif(error)
6646d571 103 string(STRIP "${ROOT_LIBDIR}" ROOT_LIBDIR)
fffaf6a5 104
209fc56a 105 # Checking for ROOT etcdir
106 execute_process(COMMAND ${ROOT_CONFIG} --etcdir OUTPUT_VARIABLE ROOT_ETCDIR ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE)
107 if(error)
108 message(FATAL_ERROR "Error retrieving ROOT etcdir: ${error}")
109 endif(error)
110 string(STRIP "${ROOT_ETCDIR}" ROOT_ETCDIR)
111
0224bae4 112 # Checking for ROOT libs
a0f34e87 113 execute_process(COMMAND ${ROOT_CONFIG} --noldflags --libs OUTPUT_VARIABLE ROOT_LIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
0224bae4 114 if(error)
115 message(FATAL_ERROR "Error retrieving ROOT libdir: ${error}")
116 endif(error)
6646d571 117 string(STRIP "${ROOT_LIBS}" ROOT_LIBS)
3c517eb8 118
a0f34e87 119 foreach(lib ${ROOT_LIBS})
120 string(REPLACE "-rdynamic" "" new_lib ${lib})
121 string(REPLACE "-l" "" lib ${new_lib})
122 set(ROOT_LIBRARIES ${ROOT_LIBRARIES} ${lib})
123 endforeach()
6646d571 124 string(STRIP "${ROOT_LIBRARIES}" ROOT_LIBRARIES)
a0f34e87 125 separate_arguments(ROOT_LIBRARIES)
3c517eb8 126
fffaf6a5 127 # Checking for ROOT incdir
128 execute_process(COMMAND ${ROOT_CONFIG} --incdir OUTPUT_VARIABLE ROOT_INCDIR ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
129 if(error)
130 message(FATAL_ERROR "Error retrieving ROOT incdir: ${error}")
131 endif(error)
6646d571 132 string(STRIP "${ROOT_INCDIR}" ROOT_INCDIR)
aff16a25 133 set(ROOT_INCLUDE_DIR ${ROOT_INCDIR})
3c517eb8 134
20fa67b6 135 # Setting ROOT compiler flags (except the -I parts) to a variable
136 execute_process(COMMAND ${ROOT_CONFIG} --auxcflags OUTPUT_VARIABLE _ROOT_CXX_FLAGS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE)
137 if(error)
138 message(FATAL_ERROR "Error retrieving ROOT compiler flags: ${error}")
139 endif(error)
140 string(STRIP "${_ROOT_CXX_FLAGS}" ROOT_CXX_FLAGS)
141
142 # Check if ROOT was built with libc++ (as opposed to stdlibc++)
143 if(ROOT_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+")
144 set(ROOT_HAS_LIBCXX TRUE)
145 else()
146 set(ROOT_HAS_LIBCXX FALSE)
147 endif()
148
149 # Check if ROOT was built with C++11 support
150 if(ROOT_CXX_FLAGS MATCHES "-std=c\\+\\+11")
151 message(STATUS "ROOT was built with C++11 support")
152 set(ROOT_HAS_CXX11 TRUE)
153 else()
154 set(ROOT_HAS_CXX11 FALSE)
155 endif()
156
fffaf6a5 157 # Checking for glibs
a0f34e87 158 execute_process(COMMAND ${ROOT_CONFIG} --noldflags --glibs OUTPUT_VARIABLE ROOT_GLIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
fffaf6a5 159 if(error)
160 message(FATAL_ERROR "Error retrieving ROOT glibs: ${error}")
161 endif(error)
162
163 # Checking for glibs
6646d571 164 string(STRIP "${ROOT_GLIBS}" ROOT_GLIBS)
a0f34e87 165
166 foreach(lib ${ROOT_GLIBS})
167 string(REPLACE "-rdynamic" "" new_lib "${lib}")
168 string(REPLACE "-l" "" lib "${new_lib}")
169 set(ROOT_GLIBRARIES ${ROOT_GLIBRARIES} ${lib})
170 endforeach()
6646d571 171 string(STRIP "${ROOT_GLIBRARIES}" ROOT_GLIBRARIES)
a0f34e87 172 separate_arguments(ROOT_GLIBRARIES)
3c517eb8 173
a0f34e87 174 # Checking for AliEn support
dcf9b878 175 # If AliEn support is enabled we need to point to AliEn
fffaf6a5 176 execute_process(COMMAND ${ROOT_CONFIG} --has-alien OUTPUT_VARIABLE ROOT_HASALIEN ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
177 if(error)
7345d84f 178 message(FATAL_ERROR "Error checking if ROOT was built with AliEn support: ${error}")
fffaf6a5 179 endif(error)
b168bfa8 180
181 #if defined
182 if(ROOT_HASALIEN)
6646d571 183 string(STRIP "${ROOT_HASALIEN}" ROOT_HASALIEN)
b168bfa8 184 if(ROOT_HASALIEN STREQUAL "yes")
7345d84f 185 if(ALIEN)
186 add_definitions(-DWITHALIEN)
187
188 # AliEn might bring some system libraries, we need to use them
189 if(EXISTS "${ALIEN}/lib")
190 link_directories(${ALIEN}/lib)
191 endif()
192
193 # api/lib should always exists
194 if(EXISTS "${ALIEN}/api/lib")
195 link_directories(${ALIEN}/api/lib)
196 endif()
197
198 # include for AliEn
199 if(EXISTS "${ALIEN}/include")
200 include_directories(SYSTEM ${ALIEN}/include)
201 endif()
202
203 # api/include always exists
204 if(EXISTS "${ALIEN}/api/include")
205 include_directories(SYSTEM ${ALIEN}/api/include)
206 endif()
207
208 set(ROOT_HASALIEN TRUE)
209 else(ALIEN)
210 message(FATAL_ERROR "ROOT was built with AliEn support but no AliEn installation found. Please set \"ALIEN\" to point to your AliEn installation.")
211 endif(ALIEN)
4d31eb1c 212 else()
213 set(ROOT_HASALIEN FALSE)
b168bfa8 214 endif()
215 endif(ROOT_HASALIEN)
3c517eb8 216
a0f34e87 217 # Checking for xml support
fffaf6a5 218 execute_process(COMMAND ${ROOT_CONFIG} --has-xml OUTPUT_VARIABLE ROOT_HASXML ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
219 if(error)
7345d84f 220 message(FATAL_ERROR "Error checking if ROOT was built with xml support: ${error}")
fffaf6a5 221 endif(error)
b168bfa8 222
223 # if defined
224 if(ROOT_HASXML)
6646d571 225 string(STRIP "${ROOT_HASXML}" ROOT_HASXML)
b168bfa8 226 if(ROOT_HASXML STREQUAL "yes")
227 add_definitions(-DWITHXML)
4d31eb1c 228 set(ROOT_HASXML TRUE)
229 else()
230 set(ROOT_HASXML FALSE)
b168bfa8 231 endif()
232 endif(ROOT_HASXML)
1dbe1076 233
1c5dc89d 234 # Checking for monalisa support
235 execute_process(COMMAND ${ROOT_CONFIG} --has-monalisa OUTPUT_VARIABLE ROOT_HASMONALISA ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
236 if(error)
237 message(FATAL_ERROR "Error checking if ROOT was built with monalisa support: ${error}")
238 endif(error)
239
240 # if defined
241 if(ROOT_HASMONALISA)
242 string(STRIP "${ROOT_HASMONALISA}" ROOT_HASMONALISA)
243 if(ROOT_HASMONALISA STREQUAL "yes")
244 set(ROOT_HASMONALISA TRUE)
245 else()
246 set(ROOT_HASMONALISA FALSE)
247 endif()
248 endif(ROOT_HASMONALISA)
249
aac9c09b 250 # Checking for OpenGL support
251 execute_process(COMMAND ${ROOT_CONFIG} --has-opengl OUTPUT_VARIABLE ROOT_HASOPENGL ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
252 if(error)
7345d84f 253 message(FATAL_ERROR "Error checking if ROOT was built with OpenGL support: ${error}")
aac9c09b 254 endif(error)
4d31eb1c 255
256 if(ROOT_HASOPENGL)
6646d571 257 string(STRIP "${ROOT_HASOPENGL}" ROOT_HASOPENGL)
4d31eb1c 258 if(ROOT_HASOPENGL STREQUAL "yes")
259 set(ROOT_HASOPENGL TRUE)
260 else()
261 set(ROOT_HASOPENGL FALSE)
262 endif()
263 endif()
264
aac9c09b 265 # Checking for fortran compiler
1dbe1076 266 execute_process(COMMAND ${ROOT_CONFIG} --f77 OUTPUT_VARIABLE ROOT_FORTRAN ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
267 if(error)
268 message(FATAL_ERROR "Error checking ROOT fortran compiler: ${error}")
269 endif(error)
6646d571 270 string(STRIP "${ROOT_FORTRAN}" ROOT_FORTRAN)
3c517eb8 271
aff16a25 272 # adding the libraries and the inc dir
273 link_directories(${ROOT_LIBDIR})
f0315837 274# include_directories(SYSTEM ${ROOT_INCLUDE_DIR})
fffaf6a5 275 set(ROOT_FOUND TRUE)
f82bfa66 276
277 # Workaround misssing XML, VMC, Minuit from ROOT static library
278 # Also adding libzma.a libfreetype.a libpcre.a
279 # To be removed where https://sft.its.cern.ch/jira/browse/ROOT-6904 issue is fixed
280 if(ALIROOT_STATIC)
281 message(WARNING "AliRoot static build enabled! libRootExtra.a will be created.\nPlease remove when ROOT https://sft.its.cern.ch/jira/browse/ROOT-6904 issue is fixed")
282
7345d84f 283 # ROOT needs xml2 but it is not built with the static version so we have to add it
f82bfa66 284 find_package(LibXml2)
285
286 if(LIBXML2_FOUND)
287
288 # adding SSL
289 find_package(OpenSSL)
290
291 if(OPENSSL_FOUND)
292 file(GLOB _extraroot "${ROOTSYS}/montercarlo/vmc/src/*.o" "${ROOTSYS}/tree/treeplayer/src/*.o" "${ROOTSYS}/io/xmlparser/src/*.o" "${ROOTSYS}/math/minuit2/src/*.o")
293 add_library(RootExtra STATIC ${_extraroot})
294 set_target_properties(RootExtra PROPERTIES COMPILE_FLAGS "${LIBXML2_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}")
295 set_target_properties(RootExtra PROPERTIES LINKER_LANGUAGE CXX)
296 target_link_libraries(RootExtra ${ROOT_LIBDIR}/libfreetype.a ${ROOT_LIBDIR}/libpcre.a ${ROOT_LIBDIR}/liblzma.a ${LIBXML2_LIBRARIES} ${OPENSSL_LIBRARIES})
297 else()
298 message(FATAL_ERROR "OpenSSL not found. Coould not generate the static RootExtra. Please install Openssl")
299 endif()
300 else()
301 message(FATAL_ERROR "libxml2 not found. Can not generate the static RootExtra. Please install libxml2")
302 endif()
303 endif(ALIROOT_STATIC)
6db31708 304else()
fffaf6a5 305 message(FATAL_ERROR "ROOT installation not found! Please point to the ROOT installation using -DROOTSYS=ROOT_INSTALL_DIR.")
6646d571 306endif(ROOTSYS)