This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
218 lines (197 loc) · 7.66 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
# Set the minimum version of CMake that's required
cmake_minimum_required(VERSION 3.12)
# Set the project name
project(fire
VERSION 0.19.0
DESCRIPTION "fire for sImulation and Reconstruction of Events"
LANGUAGES C CXX)
# Set the default release type to "Release". If a release type is specified
# at the command line, it's respected.
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)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
# necessary dependencies
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
find_package(Boost REQUIRED COMPONENTS log)
find_package(HighFive REQUIRED)
# optional dependency
include(CMakeDependentOption)
find_package(ROOT 6.20 QUIET)
# the option fire_USER_ROOT is
# ON (by default, still settable by user) if ROOT_FOUND is true and
# is OFF and not settably by user if ROOT_FOUND is false
cmake_dependent_option(fire_USE_ROOT
"Enable ability to read files produced with ROOT-based Framework"
ON "ROOT_FOUND" OFF)
# Execute the command to extract the SHA1 hash of the current git tag.
# 'git' is removed from within the container to discourage opening a shell
# in the container, so we need to go to some lengths in order to avoid using 'git'
# The variable GIT_SHA1 will be set to contain the hash.
set(git_dir "${PROJECT_SOURCE_DIR}/.git")
if (NOT IS_DIRECTORY "${git_dir}")
# we are a submodule of another project
file(READ "${git_dir}" git_dir)
string(REGEX REPLACE "^gitdir: " "" git_dir ${git_dir})
string(REGEX REPLACE "\n$" "" git_dir ${git_dir})
endif()
file(READ "${git_dir}/HEAD" current_ref)
string(REGEX REPLACE "\n$" "" current_ref ${current_ref})
if (current_ref MATCHES "^ref:.*$")
# on a branch
string(REGEX REPLACE "^ref: " "" current_ref "${current_ref}")
file(READ "${git_dir}/${current_ref}" GIT_SHA1)
string(REGEX REPLACE "\n$" "" GIT_SHA1 ${GIT_SHA1})
else()
# in detached head state (probably on a tag)
set(GIT_SHA1 ${current_ref})
endif()
message(STATUS "Deduced git SHA: ${GIT_SHA1}")
# Copies the file 'Version.h.in', substitutes the value of GIT_SHA1 and writes
# it out to Version.h.
configure_file(${PROJECT_SOURCE_DIR}/include/fire/version/Version.h.in
${PROJECT_BINARY_DIR}/include/fire/version/Version.h)
install(FILES ${PROJECT_BINARY_DIR}/include/fire/version/Version.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/fire/version)
add_library(version INTERFACE)
target_include_directories(version
INTERFACE
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>"
)
add_library(exception SHARED src/fire/exception/Exception.cxx)
target_include_directories(exception
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>"
)
add_library(factory SHARED src/fire/factory/Factory.cxx)
target_link_libraries(factory PUBLIC exception Boost::boost)
target_include_directories(factory
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>"
)
add_library(logging SHARED src/fire/logging/Logger.cxx)
target_link_libraries(logging PUBLIC Boost::log)
target_include_directories(logging
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>"
)
add_library(config SHARED src/fire/config/Python.cxx)
target_link_libraries(config PUBLIC exception Python3::Python Boost::boost)
if (fire_USE_ROOT)
message(STATUS "Building ROOT reader")
# include ROOT reader in io submodule
add_library(io SHARED
src/fire/io/Writer.cxx
src/fire/io/Atomic.cxx
src/fire/io/Open.cxx
src/fire/io/ParameterStorage.cxx
src/fire/io/h5/Reader.cxx
src/fire/io/root/Reader.cxx)
target_link_libraries(io PUBLIC version config HighFive ROOT::Core ROOT::TreePlayer)
else()
message(WARNING "Reading ROOT files will not be supported.")
add_library(io SHARED
src/fire/io/Writer.cxx
src/fire/io/Atomic.cxx
src/fire/io/Open.cxx
src/fire/io/ParameterStorage.cxx
src/fire/io/h5/Reader.cxx)
target_link_libraries(io PUBLIC version config HighFive)
endif()
add_library(framework SHARED
src/fire/StorageControl.cxx
src/fire/Event.cxx
src/fire/EventHeader.cxx
src/fire/Processor.cxx
src/fire/Process.cxx
src/fire/RunHeader.cxx
src/fire/ConditionsIntervalOfValidity.cxx
src/fire/ConditionsProvider.cxx
src/fire/Conditions.cxx
src/fire/RandomNumberSeedService.cxx
src/fire/UserReader.cxx
)
target_link_libraries(framework PUBLIC logging version exception config factory io Boost::boost)
target_include_directories(framework PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>")
if(fire_USE_ROOT)
# generate dictionary source file from headers and link def
root_generate_dictionary(fireDict
${PROJECT_SOURCE_DIR}/include/fire/RunHeader.h
${PROJECT_SOURCE_DIR}/include/fire/EventHeader.h
LINKDEF ${PROJECT_SOURCE_DIR}/include/fire/fireLinkDef.h
MODULE framework)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libframework_rdict.pcm DESTINATION lib)
endif()
# Compiling the fire library requires features introduced by the cxx 17 standard.
# also to avoid conflicts, we expand the library prefix from 'lib' to 'libfire_'
set_target_properties(
framework exception config factory io logging
PROPERTIES CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
PREFIX "libfire_")
# installing the fire target and generate CMake-compatible package files
# is done by following the documentation linked below
# https://cmake.org/cmake/help/git-stage/guide/importing-exporting/index.html
install(TARGETS framework exception config factory io version logging
EXPORT fireTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
# need pattern to exclude version header configured by CMake above
install(DIRECTORY include/ DESTINATION include/ FILES_MATCHING PATTERN "*.h")
# install everything except the pytest modules
install(DIRECTORY python/ DESTINATION python/ FILES_MATCHING
PATTERN "*.py" # INCLUDE
PATTERN "test_*" EXCLUDE
PATTERN ".pytest_cache" EXCLUDE
PATTERN "__pycache__" EXCLUDE
)
# install the export file
install(EXPORT fireTargets
FILE fireTargets.cmake
NAMESPACE fire::
DESTINATION lib/cmake/fire
)
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/fireConfig.cmake"
INSTALL_DESTINATION lib/cmake/fire
)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/fireConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/fireConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/fireConfigVersion.cmake"
DESTINATION lib/cmake/fire
)
# Add the fire executable
add_executable(fire app/fire.cxx)
target_link_libraries(fire PRIVATE framework)
install(TARGETS fire DESTINATION bin)
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
if (BUILD_TESTING)
# compile C++ tests in test/ directory
add_subdirectory(test)
# add Python test executable
add_test(NAME "pytest"
COMMAND python3 -m pytest -v
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python)
endif()
endif()