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