Warning, /DD4hep/cmake/DD4hepBuild.cmake is written in an unsupported language. File is not indexed.
0001 #=================================================================================
0002 #
0003 # AIDA Detector description implementation
0004 #---------------------------------------------------------------------------------
0005 # Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0006 # All rights reserved.
0007 #
0008 # For the licensing terms see $DD4hepINSTALL/LICENSE.
0009 # For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0010 #
0011 #=================================================================================
0012
0013
0014 include ( CMakeParseArguments )
0015
0016 if(DD4hepBuild_included)
0017 RETURN()
0018 endif()
0019 message(STATUS "Including DD4hepBuild.cmake")
0020 set ( DD4hepBuild_included ON )
0021
0022 #---------------------------------------------------------------------------------------------------
0023 macro(dd4hep_to_parent_scope val)
0024 set ( ${val} ${${val}} PARENT_SCOPE )
0025 endmacro(dd4hep_to_parent_scope)
0026 #---------------------------------------------------------------------------------------------------
0027 macro(dd4hep_use_python_executable)
0028 dd4hep_print("|++> Using python executable: ${Python_EXECUTABLE}")
0029 endmacro(dd4hep_use_python_executable)
0030 #---------------------------------------------------------------------------------------------------
0031 # MACRO: dd4hep_set_compiler_flags
0032 #
0033 # Set compiler flags
0034 #
0035 # \author M.Frank
0036 # \version 1.0
0037 #
0038 #---------------------------------------------------------------------------------------------------
0039 macro(dd4hep_set_compiler_flags)
0040 include(CheckCXXCompilerFlag)
0041
0042 SET(COMPILER_FLAGS -Wshadow -Wformat-security -Wno-long-long -Wdeprecated -fdiagnostics-color=auto -Wall -Wextra -pedantic )
0043
0044 # AppleClang/Clang specific warning flags
0045 if(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
0046 set ( COMPILER_FLAGS ${COMPILER_FLAGS} -Winconsistent-missing-override -Wno-c++1z-extensions -Wheader-hygiene )
0047 else()
0048 set ( COMPILER_FLAGS ${COMPILER_FLAGS} -Wno-psabi)
0049 endif()
0050
0051 FOREACH( FLAG ${COMPILER_FLAGS} )
0052 ## meed to replace the minus or plus signs from the variables, because it is passed
0053 ## as a macro to g++ which causes a warning about no whitespace after macro
0054 ## definition
0055 STRING(REPLACE "-" "_" FLAG_WORD ${FLAG} )
0056 STRING(REPLACE "+" "P" FLAG_WORD ${FLAG_WORD} )
0057
0058 CHECK_CXX_COMPILER_FLAG( "${FLAG}" CXX_FLAG_WORKS_${FLAG_WORD} )
0059 IF( ${CXX_FLAG_WORKS_${FLAG_WORD}} )
0060 dd4hep_debug("|DDD> Adding ${FLAG} to CXX_FLAGS" )
0061 SET ( CMAKE_CXX_FLAGS "${FLAG} ${CMAKE_CXX_FLAGS} ")
0062 ELSE()
0063 dd4hep_debug("|DDD> NOT Adding ${FLAG} to CXX_FLAGS" )
0064 ENDIF()
0065 ENDFOREACH()
0066
0067 CHECK_CXX_COMPILER_FLAG("-ftls-model=global-dynamic" CXX_FLAG_WORKS_FTLS_global_dynamic)
0068
0069 if (CXX_FLAG_WORKS_FTLS_global_dynamic)
0070 set ( CMAKE_CXX_FLAGS "-ftls-model=global-dynamic ${CMAKE_CXX_FLAGS} ")
0071 else()
0072 message( FATAL_ERROR "The provided compiler does not support the flag -ftls-model=global-dynamic" )
0073 endif()
0074
0075 find_package(Threads REQUIRED)
0076
0077 if ( THREADS_HAVE_PTHREAD_ARG OR CMAKE_USE_PTHREADS_INIT )
0078 set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
0079 SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
0080 elseif ( CMAKE_THREAD_LIBS_INIT )
0081 SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
0082 else()
0083 # Assume standard gcc and pthreads library
0084 SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
0085 message( STATUS "Unknown thread library: CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}" )
0086 endif()
0087
0088 # resolve which linker we use
0089 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -Wl,--version OUTPUT_VARIABLE stdout ERROR_QUIET)
0090 if("${stdout}" MATCHES "GNU ")
0091 set(LINKER_TYPE "GNU")
0092 dd4hep_debug("|DDD> Detected GNU compatible linker: ${stdout}" )
0093 else()
0094 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -Wl,-v ERROR_VARIABLE stderr )
0095 if(("${stderr}" MATCHES "PROGRAM:ld") AND ("${stderr}" MATCHES "PROJECT:ld64"))
0096 set(LINKER_TYPE "APPLE")
0097 dd4hep_debug("|DDD> Detected Apple linker: ${stderr}" )
0098 else()
0099 set(LINKER_TYPE "unknown")
0100 dd4hep_debug("|DDD> Detected unknown linker: ${stdout} ${stderr}" )
0101 endif()
0102 endif()
0103
0104 if("${LINKER_TYPE}" STREQUAL "APPLE")
0105 SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
0106 elseif("${LINKER_TYPE}" STREQUAL "GNU")
0107 SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined,--as-needed")
0108 else()
0109 MESSAGE( WARNING "No known linker (GNU or Apple) has been detected, pass no flags to linker" )
0110 endif()
0111
0112 #---RPATH options-------------------------------------------------------------------------------
0113 # When building, don't use the install RPATH already (but later on when installing)
0114 set(CMAKE_SKIP_BUILD_RPATH FALSE) # don't skip the full RPATH for the build tree
0115 set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # use always the build RPATH for the build tree
0116 set(CMAKE_MACOSX_RPATH TRUE) # use RPATH for MacOSX
0117 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # point to directories outside the build tree to the install RPATH
0118
0119 # Check whether to add RPATH to the installation (the build tree always has the RPATH enabled)
0120 if(APPLE)
0121 set(CMAKE_INSTALL_NAME_DIR "@rpath")
0122 set(CMAKE_INSTALL_RPATH "@loader_path/../lib") # self relative LIBDIR
0123 # the RPATH to be used when installing, but only if it's not a system directory
0124 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
0125 if("${isSystemDir}" STREQUAL "-1")
0126 set(CMAKE_INSTALL_RPATH "@loader_path/../lib")
0127 endif("${isSystemDir}" STREQUAL "-1")
0128 elseif(DD4HEP_SET_RPATH)
0129 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") # install LIBDIR
0130 # the RPATH to be used when installing, but only if it's not a system directory
0131 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
0132 if("${isSystemDir}" STREQUAL "-1")
0133 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
0134 endif("${isSystemDir}" STREQUAL "-1")
0135 else()
0136 set(CMAKE_SKIP_INSTALL_RPATH TRUE) # skip the full RPATH for the install tree
0137 endif()
0138 endmacro(dd4hep_set_compiler_flags)
0139
0140 #---------------------------------------------------------------------------------------------------
0141 # dd4hep_debug
0142 #
0143 # Print messages if debug flag is enabled
0144 #
0145 # \author M.Frank
0146 # \version 1.0
0147 #
0148 #---------------------------------------------------------------------------------------------------
0149 function ( dd4hep_debug msg )
0150 if(DD4HEP_DEBUG_CMAKE)
0151 get_property(pkg DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY PACKAGE_NAME)
0152 string ( LENGTH "${msg}" lmsg )
0153 if ( ${lmsg} GREATER 1024 )
0154 string ( SUBSTRING "${msg}" 0 132 pmsg )
0155 message( STATUS "D++> [${pkg}] ${pmsg}" )
0156 else()
0157 message( STATUS "D++> [${pkg}] ${msg}" )
0158 endif()
0159 endif()
0160 endfunction( dd4hep_debug )
0161
0162 #---------------------------------------------------------------------------------------------------
0163 # dd4hep_print
0164 #
0165 #
0166 # \author M.Frank
0167 # \version 1.0
0168 #
0169 #---------------------------------------------------------------------------------------------------
0170 function ( dd4hep_print msg )
0171 message ( STATUS ${msg} )
0172 endfunction ( dd4hep_print )
0173
0174 function ( dd4hep_skipmsg msg )
0175 message ( STATUS "SKIPPED !!!!!!!!!!!!!! ${msg}" )
0176 endfunction ( dd4hep_skipmsg )
0177
0178 #---------------------------------------------------------------------------------------------------
0179 # dd4hep_fatal
0180 #
0181 #
0182 # \author M.Frank
0183 # \version 1.0
0184 #
0185 #---------------------------------------------------------------------------------------------------
0186 function ( dd4hep_fatal msg )
0187 get_property(pkg DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY PACKAGE_NAME)
0188 if ( "${pkg}" STREQUAL "" )
0189 message ( FATAL_ERROR "++> ${msg}" )
0190 else()
0191 message ( FATAL_ERROR "++> [${pkg}] ${msg}" )
0192 endif()
0193 endfunction ( dd4hep_fatal )
0194
0195 #---------------------------------------------------------------------------------------------------
0196 # dd4hep_set_version
0197 #
0198 # Set version structure for building the DD4hep software
0199 #
0200 # \author M.Frank
0201 # \version 1.0
0202 #
0203 #---------------------------------------------------------------------------------------------------
0204 function ( dd4hep_set_version packageName )
0205 cmake_parse_arguments ( ARG "" "MAJOR;MINOR;PATCH" "" ${ARGN} )
0206 if ( NOT "${packageName}" STREQUAL "" )
0207 project ( ${packageName} )
0208 else()
0209 dd4hep_fatal ( "${packageName}: !!! Attempt to define a DD4hep project without a name !!!" )
0210 endif()
0211 set ( major ${ARG_MAJOR} )
0212 set ( minor ${ARG_MINOR} )
0213 set ( patch ${ARG_PATCH} )
0214
0215 if ( "${major}" STREQUAL "" )
0216 set ( major ${DD4hep_VERSION_MAJOR} )
0217 endif()
0218 if ( "${minor}" STREQUAL "" )
0219 set ( minor ${DD4hep_VERSION_MINOR} )
0220 endif()
0221 if ( "${patch}" STREQUAL "" )
0222 set ( patch ${DD4hep_VERSION_PATCH} )
0223 endif()
0224
0225 if ( NOT ("${major}" STREQUAL "" OR "${minor}" STREQUAL "" OR "${patch}" STREQUAL "") )
0226 set( ${packageName}_VERSION_MAJOR ${major} PARENT_SCOPE )
0227 set( ${packageName}_VERSION_MINOR ${minor} PARENT_SCOPE )
0228 set( ${packageName}_VERSION_PATCH ${patch} PARENT_SCOPE )
0229 set( ${packageName}_VERSION "${major}.${minor}" PARENT_SCOPE )
0230 set( ${packageName}_SOVERSION "${major}.${minor}" PARENT_SCOPE )
0231 else()
0232 dd4hep_fatal ( "${packageName}: No Package versions specified.....-> ( ${major}.${minor}.${patch} )" )
0233 endif()
0234 endfunction( dd4hep_set_version )
0235
0236 #---------------------------------------------------------------------------------------------------
0237 # dd4hep_print_options
0238 #
0239 # Print the current option setup for informational purposes
0240 #
0241 # \author M.Frank
0242 # \version 1.0
0243 #---------------------------------------------------------------------------------------------------
0244 function ( dd4hep_print_options )
0245 dd4hep_print ( "+-------------------------------------------------------------------------------" )
0246 dd4hep_print ( "| DD4hep build setup: " )
0247 dd4hep_print ( "| " )
0248 dd4hep_print ( "| CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH} " )
0249 dd4hep_print ( "| DD4HEP_USE_XERCESC: ${DD4HEP_USE_XERCESC} " )
0250 dd4hep_print ( "| XERCESC_ROOT_DIR: ${XERCESC_ROOT_DIR} " )
0251 dd4hep_print ( "| DD4HEP_USE_LCIO: ${DD4HEP_USE_LCIO} " )
0252 dd4hep_print ( "| LCIO_DIR: ${LCIO_DIR} " )
0253 dd4hep_print ( "| DD4HEP_USE_EDM4HEP: ${DD4HEP_USE_EDM4HEP} " )
0254 dd4hep_print ( "| EDM4HEP_DIR: ${EDM4HEP_DIR} " )
0255 dd4hep_print ( "| DD4HEP_USE_GEANT4: ${DD4HEP_USE_GEANT4} " )
0256 dd4hep_print ( "| Geant4_DIR: ${Geant4_DIR} " )
0257 dd4hep_print ( "| DD4HEP_USE_PYROOT: ${DD4HEP_USE_PYROOT} " )
0258 dd4hep_print ( "| BUILD_TESTING: ${BUILD_TESTING} " )
0259 dd4hep_print ( "| " )
0260 dd4hep_print ( "+-------------------------------------------------------------------------------" )
0261 endfunction ( dd4hep_print_options )
0262
0263 #---------------------------------------------------------------------------------------------------
0264 # dd4hep_print_cmake_options
0265 #
0266 # usage() like function to be called if bad cmake arguments are supplied....
0267 #
0268 # \author M.Frank
0269 # \version 1.0
0270 #---------------------------------------------------------------------------------------------------
0271 function( dd4hep_print_cmake_options )
0272 cmake_parse_arguments ( ARG "" "ERROR" "OPTIONAL" ${ARGN} )
0273 if ( NOT "${ARG_OPTIONAL}" STREQUAL "" )
0274 dd4hep_print ( "+---------------------------------------------------------------------------+")
0275 foreach ( opt ${ARG_OPTIONAL} )
0276 dd4hep_print ( "| ${opt}" )
0277 endforeach()
0278 endif()
0279 dd4hep_print ( "+--Option name ------Description ----------------------------------Default-+")
0280 dd4hep_print ( "| DD4HEP_USE_XERCESC Enable 'Detector Builders' based on XercesC OFF |")
0281 dd4hep_print ( "| Requires XERCESC_ROOT_DIR to be set |")
0282 dd4hep_print ( "| or XercesC in CMAKE_MODULE_PATH |")
0283 dd4hep_print ( "| DD4HEP_USE_GEANT4 Enable the simulation part based on Geant4 OFF |")
0284 dd4hep_print ( "| Requires Geant_DIR to be set |")
0285 dd4hep_print ( "| or Geant4 in CMAKE_MODULE_PATH |")
0286 dd4hep_print ( "| DD4HEP_USE_LCIO Build lcio extensions OFF |")
0287 dd4hep_print ( "| Requires LCIO_DIR to be set |")
0288 dd4hep_print ( "| or LCIO in CMAKE_MODULE_PATH |")
0289 dd4hep_print ( "| DD4HEP_USE_EDM4HEP Build edm4hep extensions OFF |")
0290 dd4hep_print ( "| Requires EDM4HEP_DIR to be set |")
0291 dd4hep_print ( "| or EDM4HEP in CMAKE_MODULE_PATH |")
0292 dd4hep_print ( "| DD4HEP_USE_GEAR Build gear wrapper for backward compatibility OFF |")
0293 dd4hep_print ( "| BUILD_TESTING Enable and build tests ON |")
0294 dd4hep_print ( "| DD4HEP_USE_PYROOT Enable 'Detector Builders' based on PyROOT OFF |")
0295 dd4hep_print ( "+---------------------------------------------------------------------------+")
0296 if ( NOT "${ARG_ERROR}" STREQUAL "" )
0297 dd4hep_fatal ( "Invalid cmake options supplied!" )
0298 endif()
0299 endfunction( dd4hep_print_cmake_options )
0300
0301 #---------------------------------------------------------------------------------------------------
0302 # dd4hep_configure_output
0303 #
0304 # Setup build and install target directories
0305 #
0306 # \author M.Frank
0307 # \version 1.0
0308 #---------------------------------------------------------------------------------------------------
0309 macro ( dd4hep_configure_output )
0310 cmake_parse_arguments ( ARG "" "OUTPUT;INSTALL" "" ${ARGN} )
0311
0312 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
0313 set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "One of: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
0314 endif()
0315
0316 if ( NOT "${ARG_OUTPUT}" STREQUAL "" )
0317 set ( LIBRARY_OUTPUT_PATH ${ARG_OUTPUT}/lib )
0318 set ( EXECUTABLE_OUTPUT_PATH ${ARG_OUTPUT}/bin )
0319 else()
0320 set ( LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib )
0321 set ( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin )
0322 endif()
0323 #------------- set the default installation directory to be the source directory
0324 dd4hep_debug("|++> dd4hep_configure_output: CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT=${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}" )
0325 if ( NOT "${ARG_INSTALL}" STREQUAL "" )
0326 set ( CMAKE_INSTALL_PREFIX ${ARG_INSTALL} CACHE PATH "Set install prefix path." FORCE )
0327 dd4hep_print( "DD4hep_configure_output: set CMAKE_INSTALL_PREFIX to ${ARG_INSTALL}" )
0328 elseif ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
0329 set( CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR} CACHE PATH
0330 "install prefix path - overwrite with -D CMAKE_INSTALL_PREFIX = ..." FORCE )
0331 dd4hep_print ( "|++> dd4hep_configure_output: CMAKE_INSTALL_PREFIX is ${CMAKE_INSTALL_PREFIX} - overwrite with -D CMAKE_INSTALL_PREFIX" )
0332 elseif ( CMAKE_INSTALL_PREFIX )
0333 dd4hep_print( "|++> dd4hep_configure_output: set CMAKE_INSTALL_PREFIX to ${CMAKE_INSTALL_PREFIX}" )
0334 set ( CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} )
0335 endif()
0336 dd4hep_debug("|++> Installation goes to: ${CMAKE_INSTALL_PREFIX} <${ARG_INSTALL}>" )
0337 endmacro ( dd4hep_configure_output )
0338
0339 #---------------------------------------------------------------------------------------------------
0340 # dd4hep_list_to_string
0341 #
0342 # Create proper string from list
0343 #
0344 # \author M.Frank
0345 # \version 1.0
0346 #---------------------------------------------------------------------------------------------------
0347 function ( dd4hep_list_to_string result )
0348 cmake_parse_arguments(ARG "" "PREFIX" "ENTRIES" ${ARGV} )
0349 set ( vals "" )
0350 foreach( v ${ARG_ENTRIES} )
0351 set ( vals "${vals} ${v}" )
0352 endforeach()
0353 if ( NOT "${vals}" STREQUAL "" )
0354 set ( vals "${ARG_PREFIX}${vals}" )
0355 endif()
0356 set ( ${result} "${vals}" PARENT_SCOPE )
0357 endfunction ( dd4hep_list_to_string )
0358
0359 #---------------------------------------------------------------------------------------------------
0360 #---------------------------------------------------------------------------------------------------
0361 # dd4hep_install_dir: DEPRECATED, used in examples
0362 #
0363 # Install all directories as indicated by all unparsed arguments to the
0364 # output destination DESTINATION.
0365 #
0366 # \author M.Frank
0367 # \version 1.0
0368 #
0369 #---------------------------------------------------------------------------------------------------
0370 function( dd4hep_install_dir )
0371 cmake_parse_arguments ( ARG "" "DESTINATION" "" ${ARGN} )
0372 if( NOT "${ARG_UNPARSED_ARGUMENTS}" STREQUAL "" )
0373 foreach ( d ${ARG_UNPARSED_ARGUMENTS} )
0374 install ( DIRECTORY ${d}
0375 DESTINATION ${ARG_DESTINATION}
0376 PATTERN ".svn" EXCLUDE )
0377 endforeach()
0378 endif()
0379 endfunction( dd4hep_install_dir )
0380
0381 #---------------------------------------------------------------------------------------------------
0382 #
0383 # \author M.Frank
0384 # \version 1.0
0385 #
0386 #---------------------------------------------------------------------------------------------------
0387 macro( dd4hep_enable_tests )
0388 cmake_parse_arguments(MACRO_ARG "" "" "" ${ARGV} )
0389 if (BUILD_TESTING)
0390 set ( BUILDNAME "${CMAKE_SYSTEM}-${CMAKE_CXX_COMPILER}-${CMAKE_BUILD_TYPE}" CACHE STRING "set build string for cdash")
0391 dd4hep_list_to_string( _dir_entries PREFIX "DIRS:" ENTRIES ${MACRO_ARG_UNPARSED_ARGUMENTS} )
0392 dd4hep_print ( "|++> Enable CTest environment....BUILD:${BUILD_TESTING} ${_dir_entries}" )
0393 include(CTest)
0394 enable_testing ()
0395 if ( NOT "${MACRO_ARG_UNPARSED_ARGUMENTS}" STREQUAL "" )
0396 foreach ( _dir ${MACRO_ARG_UNPARSED_ARGUMENTS} )
0397 add_subdirectory ( ${_dir} )
0398 endforeach()
0399 endif()
0400 endif()
0401 endmacro( dd4hep_enable_tests )
0402
0403 #---------------------------------------------------------------------------------------------------
0404 macro ( dd4hep_configure_scripts _pkg )
0405 cmake_parse_arguments(MACRO_ARG "DEFAULT_SETUP;WITH_TESTS" "RUN_SCRIPT" "" ${ARGV} )
0406 # PackageName is a variable required by existing LC build scripts.
0407 # Set it here and unset it at the end of the scope...
0408 set( PackageName ${_pkg} )
0409 dd4hep_list_to_string( _dir_entries PREFIX "DIRS:" ENTRIES ${MACRO_ARG_UNPARSED_ARGUMENTS} )
0410 dd4hep_print ( "|++> Setting up test environment for ${PackageName}: Testing:${BUILD_TESTING} Setup:${MACRO_ARG_DEFAULT_SETUP} With Tests(${MACRO_ARG_WITH_TESTS}): ${_dir_entries}" )
0411 if ( (NOT "${MACRO_ARG_DEFAULT_SETUP}" STREQUAL "") OR (NOT "${_pkg}" STREQUAL "") )
0412 configure_file( ${DD4hep_DIR}/cmake/run_test_package.sh ${EXECUTABLE_OUTPUT_PATH}/run_test_${_pkg}.sh @ONLY)
0413 INSTALL(PROGRAMS ${EXECUTABLE_OUTPUT_PATH}/run_test_${_pkg}.sh DESTINATION bin )
0414 #---- configure run environment ---------------
0415 configure_file( ${DD4hep_DIR}/cmake/thisdd4hep_package.sh.in ${EXECUTABLE_OUTPUT_PATH}/this${_pkg}.sh @ONLY)
0416 install(PROGRAMS ${EXECUTABLE_OUTPUT_PATH}/this${_pkg}.sh DESTINATION bin )
0417 #--- install target-------------------------------------
0418 if ( IS_DIRECTORY scripts )
0419 dd4hep_install_dir ( compact scripts DESTINATION examples/${_pkg} )
0420 endif()
0421 if ( IS_DIRECTORY compact )
0422 dd4hep_install_dir ( compact DESTINATION examples/${_pkg} )
0423 endif()
0424 endif()
0425 dd4hep_enable_tests ( ${MACRO_ARG_UPARSED_ARGUMENTS} )
0426 unset( PackageName )
0427 endmacro( dd4hep_configure_scripts )
0428
0429 #---------------------------------------------------------------------------------------------------
0430 # dd4hep_add_test_reg
0431 #
0432 # Add test with regular expression output parsing.
0433 # OUTPUT Output file of the test (Default: empty)
0434 # COMMAND Command to execute
0435 # EXEC_ARGS Arguments to the command
0436 # REGEX_PASS Regular expression to indicate that the test succeeded
0437 # REGEX_FAIL Regular expression to indicate that the test failed
0438 #
0439 # \author M.Frank
0440 # \version 1.0
0441 #
0442 #---------------------------------------------------------------------------------------------------
0443 function ( dd4hep_add_test_reg test_name )
0444 cmake_parse_arguments(ARG "" "OUTPUT" "COMMAND;DEPENDS;EXEC_ARGS;REGEX_PASS;REGEX_PASSED;REGEX_FAIL;REGEX_FAILED" ${ARGN} )
0445 set ( missing )
0446 set ( use_test 1 )
0447
0448 if ( "${use_test}" STREQUAL "" )
0449 dd4hep_print ( "*** Will not build/execute test ${test_name}. Missing dependencies: ${missing} ")
0450 else()
0451
0452 set ( cmd ${ARG_COMMAND} )
0453 if ( "${cmd}" STREQUAL "" )
0454 set ( cmd ${CMAKE_INSTALL_PREFIX}/bin/run_test.sh ${test_name} )
0455 endif()
0456
0457 set ( passed ${ARG_REGEX_PASS} ${ARG_REGEX_PASSED} )
0458 if ( "${passed}" STREQUAL "NONE" )
0459 unset ( passed )
0460 elseif ( "${passed}" STREQUAL "" )
0461 set ( passed "TEST_PASSED" )
0462 endif()
0463
0464 set ( failed ${ARG_REGEX_FAIL} ${ARG_REGEX_FAILED} )
0465 if ( "${failed}" STREQUAL "NONE" )
0466 unset ( failed )
0467 endif()
0468 set ( output ${ARG_OUTPUT} )
0469
0470 set ( args ${ARG_EXEC_ARGS} )
0471 if ( "${args}" STREQUAL "" )
0472 set ( args ${test_name} )
0473 endif()
0474 add_test(NAME t_${test_name} COMMAND ${cmd} ${output} ${args} ${output} )
0475 if ( NOT "${passed}" STREQUAL "" )
0476 set_tests_properties( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "${passed}" )
0477 endif()
0478 if ( NOT "${failed}" STREQUAL "" )
0479 set_tests_properties( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "${failed}" )
0480 endif()
0481 # Set test dependencies if present
0482 foreach ( _dep ${ARG_DEPENDS} )
0483 set_property( TEST t_${test_name} APPEND PROPERTY DEPENDS t_${_dep} )
0484 endforeach()
0485 endif()
0486 endfunction()
0487
0488 #---------------------------------------------------------------------------------------------------
0489 # fill_dd4hep_library_path
0490 #
0491 #
0492 # \author M.Petric
0493 # \version 1.0
0494 #
0495 #---------------------------------------------------------------------------------------------------
0496 function ( fill_dd4hep_library_path )
0497 string(REGEX REPLACE "/lib/libCore.*" "" ROOT_ROOT ${ROOT_Core_LIBRARY})
0498 SET( ENV{DD4HEP_LIBRARY_PATH} ${ROOT_ROOT}/lib )
0499 if ( NOT "${Boost_LIBRARY_DIRS}" STREQUAL "" )
0500 SET( ENV{DD4HEP_LIBRARY_PATH} $ENV{DD4HEP_LIBRARY_PATH}:${Boost_LIBRARY_DIRS} )
0501 else()
0502 dd4hep_print("|++> The boost library path cannot be determined. Problems maybe ahead.")
0503 endif()
0504 if ( ${DD4HEP_USE_GEANT4} )
0505 string(REGEX REPLACE "/lib/Geant4.*" "" Geant4_ROOT ${Geant4_DIR})
0506 SET( ENV{DD4HEP_LIBRARY_PATH} ${Geant4_ROOT}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0507 endif()
0508
0509 if(${DD4HEP_USE_LCIO})
0510 SET( ENV{DD4HEP_LIBRARY_PATH} ${LCIO_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0511 endif()
0512
0513 if(${DD4HEP_USE_EDM4HEP})
0514 SET( ENV{DD4HEP_LIBRARY_PATH} ${EDM4HEP_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0515 endif()
0516
0517 SET( ENV{DD4HEP_LIBRARY_PATH} ${CLHEP_ROOT_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0518
0519 if(${DD4HEP_USE_XERCESC})
0520 SET( ENV{DD4HEP_LIBRARY_PATH} ${XERCESC_ROOT_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0521 endif()
0522
0523 SET( ENV{DD4HEP_LIBRARY_PATH} ${CMAKE_BINARY_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0524 endfunction()
0525
0526
0527 #---------------------------------------------------------------------------------------------------
0528 # dd4hep_add_dictionary
0529 #
0530 # Arguments
0531 # ---------
0532 # dictionary -> dictionary name
0533 # SOURCES -> Globbing expression to find source files
0534 # EXCLUDE -> Files to exclude if they are found via SOURCES
0535 # LINKDEF -> Last entry when calling rootcling
0536 # USES -> Libraries needed to link the binary
0537 #
0538 # OPTIONS -> Options to pass to rootcling
0539 # INCLUDES -> Additional include directories need to compile the binary
0540 # DEFINITIONS -> Additional compiler definitions to compile the sources
0541 # OUTPUT ->
0542 #
0543 # USE_COMMAND_TO_GENERATE -> Go back to previous way of generating dictionary without creating temporary files
0544 #
0545 # \author A.Sailer
0546 # \version 1.0
0547 #
0548 #---------------------------------------------------------------------------------------------------
0549 function(dd4hep_add_dictionary dictionary )
0550 cmake_parse_arguments(ARG "USE_COMMAND_TO_GENERATE" "" "SOURCES;EXCLUDE;LINKDEF;OPTIONS;USES;DEFINITIONS;INCLUDES;OUTPUT" ${ARGN} )
0551 dd4hep_print ( "|++++> Building dictionary ... ${dictionary}" )
0552
0553 file(GLOB headers ${ARG_SOURCES})
0554 file(GLOB excl_headers ${ARG_EXCLUDE})
0555
0556 foreach( f ${excl_headers} )
0557 list( REMOVE_ITEM headers ${f} )
0558 dd4hep_debug ( "|++ exclude: ${f}" )
0559 endforeach()
0560
0561 foreach( f ${headers} )
0562 dd4hep_debug ( "|++ ${dictionary} is using: ${f}" )
0563 endforeach()
0564
0565 set(inc_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include)
0566 foreach(inc ${ARG_INCLUDES})
0567 LIST(APPEND inc_dirs ${inc})
0568 endforeach()
0569
0570 set(comp_defs)
0571 foreach(def ${ARG_DEFINITIONS})
0572 LIST(APPEND comp_defs ${def})
0573 endforeach()
0574
0575 foreach(DEP ${ARG_USES})
0576 # Get INCLUDE DIRECTORIES from Dependencies
0577 LIST(APPEND inc_dirs $<TARGET_PROPERTY:${DEP},INTERFACE_INCLUDE_DIRECTORIES>)
0578 # Get COMPILE DEFINITIONS from Dependencies
0579 LIST(APPEND comp_defs $<TARGET_PROPERTY:${DEP},INTERFACE_COMPILE_DEFINITIONS>)
0580 endforeach()
0581
0582 #
0583 file ( GLOB linkdefs ${ARG_LINKDEF} )
0584 #
0585 dd4hep_debug("|++ Linkdef: '${linkdefs}'" )
0586 dd4hep_debug("|++ Definition: '${comp_defs}'" )
0587 dd4hep_debug("|++ Include: '${inc_dirs}'" )
0588 dd4hep_debug("|++ Files: '${headers}'" )
0589 dd4hep_debug("|++ Unparsed: '${ARG_UNPARSED_ARGUMENTS}'" )
0590 dd4hep_debug("|++ Sources: '${CMAKE_CURRENT_SOURCE_DIR}'" )
0591 #
0592 set ( output_dir ${CMAKE_CURRENT_BINARY_DIR}/../lib )
0593 if ( NOT "${ARG_OUTPUT}" STREQUAL "" )
0594 set ( output_dir ${ARG_OUTPUT} )
0595 endif()
0596 EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${output_dir})
0597
0598 add_custom_target(${dictionary}
0599 DEPENDS ${dictionary}.cxx ${output_dir}/${dictionary}_rdict.pcm ${headers} ${linkdefs}
0600 )
0601 if(NOT ARG_USE_COMMAND_TO_GENERATE)
0602 file(GENERATE OUTPUT create_${dictionary}_$<CONFIG>$<COMPILE_LANGUAGE>.sh
0603 CONTENT "${ROOT_rootcling_CMD} -f ${dictionary}.cxx -s ${output_dir}/${dictionary} -inlineInputHeader ${ARG_OPTIONS} $<$<BOOL:$<JOIN:${comp_defs},>>:-D$<JOIN:$<REMOVE_DUPLICATES:${comp_defs}>,;-D>> $<$<BOOL:$<JOIN:${inc_dirs},>>:-I$<JOIN:$<REMOVE_DUPLICATES:${inc_dirs}>,;-I>> $<JOIN:${headers},;> $<JOIN:${linkdefs},;>"
0604 )
0605 add_custom_command(OUTPUT fixed_create_${dictionary}_$<CONFIG>CXX.sh
0606 COMMAND sed "s/\;/ /g" create_${dictionary}_$<CONFIG>CXX.sh > fixed_create_${dictionary}_$<CONFIG>CXX.sh
0607 DEPENDS create_${dictionary}_$<CONFIG>CXX.sh
0608 )
0609 add_custom_command(OUTPUT ${dictionary}.cxx ${output_dir}/${dictionary}_rdict.pcm
0610 COMMAND /bin/sh fixed_create_${dictionary}_$<CONFIG>CXX.sh
0611 DEPENDS fixed_create_${dictionary}_$<CONFIG>CXX.sh ${headers} ${linkdefs}
0612 )
0613 else()
0614 add_custom_command(OUTPUT ${dictionary}.cxx ${output_dir}/${dictionary}_rdict.pcm
0615 COMMAND ${ROOT_rootcling_CMD}
0616 ARGS -f ${dictionary}.cxx -s ${output_dir}/${dictionary} -inlineInputHeader
0617 ${ARG_OPTIONS}
0618 "$<$<BOOL:$<JOIN:${comp_defs},>>:-D$<JOIN:$<REMOVE_DUPLICATES:${comp_defs}>,;-D>>"
0619 "$<$<BOOL:$<JOIN:${inc_dirs},>>:-I$<JOIN:$<REMOVE_DUPLICATES:${inc_dirs}>,;-I>>"
0620 "$<JOIN:${headers},;>" "$<JOIN:${linkdefs},;>"
0621
0622 DEPENDS ${headers} ${linkdefs}
0623 COMMAND_EXPAND_LISTS
0624 )
0625 endif()
0626 set_source_files_properties(${dictionary}.cxx ${output_dir}/${dictionary}_rdict.pcm
0627 PROPERTIES
0628 GENERATED TRUE
0629 COMPILE_FLAGS "-Wno-unused-function -Wno-overlength-strings"
0630 )
0631
0632 # Install the binary to the destination directory
0633 install(FILES ${output_dir}/${dictionary}_rdict.pcm DESTINATION lib)
0634
0635 endfunction()
0636
0637
0638 #---------------------------------------------------------------------------------------------------
0639 #
0640 # dd4hep_add_plugin
0641 #
0642 # Arguments
0643 # ---------
0644 # binary -> plugin name
0645 # SOURCES -> Globbing expression to find source files
0646 # GENERATED -> List of source files
0647 # USES -> Libraries needed to link the binary
0648 #
0649 # INCLUDES -> Additional include directories need to compile the binary
0650 # DEFINITIONS -> Optional compiler definitions to compile the sources
0651 # NOINSTALL -> If set do not install the plugin
0652 # \author A.Sailer
0653 # \version 1.0
0654 #
0655 #---------------------------------------------------------------------------------------------------
0656 function(dd4hep_add_plugin binary)
0657 cmake_parse_arguments(ARG "NOINSTALL" "" "SOURCES;GENERATED;USES;INCLUDES;DEFINITIONS" ${ARGN})
0658 if ( ${ARG_NOINSTALL} )
0659 set(NOINSTALL NOINSTALL)
0660 endif()
0661 file(GLOB SOURCES ${ARG_SOURCES})
0662 dd4hep_print("|++> Building Plugin: ${binary}")
0663 dd4hep_debug("|++++> SOURCES ${SOURCES}")
0664 dd4hep_debug("|++++> USES ${ARG_USES}")
0665 dd4hep_debug("|++++> INCLUDES ${ARG_INCLUDES}")
0666 dd4hep_debug("|++++> DEFINITIONS ${ARG_DEFINITIONS}")
0667 IF(NOT DEFINED BUILD_SHARED_LIBS)
0668 SET(STATIC_OR_SHARED SHARED)
0669 ENDIF()
0670 add_library(${binary} ${STATIC_OR_SHARED} ${SOURCES} ${ARG_GENERATED})
0671 target_link_libraries(${binary} PUBLIC ${ARG_USES})
0672 target_include_directories(${binary} PUBLIC ${ARG_INCLUDES})
0673 target_compile_definitions(${binary} PUBLIC ${ARG_DEFINITIONS})
0674 IF(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
0675 dd4hep_generate_rootmap(${binary})
0676 ENDIF()
0677 if(NOT ${ARG_NOINSTALL})
0678 set(install_destination "lib")
0679 if(CMAKE_INSTALL_LIBDIR)
0680 set(install_destination ${CMAKE_INSTALL_LIBDIR})
0681 endif()
0682 install(TARGETS ${binary}
0683 ARCHIVE DESTINATION ${install_destination}
0684 LIBRARY DESTINATION ${install_destination}
0685 )
0686 endif()
0687 endfunction(dd4hep_add_plugin)
0688
0689
0690 #
0691 # Macro to set up ROOT:: targets so that we can use the same code for root 6.8 and for root 6.10 and beyond
0692 # This is called in dd4hep, and in DD4hepConfig
0693 #
0694 macro(DD4HEP_SETUP_ROOT_TARGETS)
0695
0696 #Check if Python version detected matches the version used to build ROOT
0697 SET(Python_FIND_FRAMEWORK LAST)
0698 IF((TARGET ROOT::PyROOT OR TARGET ROOT::ROOTTPython) AND ${ROOT_VERSION} VERSION_GREATER_EQUAL 6.19)
0699 # some cmake versions don't include python patch level in PYTHON_VERSION
0700 IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0 AND CMAKE_VERSION VERSION_LESS_EQUAL 3.17.2)
0701 string(REGEX MATCH [23]\\.[0-9]+ REQUIRE_PYTHON_VERSION ${ROOT_PYTHON_VERSION})
0702 ELSE()
0703 SET(REQUIRE_PYTHON_VERSION ${ROOT_PYTHON_VERSION})
0704 ENDIF()
0705 dd4hep_debug("D++> Python version used for building ROOT ${ROOT_PYTHON_VERSION}" )
0706 if (NOT DD4HEP_RELAX_PYVER)
0707 dd4hep_debug("D++> Required python version ${REQUIRE_PYTHON_VERSION}")
0708 FIND_PACKAGE(Python ${REQUIRE_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Development)
0709 FIND_PACKAGE(Python ${REQUIRE_PYTHON_VERSION} EXACT QUIET COMPONENTS Interpreter)
0710 else()
0711 FIND_PACKAGE(Python REQUIRED COMPONENTS Development)
0712 FIND_PACKAGE(Python QUIET COMPONENTS Interpreter)
0713 dd4hep_debug("D++> Found python version ${Python_VERSION}")
0714 string(REPLACE "." ";" _root_pyver_tuple ${REQUIRE_PYTHON_VERSION})
0715 list(GET _root_pyver_tuple 0 _root_pyver_major)
0716 list(GET _root_pyver_tuple 1 _root_pyver_minor)
0717 if (NOT "${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}" VERSION_EQUAL "${_root_pyver_major}.${_root_pyver_minor}")
0718 dd4hep_print("WARNING: Mismatch in Python version: ${Python_VERSION} vs. ${REQUIRE_PYTHON_VERSION}")
0719 dd4hep_print(" ABI compatibility should not be assumed!")
0720 endif()
0721 endif()
0722 ELSE()
0723 FIND_PACKAGE(Python COMPONENTS Development)
0724 FIND_PACKAGE(Python QUIET COMPONENTS Interpreter)
0725 ENDIF()
0726 IF("${Python_EXECUTABLE}" STREQUAL "")
0727 set (Python_EXECUTABLE python${Python_VERSION_MAJOR})
0728 ENDIF()
0729 dd4hep_print("|++> Using python executable: ${Python_EXECUTABLE}")
0730
0731 SET(DD4HEP_PYTHON_INSTALL_DIR lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages)
0732
0733 #ROOT CXX Flags are a string with quotes, not a list, so we need to convert to a list...
0734 string(REPLACE " " ";" DD4HEP_ROOT_CXX_FLAGS ${ROOT_CXX_FLAGS})
0735
0736 IF(NOT TARGET ROOT::Core)
0737 #in ROOT before 6.10 there is no ROOT namespace, so we create ROOT::Core ourselves
0738 ADD_LIBRARY(ROOT::Core INTERFACE IMPORTED GLOBAL)
0739 SET_TARGET_PROPERTIES(ROOT::Core
0740 PROPERTIES
0741 INTERFACE_COMPILE_OPTIONS "${DD4HEP_ROOT_CXX_FLAGS}"
0742 INTERFACE_INCLUDE_DIRECTORIES ${ROOT_INCLUDE_DIRS}
0743 )
0744 # there is also no dependency between the targets
0745 TARGET_LINK_LIBRARIES(ROOT::Core INTERFACE Core)
0746 # we list here the targets we use in dd4hep, as later versions of root have the namespace, we do not have to to this
0747 # for ever
0748 foreach(LIB PyROOT Geom GenVector Eve Graf3d RGL Gui RIO MathCore MathMore EG EGL Rint Tree Hist Physics Gdml)
0749 IF(TARGET ${LIB})
0750 ADD_LIBRARY(ROOT::${LIB} INTERFACE IMPORTED GLOBAL)
0751 TARGET_LINK_LIBRARIES(ROOT::${LIB} INTERFACE ${LIB} ROOT::Core)
0752 ENDIF()
0753 endforeach()
0754 ELSEIF(${ROOT_VERSION} VERSION_GREATER_EQUAL 6.12 AND ${ROOT_VERSION} VERSION_LESS 6.14)
0755 # Root 6.12 exports ROOT::Core, but does not assign include directories to the target
0756 SET_TARGET_PROPERTIES(ROOT::Core
0757 PROPERTIES
0758 INTERFACE_COMPILE_OPTIONS "${DD4HEP_ROOT_CXX_FLAGS}"
0759 INTERFACE_INCLUDE_DIRECTORIES ${ROOT_INCLUDE_DIRS}
0760 )
0761
0762 ENDIF()
0763
0764 dd4hep_debug("ROOT Libraries ${ROOT_LIBRARIES}")
0765 dd4hep_debug("ROOT CXX_FLAGS ${DD4HEP_ROOT_CXX_FLAGS}")
0766 dd4hep_debug("ROOT INCL DIRS ${ROOT_INCLUDE_DIRS}")
0767 dd4hep_debug("ROOT_VERSION: ${ROOT_VERSION}" )
0768
0769 ENDMACRO()
0770
0771 #
0772 # Do some processing of the imported Boost Targets
0773 # Some libraries are only needed for cxx std 14
0774 # we also have to make sure the boost library location is known in that case
0775 #
0776 #
0777
0778 MACRO(DD4HEP_SETUP_BOOST_TARGETS)
0779
0780 SET_TARGET_PROPERTIES(Boost::boost
0781 PROPERTIES
0782 INTERFACE_COMPILE_DEFINITIONS BOOST_SPIRIT_USE_PHOENIX_V3
0783 )
0784
0785 # Try to compile with filesystem header linking against different FS libraries
0786 SET(HAVE_FILESYSTEM False)
0787 dd4hep_debug("|++> Checking if compiler supports filesystem library")
0788 # stdc++fs needed in gcc8, no lib for gcc9.1, c++fs for llvm
0789 FOREACH(FS_LIB_NAME stdc++fs "" c++fs )
0790 dd4hep_debug("|++++> linking against ${FS_LIB_NAME}")
0791 try_compile(HAVE_FILESYSTEM ${CMAKE_BINARY_DIR}/try ${DD4hep_DIR}/cmake/TryFileSystem.cpp
0792 CXX_STANDARD ${CMAKE_CXX_STANDARD}
0793 CXX_EXTENSIONS False
0794 OUTPUT_VARIABLE HAVE_FS_OUTPUT
0795 LINK_LIBRARIES ${FS_LIB_NAME}
0796 )
0797 dd4hep_debug("|++++> ${HAVE_FS_OUTPUT}")
0798 IF(HAVE_FILESYSTEM)
0799 dd4hep_print("|++> Compiler supports filesystem when linking against ${FS_LIB_NAME}")
0800 SET(FS_LIBRARIES ${FS_LIB_NAME})
0801 BREAK()
0802 ENDIF()
0803 dd4hep_debug("|++++> Compiler not compatible when linking against ${FS_LIB_NAME}")
0804 ENDFOREACH()
0805
0806 IF(NOT HAVE_FILESYSTEM)
0807 dd4hep_print("|++> Compiler does not have filesystem support, falling back to Boost::filesystem")
0808 FIND_PACKAGE(Boost 1.56 REQUIRED COMPONENTS filesystem system)
0809 SET(FS_LIBRARIES Boost::filesystem Boost::system)
0810 SET_TARGET_PROPERTIES(Boost::filesystem
0811 PROPERTIES
0812 INTERFACE_COMPILE_DEFINITIONS USE_BOOST_FILESYSTEM
0813 )
0814 GET_TARGET_PROPERTY(BOOST_FILESYSTEM_LOC Boost::filesystem IMPORTED_LOCATION)
0815 GET_FILENAME_COMPONENT(BOOST_DIR ${BOOST_FILESYSTEM_LOC} DIRECTORY)
0816 ENDIF()
0817
0818
0819 ENDMACRO()
0820
0821 #
0822 # Do some processing of the imported Geant4 Targets, CLHEP treatment etc.
0823 # Will only be done once, repeated calls should have no effect
0824 #
0825 MACRO(DD4HEP_SETUP_GEANT4_TARGETS)
0826
0827 # only do this once
0828 IF(NOT TARGET Geant4::Interface)
0829
0830 #include( ${Geant4_USE_FILE} ) # do not use the use file, this is not very considerate...
0831 IF((NOT ${Geant4_TLS_MODEL} STREQUAL "global-dynamic") AND NOT ${DD4HEP_IGNORE_GEANT4_TLS})
0832 MESSAGE(FATAL_ERROR "Geant4 was built with ${Geant4_TLS_MODEL}, DD4hep requires 'global-dynamic'! Ignore this ERROR with DD4HEP_IGNORE_GEANT4_TLS=True ")
0833 ENDIF()
0834
0835 if(Geant4_builtin_clhep_FOUND)
0836 dd4hep_debug("Using Geant4 internal CLHEP")
0837 if(TARGET CLHEP::CLHEP)
0838 message(WARNING "CLHEP::CLHEP already exists, this may cause problems if there are two different installations of CLHEP, one from Geant4 and one external")
0839 else()
0840 ADD_LIBRARY(CLHEP::CLHEP INTERFACE IMPORTED GLOBAL)
0841 endif()
0842 SET_TARGET_PROPERTIES(CLHEP::CLHEP
0843 PROPERTIES
0844 INTERFACE_INCLUDE_DIRECTORIES "${Geant4_INCLUDE_DIRS}"
0845 )
0846 if(TARGET Geant4::G4clhep)
0847 TARGET_LINK_LIBRARIES(CLHEP::CLHEP INTERFACE Geant4::G4clhep)
0848 else()
0849 TARGET_LINK_LIBRARIES(CLHEP::CLHEP INTERFACE G4clhep)
0850 endif()
0851
0852 else()
0853 IF(NOT TARGET CLHEP::CLHEP)
0854 FIND_PACKAGE(CLHEP REQUIRED CONFIG)
0855 ENDIF()
0856 set(CLHEP CLHEP::CLHEP)
0857 dd4hep_debug("Using External CLHEP")
0858 dd4hep_debug("CLHEP Libraries ${CLHEP_LIBRARIES}")
0859 dd4hep_debug("CLHEP CXX_FLAGS ${CLHEP_CXX_FLAGS}")
0860 dd4hep_debug("CLHEP INCL DIRS ${CLHEP_INCLUDE_DIRS}")
0861 dd4hep_debug("CLHEP_VERSION: ${CLHEP_VERSION}" )
0862 endif()
0863
0864 dd4hep_debug("Geant4 Libraries ${Geant4_LIBRARIES}")
0865 dd4hep_debug("Geant4 CXX_FLAGS ${Geant4_CXX_FLAGS}")
0866 dd4hep_debug("Geant4 INCL DIRS ${Geant4_INCLUDE_DIRS}")
0867 dd4hep_debug("Geant4_VERSION: ${Geant4_VERSION}" )
0868
0869 # Geant4 CXX Flags are a string with quotes, not a list, so we need to convert to a list...
0870 # Geant4::10.2.2 at least, not in 10.5 (check where it switches)
0871 string(REPLACE " " ";" Geant4_Flags ${Geant4_CXX_FLAGS} ${Geant4_CXX_FLAGS_${CMAKE_BUILD_TYPE}})
0872
0873 #Geant4_DEFINITIONS already include -D, we have to get rid of that so we can join things when creating dictionaries
0874 SET(G4_DEF_TEMP "")
0875 foreach(def ${Geant4_DEFINITIONS})
0876 string(REPLACE "-D" "" def ${def})
0877 LIST(APPEND G4_DEF_TEMP ${def})
0878 endforeach()
0879 SET(DD4HEP_Geant4_DEFINITIONS ${G4_DEF_TEMP})
0880 UNSET(G4_DEF_TEMP)
0881
0882 ADD_LIBRARY(Geant4::Interface INTERFACE IMPORTED GLOBAL)
0883
0884 SET_TARGET_PROPERTIES(Geant4::Interface
0885 PROPERTIES
0886 INTERFACE_COMPILE_OPTIONS "${Geant4_Flags}"
0887 INTERFACE_COMPILE_DEFINITIONS "${DD4HEP_Geant4_DEFINITIONS}"
0888 INTERFACE_INCLUDE_DIRECTORIES "${Geant4_INCLUDE_DIRS}"
0889 )
0890
0891 IF(CLHEP)
0892 dd4hep_debug("Adding CLHEP to Geant4::Interface Dependencies")
0893 TARGET_LINK_LIBRARIES(Geant4::Interface INTERFACE ${CLHEP})
0894 ENDIF()
0895
0896 # Geant4_LIBRARIES are imported targets, we just add them all to our own interface library for convenience
0897 # Geant4 Libraries do not (yet) use a namespace
0898 foreach(LIB ${Geant4_LIBRARIES})
0899 TARGET_LINK_LIBRARIES(Geant4::Interface INTERFACE ${LIB})
0900 endforeach()
0901
0902 dd4hep_debug("Geant4 Libraries ${Geant4_LIBRARIES};${Geant4_COMPONENT_LIBRARIES}")
0903 dd4hep_debug("Geant4 Location ${Geant4_LOCATION}")
0904 dd4hep_debug("Geant4 Defintitions ${Geant4_DEFINITIONS}")
0905 dd4hep_debug("Geant4 CXX_FLAGS ${Geant4_CXX_FLAGS}")
0906 dd4hep_debug("Geant4 INCL DIRS ${Geant4_INCLUDE_DIRS}")
0907 dd4hep_debug("Geant4_VERSION: ${Geant4_VERSION}" )
0908
0909 ENDIF()
0910 ENDMACRO()
0911
0912 #
0913 # Create Interface library for LCIO
0914 #
0915 MACRO(DD4HEP_SETUP_LCIO_TARGETS)
0916 IF(NOT TARGET LCIO::lcio)
0917 ADD_LIBRARY(LCIO::lcio INTERFACE IMPORTED GLOBAL)
0918 SET_TARGET_PROPERTIES(LCIO::lcio
0919 PROPERTIES
0920 INTERFACE_INCLUDE_DIRECTORIES "${LCIO_INCLUDE_DIRS}"
0921 INTERFACE_LINK_LIBRARIES "${LCIO_LIBRARIES}"
0922 )
0923 ENDIF()
0924 ENDMACRO()