Warning, /EICrecon/CMakeLists.txt is written in an unsupported language. File is not indexed.
0001 # cmake-format: off
0002 #
0003 # Variables to control this CMake build:
0004 # ===================================================================================
0005 # CMake flag | environment variable | Description
0006 # ===================================================================================
0007 # -- (under review) | EDM4HEP_ROOT | Edm4Hep installation directory
0008 #------------------------------------------------------------------------------------
0009 # -DCMAKE_CXX_STANDARD | 17 - standard for C++ compilation
0010 # ===================================================================================
0011 #
0012 #
0013 # ==============================================================
0014 # DEPENDENCIES (used by find_package)
0015 # ==============================================================
0016 # Name | Description
0017 # ==============================================================
0018 # JANA | Jana2 framework
0019 # EDM4HEP | Event data model based on podio
0020 # podio | IO library
0021 # DD4hep | Geometry framework
0022 # ROOT | CERN ROOT
0023 # spdlog | Formatting library
0024 # IRT | Indirect Ray Tracing library
0025 # ==============================================================
0026 #
0027 # cmake-format: on
0028
0029 cmake_minimum_required(VERSION 3.24)
0030
0031 # 3.27: find_package() uses upper-case <PACKAGENAME>_ROOT variables
0032 cmake_policy(SET CMP0144 NEW)
0033
0034 project(EICrecon LANGUAGES CXX)
0035
0036 # CMake includes
0037 include(CheckCXXCompilerFlag)
0038
0039 # Set version based on git
0040 include(cmake/git_version.cmake)
0041 set_git_version(CMAKE_PROJECT_VERSION)
0042
0043 # Set a default build type if none was specified
0044 set(default_build_type "Release")
0045 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
0046 message(
0047 STATUS
0048 "Setting build type to '${default_build_type}' as none was specified.")
0049 set(CMAKE_BUILD_TYPE
0050 "${default_build_type}"
0051 CACHE STRING "Choose the type of build." FORCE)
0052 # Set the possible values of build type for cmake-gui
0053 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
0054 "MinSizeRel" "RelWithDebInfo")
0055 endif()
0056
0057 # Set default standard to C++20
0058 set(CMAKE_CXX_STANDARD_MIN 20)
0059 set(CMAKE_CXX_STANDARD
0060 ${CMAKE_CXX_STANDARD_MIN}
0061 CACHE STRING "C++ standard to be used")
0062 if(CMAKE_CXX_STANDARD LESS CMAKE_CXX_STANDARD_MIN)
0063 message(
0064 FATAL_ERROR
0065 "Unsupported C++ standard: ${CMAKE_CXX_STANDARD} (at least ${CMAKE_CXX_STANDARD_MIN} required)"
0066 )
0067 endif()
0068 set(CMAKE_CXX_STANDARD_REQUIRED ON)
0069 set(CMAKE_CXX_EXTENSIONS OFF)
0070
0071 # Infrastructure to support use of --no-as-needed
0072 include(CheckLinkerFlag)
0073 check_linker_flag(CXX "LINKER:--no-as-needed" CXX_LINKER_HAS_no_as_needed)
0074 set(CMAKE_CXX_LINK_LIBRARY_USING_NO_AS_NEEDED_SUPPORTED TRUE)
0075 set(CMAKE_CXX_LINK_LIBRARY_USING_NO_AS_NEEDED
0076 "LINKER:--push-state,--no-as-needed" "<LINK_ITEM>" "LINKER:--pop-state")
0077
0078 # Export compile commands as json for run-clang-tidy
0079 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
0080
0081 # This PROJECT_SOURCE_DIR at this point corresponds to repository root. Saving
0082 # it as EICRECON_SOURCE_DIR so can be used for jana_plugin.cmake to correctly
0083 # set plugin includes (and in other places as needed)
0084 set(EICRECON_SOURCE_DIR ${PROJECT_SOURCE_DIR})
0085
0086 # Also use clang-tidy integration in CMake
0087 option(ENABLE_CLANG_TIDY "Enable clang-tidy integration in cmake" OFF)
0088 if(ENABLE_CLANG_TIDY)
0089 find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
0090 if(CLANG_TIDY_EXE)
0091 message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
0092 set(CMAKE_CXX_CLANG_TIDY
0093 "${CLANG_TIDY_EXE}"
0094 CACHE STRING "" FORCE)
0095 else()
0096 set(CMAKE_CXX_CLANG_TIDY
0097 ""
0098 CACHE STRING "" FORCE)
0099 endif()
0100 endif()
0101
0102 # Enable -fPIC for all targets
0103 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
0104
0105 # Install to the top directory by default
0106 if(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
0107 set(CMAKE_INSTALL_PREFIX
0108 ${CMAKE_SOURCE_DIR}
0109 CACHE PATH "Install in top directory by default" FORCE)
0110 endif()
0111
0112 # Install to standard location
0113 include(GNUInstallDirs)
0114
0115 # Default plugins installation directory is 'plugins'
0116 if(NOT DEFINED PLUGIN_OUTPUT_DIRECTORY)
0117 set(PLUGIN_OUTPUT_DIRECTORY "lib/${PROJECT_NAME}/plugins")
0118 message(STATUS "${CMAKE_PROJECT_NAME}: Set default PLUGIN_OUTPUT_DIRECTORY")
0119 endif()
0120 message(
0121 STATUS
0122 "${CMAKE_PROJECT_NAME}: PLUGIN_OUTPUT_DIRECTORY: ${PLUGIN_OUTPUT_DIRECTORY}"
0123 )
0124
0125 # Default plugins static libraries installation directory is 'lib'
0126 if(NOT DEFINED PLUGIN_LIBRARY_OUTPUT_DIRECTORY)
0127 set(PLUGIN_LIBRARY_OUTPUT_DIRECTORY "lib")
0128 message(STATUS "${CMAKE_PROJECT_NAME}: Set default PLUGIN_OUTPUT_DIRECTORY")
0129 endif()
0130 message(
0131 STATUS
0132 "${CMAKE_PROJECT_NAME}: PLUGIN_LIBRARY_OUTPUT_DIRECTORY: ${PLUGIN_LIBRARY_OUTPUT_DIRECTORY}"
0133 )
0134
0135 # Use, i.e. don't skip the full RPATH for the build tree, and use relative paths
0136 # for relocatable build products
0137 set(CMAKE_SKIP_BUILD_RPATH FALSE)
0138 set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
0139
0140 # When building, don't use the install RPATH already (but later on when
0141 # installing)
0142 set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
0143 set(CMAKE_SKIP_INSTALL_RPATH FALSE)
0144 set(CMAKE_INSTALL_RPATH
0145 "${CMAKE_INSTALL_PREFIX}/${PLUGIN_LIBRARY_OUTPUT_DIRECTORY};${CMAKE_INSTALL_PREFIX}/${PLUGIN_OUTPUT_DIRECTORY}"
0146 )
0147
0148 # Add the automatically determined parts of the RPATH which point to directories
0149 # outside the build tree to the install RPATH
0150 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
0151
0152 # Check and print what JANA2 is used
0153 find_package(JANA REQUIRED)
0154 message(STATUS "${CMAKE_PROJECT_NAME}: JANA2 CMake : ${JANA_DIR}")
0155 message(STATUS "${CMAKE_PROJECT_NAME}: JANA2 includes: ${JANA_INCLUDE_DIR}")
0156 message(STATUS "${CMAKE_PROJECT_NAME}: JANA2 library : ${JANA_LIBRARY}")
0157
0158 # Algorithms
0159 find_package(algorithms 1.0.0 REQUIRED Core)
0160
0161 # PODIO, EDM4HEP, EDM4EIC event models
0162 find_package(Eigen3 REQUIRED)
0163 find_package(podio REQUIRED)
0164 find_package(EDM4HEP 0.7.1 REQUIRED)
0165 find_package(EDM4EIC 5.0 REQUIRED)
0166
0167 # spdlog
0168 find_package(spdlog REQUIRED)
0169
0170 # fmt
0171 find_package(fmt 9.0.0 REQUIRED)
0172
0173 # Guidelines Support Library
0174 find_package(Microsoft.GSL CONFIG)
0175
0176 # Remove PODIO_JSON_OUTPUT (ref: https://github.com/AIDASoft/podio/issues/475)
0177 get_target_property(EDM4HEP_INTERFACE_COMPILE_DEFINITIONS EDM4HEP::edm4hep
0178 INTERFACE_COMPILE_DEFINITIONS)
0179 if(EDM4HEP_INTERFACE_COMPILE_DEFINITIONS)
0180 list(FILTER EDM4HEP_INTERFACE_COMPILE_DEFINITIONS EXCLUDE REGEX
0181 [[^PODIO_JSON_OUTPUT$]])
0182 set_property(
0183 TARGET EDM4HEP::edm4hep PROPERTY INTERFACE_COMPILE_DEFINITIONS
0184 ${EDM4HEP_INTERFACE_COMPILE_DEFINITIONS})
0185 endif()
0186 get_target_property(EDM4EIC_INTERFACE_COMPILE_DEFINITIONS EDM4EIC::edm4eic
0187 INTERFACE_COMPILE_DEFINITIONS)
0188 if(EDM4EIC_INTERFACE_COMPILE_DEFINITIONS)
0189 list(FILTER EDM4EIC_INTERFACE_COMPILE_DEFINITIONS EXCLUDE REGEX
0190 [[^PODIO_JSON_OUTPUT$]])
0191 set_property(
0192 TARGET EDM4EIC::edm4eic PROPERTY INTERFACE_COMPILE_DEFINITIONS
0193 ${EDM4EIC_INTERFACE_COMPILE_DEFINITIONS})
0194 endif()
0195
0196 # DD4Hep is required for the most of the part
0197 find_package(DD4hep REQUIRED)
0198
0199 # ACTS cmake-lint: disable=C0103
0200 find_package(Acts REQUIRED COMPONENTS Core PluginDD4hep PluginJson)
0201 set(Acts_VERSION_MIN "19.0.0")
0202 set(Acts_VERSION
0203 "${Acts_VERSION_MAJOR}.${Acts_VERSION_MINOR}.${Acts_VERSION_PATCH}")
0204 if(${Acts_VERSION} VERSION_LESS ${Acts_VERSION_MIN} AND NOT "${Acts_VERSION}"
0205 STREQUAL "9.9.9")
0206 message(
0207 FATAL_ERROR
0208 "Acts version ${Acts_VERSION_MIN} or higher required, but ${Acts_VERSION} found"
0209 )
0210 endif()
0211 # ActsCore
0212 get_target_property(ACTS_COMPILE_FEATURES ActsCore INTERFACE_COMPILE_FEATURES)
0213 if(NOT "cxx_std_${CMAKE_CXX_STANDARD}" IN_LIST ACTS_COMPILE_FEATURES)
0214 message(
0215 WARNING
0216 "Acts has not been built with the requested C++ standard ${CMAKE_CXX_STANDARD}."
0217 )
0218 endif()
0219
0220 # ROOT
0221 find_package(ROOT REQUIRED)
0222 # Check that ROOT is compiled with a modern enough c++ standard
0223 get_target_property(ROOT_COMPILE_FEATURES ROOT::Core INTERFACE_COMPILE_FEATURES)
0224 if(NOT "cxx_std_${CMAKE_CXX_STANDARD}" IN_LIST ROOT_COMPILE_FEATURES)
0225 message(
0226 WARNING
0227 "ROOT has not been built with the requested C++ standard ${CMAKE_CXX_STANDARD}."
0228 )
0229 endif()
0230
0231 # ONNX Runtime
0232 option(USE_ONNX "Compile with ONNX support" ON)
0233 if(${USE_ONNX})
0234 find_package(onnxruntime CONFIG)
0235 add_compile_definitions(USE_ONNX)
0236 endif()
0237
0238 # Add CMake additional functionality:
0239 include(cmake/jana_plugin.cmake) # Add common settings for plugins
0240 list(APPEND CMAKE_MODULE_PATH ${EICRECON_SOURCE_DIR}/cmake
0241 )# Find Find<Modules>.cmake
0242
0243 enable_testing()
0244
0245 # Address sanitizer
0246 option(USE_ASAN "Compile with address sanitizer" OFF)
0247 if(${USE_ASAN})
0248 add_compile_options(-fsanitize=address -fno-omit-frame-pointer -g -O1)
0249 add_link_options(-fsanitize=address)
0250 install(FILES .github/asan.supp .github/lsan.supp
0251 DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
0252 endif()
0253
0254 # Thread sanitizer
0255 option(USE_TSAN "Compile with thread sanitizer" OFF)
0256 if(${USE_TSAN})
0257 add_compile_options(-fsanitize=thread -g -O1)
0258 add_link_options(-fsanitize=thread)
0259 install(FILES .github/tsan.supp
0260 DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
0261 endif()
0262
0263 # Undefined behavior sanitizer
0264 option(USE_UBSAN "Compile with undefined behavior sanitizer" OFF)
0265 if(${USE_UBSAN})
0266 foreach(sanitizer undefined float-divide-by-zero unsigned-integer-overflow
0267 implicit-conversion local-bounds nullability)
0268 check_cxx_compiler_flag("-fsanitize=${sanitizer}"
0269 CXX_COMPILER_HAS_sanitize_${sanitizer})
0270 if(CXX_COMPILER_HAS_sanitize_${sanitizer})
0271 add_compile_options(-fsanitize=${sanitizer})
0272 add_link_options(-fsanitize=${sanitizer})
0273 endif()
0274 endforeach()
0275 add_compile_options(-g -O1)
0276 install(FILES .github/ubsan.supp
0277 DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
0278 endif()
0279
0280 # Compress debug symbols if supported
0281 check_cxx_compiler_flag("-gz" CXX_COMPILER_HAS_gz)
0282 if(CXX_COMPILER_HAS_gz)
0283 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -gz")
0284 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -gz")
0285 endif()
0286
0287 add_subdirectory(src/services)
0288 add_subdirectory(src/algorithms)
0289 add_subdirectory(src/benchmarks)
0290 add_subdirectory(src/detectors)
0291 add_subdirectory(src/examples)
0292 add_subdirectory(src/extensions)
0293 add_subdirectory(src/factories)
0294 add_subdirectory(src/global)
0295 add_subdirectory(src/scripts)
0296 add_subdirectory(src/tests)
0297 add_subdirectory(src/utilities)
0298
0299 # Install all cmake helpers
0300 include(CMakePackageConfigHelpers)
0301 configure_package_config_file(
0302 cmake/${PROJECT_NAME}Config.cmake.in
0303 ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
0304 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
0305 write_basic_package_version_file(
0306 ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake
0307 VERSION ${CMAKE_PROJECT_VERSION}
0308 COMPATIBILITY SameMajorVersion)
0309 install(
0310 FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
0311 ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake
0312 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
0313 install(
0314 EXPORT ${PROJECT_NAME}Targets
0315 NAMESPACE ${PROJECT_NAME}::
0316 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
0317 install(
0318 DIRECTORY cmake/
0319 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
0320 FILES_MATCHING
0321 PATTERN *.cmake)