Back to home page

EIC code displayed by LXR

 
 

    


Warning, /DD4hep/CMakeLists.txt is written in an unsupported language. File is not indexed.

0001 cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
0002 PROJECT( DD4hep LANGUAGES NONE)
0003 SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DD4hep)
0004 
0005 #################
0006 # Setup version #
0007 #################
0008 
0009 SET( DD4hep_VERSION_MAJOR 1 )
0010 SET( DD4hep_VERSION_MINOR 37 )
0011 SET( DD4hep_VERSION_PATCH 0 )
0012 
0013 #######################
0014 # Basic project setup #
0015 #######################
0016 
0017 set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake )
0018 
0019 IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
0020   SET( CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR} CACHE PATH
0021        "install prefix path  - overwrite with -D CMAKE_INSTALL_PREFIX = ..."
0022        FORCE )
0023  MESSAGE(STATUS "CMAKE_INSTALL_PREFIX is ${CMAKE_INSTALL_PREFIX} - overwrite with -D CMAKE_INSTALL_PREFIX" )
0024 ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
0025 
0026 # When enabling DDG4 on Alma 9 and related, CMAKE_INSTALL_LIBDIR is set to lib64
0027 # Here, we force it to be lib if unset
0028 if(NOT CMAKE_INSTALL_LIBDIR)
0029   set(CMAKE_INSTALL_LIBDIR lib CACHE STRING "Installation directory for libraries" FORCE)
0030 endif()
0031 
0032 ###############################################
0033 # Setup the environment for the documentation #
0034 ###############################################
0035 
0036 OPTION(BUILD_DOCS_ONLY "Build documentation only" OFF)
0037 OPTION(BUILD_DOCS "Build documentation" ON)
0038 
0039 # Add targets for Doxygen code reference and LaTeX User manual
0040 
0041 if (BUILD_DOCS)
0042     ADD_SUBDIRECTORY(doc)
0043 ENDIF()
0044 
0045 # If only building docs, stop processing the rest of the CMake file:
0046 IF(BUILD_DOCS_ONLY)
0047   RETURN()
0048 ENDIF()
0049 
0050 #############################################################
0051 # Enable CXX as project language to perform compiler checks #
0052 #############################################################
0053 
0054 ENABLE_LANGUAGE(CXX)
0055 # Set C++ standard
0056 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard used for compiling")
0057 set(CMAKE_CXX_STANDARD_REQUIRED ON)
0058 set(CMAKE_CXX_EXTENSIONS OFF)
0059 
0060 SET(DD4hep_DIR ${CMAKE_SOURCE_DIR} CACHE STRING "DD4hep directory")
0061 SET(DD4hep_ROOT ${CMAKE_INSTALL_PREFIX})
0062 
0063 IF(${CMAKE_CXX_STANDARD} LESS 17)
0064   MESSAGE(FATAL_ERROR "DD4hep requires at least CXX Standard 17 to compile")
0065 ENDIF()
0066 
0067 ###############################
0068 # Define DD4hep build options #
0069 ###############################
0070 # NINJA ONLY
0071 # Limit number of parallel DDParser builds to number equal to 2 gigs per core
0072 cmake_host_system_information(RESULT HOST_RAM_MB QUERY TOTAL_PHYSICAL_MEMORY)
0073 math(EXPR DD4HEP_HIGH_MEM_POOL_DEPTH "${HOST_RAM_MB} / 2000" OUTPUT_FORMAT DECIMAL)
0074 
0075 option(DD4HEP_USE_XERCESC       "Enable 'Detector Builders' based on XercesC"   OFF)
0076 option(DD4HEP_USE_GEANT4        "Enable the simulation part based on Geant4"    OFF)
0077 option(DD4HEP_IGNORE_GEANT4_TLS "Ignore the tls flag Geant4 was compiled with"  OFF)
0078 option(DD4HEP_USE_GEAR          "Build gear wrapper for backward compatibility" OFF)
0079 option(DD4HEP_USE_LCIO          "Build lcio extensions"                         OFF)
0080 option(DD4HEP_USE_GEANT4_UNITS  "Build using Geant4 units throughout"           OFF)
0081 option(DD4HEP_USE_EDM4HEP       "Build edm4hep extensions"                      OFF)
0082 option(DD4HEP_USE_HEPMC3        "Build hepmc3 extensions"                       OFF)
0083 option(DD4HEP_USE_TBB           "Build features that require TBB"               OFF)
0084 option(DD4HEP_LOAD_ASSIMP       "Download and build ASSIMP from github"         OFF)
0085 option(DD4HEP_DISABLE_PACKAGES  "Selectively disable DD4HEP sub-packages [Separate multiples by space]"  OFF)
0086 option(BUILD_TESTING            "Enable and build tests"                        ON)
0087 option(BUILD_SHARED_LIBS        "If OFF build STATIC Libraries"                 ON)
0088 option(DD4HEP_SET_RPATH         "Link libraries with built-in RPATH (run-time search path)" ON)
0089 option(DD4HEP_RELAX_PYVER       "Do not require exact python version match with ROOT" OFF)
0090 #
0091 OPTION(DD4HEP_BUILD_EXAMPLES    "Build all the examples"                        OFF)
0092 OPTION(DD4HEP_DEBUG_CMAKE       "Print debugging information for DD4hep CMAKE"  OFF)
0093 #
0094 SET(DD4HEP_BUILD_PACKAGES "DDRec DDDetectors DDCond DDAlign DDCAD DDDigi DDG4 DDEve UtilityApps"
0095     CACHE STRING "List of DD4hep packages to build")
0096 #
0097 SEPARATE_ARGUMENTS(DD4HEP_BUILD_PACKAGES)
0098 IF( DD4HEP_DISABLE_PACKAGES )
0099     STRING(REPLACE " " ";" DISABLED_PACKAGES "${DD4HEP_DISABLE_PACKAGES}" )
0100     STRING(REPLACE "," ";" DISABLED_PACKAGES "${DISABLED_PACKAGES}" )
0101     FOREACH( PKG ${DISABLED_PACKAGES} )
0102       LIST(REMOVE_ITEM DD4HEP_BUILD_PACKAGES ${PKG})
0103       MESSAGE(STATUS "Disable package: ${PKG}" )
0104     ENDFOREACH()
0105 ENDIF()
0106 MESSAGE(STATUS "Will be building these packages: ${DD4HEP_BUILD_PACKAGES}")
0107 
0108 SET(DD4HEP_USE_EXISTING_DD4HEP "" CACHE STRING "Build some parts of DD4hep against an existing installation")
0109 SET(DD4HEP_HIGH_MEM_POOL_DEPTH "${DD4HEP_HIGH_MEM_POOL_DEPTH}" CACHE STRING "Number of build slots for high memory compile units (DDParsers), Ninja only")
0110 
0111 SET(DD4HEP_BUILD_DEBUG "" CACHE STRING "Enable some DEBUG features in DD4hep. Set to 'ON' or 'OFF' to override default handling")
0112 
0113 IF(DD4HEP_BUILD_DEBUG AND NOT DD4HEP_BUILD_DEBUG MATCHES "ON|OFF")
0114   MESSAGE(FATAL_ERROR "Invalid value for DD4HEP_BUILD_DEBUG, ${DD4HEP_BUILD_DEBUG}, use '', 'ON', 'OFF'")
0115 ENDIF()
0116 
0117 # create the job pool
0118 set_property(GLOBAL PROPERTY JOB_POOLS HIGH_MEM_POOL=${DD4HEP_HIGH_MEM_POOL_DEPTH})
0119 #####################
0120 # Configure version #
0121 #####################
0122 
0123 include ( DD4hepBuild )
0124 dd4hep_set_version(DD4hep
0125         MAJOR ${DD4hep_VERSION_MAJOR}
0126         MINOR ${DD4hep_VERSION_MINOR}
0127         PATCH ${DD4hep_VERSION_PATCH} )
0128 
0129 configure_file (
0130         "${PROJECT_SOURCE_DIR}/cmake/Version.h.in"
0131         "${PROJECT_SOURCE_DIR}/DDCore/include/DD4hep/Version.h"
0132 )
0133 
0134 dd4hep_configure_output( OUTPUT "${PROJECT_BINARY_DIR}" INSTALL "${CMAKE_INSTALL_PREFIX}" )
0135 
0136 ########################
0137 # Resolve dependencies #
0138 ########################
0139 
0140 # Configure ROOT
0141 find_package (ROOT 6.08 REQUIRED CONFIG)
0142 DD4HEP_SETUP_ROOT_TARGETS()
0143 # ROOT no longer finds nlohmann_json unless we ask for the ROOTEve component, so we ask
0144 # for the ROOTEve component if the ROOTEve component exists.
0145 # DDEve and one executable in UtilityApps depend on this
0146 if(TARGET ROOT::ROOTEve)
0147   find_package (ROOT REQUIRED COMPONENTS ROOTEve CONFIG)
0148 endif()
0149 
0150 # Set when the minimum required CMake version is at least 3.30
0151 if(POLICY CMP0167)
0152   cmake_policy(SET CMP0167 NEW)
0153 endif()
0154 find_package(Boost 1.49 REQUIRED)
0155 DD4HEP_SETUP_BOOST_TARGETS()
0156 
0157 # Configure Geant4
0158 if(DD4HEP_USE_GEANT4)
0159   find_package( Geant4 10.2.2 REQUIRED  gdml ui_all vis_all CONFIG)
0160   IF(NOT Geant4_builtin_clhep_FOUND)
0161     SET(DD4HEP_USE_CLHEP TRUE)
0162   ENDIF()
0163   if(Geant4_CXX_STANDARD MATCHES "[0-9]+" AND Geant4_CXX_STANDARD LESS ${CMAKE_CXX_STANDARD})
0164     message(FATAL_ERROR "Geant4 was compiled with C++${Geant4_CXX_STANDARD}, but DD4hep requires C++${CMAKE_CXX_STANDARD}")
0165   endif()
0166 
0167   DD4HEP_SETUP_GEANT4_TARGETS()
0168   # Geant4 sets the CLHEP include directory to include_directories, we undo this here
0169   # we don't do this inside DD4hep_SETUP_GEANT4_TARGETS, because that is also used in
0170   # DD4hepConfig by users of DD4hep
0171   SET_DIRECTORY_PROPERTIES(PROPERTIES INCLUDE_DIRECTORIES "")
0172 endif()
0173 
0174 if(DD4HEP_USE_LCIO)
0175   find_package(LCIO REQUIRED CONFIG)
0176   DD4HEP_SETUP_LCIO_TARGETS()
0177 endif()
0178 
0179 if(DD4HEP_USE_EDM4HEP)
0180   # EDM4hep is "SameMajorVersion" compatible so we try to find a recent version
0181   # first and fall back to a compatible on in case we don't find it
0182   find_package(EDM4HEP 1.0)
0183   if (NOT EDM4HEP_FOUND)
0184     message(STATUS "EDM4HEP 1.0 not found, falling back to at least version 0.10.5")
0185     find_package(EDM4HEP 0.10.5 REQUIRED)
0186   endif()
0187   # we need podio with Frame support (>=0.16.3)
0188   # podio is "SameMajorVersion" compatible
0189   find_package(podio 1.0)
0190   if(NOT podio_FOUND)
0191     message(STATUS "podio 1.0 not found, falling back to at least version 0.16.7")
0192     find_package(podio 0.16.7 REQUIRED)  # this will not find 1.0 and newer
0193   endif()
0194 #  DD4HEP_SETUP_EDM4HEP_TARGETS()
0195 endif()
0196 
0197 if(DD4HEP_USE_HEPMC3)
0198   find_package(HepMC3 REQUIRED)
0199 
0200   # Optional dependencies for compressed input support
0201   if(HEPMC3_VERSION VERSION_GREATER_EQUAL "3.02.05")
0202     option(DD4HEP_HEPMC3_COMPRESSION_SUPPORT "Enable reading of compressed HepMC files" OFF)
0203     if(DD4HEP_HEPMC3_COMPRESSION_SUPPORT)
0204       find_package(ZLIB REQUIRED)
0205       find_package(LibLZMA REQUIRED)
0206       find_package(BZip2 REQUIRED)
0207     endif()
0208   else()
0209     option(DD4HEP_HEPMC3_COMPRESSION_SUPPORT "Enable reading of compressed HepMC files" OFF)
0210     if(DD4HEP_HEPMC3_COMPRESSION_SUPPORT)
0211       message(FATAL_ERROR "HepMC3 >= 3.2.5 is required for -DDD4HEP_HEPMC3_COMPRESSION_SUPPORT=ON")
0212     endif()
0213   endif()
0214 endif()
0215 
0216 if(DD4HEP_USE_TBB)
0217   find_package(TBB REQUIRED CONFIG)
0218 endif()
0219 
0220 
0221 ######################
0222 # Set compiler flags #
0223 ######################
0224 
0225 dd4hep_set_compiler_flags()
0226 
0227 ####################
0228 # Include packages #
0229 ####################
0230 include(DD4hep)
0231 include(DD4hepMacros) 
0232 
0233 if( DEFINED DD4HEP_WITH_GEANT4 OR DEFINED DD4HEP_WITH_GEAR )
0234   dd4hep_print_cmake_options( OPTIONAL "Obsolete options: only the following are allowed:" ERROR 1 )
0235 endif()
0236 
0237 IF(DD4HEP_USE_EXISTING_DD4HEP)
0238 
0239   MESSAGE(STATUS "|!!> Using pre-existing DD4hep: ${DD4HEP_USE_EXISTING_DD4HEP}")
0240   SET(CMAKE_PROJECT_NAME DD4hepSelected)
0241   dd4hep_set_version(${CMAKE_PROJECT_NAME}
0242     MAJOR ${${CMAKE_PROJECT_NAME}_VERSION_MAJOR}
0243     MINOR ${${CMAKE_PROJECT_NAME}_VERSION_MINOR}
0244     PATCH ${${CMAKE_PROJECT_NAME}_VERSION_PATCH} )
0245 
0246   FIND_PACKAGE(DD4hep REQUIRED  NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH
0247     PATHS ${DD4HEP_USE_EXISTING_DD4HEP})
0248 
0249   dd4hep_configure_output( OUTPUT "${PROJECT_BINARY_DIR}" INSTALL "${CMAKE_INSTALL_PREFIX}" )
0250 
0251   FOREACH(DDPackage IN LISTS DD4HEP_BUILD_PACKAGES)
0252     dd4hep_print("|> Building ${DDPackage}")
0253     add_subdirectory(${DDPackage})
0254   ENDFOREACH()
0255   LIST(GET DD4HEP_BUILD_PACKAGES 0 DD4HEP_SELECTED_PACKAGE)
0256 ELSE()
0257 
0258   include(DD4hep_XML_setup)
0259 
0260   #These packages are mandatory
0261   SET(DD4HEP_SELECTED_PACKAGE DDCore)
0262   FOREACH(DDPackage GaudiPluginService DDParsers DDCore)
0263     dd4hep_print("|> Building ${DDPackage}")
0264     add_subdirectory(${DDPackage})
0265   ENDFOREACH()
0266   IF(DD4HEP_BUILD_DEBUG MATCHES "ON" OR (CMAKE_BUILD_TYPE MATCHES "DEBUG|Debug" AND NOT DD4HEP_BUILD_DEBUG MATCHES "OFF"))
0267     message(STATUS "BUILD DD4HEP and depending software with debug extensions")
0268     target_compile_definitions(DDCore PUBLIC DD4HEP_DEBUG=1)
0269     set(DD4HEP_BUILD_DEBUG ON)
0270   ELSE()
0271     set(DD4HEP_BUILD_DEBUG OFF)
0272   ENDIF()
0273 
0274   message(STATUS "BUILD Packages: ${DD4HEP_BUILD_PACKAGES}")
0275   FOREACH(DDPackage IN LISTS DD4HEP_BUILD_PACKAGES)
0276     dd4hep_print("|> Building ${DDPackage}")
0277     add_subdirectory(${DDPackage})
0278   ENDFOREACH()
0279 
0280   if(BUILD_TESTING)
0281     dd4hep_enable_tests()
0282     add_subdirectory(DDTest)
0283   endif()
0284 
0285   if(DD4HEP_BUILD_EXAMPLES)
0286     add_subdirectory(examples)
0287   endif()
0288 
0289 
0290 ENDIF(DD4HEP_USE_EXISTING_DD4HEP)
0291 
0292 #########################
0293 # Configure and install #
0294 #########################
0295 configure_file(cmake/thisdd4hep.sh       bin/thisdd4hep.sh       @ONLY)
0296 configure_file(cmake/thisdd4hep_only.sh  bin/thisdd4hep_only.sh  @ONLY)
0297 configure_file(cmake/run_test.sh         bin/run_test.sh         @ONLY)
0298 
0299 install(FILES    ${CMAKE_BINARY_DIR}/bin/thisdd4hep.sh DESTINATION bin )
0300 install(FILES    ${CMAKE_BINARY_DIR}/bin/thisdd4hep_only.sh DESTINATION bin )
0301 install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/run_test.sh         DESTINATION bin )
0302 
0303 install(DIRECTORY cmake
0304   DESTINATION ${CMAKE_INSTALL_PREFIX}
0305   FILES_MATCHING PATTERN "*.cmake" PATTERN "thisdd4hep_package.sh.in" PATTERN "run*.sh" PATTERN "*.cpp"
0306   PATTERN ".svn" EXCLUDE
0307   )
0308 
0309 #--- enable CPack --------------------------------------------
0310 
0311 option(ENABLE_CPACK "Whether or not to use cpack config" OFF)
0312 if(ENABLE_CPACK)
0313   include(cmake/DD4hepCPack.cmake)
0314 endif()
0315 
0316 ###############################
0317 # Dispaly final configuration #
0318 ###############################
0319 
0320 display_std_variables()
0321 
0322 ######################################################
0323 # generate and install following configuration files #
0324 ######################################################
0325 
0326 CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/cmake/DD4hepConfig.cmake.in
0327   ${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake @ONLY
0328   )
0329 INSTALL(FILES ${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake DESTINATION cmake)
0330 
0331 dd4hep_generate_package_configuration_files( ${CMAKE_PROJECT_NAME}Config.cmake )
0332 
0333 if(APPLE)
0334   SET ( ENV{DD4HEP_LIBRARY_PATH} $ENV{DYLD_LIBRARY_PATH} )
0335 else()
0336   SET ( ENV{DD4HEP_LIBRARY_PATH} ${LD_LIBRARY_PATH} )
0337   SET ( DD4HEP_LIBRARY_PATH      ${LD_LIBRARY_PATH} )
0338 endif()
0339 
0340 #######################
0341 # Treatment for Apple #
0342 #######################
0343 
0344 if(APPLE)
0345   fill_dd4hep_library_path()
0346   message(STATUS "DD4HEP_LIBRARY_PATH= $ENV{DD4HEP_LIBRARY_PATH}")
0347 endif()
0348 
0349 INSTALL(EXPORT DD4hep 
0350   NAMESPACE DD4hep::
0351   FILE ${CMAKE_PROJECT_NAME}Config-targets.cmake
0352   DESTINATION cmake
0353   )