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} LANGUAGES CXX )
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 set(DD4HEP_INSTALL_LIBDIR lib)
0416 if(CMAKE_INSTALL_LIBDIR)
0417 set(DD4HEP_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
0418 endif()
0419 configure_file( ${DD4hep_DIR}/cmake/thisdd4hep_package.sh.in ${EXECUTABLE_OUTPUT_PATH}/this${_pkg}.sh @ONLY)
0420 unset(DD4HEP_INSTALL_LIBDIR)
0421 install(PROGRAMS ${EXECUTABLE_OUTPUT_PATH}/this${_pkg}.sh DESTINATION bin )
0422 #--- install target-------------------------------------
0423 if ( IS_DIRECTORY scripts )
0424 dd4hep_install_dir ( compact scripts DESTINATION examples/${_pkg} )
0425 endif()
0426 if ( IS_DIRECTORY compact )
0427 dd4hep_install_dir ( compact DESTINATION examples/${_pkg} )
0428 endif()
0429 endif()
0430 dd4hep_enable_tests ( ${MACRO_ARG_UPARSED_ARGUMENTS} )
0431 unset( PackageName )
0432 endmacro( dd4hep_configure_scripts )
0433
0434 #---------------------------------------------------------------------------------------------------
0435 # dd4hep_add_test_reg
0436 #
0437 # Add test with regular expression output parsing.
0438 # OUTPUT Output file of the test (Default: empty)
0439 # COMMAND Command to execute
0440 # EXEC_ARGS Arguments to the command
0441 # REGEX_PASS Regular expression to indicate that the test succeeded
0442 # REGEX_FAIL Regular expression to indicate that the test failed
0443 #
0444 # \author M.Frank
0445 # \version 1.0
0446 #
0447 #---------------------------------------------------------------------------------------------------
0448 function ( dd4hep_add_test_reg test_name )
0449 cmake_parse_arguments(ARG "" "OUTPUT" "COMMAND;DEPENDS;EXEC_ARGS;REGEX_PASS;REGEX_PASSED;REGEX_FAIL;REGEX_FAILED" ${ARGN} )
0450 set ( missing )
0451 set ( use_test 1 )
0452
0453 if ( "${use_test}" STREQUAL "" )
0454 dd4hep_print ( "*** Will not build/execute test ${test_name}. Missing dependencies: ${missing} ")
0455 else()
0456
0457 set ( cmd ${ARG_COMMAND} )
0458 if ( "${cmd}" STREQUAL "" )
0459 set ( cmd ${CMAKE_INSTALL_PREFIX}/bin/run_test.sh ${test_name} )
0460 endif()
0461
0462 set ( passed ${ARG_REGEX_PASS} ${ARG_REGEX_PASSED} )
0463 if ( "${passed}" STREQUAL "NONE" )
0464 unset ( passed )
0465 elseif ( "${passed}" STREQUAL "" )
0466 set ( passed "TEST_PASSED" )
0467 endif()
0468
0469 set ( failed ${ARG_REGEX_FAIL} ${ARG_REGEX_FAILED} )
0470 if ( "${failed}" STREQUAL "NONE" )
0471 unset ( failed )
0472 endif()
0473 set ( output ${ARG_OUTPUT} )
0474
0475 set ( args ${ARG_EXEC_ARGS} )
0476 if ( "${args}" STREQUAL "" )
0477 set ( args ${test_name} )
0478 endif()
0479 add_test(NAME t_${test_name} COMMAND ${cmd} ${output} ${args} ${output} )
0480 if ( NOT "${passed}" STREQUAL "" )
0481 set_tests_properties( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "${passed}" )
0482 endif()
0483 if ( NOT "${failed}" STREQUAL "" )
0484 set_tests_properties( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "${failed}" )
0485 endif()
0486 # Set test dependencies if present
0487 foreach ( _dep ${ARG_DEPENDS} )
0488 set_property( TEST t_${test_name} APPEND PROPERTY DEPENDS t_${_dep} )
0489 endforeach()
0490 endif()
0491 endfunction()
0492
0493 #---------------------------------------------------------------------------------------------------
0494 # fill_dd4hep_library_path
0495 #
0496 #
0497 # \author M.Petric
0498 # \version 1.0
0499 #
0500 #---------------------------------------------------------------------------------------------------
0501 function ( fill_dd4hep_library_path )
0502 string(REGEX REPLACE "/lib/libCore.*" "" ROOT_ROOT ${ROOT_Core_LIBRARY})
0503 SET( ENV{DD4HEP_LIBRARY_PATH} ${ROOT_ROOT}/lib )
0504 if ( NOT "${Boost_LIBRARY_DIRS}" STREQUAL "" )
0505 SET( ENV{DD4HEP_LIBRARY_PATH} $ENV{DD4HEP_LIBRARY_PATH}:${Boost_LIBRARY_DIRS} )
0506 else()
0507 dd4hep_print("|++> The boost library path cannot be determined. Problems maybe ahead.")
0508 endif()
0509 if ( ${DD4HEP_USE_GEANT4} )
0510 string(REGEX REPLACE "/lib/Geant4.*" "" Geant4_ROOT ${Geant4_DIR})
0511 SET( ENV{DD4HEP_LIBRARY_PATH} ${Geant4_ROOT}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0512 endif()
0513
0514 if(${DD4HEP_USE_LCIO})
0515 SET( ENV{DD4HEP_LIBRARY_PATH} ${LCIO_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0516 endif()
0517
0518 if(${DD4HEP_USE_EDM4HEP})
0519 SET( ENV{DD4HEP_LIBRARY_PATH} ${EDM4HEP_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0520 endif()
0521
0522 SET( ENV{DD4HEP_LIBRARY_PATH} ${CLHEP_ROOT_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0523
0524 if(${DD4HEP_USE_XERCESC})
0525 SET( ENV{DD4HEP_LIBRARY_PATH} ${XERCESC_ROOT_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0526 endif()
0527
0528 SET( ENV{DD4HEP_LIBRARY_PATH} ${CMAKE_BINARY_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
0529 endfunction()
0530
0531
0532 #---------------------------------------------------------------------------------------------------
0533 # dd4hep_add_dictionary
0534 #
0535 # Arguments
0536 # ---------
0537 # dictionary -> dictionary name
0538 # SOURCES -> Globbing expression to find source files
0539 # EXCLUDE -> Files to exclude if they are found via SOURCES
0540 # LINKDEF -> Last entry when calling rootcling
0541 # USES -> Libraries needed to link the binary
0542 #
0543 # OPTIONS -> Options to pass to rootcling
0544 # INCLUDES -> Additional include directories need to compile the binary
0545 # DEFINITIONS -> Additional compiler definitions to compile the sources
0546 # OUTPUT ->
0547 #
0548 # USE_COMMAND_TO_GENERATE -> Go back to previous way of generating dictionary without creating temporary files
0549 #
0550 # \author A.Sailer
0551 # \version 1.0
0552 #
0553 #---------------------------------------------------------------------------------------------------
0554 function(dd4hep_add_dictionary dictionary )
0555 cmake_parse_arguments(ARG "USE_COMMAND_TO_GENERATE" "" "SOURCES;EXCLUDE;LINKDEF;OPTIONS;USES;DEFINITIONS;INCLUDES;OUTPUT" ${ARGN} )
0556 dd4hep_print ( "|++++> Building dictionary ... ${dictionary}" )
0557
0558 file(GLOB headers ${ARG_SOURCES})
0559 file(GLOB excl_headers ${ARG_EXCLUDE})
0560
0561 foreach( f ${excl_headers} )
0562 list( REMOVE_ITEM headers ${f} )
0563 dd4hep_debug ( "|++ exclude: ${f}" )
0564 endforeach()
0565
0566 foreach( f ${headers} )
0567 dd4hep_debug ( "|++ ${dictionary} is using: ${f}" )
0568 endforeach()
0569
0570 set(inc_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include)
0571 foreach(inc ${ARG_INCLUDES})
0572 LIST(APPEND inc_dirs ${inc})
0573 endforeach()
0574
0575 set(comp_defs)
0576 foreach(def ${ARG_DEFINITIONS})
0577 LIST(APPEND comp_defs ${def})
0578 endforeach()
0579
0580 foreach(DEP ${ARG_USES})
0581 # Get INCLUDE DIRECTORIES from Dependencies
0582 LIST(APPEND inc_dirs $<TARGET_PROPERTY:${DEP},INTERFACE_INCLUDE_DIRECTORIES>)
0583 # Get COMPILE DEFINITIONS from Dependencies
0584 LIST(APPEND comp_defs $<TARGET_PROPERTY:${DEP},INTERFACE_COMPILE_DEFINITIONS>)
0585 endforeach()
0586
0587 #
0588 file ( GLOB linkdefs ${ARG_LINKDEF} )
0589 #
0590 dd4hep_debug("|++ Linkdef: '${linkdefs}'" )
0591 dd4hep_debug("|++ Definition: '${comp_defs}'" )
0592 dd4hep_debug("|++ Include: '${inc_dirs}'" )
0593 dd4hep_debug("|++ Files: '${headers}'" )
0594 dd4hep_debug("|++ Unparsed: '${ARG_UNPARSED_ARGUMENTS}'" )
0595 dd4hep_debug("|++ Sources: '${CMAKE_CURRENT_SOURCE_DIR}'" )
0596 #
0597 set ( output_dir ${CMAKE_CURRENT_BINARY_DIR}/../lib )
0598 if ( NOT "${ARG_OUTPUT}" STREQUAL "" )
0599 set ( output_dir ${ARG_OUTPUT} )
0600 endif()
0601 EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${output_dir})
0602
0603 add_custom_target(${dictionary}
0604 DEPENDS ${dictionary}.cxx ${output_dir}/${dictionary}_rdict.pcm ${headers} ${linkdefs}
0605 )
0606 if(NOT ARG_USE_COMMAND_TO_GENERATE)
0607 file(GENERATE OUTPUT create_${dictionary}_$<CONFIG>$<COMPILE_LANGUAGE>.sh
0608 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},;>"
0609 )
0610 add_custom_command(OUTPUT fixed_create_${dictionary}_$<CONFIG>CXX.sh
0611 COMMAND sed "s/\;/ /g" create_${dictionary}_$<CONFIG>CXX.sh > fixed_create_${dictionary}_$<CONFIG>CXX.sh
0612 DEPENDS create_${dictionary}_$<CONFIG>CXX.sh
0613 )
0614 add_custom_command(OUTPUT ${dictionary}.cxx ${output_dir}/${dictionary}_rdict.pcm
0615 COMMAND /bin/sh fixed_create_${dictionary}_$<CONFIG>CXX.sh
0616 DEPENDS fixed_create_${dictionary}_$<CONFIG>CXX.sh ${headers} ${linkdefs}
0617 )
0618 else()
0619 add_custom_command(OUTPUT ${dictionary}.cxx ${output_dir}/${dictionary}_rdict.pcm
0620 COMMAND ${ROOT_rootcling_CMD}
0621 ARGS -f ${dictionary}.cxx -s ${output_dir}/${dictionary} -inlineInputHeader
0622 ${ARG_OPTIONS}
0623 "$<$<BOOL:$<JOIN:${comp_defs},>>:-D$<JOIN:$<REMOVE_DUPLICATES:${comp_defs}>,;-D>>"
0624 "$<$<BOOL:$<JOIN:${inc_dirs},>>:-I$<JOIN:$<REMOVE_DUPLICATES:${inc_dirs}>,;-I>>"
0625 "$<JOIN:${headers},;>" "$<JOIN:${linkdefs},;>"
0626
0627 DEPENDS ${headers} ${linkdefs}
0628 COMMAND_EXPAND_LISTS
0629 )
0630 endif()
0631 set_source_files_properties(${dictionary}.cxx ${output_dir}/${dictionary}_rdict.pcm
0632 PROPERTIES
0633 GENERATED TRUE
0634 COMPILE_FLAGS "-Wno-unused-function -Wno-overlength-strings"
0635 )
0636
0637 # Install the binary to the destination directory
0638 set(DD4HEP_INSTALL_LIBDIR lib)
0639 if(CMAKE_INSTALL_LIBDIR)
0640 set(DD4HEP_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
0641 endif()
0642 install(FILES ${output_dir}/${dictionary}_rdict.pcm DESTINATION ${DD4HEP_INSTALL_LIBDIR})
0643 unset(DD4HEP_INSTALL_LIBDIR)
0644
0645 endfunction()
0646
0647
0648 #---------------------------------------------------------------------------------------------------
0649 #
0650 # dd4hep_add_plugin
0651 #
0652 # Arguments
0653 # ---------
0654 # binary -> plugin name
0655 # SOURCES -> Globbing expression to find source files
0656 # GENERATED -> List of source files
0657 # USES -> Libraries needed to link the binary
0658 #
0659 # INCLUDES -> Additional include directories need to compile the binary
0660 # DEFINITIONS -> Optional compiler definitions to compile the sources
0661 # NOINSTALL -> If set do not install the plugin
0662 # \author A.Sailer
0663 # \version 1.0
0664 #
0665 #---------------------------------------------------------------------------------------------------
0666 function(dd4hep_add_plugin binary)
0667 cmake_parse_arguments(ARG "NOINSTALL" "" "SOURCES;GENERATED;USES;INCLUDES;DEFINITIONS" ${ARGN})
0668 if ( ${ARG_NOINSTALL} )
0669 set(NOINSTALL NOINSTALL)
0670 endif()
0671 file(GLOB SOURCES ${ARG_SOURCES})
0672 dd4hep_print("|++> Building Plugin: ${binary}")
0673 dd4hep_debug("|++++> SOURCES ${SOURCES}")
0674 dd4hep_debug("|++++> USES ${ARG_USES}")
0675 dd4hep_debug("|++++> INCLUDES ${ARG_INCLUDES}")
0676 dd4hep_debug("|++++> DEFINITIONS ${ARG_DEFINITIONS}")
0677 IF(NOT DEFINED BUILD_SHARED_LIBS)
0678 SET(STATIC_OR_SHARED SHARED)
0679 ENDIF()
0680 add_library(${binary} ${STATIC_OR_SHARED} ${SOURCES} ${ARG_GENERATED})
0681 target_link_libraries(${binary} PUBLIC ${ARG_USES})
0682 target_include_directories(${binary} PUBLIC ${ARG_INCLUDES})
0683 target_compile_definitions(${binary} PUBLIC ${ARG_DEFINITIONS})
0684 IF(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
0685 dd4hep_generate_rootmap(${binary})
0686 ENDIF()
0687 if(NOT ${ARG_NOINSTALL})
0688 set(install_destination "lib")
0689 if(CMAKE_INSTALL_LIBDIR)
0690 set(install_destination ${CMAKE_INSTALL_LIBDIR})
0691 endif()
0692 install(TARGETS ${binary}
0693 ARCHIVE DESTINATION ${install_destination}
0694 LIBRARY DESTINATION ${install_destination}
0695 )
0696 endif()
0697 endfunction(dd4hep_add_plugin)
0698
0699
0700 #
0701 # 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
0702 # This is called in dd4hep, and in DD4hepConfig
0703 #
0704 macro(DD4HEP_SETUP_ROOT_TARGETS)
0705
0706 #Check if Python version detected matches the version used to build ROOT
0707 SET(Python_FIND_FRAMEWORK LAST)
0708 IF((TARGET ROOT::PyROOT OR TARGET ROOT::ROOTTPython) AND ${ROOT_VERSION} VERSION_GREATER_EQUAL 6.19)
0709 # some cmake versions don't include python patch level in PYTHON_VERSION
0710 IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0 AND CMAKE_VERSION VERSION_LESS_EQUAL 3.17.2)
0711 string(REGEX MATCH [23]\\.[0-9]+ REQUIRE_PYTHON_VERSION ${ROOT_PYTHON_VERSION})
0712 ELSE()
0713 SET(REQUIRE_PYTHON_VERSION ${ROOT_PYTHON_VERSION})
0714 ENDIF()
0715 dd4hep_debug("D++> Python version used for building ROOT ${ROOT_PYTHON_VERSION}" )
0716 if (NOT DD4HEP_RELAX_PYVER)
0717 dd4hep_debug("D++> Required python version ${REQUIRE_PYTHON_VERSION}")
0718 FIND_PACKAGE(Python ${REQUIRE_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Development)
0719 FIND_PACKAGE(Python ${REQUIRE_PYTHON_VERSION} EXACT QUIET COMPONENTS Interpreter)
0720 else()
0721 FIND_PACKAGE(Python REQUIRED COMPONENTS Development)
0722 FIND_PACKAGE(Python QUIET COMPONENTS Interpreter)
0723 dd4hep_debug("D++> Found python version ${Python_VERSION}")
0724 string(REPLACE "." ";" _root_pyver_tuple ${REQUIRE_PYTHON_VERSION})
0725 list(GET _root_pyver_tuple 0 _root_pyver_major)
0726 list(GET _root_pyver_tuple 1 _root_pyver_minor)
0727 if (NOT "${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}" VERSION_EQUAL "${_root_pyver_major}.${_root_pyver_minor}")
0728 dd4hep_print("WARNING: Mismatch in Python version: ${Python_VERSION} vs. ${REQUIRE_PYTHON_VERSION}")
0729 dd4hep_print(" ABI compatibility should not be assumed!")
0730 endif()
0731 endif()
0732 ELSE()
0733 FIND_PACKAGE(Python COMPONENTS Development)
0734 FIND_PACKAGE(Python QUIET COMPONENTS Interpreter)
0735 ENDIF()
0736 IF("${Python_EXECUTABLE}" STREQUAL "")
0737 set (Python_EXECUTABLE python${Python_VERSION_MAJOR})
0738 ENDIF()
0739 dd4hep_print("|++> Using python executable: ${Python_EXECUTABLE}")
0740
0741 # For Python 3.13+ with free-threading (PEP 703), the site-packages directory
0742 # includes a 't' suffix (e.g., python3.14t/site-packages). We use Python's
0743 # own SITEARCH to get the correct path including any ABI suffixes.
0744 string(REGEX MATCH "python[0-9]+\\.[0-9]+[a-z]*/site-packages" _python_site_subdir "${Python_SITEARCH}")
0745 if(NOT _python_site_subdir)
0746 # Fallback to manual construction if regex fails
0747 set(_python_site_subdir "python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")
0748 MESSAGE(WARNING "Could not extract site-packages path from Python_SITEARCH")
0749 MESSAGE(WARNING "Python_SITEARCH=${Python_SITEARCH}")
0750 MESSAGE(WARNING "Using fallback: ${_python_site_subdir}")
0751 endif()
0752 SET(DD4HEP_PYTHON_INSTALL_DIR lib/${_python_site_subdir})
0753 unset(_python_site_subdir)
0754
0755 #ROOT CXX Flags are a string with quotes, not a list, so we need to convert to a list...
0756 string(REPLACE " " ";" DD4HEP_ROOT_CXX_FLAGS ${ROOT_CXX_FLAGS})
0757
0758 IF(NOT TARGET ROOT::Core)
0759 #in ROOT before 6.10 there is no ROOT namespace, so we create ROOT::Core ourselves
0760 ADD_LIBRARY(ROOT::Core INTERFACE IMPORTED GLOBAL)
0761 SET_TARGET_PROPERTIES(ROOT::Core
0762 PROPERTIES
0763 INTERFACE_COMPILE_OPTIONS "${DD4HEP_ROOT_CXX_FLAGS}"
0764 INTERFACE_INCLUDE_DIRECTORIES ${ROOT_INCLUDE_DIRS}
0765 )
0766 # there is also no dependency between the targets
0767 TARGET_LINK_LIBRARIES(ROOT::Core INTERFACE Core)
0768 # we list here the targets we use in dd4hep, as later versions of root have the namespace, we do not have to to this
0769 # for ever
0770 foreach(LIB PyROOT Geom GenVector Eve Graf3d RGL Gui RIO MathCore MathMore EG EGL Rint Tree Hist Physics Gdml)
0771 IF(TARGET ${LIB})
0772 ADD_LIBRARY(ROOT::${LIB} INTERFACE IMPORTED GLOBAL)
0773 TARGET_LINK_LIBRARIES(ROOT::${LIB} INTERFACE ${LIB} ROOT::Core)
0774 ENDIF()
0775 endforeach()
0776 ELSEIF(${ROOT_VERSION} VERSION_GREATER_EQUAL 6.12 AND ${ROOT_VERSION} VERSION_LESS 6.14)
0777 # Root 6.12 exports ROOT::Core, but does not assign include directories to the target
0778 SET_TARGET_PROPERTIES(ROOT::Core
0779 PROPERTIES
0780 INTERFACE_COMPILE_OPTIONS "${DD4HEP_ROOT_CXX_FLAGS}"
0781 INTERFACE_INCLUDE_DIRECTORIES ${ROOT_INCLUDE_DIRS}
0782 )
0783
0784 ENDIF()
0785
0786 dd4hep_debug("ROOT Libraries ${ROOT_LIBRARIES}")
0787 dd4hep_debug("ROOT CXX_FLAGS ${DD4HEP_ROOT_CXX_FLAGS}")
0788 dd4hep_debug("ROOT INCL DIRS ${ROOT_INCLUDE_DIRS}")
0789 dd4hep_debug("ROOT_VERSION: ${ROOT_VERSION}" )
0790
0791 ENDMACRO()
0792
0793 #
0794 # Do some processing of the imported Boost Targets
0795 # Some libraries are only needed for cxx std 14
0796 # we also have to make sure the boost library location is known in that case
0797 #
0798 #
0799
0800 MACRO(DD4HEP_SETUP_BOOST_TARGETS)
0801
0802 SET_TARGET_PROPERTIES(Boost::boost
0803 PROPERTIES
0804 INTERFACE_COMPILE_DEFINITIONS BOOST_SPIRIT_USE_PHOENIX_V3
0805 )
0806
0807 # Try to compile with filesystem header linking against different FS libraries
0808 SET(HAVE_FILESYSTEM False)
0809 dd4hep_debug("|++> Checking if compiler supports filesystem library")
0810 # stdc++fs needed in gcc8, no lib for gcc9.1, c++fs for llvm
0811 FOREACH(FS_LIB_NAME stdc++fs "" c++fs )
0812 dd4hep_debug("|++++> linking against ${FS_LIB_NAME}")
0813 try_compile(HAVE_FILESYSTEM ${CMAKE_BINARY_DIR}/try ${DD4hep_DIR}/cmake/TryFileSystem.cpp
0814 CXX_STANDARD ${CMAKE_CXX_STANDARD}
0815 CXX_EXTENSIONS False
0816 OUTPUT_VARIABLE HAVE_FS_OUTPUT
0817 LINK_LIBRARIES ${FS_LIB_NAME}
0818 )
0819 dd4hep_debug("|++++> ${HAVE_FS_OUTPUT}")
0820 IF(HAVE_FILESYSTEM)
0821 dd4hep_print("|++> Compiler supports filesystem when linking against ${FS_LIB_NAME}")
0822 SET(FS_LIBRARIES ${FS_LIB_NAME})
0823 BREAK()
0824 ENDIF()
0825 dd4hep_debug("|++++> Compiler not compatible when linking against ${FS_LIB_NAME}")
0826 ENDFOREACH()
0827
0828 IF(NOT HAVE_FILESYSTEM)
0829 dd4hep_print("|++> Compiler does not have filesystem support, falling back to Boost::filesystem")
0830 FIND_PACKAGE(Boost 1.56 REQUIRED COMPONENTS filesystem system)
0831 SET(FS_LIBRARIES Boost::filesystem Boost::system)
0832 SET_TARGET_PROPERTIES(Boost::filesystem
0833 PROPERTIES
0834 INTERFACE_COMPILE_DEFINITIONS USE_BOOST_FILESYSTEM
0835 )
0836 GET_TARGET_PROPERTY(BOOST_FILESYSTEM_LOC Boost::filesystem IMPORTED_LOCATION)
0837 GET_FILENAME_COMPONENT(BOOST_DIR ${BOOST_FILESYSTEM_LOC} DIRECTORY)
0838 ENDIF()
0839
0840
0841 ENDMACRO()
0842
0843 #
0844 # Do some processing of the imported Geant4 Targets, CLHEP treatment etc.
0845 # Will only be done once, repeated calls should have no effect
0846 #
0847 MACRO(DD4HEP_SETUP_GEANT4_TARGETS)
0848
0849 # only do this once
0850 IF(NOT TARGET Geant4::Interface)
0851
0852 #include( ${Geant4_USE_FILE} ) # do not use the use file, this is not very considerate...
0853 IF((NOT ${Geant4_TLS_MODEL} STREQUAL "global-dynamic") AND NOT ${DD4HEP_IGNORE_GEANT4_TLS})
0854 MESSAGE(FATAL_ERROR "Geant4 was built with ${Geant4_TLS_MODEL}, DD4hep requires 'global-dynamic'! Ignore this ERROR with DD4HEP_IGNORE_GEANT4_TLS=True ")
0855 ENDIF()
0856
0857 if(Geant4_builtin_clhep_FOUND)
0858 dd4hep_debug("Using Geant4 internal CLHEP")
0859 if(TARGET CLHEP::CLHEP)
0860 message(WARNING "CLHEP::CLHEP already exists, this may cause problems if there are two different installations of CLHEP, one from Geant4 and one external")
0861 else()
0862 ADD_LIBRARY(CLHEP::CLHEP INTERFACE IMPORTED GLOBAL)
0863 endif()
0864 SET_TARGET_PROPERTIES(CLHEP::CLHEP
0865 PROPERTIES
0866 INTERFACE_INCLUDE_DIRECTORIES "${Geant4_INCLUDE_DIRS}"
0867 )
0868 if(TARGET Geant4::G4clhep)
0869 TARGET_LINK_LIBRARIES(CLHEP::CLHEP INTERFACE Geant4::G4clhep)
0870 else()
0871 TARGET_LINK_LIBRARIES(CLHEP::CLHEP INTERFACE G4clhep)
0872 endif()
0873
0874 else()
0875 IF(NOT TARGET CLHEP::CLHEP)
0876 FIND_PACKAGE(CLHEP REQUIRED CONFIG)
0877 ENDIF()
0878 set(CLHEP CLHEP::CLHEP)
0879 dd4hep_debug("Using External CLHEP")
0880 dd4hep_debug("CLHEP Libraries ${CLHEP_LIBRARIES}")
0881 dd4hep_debug("CLHEP CXX_FLAGS ${CLHEP_CXX_FLAGS}")
0882 dd4hep_debug("CLHEP INCL DIRS ${CLHEP_INCLUDE_DIRS}")
0883 dd4hep_debug("CLHEP_VERSION: ${CLHEP_VERSION}" )
0884 endif()
0885
0886 dd4hep_debug("Geant4 Libraries ${Geant4_LIBRARIES}")
0887 dd4hep_debug("Geant4 CXX_FLAGS ${Geant4_CXX_FLAGS}")
0888 dd4hep_debug("Geant4 INCL DIRS ${Geant4_INCLUDE_DIRS}")
0889 dd4hep_debug("Geant4_VERSION: ${Geant4_VERSION}" )
0890
0891 # Geant4 CXX Flags are a string with quotes, not a list, so we need to convert to a list...
0892 # Geant4::10.2.2 at least, not in 10.5 (check where it switches)
0893 string(REPLACE " " ";" Geant4_Flags ${Geant4_CXX_FLAGS} ${Geant4_CXX_FLAGS_${CMAKE_BUILD_TYPE}})
0894
0895 #Geant4_DEFINITIONS already include -D, we have to get rid of that so we can join things when creating dictionaries
0896 SET(G4_DEF_TEMP "")
0897 foreach(def ${Geant4_DEFINITIONS})
0898 string(REPLACE "-D" "" def ${def})
0899 LIST(APPEND G4_DEF_TEMP ${def})
0900 endforeach()
0901 SET(DD4HEP_Geant4_DEFINITIONS ${G4_DEF_TEMP})
0902 UNSET(G4_DEF_TEMP)
0903
0904 ADD_LIBRARY(Geant4::Interface INTERFACE IMPORTED GLOBAL)
0905
0906 SET_TARGET_PROPERTIES(Geant4::Interface
0907 PROPERTIES
0908 INTERFACE_COMPILE_OPTIONS "${Geant4_Flags}"
0909 INTERFACE_COMPILE_DEFINITIONS "${DD4HEP_Geant4_DEFINITIONS}"
0910 INTERFACE_INCLUDE_DIRECTORIES "${Geant4_INCLUDE_DIRS}"
0911 )
0912
0913 IF(CLHEP)
0914 dd4hep_debug("Adding CLHEP to Geant4::Interface Dependencies")
0915 TARGET_LINK_LIBRARIES(Geant4::Interface INTERFACE ${CLHEP})
0916 ENDIF()
0917
0918 # Geant4_LIBRARIES are imported targets, we just add them all to our own interface library for convenience
0919 # Geant4 Libraries do not (yet) use a namespace
0920 foreach(LIB ${Geant4_LIBRARIES})
0921 TARGET_LINK_LIBRARIES(Geant4::Interface INTERFACE ${LIB})
0922 endforeach()
0923
0924 dd4hep_debug("Geant4 Libraries ${Geant4_LIBRARIES};${Geant4_COMPONENT_LIBRARIES}")
0925 dd4hep_debug("Geant4 Location ${Geant4_LOCATION}")
0926 dd4hep_debug("Geant4 Defintitions ${Geant4_DEFINITIONS}")
0927 dd4hep_debug("Geant4 CXX_FLAGS ${Geant4_CXX_FLAGS}")
0928 dd4hep_debug("Geant4 INCL DIRS ${Geant4_INCLUDE_DIRS}")
0929 dd4hep_debug("Geant4_VERSION: ${Geant4_VERSION}" )
0930
0931 ENDIF()
0932 ENDMACRO()
0933
0934 #
0935 # Create Interface library for LCIO
0936 #
0937 MACRO(DD4HEP_SETUP_LCIO_TARGETS)
0938 IF(NOT TARGET LCIO::lcio)
0939 ADD_LIBRARY(LCIO::lcio INTERFACE IMPORTED GLOBAL)
0940 SET_TARGET_PROPERTIES(LCIO::lcio
0941 PROPERTIES
0942 INTERFACE_INCLUDE_DIRECTORIES "${LCIO_INCLUDE_DIRS}"
0943 INTERFACE_LINK_LIBRARIES "${LCIO_LIBRARIES}"
0944 )
0945 ENDIF()
0946 ENDMACRO()