diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f8b56c..67c863f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.15) -project(k4SimGeant4) +project(k4SimGeant4 LANGUAGES CXX) #--------------------------------------------------------------- # Options @@ -11,32 +11,24 @@ find_package(ROOT COMPONENTS RIO Tree) #--------------------------------------------------------------- # Load macros and functions for Gaudi-based projects -find_package(Gaudi) -find_package(k4FWCore) -find_package(Geant4) -find_package(DD4hep) -find_package(CLHEP) +find_package(Gaudi REQUIRED) +find_package(k4FWCore REQUIRED) find_package(EDM4HEP 0.99) +find_package(Geant4 REQUIRED) +find_package(DD4hep REQUIRED) +find_package(CLHEP REQUIRED) #--------------------------------------------------------------- +include(cmake/Key4hepConfig.cmake) + include(GNUInstallDirs) include(CTest) -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "RPATH USE LINK PATH") - if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/InstallArea/ CACHE PATH "Install path prefix, prepended onto install directories." FORCE ) endif() -# Set up C++ Standard -# ``-DCMAKE_CXX_STANDARD=`` when invoking CMake -set(CMAKE_CXX_STANDARD 17 CACHE STRING "") - -if(NOT CMAKE_CXX_STANDARD MATCHES "17|20") - message(FATAL_ERROR "Unsupported C++ standard: ${CMAKE_CXX_STANDARD}") -endif() - message(${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) message(${CMAKE_MODULE_PATH}) diff --git a/cmake/Key4hepConfig.cmake b/cmake/Key4hepConfig.cmake new file mode 100644 index 0000000..7579de1 --- /dev/null +++ b/cmake/Key4hepConfig.cmake @@ -0,0 +1,88 @@ +# Do not edit this file, it will be overwritten! +# The template file can be found in +# https://github.com/key4hep/key4hep-dev-utils/blob/main/defaults/cmake/Key4hepConfig.cmake + +macro(key4hep_set_compiler_flags) + + set(COMPILER_FLAGS "-fPIC -Wall -Wextra -Wpedantic -Wshadow -Wdeprecated") + + if(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$") + set(COMPILER_FLAGS "${COMPILER_FLAGS} -Winconsistent-missing-override -Wheader-hygiene -fcolor-diagnostics") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(COMPILER_FLAGS "${COMPILER_FLAGS} -fdiagnostics-color=always -Wno-dangling-reference") + endif() + + if (DEFINED KEY4HEP_SET_COMPILER_FLAGS AND NOT KEY4HEP_SET_COMPILER_FLAGS) + else() + set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}") + endif() + +endmacro() + +macro(key4hep_set_build_type) + + # For ccmake and cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "None" "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + + if(NOT CMAKE_CONFIGURATION_TYPES) + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo + CACHE STRING "Choose the type of build, options are: None, Release, MinSizeRel, Debug, RelWithDebInfo (default)" + FORCE + ) + else() + set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" + CACHE STRING "Choose the type of build, options are: None, Release, MinSizeRel, Debug, RelWithDebInfo (default)" + FORCE + ) + endif() + endif() +endmacro() + +macro(key4hep_set_cxx_standard_and_extensions) + set(CMAKE_CXX_STANDARD 20 CACHE STRING "") + + if(NOT CMAKE_CXX_STANDARD MATCHES "20|23") + message(FATAL_ERROR "Unsupported C++ standard: ${CMAKE_CXX_STANDARD}, supported values are 20 and 23") + endif() + + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) + +endmacro() + +macro(key4hep_set_rpath) + # When building, don't use the install RPATH already (but later on when installing) + set(CMAKE_SKIP_BUILD_RPATH FALSE) # don't skip the full RPATH for the build tree + set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # use always the build RPATH for the build tree + set(CMAKE_MACOSX_RPATH TRUE) # use RPATH for MacOSX + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # point to directories outside the build tree to the install RPATH + + # Check whether to add RPATH to the installation (the build tree always has the RPATH enabled) + if(APPLE) + set(CMAKE_INSTALL_NAME_DIR "@rpath") + set(CMAKE_INSTALL_RPATH "@loader_path/../lib") # self relative LIBDIR + # the RPATH to be used when installing, but only if it's not a system directory + list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) + if("${isSystemDir}" STREQUAL "-1") + set(CMAKE_INSTALL_RPATH "@loader_path/../lib") + endif() + elseif(DEFINED KEY4HEP_SET_RPATH AND NOT KEY4HEP_SET_RPATH) + set(CMAKE_SKIP_INSTALL_RPATH TRUE) # skip the full RPATH for the install tree + else() + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBDIR}") # install LIBDIR + # the RPATH to be used when installing, but only if it's not a system directory + list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) + if("${isSystemDir}" STREQUAL "-1") + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBDIR}") + endif() + endif() +endmacro() + +################################################### + +key4hep_set_compiler_flags() +key4hep_set_build_type() +key4hep_set_cxx_standard_and_extensions() +key4hep_set_rpath()