Warning, /DD4hep/cmake/DD4hepMacros.cmake is written in an unsupported language. File is not indexed.
0001 ######################################################################
0002 #
0003 # Useful cmake macros for building DD4hep
0004 #
0005 ######################################################################
0006
0007 # taken from cmake4hep (https://svnsrv.desy.de/desy/aidasoft/cmake4hep/trunk) :
0008
0009
0010 #---------------------------------------------------------------------------
0011 # helper macro to display standard cmake variables and force write to cache
0012 # otherwise outdated values may appear in ccmake gui
0013 MACRO( DISPLAY_STD_VARIABLES )
0014 #---------------------------------------------------------------------------
0015
0016 MESSAGE( STATUS )
0017 MESSAGE( STATUS "-------------------------------------------------------------------------------" )
0018 MESSAGE( STATUS "Change values with: cmake -D<Variable>=<Value>" )
0019
0020 IF( DEFINED CMAKE_INSTALL_PREFIX )
0021 MESSAGE( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" )
0022 ENDIF()
0023
0024
0025 IF( DEFINED CMAKE_BUILD_TYPE )
0026 MESSAGE( STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}" )
0027 ENDIF()
0028
0029 IF( DEFINED CMAKE_CXX_FLAGS )
0030 MESSAGE( STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}" )
0031 ENDIF()
0032
0033 IF( DEFINED CMAKE_CXX_STANDARD )
0034 MESSAGE( STATUS "CMAKE_CXX_STANDARD = ${CMAKE_CXX_STANDARD}" )
0035 ENDIF()
0036
0037 IF( DEFINED CMAKE_SHARED_LINKER_FLAGS )
0038 MESSAGE( STATUS "CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}" )
0039 ENDIF()
0040
0041 IF( DEFINED BUILD_SHARED_LIBS )
0042 MESSAGE( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )
0043 ENDIF()
0044
0045 IF( DEFINED BUILD_TESTING )
0046 MESSAGE( STATUS "BUILD_TESTING = ${BUILD_TESTING}" )
0047 ENDIF()
0048
0049 IF( DEFINED CMAKE_PREFIX_PATH )
0050 LIST( REMOVE_DUPLICATES CMAKE_PREFIX_PATH )
0051 #MESSAGE( STATUS "CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}" )
0052 MESSAGE( STATUS "CMAKE_PREFIX_PATH =" )
0053 FOREACH( _path ${CMAKE_PREFIX_PATH} )
0054 MESSAGE( STATUS " ${_path};" )
0055 ENDFOREACH()
0056 #SET( CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}" CACHE PATH "CMAKE_PREFIX_PATH" FORCE )
0057 ENDIF()
0058
0059 IF( DEFINED CMAKE_MODULE_PATH )
0060 LIST( REMOVE_DUPLICATES CMAKE_MODULE_PATH )
0061 #MESSAGE( STATUS "CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}" )
0062 MESSAGE( STATUS "CMAKE_MODULE_PATH =" )
0063 FOREACH( _path ${CMAKE_MODULE_PATH} )
0064 MESSAGE( STATUS " ${_path};" )
0065 ENDFOREACH()
0066 SET( CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" CACHE PATH "CMAKE_MODULE_PATH" FORCE )
0067 ENDIF()
0068
0069 MESSAGE( STATUS "-------------------------------------------------------------------------------" )
0070 MESSAGE( STATUS )
0071
0072 ENDMACRO( DISPLAY_STD_VARIABLES )
0073
0074
0075
0076 #---------------------------------------------------------------------------
0077 # helper macro for generating project configuration file
0078 MACRO( DD4HEP_GENERATE_PACKAGE_CONFIGURATION_FILES )
0079 #---------------------------------------------------------------------------
0080
0081 FOREACH( arg ${ARGN} )
0082 IF( ${arg} MATCHES "Config.cmake" )
0083 IF( EXISTS "${PROJECT_SOURCE_DIR}/cmake/${arg}.in" )
0084 CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/cmake/${arg}.in"
0085 "${PROJECT_BINARY_DIR}/${arg}" @ONLY
0086 )
0087 INSTALL( FILES "${PROJECT_BINARY_DIR}/${arg}" DESTINATION ./cmake )
0088 ENDIF()
0089 ENDIF()
0090 ENDFOREACH()
0091
0092 INCLUDE( CMakePackageConfigHelpers )
0093 WRITE_BASIC_PACKAGE_VERSION_FILE( ${CMAKE_PROJECT_NAME}ConfigVersion.cmake
0094 VERSION ${DD4hep_VERSION}
0095 COMPATIBILITY AnyNewerVersion )
0096 INSTALL( FILES "${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake" DESTINATION ./cmake )
0097
0098 ENDMACRO( DD4HEP_GENERATE_PACKAGE_CONFIGURATION_FILES )
0099
0100
0101 ##############################################################################
0102 # macro for checkin package libraries in ${PKG_ROOT}/lib
0103 #
0104 #
0105 # macro usage:
0106 # CHECK_PACKAGE_LIBS( PACKAGE_NAME stdlib1 stdlib2 ... stdlibn )
0107 # only standard libraries should be passed as arguments to the macro
0108 # component libraries are set by cmake in PKG_FIND_COMPONENTS (when
0109 # calling FIND_PACKAGE with COMPONENTS argument) or through the
0110 # variable PKG_USE_COMPONENTS
0111 #
0112 #
0113 # required variables:
0114 # PKG_ROOT : path to PKG root directory
0115 #
0116 #
0117 # returns following variables:
0118 # PKG_LIBRARY_DIRS : list of paths to be used with LINK_DIRECTORIES
0119 # PGK_LIBRARIES : list of STANDARD libraries (NOT including COMPONENTS)
0120 # PKG_COMPONENT_LIBRARIES : list of COMPONENT libraries
0121 # PKG_${COMPONENT}_FOUND : set to TRUE or FALSE for each library
0122 # PKG_${COMPONENT}_LIBRARY : path to each individual library
0123 #
0124 #
0125 # PKG_LIBRARIES and PKG_LIBRARY_DIRS will be empty if any of the standard
0126 # libraries is missing
0127 #
0128 # @author Jan Engels, Desy
0129 ##############################################################################
0130
0131
0132 SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )
0133
0134 MACRO( CHECK_PACKAGE_LIBS _pkgname )
0135
0136 SET( _std_lib_missing FALSE )
0137 SET( _ext_lib_missing FALSE )
0138
0139 SET( _std_libnames ${ARGN} )
0140 SET( _ext_libnames ${${_pkgname}_FIND_COMPONENTS} ${${_pkgname}_USE_COMPONENTS} )
0141
0142 IF( _ext_libnames )
0143 SEPARATE_ARGUMENTS( _ext_libnames )
0144 LIST( REMOVE_DUPLICATES _ext_libnames )
0145 ENDIF()
0146
0147 IF( NOT ${_pkgname}_FIND_QUIETLY )
0148 MESSAGE( STATUS "|++> Check for ${_pkgname}_LIBRARIES: ${_std_libnames}" )
0149 IF( _ext_libnames )
0150 MESSAGE( STATUS "|++> Check for ${_pkgname}_COMPONENT_LIBRARIES: ${_ext_libnames}" )
0151 ENDIF()
0152 ENDIF()
0153
0154 SET( ${_pkgname}_LIBRARY_DIRS )
0155 MARK_AS_ADVANCED( ${_pkgname}_LIBRARY_DIRS )
0156
0157 SET( ${_pkgname}_LIBRARIES )
0158 MARK_AS_ADVANCED( ${_pkgname}_LIBRARIES )
0159
0160 SET( ${_pkgname}_COMPONENT_LIBRARIES )
0161 MARK_AS_ADVANCED( ${_pkgname}_COMPONENT_LIBRARIES )
0162
0163 SET( ${_pkgname}_COMPONENT_VARIABLES )
0164 MARK_AS_ADVANCED( ${_pkgname}_COMPONENT_VARIABLES )
0165
0166 FOREACH( _libname ${_std_libnames} ${_ext_libnames} )
0167
0168 # flag to check if it is a standard or a component library
0169 LIST( FIND _std_libnames "${_libname}" _aux )
0170 IF( ${_aux} LESS 0 )
0171 SET( _is_std_lib FALSE )
0172 ELSE()
0173 SET( _is_std_lib TRUE )
0174 ENDIF()
0175
0176 # libname in upper case
0177 STRING( TOUPPER ${_libname} _ulibname )
0178
0179 SET( ${_pkgname}_${_ulibname}_LIBRARY ${_pkgname}_${_ulibname}_LIBRARY-NOTFOUND )
0180 MARK_AS_ADVANCED( ${_pkgname}_${_ulibname}_LIBRARY )
0181
0182 # WARNING: using PATH_SUFFIXES may cause problems when using variable CMAKE_FIND_ROOT_PATH
0183 # this problem does not occur if expanding PATHS
0184 # look in FindMySQL.cmake for more info
0185 #FIND_LIBRARY( ${_pkgname}_${_ulibname}_LIBRARY NAMES ${_libname} PATHS
0186 # ${${_pkgname}_ROOT} ${${_pkgname}_DIR} ${${_pkgname}_LIB_SEARCH_PATH}
0187 # PATH_SUFFIXES lib64 lib
0188 # NO_DEFAULT_PATH
0189 #)
0190
0191 FIND_LIBRARY( ${_pkgname}_${_ulibname}_LIBRARY NAMES ${_libname} PATHS
0192 ${${_pkgname}_ROOT}/lib64 ${${_pkgname}_ROOT}/lib
0193 ${${_pkgname}_DIR}/lib64 ${${_pkgname}_DIR}/lib
0194 ${${_pkgname}_LIB_SEARCH_PATH} ${${_pkgname}_LIB_SEARCH_PATH}/lib64 ${${_pkgname}_LIB_SEARCH_PATH}/lib
0195 NO_DEFAULT_PATH
0196 )
0197
0198 IF( NOT ${_pkgname}_DIR )
0199 FIND_LIBRARY( ${_pkgname}_${_ulibname}_LIBRARY NAMES ${_libname} )
0200 ENDIF()
0201
0202 IF( ${_pkgname}_FIND_REQUIRED )
0203 LIST( APPEND ${_pkgname}_COMPONENT_VARIABLES ${_pkgname}_${_ulibname}_LIBRARY )
0204 ENDIF()
0205
0206 IF( ${_pkgname}_${_ulibname}_LIBRARY ) # if library found
0207
0208 SET( ${_pkgname}_${_ulibname}_FOUND TRUE )
0209
0210 # split libraries in PKG_LIBRARIES and PKG_COMPONENT_LIBRARIES
0211 IF( _is_std_lib )
0212 LIST( APPEND ${_pkgname}_LIBRARIES ${${_pkgname}_${_ulibname}_LIBRARY} )
0213 ELSE()
0214 LIST( APPEND ${_pkgname}_COMPONENT_LIBRARIES ${${_pkgname}_${_ulibname}_LIBRARY} )
0215 ENDIF()
0216
0217 GET_FILENAME_COMPONENT( _aux ${${_pkgname}_${_ulibname}_LIBRARY} PATH )
0218 LIST( APPEND ${_pkgname}_LIBRARY_DIRS ${_aux} )
0219
0220 IF( NOT ${_pkgname}_FIND_QUIETLY )
0221 MESSAGE( STATUS "|++> Check for ${_pkgname}_${_ulibname}_LIBRARY: ${${_pkgname}_${_ulibname}_LIBRARY} -- ok" )
0222 ENDIF()
0223
0224 ELSE() # library not found
0225
0226 SET( ${_pkgname}_${_ulibname}_FOUND FALSE )
0227
0228 IF( _is_std_lib )
0229 SET( _std_lib_missing TRUE )
0230 ELSE()
0231 SET( _ext_lib_missing TRUE )
0232 ENDIF()
0233
0234 IF( NOT ${_pkgname}_FIND_QUIETLY )
0235 MESSAGE( STATUS "|++> Check for ${_pkgname}_${_ulibname}_LIBRARY: ${_libname} -- failed" )
0236 ENDIF()
0237
0238 ENDIF()
0239
0240 ENDFOREACH()
0241
0242 # clear PKG_LIBRARIES if standard library is missing
0243 IF( _std_lib_missing )
0244 SET( ${_pkgname}_LIBRARIES )
0245 ENDIF()
0246
0247 # clear PKG_COMPONENT_LIBRARIES if a component library is missing and
0248 # FIND_PACKAGE called with REQUIRED argument
0249 IF( _ext_lib_missing AND ${_pkgname}_FIND_REQUIRED )
0250 SET( ${_pkgname}_COMPONENT_LIBRARIES )
0251 ENDIF()
0252
0253 # remove duplicate paths in PKG_LIBRARY_DIRS
0254 IF( ${_pkgname}_LIBRARY_DIRS )
0255 LIST( REMOVE_DUPLICATES ${_pkgname}_LIBRARY_DIRS )
0256 ENDIF()
0257
0258 # debug
0259 #MESSAGE( STATUS "${_pkgname}_LIBRARIES: ${${_pkgname}_LIBRARIES}" )
0260 #MESSAGE( STATUS "${_pkgname}_COMPONENT_LIBRARIES: ${${_pkgname}_COMPONENT_LIBRARIES}" )
0261 #MESSAGE( STATUS "${_pkgname}_LIBRARY_DIRS: ${${_pkgname}_LIBRARY_DIRS}" )
0262
0263 ENDMACRO( CHECK_PACKAGE_LIBS _pkgname )
0264
0265