Warning, /estarlight/utils/cmake_modules/FindROOT.cmake is written in an unsupported language. File is not indexed.
0001 ###########################################################################
0002 #
0003 # Copyright 2010
0004 #
0005 # This file is part of Starlight.
0006 #
0007 # Starlight is free software: you can redistribute it and/or modify
0008 # it under the terms of the GNU General Public License as published by
0009 # the Free Software Foundation, either version 3 of the License, or
0010 # (at your option) any later version.
0011 #
0012 # Starlight is distributed in the hope that it will be useful,
0013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015 # GNU General Public License for more details.
0016 #
0017 # You should have received a copy of the GNU General Public License
0018 # along with Starlight. If not, see <http://www.gnu.org/licenses/>.
0019 #
0020 ###########################################################################
0021 #
0022 # File and Version Information:
0023 # $Rev:: 28 $: revision of last commit
0024 # $Author:: bgrube $: author of last commit
0025 # $Date:: 2010-12-10 18:30:01 +0000 #$: date of last commit
0026 #
0027 # Description:
0028 # cmake module for finding ROOT installation
0029 # requires root-config to be in PATH
0030 # based on AliRoots's FindROOT.cmake (r41015)
0031 # in https://alisoft.cern.ch/AliRoot/trunk/cmake/modules
0032 #
0033 # following variables are defined:
0034 # ROOT_CONFIG_EXECUTABLE - path to root-config program
0035 # ROOTSYS - path to root installation directory
0036 # ROOT_TARGET - target architecture
0037 # ROOT_F77 - Fortran complier used building ROOT
0038 # ROOT_CC - C complier used building ROOT
0039 # ROOT_CPP - C++ complier used building ROOT
0040 # ROOT_VERSION - ROOT version
0041 # ROOT_SVN_REVISION - ROOT subversion revision
0042 # ROOT_BIN_DIR - ROOT executable directory
0043 # ROOT_INCLUDE_DIR - ROOT header directory
0044 # ROOT_LIBRARY_DIR - ROOT library directory
0045 # ROOT_LIBRARIES - linker flags for ROOT libraries
0046 # ROOT_AUX_LIBRARIES - linker flags for auxiliary libraries
0047 # ROOTCINT_EXECUTABLE - path to rootcint program
0048 # ROOT_MAJOR_VERSION - ROOT major version
0049 # ROOT_MINOR_VERSION - ROOT minor version
0050 # ROOT_PATCH_VERSION - ROOT patch level
0051 # ROOT_LIBS - list of ROOT library files
0052 #
0053 # Example usage:
0054 # find_package(ROOT 5.26 REQUIRED Minuit2)
0055 #
0056 #
0057 # The module also provides a function to generate ROOT dictionaries.
0058 # Example usage:
0059 # set(ROOTPWA_DICTIONARY ${CMAKE_CURRENT_BINARY_DIR}/someDict.cc) # set dictionary path
0060 # root_generate_dictionary(
0061 # "${ROOTPWA_DICTIONARY}" # path to dictionary to generate
0062 # "${INCLUDE_DIR1};${INCLUDE_DIR2}" # list of includes
0063 # "class1.h;class2.h;class3.h" # list of classes to process
0064 # "someLinkDef.h" # ROOT linkDef file
0065 # )
0066 # set(SOURCES ${SOURCES} ${ROOTPWA_DICTIONARY}) # append dictionary to sources
0067 #
0068 #
0069 ###########################################################################
0070
0071
0072 set(ROOT_FOUND FALSE)
0073 set(ROOT_ERROR_REASON "")
0074 set(ROOT_DEFINITIONS "")
0075 set(ROOT_LIBS)
0076
0077
0078 find_program(ROOT_CONFIG_EXECUTABLE root-config)
0079 if(NOT ROOT_CONFIG_EXECUTABLE)
0080 set(ROOT_ERROR_REASON "${ROOT_ERROR_REASON} Cannot find root-config.")
0081 else()
0082
0083 set(ROOT_FOUND TRUE)
0084
0085 execute_process(
0086 COMMAND ${ROOT_CONFIG_EXECUTABLE} --prefix
0087 OUTPUT_VARIABLE ROOTSYS
0088 OUTPUT_STRIP_TRAILING_WHITESPACE)
0089
0090 execute_process(
0091 COMMAND ${ROOT_CONFIG_EXECUTABLE} --arch
0092 OUTPUT_VARIABLE ROOT_TARGET
0093 OUTPUT_STRIP_TRAILING_WHITESPACE)
0094
0095 execute_process(
0096 COMMAND ${ROOT_CONFIG_EXECUTABLE} --f77
0097 OUTPUT_VARIABLE ROOT_F77
0098 OUTPUT_STRIP_TRAILING_WHITESPACE)
0099
0100 execute_process(
0101 COMMAND ${ROOT_CONFIG_EXECUTABLE} --cc
0102 OUTPUT_VARIABLE ROOT_CC
0103 OUTPUT_STRIP_TRAILING_WHITESPACE)
0104
0105 execute_process(
0106 COMMAND ${ROOT_CONFIG_EXECUTABLE} --cxx
0107 OUTPUT_VARIABLE ROOT_CPP
0108 OUTPUT_STRIP_TRAILING_WHITESPACE)
0109
0110 execute_process(
0111 COMMAND ${ROOT_CONFIG_EXECUTABLE} --version
0112 OUTPUT_VARIABLE ROOT_VERSION
0113 OUTPUT_STRIP_TRAILING_WHITESPACE)
0114
0115 execute_process(
0116 COMMAND ${ROOT_CONFIG_EXECUTABLE} --svn-revision
0117 OUTPUT_VARIABLE ROOT_SVN_REVISION
0118 OUTPUT_STRIP_TRAILING_WHITESPACE)
0119
0120 execute_process(
0121 COMMAND ${ROOT_CONFIG_EXECUTABLE} --bindir
0122 OUTPUT_VARIABLE ROOT_BIN_DIR
0123 OUTPUT_STRIP_TRAILING_WHITESPACE)
0124 if(NOT EXISTS "${ROOT_BIN_DIR}")
0125 set(ROOT_FOUND FALSE)
0126 set(ROOT_ERROR_REASON "${ROOT_ERROR_REASON} ROOT executable directory ${ROOT_BIN_DIR} does not exist.")
0127 endif()
0128
0129 execute_process(
0130 COMMAND ${ROOT_CONFIG_EXECUTABLE} --incdir
0131 OUTPUT_VARIABLE ROOT_INCLUDE_DIR
0132 OUTPUT_STRIP_TRAILING_WHITESPACE)
0133 if(NOT EXISTS "${ROOT_INCLUDE_DIR}")
0134 set(ROOT_FOUND FALSE)
0135 set(ROOT_ERROR_REASON "${ROOT_ERROR_REASON} ROOT include directory ${ROOT_INCLUDE_DIR} does not exist.")
0136 endif()
0137
0138 execute_process(
0139 COMMAND ${ROOT_CONFIG_EXECUTABLE} --libdir
0140 OUTPUT_VARIABLE ROOT_LIBRARY_DIR
0141 OUTPUT_STRIP_TRAILING_WHITESPACE)
0142 if(NOT EXISTS "${ROOT_LIBRARY_DIR}")
0143 set(ROOT_FOUND FALSE)
0144 set(ROOT_ERROR_REASON "${ROOT_ERROR_REASON} ROOT library directory ${ROOT_LIBRARY_DIR} does not exist.")
0145 endif()
0146
0147 execute_process(
0148 COMMAND ${ROOT_CONFIG_EXECUTABLE} --noauxlibs --glibs
0149 OUTPUT_VARIABLE ROOT_LIBRARIES
0150 OUTPUT_STRIP_TRAILING_WHITESPACE)
0151
0152 execute_process(
0153 COMMAND ${ROOT_CONFIG_EXECUTABLE} --auxlibs
0154 OUTPUT_VARIABLE ROOT_AUX_LIBRARIES
0155 OUTPUT_STRIP_TRAILING_WHITESPACE)
0156
0157 find_program(ROOTCINT_EXECUTABLE rootcint)
0158 if(NOT ROOTCINT_EXECUTABLE)
0159 set(ROOT_FOUND FALSE)
0160 set(ROOT_ERROR_REASON "${ROOT_ERROR_REASON} Cannot find rootcint.")
0161 endif()
0162
0163 # parse version string
0164 string(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1"
0165 ROOT_MAJOR_VERSION "${ROOT_VERSION}")
0166 string(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1"
0167 ROOT_MINOR_VERSION "${ROOT_VERSION}")
0168 string(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1"
0169 ROOT_PATCH_VERSION "${ROOT_VERSION}")
0170 # make sure minor version is specified
0171 if(ROOT_FIND_VERSION AND NOT ROOT_FIND_VERSION_MINOR)
0172 message(FATAL_ERROR "When requesting a specific version of ROOT, you must provide at least the major and minor version numbers, e.g., 5.22")
0173 endif()
0174 # set patchlevel to 0, if not specified
0175 if(NOT ROOT_FIND_VERSION_PATCH)
0176 set(ROOT_FIND_VERSION_PATCH 0)
0177 endif()
0178 # compute an overall version number which can be compared at once
0179 math(EXPR _ROOT_FIND_VERSION "${ROOT_FIND_VERSION_MAJOR} * 10000 + ${ROOT_FIND_VERSION_MINOR} * 100 + ${ROOT_FIND_VERSION_PATCH}")
0180 math(EXPR _ROOT_VERSION "${ROOT_MAJOR_VERSION} * 10000 + ${ROOT_MINOR_VERSION} * 100 + ${ROOT_PATCH_VERSION}")
0181 # compare version
0182 if(ROOT_FIND_VERSION_EXACT)
0183 if(NOT _ROOT_VERSION EQUAL "${_ROOT_FIND_VERSION}")
0184 set(ROOT_FOUND FALSE)
0185 set(ROOT_ERROR_REASON "${ROOT_ERROR_REASON} ROOT version ${ROOT_VERSION} does not match requested version ${ROOT_FIND_VERSION_MAJOR}.${ROOT_FIND_VERSION_MINOR}/${ROOT_FIND_VERSION_PATCH}.")
0186 endif()
0187 else()
0188 if(_ROOT_VERSION LESS "${_ROOT_FIND_VERSION}")
0189 set(ROOT_FOUND FALSE)
0190 set(ROOT_ERROR_REASON "${ROOT_ERROR_REASON} ROOT version ${ROOT_VERSION} is lower than requested version ${ROOT_FIND_VERSION_MAJOR}.${ROOT_FIND_VERSION_MINOR}/${ROOT_FIND_VERSION_PATCH}.")
0191 endif()
0192 endif()
0193
0194 endif()
0195
0196
0197 # generate list of ROOT libraries
0198 if(ROOT_FOUND)
0199
0200 # create list of internal libraries from root-config output
0201 set(_LIBRARY_NAMES)
0202 set(_EXTERNAL_ZLIB)
0203 separate_arguments(ROOT_LIBRARIES)
0204 # remove first -L entry
0205 list(REMOVE_AT ROOT_LIBRARIES 0)
0206 # loop over -l entries
0207 foreach(_LIBRARY ${ROOT_LIBRARIES})
0208 # extract library name from compiler flag and append to list
0209 string(REGEX REPLACE "^-.(.*)$" "\\1" _LIBNAME "${_LIBRARY}")
0210 # workaround for root-config inconsistency: if ROOT is built with --disable-builtin-zlib
0211 # root-config returns the flag for the external zlib together with the internal libraries
0212 if(_LIBNAME STREQUAL "z")
0213 set(_EXTERNAL_ZLIB "-lz")
0214 else()
0215 list(APPEND _LIBRARY_NAMES ${_LIBNAME})
0216 endif()
0217 endforeach()
0218
0219 # append components
0220 list(REMOVE_DUPLICATES ROOT_FIND_COMPONENTS)
0221 if(ROOT_FIND_COMPONENTS)
0222 set(_LIBRARY_NAMES "${_LIBRARY_NAMES};${ROOT_FIND_COMPONENTS}")
0223 endif()
0224
0225 # check whether libraries exist
0226 foreach(_LIBNAME ${_LIBRARY_NAMES})
0227 find_library(_ROOT_LIB_${_LIBNAME}
0228 NAMES ${_LIBNAME}
0229 PATHS ${ROOT_LIBRARY_DIR}
0230 NO_DEFAULT_PATH)
0231 if(NOT _ROOT_LIB_${_LIBNAME})
0232 set(ROOT_FOUND FALSE)
0233 set(ROOT_ERROR_REASON "${ROOT_ERROR_REASON} Cannot find ROOT library ${_LIBNAME} in ${ROOT_LIBRARY_DIR}.")
0234 else()
0235 list(APPEND ROOT_LIBS ${_ROOT_LIB_${_LIBNAME}})
0236 endif()
0237 endforeach()
0238
0239 # create list of external libraries from root-config output
0240 separate_arguments(ROOT_AUX_LIBRARIES)
0241 # append external zlib to auxiliary libraries
0242 if(_EXTERNAL_ZLIB)
0243 list(APPEND ROOT_AUX_LIBRARIES ${_EXTERNAL_ZLIB})
0244 endif()
0245 # loop over -l entries
0246 foreach(_LIBRARY ${ROOT_AUX_LIBRARIES})
0247 # extract library name from compiler flag
0248 string(REGEX MATCH "^-l(.*)$" _LIBNAME "${_LIBRARY}")
0249 if(_LIBNAME)
0250 string(REGEX REPLACE "^-.(.*)$" "\\1" _LIBNAME "${_LIBNAME}")
0251 # check whether libraries exist
0252 find_library(_AUX_LIB_${_LIBNAME}
0253 NAMES ${_LIBNAME})
0254 if(NOT _AUX_LIB_${_LIBNAME})
0255 set(ROOT_FOUND FALSE)
0256 set(ROOT_ERROR_REASON "${ROOT_ERROR_REASON} Cannot find ROOT library ${_LIBNAME}.")
0257 else()
0258 list(APPEND ROOT_LIBS ${_AUX_LIB_${_LIBNAME}})
0259 endif()
0260 endif()
0261 endforeach()
0262
0263 endif()
0264
0265
0266 # make variables changeable
0267 mark_as_advanced(
0268 ROOT_INCLUDE_DIR
0269 ROOT_LIBRARY_DIR
0270 ROOT_LIBRARIES
0271 ROOT_LIBS
0272 ROOT_DEFINITIONS
0273 )
0274
0275
0276 # report result
0277 if(ROOT_FOUND)
0278 message(STATUS "Found ROOT version ${ROOT_VERSION} r${ROOT_SVN_REVISION} in ${ROOTSYS}")
0279 message(STATUS "Using ROOT include dir ${ROOT_INCLUDE_DIR}")
0280 message(STATUS "Using ROOT library dir ${ROOT_LIBRARY_DIR}")
0281 message(STATUS "Using ROOT libraries: ${ROOT_LIBRARIES}")
0282 message(STATUS "Using ROOT additional components: ${ROOT_FIND_COMPONENTS}")
0283 else()
0284 if(ROOT_FIND_REQUIRED)
0285 message(FATAL_ERROR "Unable to find requested ROOT installation:${ROOT_ERROR_REASON}")
0286 else()
0287 if(NOT ROOT_FIND_QUIETLY)
0288 message(STATUS "ROOT was not found.")
0289 endif()
0290 endif()
0291 endif()
0292
0293
0294 # macro that generates ROOT dictionary
0295 function(root_generate_dictionary DICT_FILE INCLUDE_DIRS HEADER_FILES LINKDEF_FILE)
0296
0297 if(NOT ROOT_FOUND)
0298 message(FATAL_ERROR "Impossible to generate dictionary ${DICT_FILE}, because no ROOT installation was found.")
0299 endif()
0300
0301 # prepare command line argument for compiler definitions (put -D in front)
0302 set(_DEFINITIONS)
0303 get_property(_DEFS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
0304 foreach(_DEF ${_DEFS})
0305 set(_DEFINITIONS "${_DEFINITIONS} -D${_DEF}")
0306 endforeach()
0307 separate_arguments(_DEFINITIONS)
0308
0309 # prepare command line argument for include directories (put -I in front)
0310 set(_INCLUDES)
0311 foreach(_FILE ${INCLUDE_DIRS})
0312 set(_INCLUDES ${_INCLUDES} -I${_FILE})
0313 endforeach()
0314
0315 # strip paths from header file names
0316 set(_HEADERS)
0317 foreach(_FILE ${HEADER_FILES})
0318 get_filename_component(_NAME ${_FILE} NAME)
0319 set(_HEADERS ${_HEADERS} ${_NAME})
0320 endforeach()
0321
0322 # add dictionary header file to output files
0323 string(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" _DICT_HEADER "${DICT_FILE}")
0324 set(OUTPUT_FILES ${DICT_FILE} ${_DICT_HEADER})
0325
0326 add_custom_command(OUTPUT ${OUTPUT_FILES}
0327 COMMAND ${ROOTCINT_EXECUTABLE}
0328 ARGS -f ${DICT_FILE} -c -DHAVE_CONFIG_H ${_DEFINITIONS} ${_INCLUDES} ${_HEADERS} ${LINKDEF_FILE}
0329 DEPENDS ${HEADER_FILES} ${LINKDEF_FILE}
0330 )
0331
0332 endfunction(root_generate_dictionary)