1 # **************************************************************************
2 # * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
4 # * Author: The ALICE Off-line Project. *
5 # * Contributors are mentioned in the code where appropriate. *
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 # **************************************************************************
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
25 # - ROOT_LIBMAP - path to rlibmap executable
26 # - ROOT_FEATURES - list of build features for ROOT
27 # - ROOT_LIBDIR - full path to ROOT library folder
28 # - ROOT_ETCDIR - full path to the ROOT's configuration directory
29 # - ROOT_LIBRARIES - libraries needed for the package to be used
30 # - ROOT_GLIBRARIES - regular + GUI ROOT libraries + path to be used during linking
31 # - ROOT_INCLUDE_DIR - full path to ROOT include folder
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
35 # - ROOT_HASALIEN - ROOT was built with AliEn support
36 # - ROOT_HASOPENGL - ROOT was built with OpenGL support
37 # - ROOT_HASXML - ROOT was built with XML support
38 # - ROOT_FORTRAN - fortran compiler
43 message(STATUS "Checking for a proper ROOT installation in ${ROOTSYS}.")
46 set(ROOT_LIBDIR ${ROOTSYS}/lib)
47 set(ROOT_INCLUDE_DIR ${ROOTSYS}/include)
49 # Check for root-config scripts
50 find_program(ROOT_CONFIG NAMES root-config PATHS ${ROOTSYS}/bin NO_DEFAULT_PATH)
53 message(FATAL_ERROR "Could not find root-config script.")
54 endif(NOT ROOT_CONFIG)
55 mark_as_advanced(ROOT_CONFIG)
58 find_program(ROOT_LIBMAP NAMES rlibmap rootcling PATHS ${ROOTSYS}/bin NO_DEFAULT_PATH)
60 message(STATUS "Found ${ROOT_LIBMAP}")
62 message(FATAL_ERROR "Could not find rlibmap executable.")
64 mark_as_advanced(ROOT_LIBMAP)
67 find_program(ROOT_CINT NAMES rootcint PATHS ${ROOTSYS}/bin NO_DEFAULT_PATH)
69 message(STATUS "Found ${ROOT_CINT}")
71 message(FATAL_ERROR "Could not find rootcint executable.")
73 mark_as_advanced(ROOT_CINT)
75 # Checking ROOT version
76 execute_process(COMMAND ${ROOT_CONFIG} --version OUTPUT_VARIABLE ROOT_VERSION ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
78 message(FATAL_ERROR "Error retrieving ROOT version : ${error}")
80 string(STRIP "${ROOT_VERSION}" ROOT_VERSION)
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}")
89 execute_process(COMMAND ${ROOT_CONFIG} --features OUTPUT_VARIABLE ROOT_FEATURES ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
91 message(FATAL_ERROR "Error retrieving ROOT features : ${error}")
93 message(STATUS "ROOT was built with the following features: ${ROOT_FEATURES}")
95 string(STRIP "${ROOT_FEATURES}" ROOT_FEATURES)
97 # Checking for ROOT libdir
98 execute_process(COMMAND ${ROOT_CONFIG} --libdir OUTPUT_VARIABLE ROOT_LIBDIR ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
100 message(FATAL_ERROR "Error retrieving ROOT libdir: ${error}")
102 string(STRIP "${ROOT_LIBDIR}" ROOT_LIBDIR)
104 # Checking for ROOT etcdir
105 execute_process(COMMAND ${ROOT_CONFIG} --etcdir OUTPUT_VARIABLE ROOT_ETCDIR ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE)
107 message(FATAL_ERROR "Error retrieving ROOT etcdir: ${error}")
109 string(STRIP "${ROOT_ETCDIR}" ROOT_ETCDIR)
111 # Checking for ROOT libs
112 execute_process(COMMAND ${ROOT_CONFIG} --noldflags --libs OUTPUT_VARIABLE ROOT_LIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
114 message(FATAL_ERROR "Error retrieving ROOT libdir: ${error}")
116 string(STRIP "${ROOT_LIBS}" ROOT_LIBS)
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})
123 string(STRIP "${ROOT_LIBRARIES}" ROOT_LIBRARIES)
124 separate_arguments(ROOT_LIBRARIES)
126 # Checking for ROOT incdir
127 execute_process(COMMAND ${ROOT_CONFIG} --incdir OUTPUT_VARIABLE ROOT_INCDIR ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
129 message(FATAL_ERROR "Error retrieving ROOT incdir: ${error}")
131 string(STRIP "${ROOT_INCDIR}" ROOT_INCDIR)
132 set(ROOT_INCLUDE_DIR ${ROOT_INCDIR})
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)
137 message(FATAL_ERROR "Error retrieving ROOT compiler flags: ${error}")
139 string(STRIP "${_ROOT_CXX_FLAGS}" ROOT_CXX_FLAGS)
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)
145 set(ROOT_HAS_LIBCXX FALSE)
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)
153 set(ROOT_HAS_CXX11 FALSE)
157 execute_process(COMMAND ${ROOT_CONFIG} --noldflags --glibs OUTPUT_VARIABLE ROOT_GLIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
159 message(FATAL_ERROR "Error retrieving ROOT glibs: ${error}")
163 string(STRIP "${ROOT_GLIBS}" ROOT_GLIBS)
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})
170 string(STRIP "${ROOT_GLIBRARIES}" ROOT_GLIBRARIES)
171 separate_arguments(ROOT_GLIBRARIES)
173 # Checking for AliEn support
174 # If AliEn support is enabled we need to point to AliEn
175 execute_process(COMMAND ${ROOT_CONFIG} --has-alien OUTPUT_VARIABLE ROOT_HASALIEN ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
177 message(FATAL_ERROR "Error checking if ROOT was built with AliEn support: ${error}")
182 string(STRIP "${ROOT_HASALIEN}" ROOT_HASALIEN)
183 if(ROOT_HASALIEN STREQUAL "yes")
185 add_definitions(-DWITHALIEN)
187 # AliEn might bring some system libraries, we need to use them
188 if(EXISTS "${ALIEN}/lib")
189 link_directories(${ALIEN}/lib)
192 # api/lib should always exists
193 if(EXISTS "${ALIEN}/api/lib")
194 link_directories(${ALIEN}/api/lib)
198 if(EXISTS "${ALIEN}/include")
199 include_directories(SYSTEM ${ALIEN}/include)
202 # api/include always exists
203 if(EXISTS "${ALIEN}/api/include")
204 include_directories(SYSTEM ${ALIEN}/api/include)
207 set(ROOT_HASALIEN TRUE)
209 message(FATAL_ERROR "ROOT was built with AliEn support but no AliEn installation found. Please set \"ALIEN\" to point to your AliEn installation.")
212 set(ROOT_HASALIEN FALSE)
216 # Checking for xml support
217 execute_process(COMMAND ${ROOT_CONFIG} --has-xml OUTPUT_VARIABLE ROOT_HASXML ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
219 message(FATAL_ERROR "Error checking if ROOT was built with xml support: ${error}")
224 string(STRIP "${ROOT_HASXML}" ROOT_HASXML)
225 if(ROOT_HASXML STREQUAL "yes")
226 add_definitions(-DWITHXML)
227 set(ROOT_HASXML TRUE)
229 set(ROOT_HASXML FALSE)
233 # Checking for OpenGL support
234 execute_process(COMMAND ${ROOT_CONFIG} --has-opengl OUTPUT_VARIABLE ROOT_HASOPENGL ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
236 message(FATAL_ERROR "Error checking if ROOT was built with OpenGL support: ${error}")
240 string(STRIP "${ROOT_HASOPENGL}" ROOT_HASOPENGL)
241 if(ROOT_HASOPENGL STREQUAL "yes")
242 set(ROOT_HASOPENGL TRUE)
244 set(ROOT_HASOPENGL FALSE)
248 # Checking for fortran compiler
249 execute_process(COMMAND ${ROOT_CONFIG} --f77 OUTPUT_VARIABLE ROOT_FORTRAN ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
251 message(FATAL_ERROR "Error checking ROOT fortran compiler: ${error}")
253 string(STRIP "${ROOT_FORTRAN}" ROOT_FORTRAN)
255 # adding the libraries and the inc dir
256 link_directories(${ROOT_LIBDIR})
257 # include_directories(SYSTEM ${ROOT_INCLUDE_DIR})
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
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")
266 # ROOT needs xml2 but it is not built with the static version so we have to add it
267 find_package(LibXml2)
272 find_package(OpenSSL)
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})
281 message(FATAL_ERROR "OpenSSL not found. Coould not generate the static RootExtra. Please install Openssl")
284 message(FATAL_ERROR "libxml2 not found. Can not generate the static RootExtra. Please install libxml2")
286 endif(ALIROOT_STATIC)
288 message(FATAL_ERROR "ROOT installation not found! Please point to the ROOT installation using -DROOTSYS=ROOT_INSTALL_DIR.")