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