-
Notifications
You must be signed in to change notification settings - Fork 29
/
CMakeLists.txt
321 lines (283 loc) · 11.2 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# cmake-format: off
#
# Variables to control this CMake build:
# ===================================================================================
# CMake flag | environment variable | Description
# ===================================================================================
# -- (under review) | EDM4HEP_ROOT | Edm4Hep installation directory
#------------------------------------------------------------------------------------
# -DCMAKE_CXX_STANDARD | 17 - standard for C++ compilation
# ===================================================================================
#
#
# ==============================================================
# DEPENDENCIES (used by find_package)
# ==============================================================
# Name | Description
# ==============================================================
# JANA | Jana2 framework
# EDM4HEP | Event data model based on podio
# podio | IO library
# DD4hep | Geometry framework
# ROOT | CERN ROOT
# spdlog | Formatting library
# IRT | Indirect Ray Tracing library
# ==============================================================
#
# cmake-format: on
cmake_minimum_required(VERSION 3.24)
# 3.27: find_package() uses upper-case <PACKAGENAME>_ROOT variables
cmake_policy(SET CMP0144 NEW)
project(EICrecon LANGUAGES CXX)
# CMake includes
include(CheckCXXCompilerFlag)
# Set version based on git
include(cmake/git_version.cmake)
set_git_version(CMAKE_PROJECT_VERSION)
# Set a default build type if none was specified
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(
STATUS
"Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE
"${default_build_type}"
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
# Set default standard to C++20
set(CMAKE_CXX_STANDARD_MIN 20)
set(CMAKE_CXX_STANDARD
${CMAKE_CXX_STANDARD_MIN}
CACHE STRING "C++ standard to be used")
if(CMAKE_CXX_STANDARD LESS CMAKE_CXX_STANDARD_MIN)
message(
FATAL_ERROR
"Unsupported C++ standard: ${CMAKE_CXX_STANDARD} (at least ${CMAKE_CXX_STANDARD_MIN} required)"
)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Infrastructure to support use of --no-as-needed
include(CheckLinkerFlag)
check_linker_flag(CXX "LINKER:--no-as-needed" CXX_LINKER_HAS_no_as_needed)
set(CMAKE_CXX_LINK_LIBRARY_USING_NO_AS_NEEDED_SUPPORTED TRUE)
set(CMAKE_CXX_LINK_LIBRARY_USING_NO_AS_NEEDED
"LINKER:--push-state,--no-as-needed" "<LINK_ITEM>" "LINKER:--pop-state")
# Export compile commands as json for run-clang-tidy
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# This PROJECT_SOURCE_DIR at this point corresponds to repository root. Saving
# it as EICRECON_SOURCE_DIR so can be used for jana_plugin.cmake to correctly
# set plugin includes (and in other places as needed)
set(EICRECON_SOURCE_DIR ${PROJECT_SOURCE_DIR})
# Also use clang-tidy integration in CMake
option(ENABLE_CLANG_TIDY "Enable clang-tidy integration in cmake" OFF)
if(ENABLE_CLANG_TIDY)
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
if(CLANG_TIDY_EXE)
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(CMAKE_CXX_CLANG_TIDY
"${CLANG_TIDY_EXE}"
CACHE STRING "" FORCE)
else()
set(CMAKE_CXX_CLANG_TIDY
""
CACHE STRING "" FORCE)
endif()
endif()
# Enable -fPIC for all targets
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Install to the top directory by default
if(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
set(CMAKE_INSTALL_PREFIX
${CMAKE_SOURCE_DIR}
CACHE PATH "Install in top directory by default" FORCE)
endif()
# Install to standard location
include(GNUInstallDirs)
# Default plugins installation directory is 'plugins'
if(NOT DEFINED PLUGIN_OUTPUT_DIRECTORY)
set(PLUGIN_OUTPUT_DIRECTORY "lib/${PROJECT_NAME}/plugins")
message(STATUS "${CMAKE_PROJECT_NAME}: Set default PLUGIN_OUTPUT_DIRECTORY")
endif()
message(
STATUS
"${CMAKE_PROJECT_NAME}: PLUGIN_OUTPUT_DIRECTORY: ${PLUGIN_OUTPUT_DIRECTORY}"
)
# Default plugins static libraries installation directory is 'lib'
if(NOT DEFINED PLUGIN_LIBRARY_OUTPUT_DIRECTORY)
set(PLUGIN_LIBRARY_OUTPUT_DIRECTORY "lib")
message(STATUS "${CMAKE_PROJECT_NAME}: Set default PLUGIN_OUTPUT_DIRECTORY")
endif()
message(
STATUS
"${CMAKE_PROJECT_NAME}: PLUGIN_LIBRARY_OUTPUT_DIRECTORY: ${PLUGIN_LIBRARY_OUTPUT_DIRECTORY}"
)
# Use, i.e. don't skip the full RPATH for the build tree, and use relative paths
# for relocatable build products
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
# When building, don't use the install RPATH already (but later on when
# installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_SKIP_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH
"${CMAKE_INSTALL_PREFIX}/${PLUGIN_LIBRARY_OUTPUT_DIRECTORY};${CMAKE_INSTALL_PREFIX}/${PLUGIN_OUTPUT_DIRECTORY}"
)
# Add the automatically determined parts of the RPATH which point to directories
# outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Check and print what JANA2 is used
find_package(JANA REQUIRED)
message(STATUS "${CMAKE_PROJECT_NAME}: JANA2 CMake : ${JANA_DIR}")
message(STATUS "${CMAKE_PROJECT_NAME}: JANA2 includes: ${JANA_INCLUDE_DIR}")
message(STATUS "${CMAKE_PROJECT_NAME}: JANA2 library : ${JANA_LIBRARY}")
# Algorithms
find_package(algorithms 1.0.0 REQUIRED Core)
# PODIO, EDM4HEP, EDM4EIC event models
find_package(Eigen3 REQUIRED)
find_package(podio REQUIRED)
find_package(EDM4HEP 0.7.1 REQUIRED)
find_package(EDM4EIC 5.0 REQUIRED)
# spdlog
find_package(spdlog REQUIRED)
# fmt
find_package(fmt 9.0.0 REQUIRED)
# Guidelines Support Library
find_package(Microsoft.GSL CONFIG)
# Remove PODIO_JSON_OUTPUT (ref: https://github.com/AIDASoft/podio/issues/475)
get_target_property(EDM4HEP_INTERFACE_COMPILE_DEFINITIONS EDM4HEP::edm4hep
INTERFACE_COMPILE_DEFINITIONS)
if(EDM4HEP_INTERFACE_COMPILE_DEFINITIONS)
list(FILTER EDM4HEP_INTERFACE_COMPILE_DEFINITIONS EXCLUDE REGEX
[[^PODIO_JSON_OUTPUT$]])
set_property(
TARGET EDM4HEP::edm4hep PROPERTY INTERFACE_COMPILE_DEFINITIONS
${EDM4HEP_INTERFACE_COMPILE_DEFINITIONS})
endif()
get_target_property(EDM4EIC_INTERFACE_COMPILE_DEFINITIONS EDM4EIC::edm4eic
INTERFACE_COMPILE_DEFINITIONS)
if(EDM4EIC_INTERFACE_COMPILE_DEFINITIONS)
list(FILTER EDM4EIC_INTERFACE_COMPILE_DEFINITIONS EXCLUDE REGEX
[[^PODIO_JSON_OUTPUT$]])
set_property(
TARGET EDM4EIC::edm4eic PROPERTY INTERFACE_COMPILE_DEFINITIONS
${EDM4EIC_INTERFACE_COMPILE_DEFINITIONS})
endif()
# DD4Hep is required for the most of the part
find_package(DD4hep REQUIRED)
# ACTS cmake-lint: disable=C0103
find_package(Acts REQUIRED COMPONENTS Core PluginDD4hep PluginJson)
set(Acts_VERSION_MIN "19.0.0")
set(Acts_VERSION
"${Acts_VERSION_MAJOR}.${Acts_VERSION_MINOR}.${Acts_VERSION_PATCH}")
if(${Acts_VERSION} VERSION_LESS ${Acts_VERSION_MIN} AND NOT "${Acts_VERSION}"
STREQUAL "9.9.9")
message(
FATAL_ERROR
"Acts version ${Acts_VERSION_MIN} or higher required, but ${Acts_VERSION} found"
)
endif()
# ActsCore
get_target_property(ACTS_COMPILE_FEATURES ActsCore INTERFACE_COMPILE_FEATURES)
if(NOT "cxx_std_${CMAKE_CXX_STANDARD}" IN_LIST ACTS_COMPILE_FEATURES)
message(
WARNING
"Acts has not been built with the requested C++ standard ${CMAKE_CXX_STANDARD}."
)
endif()
# ROOT
find_package(ROOT REQUIRED)
# Check that ROOT is compiled with a modern enough c++ standard
get_target_property(ROOT_COMPILE_FEATURES ROOT::Core INTERFACE_COMPILE_FEATURES)
if(NOT "cxx_std_${CMAKE_CXX_STANDARD}" IN_LIST ROOT_COMPILE_FEATURES)
message(
WARNING
"ROOT has not been built with the requested C++ standard ${CMAKE_CXX_STANDARD}."
)
endif()
# ONNX Runtime
option(USE_ONNX "Compile with ONNX support" ON)
if(${USE_ONNX})
find_package(onnxruntime CONFIG)
add_compile_definitions(USE_ONNX)
endif()
# Add CMake additional functionality:
include(cmake/jana_plugin.cmake) # Add common settings for plugins
list(APPEND CMAKE_MODULE_PATH ${EICRECON_SOURCE_DIR}/cmake
)# Find Find<Modules>.cmake
enable_testing()
# Address sanitizer
option(USE_ASAN "Compile with address sanitizer" OFF)
if(${USE_ASAN})
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -g -O1)
add_link_options(-fsanitize=address)
install(FILES .github/asan.supp .github/lsan.supp
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
endif()
# Thread sanitizer
option(USE_TSAN "Compile with thread sanitizer" OFF)
if(${USE_TSAN})
add_compile_options(-fsanitize=thread -g -O1)
add_link_options(-fsanitize=thread)
install(FILES .github/tsan.supp
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
endif()
# Undefined behavior sanitizer
option(USE_UBSAN "Compile with undefined behavior sanitizer" OFF)
if(${USE_UBSAN})
foreach(sanitizer undefined float-divide-by-zero unsigned-integer-overflow
implicit-conversion local-bounds nullability)
check_cxx_compiler_flag("-fsanitize=${sanitizer}"
CXX_COMPILER_HAS_sanitize_${sanitizer})
if(CXX_COMPILER_HAS_sanitize_${sanitizer})
add_compile_options(-fsanitize=${sanitizer})
add_link_options(-fsanitize=${sanitizer})
endif()
endforeach()
add_compile_options(-g -O1)
install(FILES .github/ubsan.supp
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
endif()
# Compress debug symbols if supported
check_cxx_compiler_flag("-gz" CXX_COMPILER_HAS_gz)
if(CXX_COMPILER_HAS_gz)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -gz")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -gz")
endif()
add_subdirectory(src/services)
add_subdirectory(src/algorithms)
add_subdirectory(src/benchmarks)
add_subdirectory(src/detectors)
add_subdirectory(src/examples)
add_subdirectory(src/extensions)
add_subdirectory(src/factories)
add_subdirectory(src/global)
add_subdirectory(src/scripts)
add_subdirectory(src/tests)
add_subdirectory(src/utilities)
# Install all cmake helpers
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
install(
DIRECTORY cmake/
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
FILES_MATCHING
PATTERN *.cmake)