CMake: removing qpythia from the depedencies
[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
1dbe1076 38# - ROOT_FORTRAN - fortran compiler
fffaf6a5 39
36799128 40set(ROOT_FOUND FALSE)
41
fffaf6a5 42if(ROOTSYS)
43 message(STATUS "Checking for a proper ROOT installation in ${ROOTSYS}.")
44
aff16a25 45 # Setting defaults
fffaf6a5 46 set(ROOT_LIBDIR ${ROOTSYS}/lib)
aff16a25 47 set(ROOT_INCLUDE_DIR ${ROOTSYS}/include)
fffaf6a5 48
49 # Check for root-config scripts
50 find_program(ROOT_CONFIG NAMES root-config PATHS ${ROOTSYS}/bin NO_DEFAULT_PATH)
51
36799128 52 if(NOT ROOT_CONFIG)
fffaf6a5 53 message(FATAL_ERROR "Could not find root-config script.")
36799128 54 endif(NOT ROOT_CONFIG)
9f4ff23c 55 mark_as_advanced(ROOT_CONFIG)
3c517eb8 56
0224bae4 57 # Check for rlibmap
8e186b29 58 find_program(ROOT_LIBMAP NAMES rlibmap rootcling PATHS ${ROOTSYS}/bin NO_DEFAULT_PATH)
0224bae4 59 if(ROOT_LIBMAP)
60 message(STATUS "Found ${ROOT_LIBMAP}")
61 else()
62 message(FATAL_ERROR "Could not find rlibmap executable.")
63 endif(ROOT_LIBMAP)
9f4ff23c 64 mark_as_advanced(ROOT_LIBMAP)
0224bae4 65
fffaf6a5 66 # Check for rootcint
67 find_program(ROOT_CINT NAMES rootcint PATHS ${ROOTSYS}/bin NO_DEFAULT_PATH)
68 if(ROOT_CINT)
69 message(STATUS "Found ${ROOT_CINT}")
70 else()
71 message(FATAL_ERROR "Could not find rootcint executable.")
72 endif(ROOT_CINT)
9f4ff23c 73 mark_as_advanced(ROOT_CINT)
fffaf6a5 74
75 # Checking ROOT version
76 execute_process(COMMAND ${ROOT_CONFIG} --version OUTPUT_VARIABLE ROOT_VERSION ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
77 if(error)
78 message(FATAL_ERROR "Error retrieving ROOT version : ${error}")
79 endif(error)
6646d571 80 string(STRIP "${ROOT_VERSION}" ROOT_VERSION)
3c517eb8 81
fffaf6a5 82 # Extract major, minor, and patch versions from
83 string(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" ROOT_VERSION_MAJOR "${ROOT_VERSION}")
84 string(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" ROOT_VERSION_MINOR "${ROOT_VERSION}")
85 string(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" ROOT_VERSION_PATCH "${ROOT_VERSION}")
86 message(STATUS "Found ROOT version ${ROOT_VERSION_MAJOR}.${ROOT_VERSION_MINOR}.${ROOT_VERSION_PATCH}")
87
88 # Print ROOT features
89 execute_process(COMMAND ${ROOT_CONFIG} --features OUTPUT_VARIABLE ROOT_FEATURES ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
90 if(error)
91 message(FATAL_ERROR "Error retrieving ROOT features : ${error}")
92 else()
7345d84f 93 message(STATUS "ROOT was built with the following features: ${ROOT_FEATURES}")
fffaf6a5 94 endif(error)
6646d571 95 string(STRIP "${ROOT_FEATURES}" ROOT_FEATURES)
3c517eb8 96
fffaf6a5 97 # Checking for ROOT libdir
98 execute_process(COMMAND ${ROOT_CONFIG} --libdir OUTPUT_VARIABLE ROOT_LIBDIR ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
99 if(error)
100 message(FATAL_ERROR "Error retrieving ROOT libdir: ${error}")
101 endif(error)
6646d571 102 string(STRIP "${ROOT_LIBDIR}" ROOT_LIBDIR)
fffaf6a5 103
209fc56a 104 # Checking for ROOT etcdir
105 execute_process(COMMAND ${ROOT_CONFIG} --etcdir OUTPUT_VARIABLE ROOT_ETCDIR ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE)
106 if(error)
107 message(FATAL_ERROR "Error retrieving ROOT etcdir: ${error}")
108 endif(error)
109 string(STRIP "${ROOT_ETCDIR}" ROOT_ETCDIR)
110
0224bae4 111 # Checking for ROOT libs
a0f34e87 112 execute_process(COMMAND ${ROOT_CONFIG} --noldflags --libs OUTPUT_VARIABLE ROOT_LIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
0224bae4 113 if(error)
114 message(FATAL_ERROR "Error retrieving ROOT libdir: ${error}")
115 endif(error)
6646d571 116 string(STRIP "${ROOT_LIBS}" ROOT_LIBS)
3c517eb8 117
a0f34e87 118 foreach(lib ${ROOT_LIBS})
119 string(REPLACE "-rdynamic" "" new_lib ${lib})
120 string(REPLACE "-l" "" lib ${new_lib})
121 set(ROOT_LIBRARIES ${ROOT_LIBRARIES} ${lib})
122 endforeach()
6646d571 123 string(STRIP "${ROOT_LIBRARIES}" ROOT_LIBRARIES)
a0f34e87 124 separate_arguments(ROOT_LIBRARIES)
3c517eb8 125
fffaf6a5 126 # Checking for ROOT incdir
127 execute_process(COMMAND ${ROOT_CONFIG} --incdir OUTPUT_VARIABLE ROOT_INCDIR ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
128 if(error)
129 message(FATAL_ERROR "Error retrieving ROOT incdir: ${error}")
130 endif(error)
6646d571 131 string(STRIP "${ROOT_INCDIR}" ROOT_INCDIR)
aff16a25 132 set(ROOT_INCLUDE_DIR ${ROOT_INCDIR})
3c517eb8 133
20fa67b6 134 # Setting ROOT compiler flags (except the -I parts) to a variable
135 execute_process(COMMAND ${ROOT_CONFIG} --auxcflags OUTPUT_VARIABLE _ROOT_CXX_FLAGS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE)
136 if(error)
137 message(FATAL_ERROR "Error retrieving ROOT compiler flags: ${error}")
138 endif(error)
139 string(STRIP "${_ROOT_CXX_FLAGS}" ROOT_CXX_FLAGS)
140
141 # Check if ROOT was built with libc++ (as opposed to stdlibc++)
142 if(ROOT_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+")
143 set(ROOT_HAS_LIBCXX TRUE)
144 else()
145 set(ROOT_HAS_LIBCXX FALSE)
146 endif()
147
148 # Check if ROOT was built with C++11 support
149 if(ROOT_CXX_FLAGS MATCHES "-std=c\\+\\+11")
150 message(STATUS "ROOT was built with C++11 support")
151 set(ROOT_HAS_CXX11 TRUE)
152 else()
153 set(ROOT_HAS_CXX11 FALSE)
154 endif()
155
fffaf6a5 156 # Checking for glibs
a0f34e87 157 execute_process(COMMAND ${ROOT_CONFIG} --noldflags --glibs OUTPUT_VARIABLE ROOT_GLIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
fffaf6a5 158 if(error)
159 message(FATAL_ERROR "Error retrieving ROOT glibs: ${error}")
160 endif(error)
161
162 # Checking for glibs
6646d571 163 string(STRIP "${ROOT_GLIBS}" ROOT_GLIBS)
a0f34e87 164
165 foreach(lib ${ROOT_GLIBS})
166 string(REPLACE "-rdynamic" "" new_lib "${lib}")
167 string(REPLACE "-l" "" lib "${new_lib}")
168 set(ROOT_GLIBRARIES ${ROOT_GLIBRARIES} ${lib})
169 endforeach()
6646d571 170 string(STRIP "${ROOT_GLIBRARIES}" ROOT_GLIBRARIES)
a0f34e87 171 separate_arguments(ROOT_GLIBRARIES)
3c517eb8 172
a0f34e87 173 # Checking for AliEn support
dcf9b878 174 # If AliEn support is enabled we need to point to AliEn
fffaf6a5 175 execute_process(COMMAND ${ROOT_CONFIG} --has-alien OUTPUT_VARIABLE ROOT_HASALIEN ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
176 if(error)
7345d84f 177 message(FATAL_ERROR "Error checking if ROOT was built with AliEn support: ${error}")
fffaf6a5 178 endif(error)
b168bfa8 179
180 #if defined
181 if(ROOT_HASALIEN)
6646d571 182 string(STRIP "${ROOT_HASALIEN}" ROOT_HASALIEN)
b168bfa8 183 if(ROOT_HASALIEN STREQUAL "yes")
7345d84f 184 if(ALIEN)
185 add_definitions(-DWITHALIEN)
186
187 # AliEn might bring some system libraries, we need to use them
188 if(EXISTS "${ALIEN}/lib")
189 link_directories(${ALIEN}/lib)
190 endif()
191
192 # api/lib should always exists
193 if(EXISTS "${ALIEN}/api/lib")
194 link_directories(${ALIEN}/api/lib)
195 endif()
196
197 # include for AliEn
198 if(EXISTS "${ALIEN}/include")
199 include_directories(SYSTEM ${ALIEN}/include)
200 endif()
201
202 # api/include always exists
203 if(EXISTS "${ALIEN}/api/include")
204 include_directories(SYSTEM ${ALIEN}/api/include)
205 endif()
206
207 set(ROOT_HASALIEN TRUE)
208 else(ALIEN)
209 message(FATAL_ERROR "ROOT was built with AliEn support but no AliEn installation found. Please set \"ALIEN\" to point to your AliEn installation.")
210 endif(ALIEN)
4d31eb1c 211 else()
212 set(ROOT_HASALIEN FALSE)
b168bfa8 213 endif()
214 endif(ROOT_HASALIEN)
3c517eb8 215
a0f34e87 216 # Checking for xml support
fffaf6a5 217 execute_process(COMMAND ${ROOT_CONFIG} --has-xml OUTPUT_VARIABLE ROOT_HASXML ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
218 if(error)
7345d84f 219 message(FATAL_ERROR "Error checking if ROOT was built with xml support: ${error}")
fffaf6a5 220 endif(error)
b168bfa8 221
222 # if defined
223 if(ROOT_HASXML)
6646d571 224 string(STRIP "${ROOT_HASXML}" ROOT_HASXML)
b168bfa8 225 if(ROOT_HASXML STREQUAL "yes")
226 add_definitions(-DWITHXML)
4d31eb1c 227 set(ROOT_HASXML TRUE)
228 else()
229 set(ROOT_HASXML FALSE)
b168bfa8 230 endif()
231 endif(ROOT_HASXML)
1dbe1076 232
aac9c09b 233 # Checking for OpenGL support
234 execute_process(COMMAND ${ROOT_CONFIG} --has-opengl OUTPUT_VARIABLE ROOT_HASOPENGL ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
235 if(error)
7345d84f 236 message(FATAL_ERROR "Error checking if ROOT was built with OpenGL support: ${error}")
aac9c09b 237 endif(error)
4d31eb1c 238
239 if(ROOT_HASOPENGL)
6646d571 240 string(STRIP "${ROOT_HASOPENGL}" ROOT_HASOPENGL)
4d31eb1c 241 if(ROOT_HASOPENGL STREQUAL "yes")
242 set(ROOT_HASOPENGL TRUE)
243 else()
244 set(ROOT_HASOPENGL FALSE)
245 endif()
246 endif()
247
aac9c09b 248 # Checking for fortran compiler
1dbe1076 249 execute_process(COMMAND ${ROOT_CONFIG} --f77 OUTPUT_VARIABLE ROOT_FORTRAN ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
250 if(error)
251 message(FATAL_ERROR "Error checking ROOT fortran compiler: ${error}")
252 endif(error)
6646d571 253 string(STRIP "${ROOT_FORTRAN}" ROOT_FORTRAN)
3c517eb8 254
aff16a25 255 # adding the libraries and the inc dir
256 link_directories(${ROOT_LIBDIR})
f0315837 257# include_directories(SYSTEM ${ROOT_INCLUDE_DIR})
fffaf6a5 258 set(ROOT_FOUND TRUE)
f82bfa66 259
260 # Workaround misssing XML, VMC, Minuit from ROOT static library
261 # Also adding libzma.a libfreetype.a libpcre.a
262 # To be removed where https://sft.its.cern.ch/jira/browse/ROOT-6904 issue is fixed
263 if(ALIROOT_STATIC)
264 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")
265
7345d84f 266 # ROOT needs xml2 but it is not built with the static version so we have to add it
f82bfa66 267 find_package(LibXml2)
268
269 if(LIBXML2_FOUND)
270
271 # adding SSL
272 find_package(OpenSSL)
273
274 if(OPENSSL_FOUND)
275 file(GLOB _extraroot "${ROOTSYS}/montercarlo/vmc/src/*.o" "${ROOTSYS}/tree/treeplayer/src/*.o" "${ROOTSYS}/io/xmlparser/src/*.o" "${ROOTSYS}/math/minuit2/src/*.o")
276 add_library(RootExtra STATIC ${_extraroot})
277 set_target_properties(RootExtra PROPERTIES COMPILE_FLAGS "${LIBXML2_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}")
278 set_target_properties(RootExtra PROPERTIES LINKER_LANGUAGE CXX)
279 target_link_libraries(RootExtra ${ROOT_LIBDIR}/libfreetype.a ${ROOT_LIBDIR}/libpcre.a ${ROOT_LIBDIR}/liblzma.a ${LIBXML2_LIBRARIES} ${OPENSSL_LIBRARIES})
280 else()
281 message(FATAL_ERROR "OpenSSL not found. Coould not generate the static RootExtra. Please install Openssl")
282 endif()
283 else()
284 message(FATAL_ERROR "libxml2 not found. Can not generate the static RootExtra. Please install libxml2")
285 endif()
286 endif(ALIROOT_STATIC)
6db31708 287else()
fffaf6a5 288 message(FATAL_ERROR "ROOT installation not found! Please point to the ROOT installation using -DROOTSYS=ROOT_INSTALL_DIR.")
6646d571 289endif(ROOTSYS)