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