-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
300 lines (251 loc) · 10.8 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
cmake_minimum_required(VERSION 3.16)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(IS_SUBPROJECT OFF)
message(STATUS "Building ReStore as a stand-alone project.")
else()
set(IS_SUBPROJECT ON)
message(STATUS "Building ReStore as a subbroject.")
endif()
# Use ccache if available
find_program(CCACHE_PROGRAM ccache)
if((NOT ${IS_SUBPROBJECT}) AND ${CCACHE_PROGRAM})
message(STATUS "Found ccache; using it to speed up compilation.")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
# Project settings
project(ReStore VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
# Find and link MPI
find_package(MPI REQUIRED)
if(MPI_CXX_FOUND)
include_directories(BEFORE SYSTEM ${MPI_CXX_INCLUDE_PATH})
link_libraries(${MPI_LIBRARIES})
endif()
# Find and link threading library (e.g. pthreads)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
link_libraries(Threads::Threads)
# Make additinal cmake modules findable
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/extern/sanitizers-cmake/cmake")
# Require out-of-source builds
include(require_out_of_source_builds)
require_out_of_source_builds()
include(CMakeDependentOption)
#include(CMakePackageConfigHelpers)
include(CTest)
include(GNUInstallDirs)
# Load (memory, adress, ...) sanitizer support
include(sanitizers)
# Enable sorting targets (of external libraries) into folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Are we building in DEBUG mode?
if(CMAKE_BUILD_TYPE MATCHES Debug)
message("!!!!! Building in DEBUG mode !!!!!")
# Enable extra checks in the STL
add_definitions(-D_GLIBCXX_DEBUG)
add_definitions(-D_GLIBCXX_DEBUG_PEDANTIC)
endif(CMAKE_BUILD_TYPE MATCHES Debug)
option(${PROJECT_NAME}_INSTALL "Add ${PROJECT_NAME} to the install list" ON)
# Options to disable building the tests, examples, benchmarks, ...
option(${PROJECT_NAME}_BUILD_TESTS "Build unit tests" ON)
option(${PROJECT_NAME}_BUILD_BENCHMARKS "Build benchmarks" ON)
# Other build options
option(${PROJECT_NAME}_SIMULATE_FAILURES "Simulate node failues (for example when running unit test)." OFF)
option(${PROJECT_NAME}_USE_FTMPI "Use a fault-tolerant MPI implementation" ON)
option(${PROJECT_NAME}_ID_RANDOMIZATION "Use randomization of block IDs." ON)
option(${PROJECT_NAME}_WARNINGS_ARE_ERRORS "Treat warnings as errors." OFF)
# Output config
if(NOT ${PROJECT_NAME}_SIMULATE_FAILURES AND NOT ${PROJECT_NAME}_USE_FTMPI)
message(FATAL_ERROR "You have to either use a fault-tolerant MPI implementation or simulated failures (or both).")
endif()
message(STATUS "Using simulated failures: ${${PROJECT_NAME}_SIMULATE_FAILURES}")
message(STATUS "Using a fault-tolerant MPI implementation: ${${PROJECT_NAME}_USE_FTMPI}")
message(STATUS "Using block id randomization: ${${PROJECT_NAME}_ID_RANDOMIZATION}")
# Extra options when building tests
cmake_dependent_option("${PROJECT_NAME}_SYSTEM_GTEST" "Use googletest version installed on the system" OFF "${PROJECT_NAME}_BUILD_TESTS" OFF)
# Library specific settings
set("NEEDS_GOOGLETEST" ${PROJECT_NAME}_BUILD_TESTS OR ${PROJECT_NAME}_BUILD_BENCHMARKS)
set("NEEDS_CPPITERTOOLS" ${PROJECT_NAME}_BUILD_TESTS OR ${PROJECT_NAME}_BUILD_BENCHMARKS)
set("NEEDS_CXXOPTS" ${PROJECT_NAME}_BUILD_BENCHMARKS)
set("NEEDS_GOOGLEBENCHMARK" ${PROJECT_NAME}_BUILD_BENCHMARKS)
set("NEEDS_BACKWARDCPP" ${PROJECT_NAME}_BUILD_TESTS OR ${PROJECT_NAME}_BUILD_BENCHMARKS)
set("NEEDS_XXHASH" ON)
if(NEEDS_GOOGLETEST)
message(STATUS "Using googletest library.")
set("${PROJECT_NAME}_GTEST_DIR" "${CMAKE_CURRENT_LIST_DIR}/extern/googletest" CACHE PATH "Path to the googletest source directory")
endif()
if(NEEDS_GOOGLEBENCHMARK)
message(STATUS "Using googlebenchmark library.")
set("${PROJECT_NAME}_GBENCHMARK_DIR" "${CMAKE_CURRENT_LIST_DIR}/extern/googlebenchmark" CACHE PATH "Path to the googlebenchmark source directory")
endif()
if(NEEDS_CPPITERTOOLS)
message(STATUS "Using cppitertools library.")
set("${PROJECT_NAME}_CPPITERTOOLS_DIR" "${CMAKE_CURRENT_LIST_DIR}/extern/cppitertools" CACHE PATH "Path to the cppitertools source directory")
endif()
if(NEEDS_CXXOPTS)
message(STATUS "Using cxxopts library.")
set("${PROJECT_NAME}_CXXOPTS_DIR" "${CMAKE_CURRENT_LIST_DIR}/extern/cxxopts" CACHE PATH "Path to the cxxopts source directory")
endif()
if(NEEDS_BACKWARDCPP)
message(STATUS "Using backwardcpp library.")
set("${PROJECT_NAME}_BACKWARDCPP_DIR" "${CMAKE_CURRENT_LIST_DIR}/extern/backward-cpp" CACHE PATH "Path to the backward-cpp source directory")
option(${PROJECT_NAME}_BACKWARD_ENABLED "Enable pretty printing of stack traces when a test case fails." ON)
else()
option(${PROJECT_NAME}_BACKWARD_ENABLED "Enable pretty printing of stack traces when a test case fails." OFF)
endif()
# Organize targets into folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# The target to be linked against by other targets. This library is an
# interface target and as such does not generate any artefacts. It rather sets
# include directories and required compiler flags.
add_library("${PROJECT_NAME}" INTERFACE)
target_sources("${PROJECT_NAME}" INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories("${PROJECT_NAME}" INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
### Compiler and linker settings ###
# This interface reflects the requirements to the compiler for building targets
# linking against.
add_library("${PROJECT_NAME}_compile_requirements" INTERFACE)
# We just want c++17 or above
target_compile_features(
"${PROJECT_NAME}_compile_requirements" INTERFACE
cxx_std_17
)
target_link_libraries("${PROJECT_NAME}" INTERFACE "${PROJECT_NAME}_compile_requirements")
# The namespace alias can be used as link target if this project is a
# subproject.
add_library("${PROJECT_NAME}::${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")
# Not added as link target to avoid propagation of warning
# flags. Only to be used by internal targets that compile the library.
add_library("${PROJECT_NAME}_warnings" INTERFACE)
# TODO: Use CheckCXXCompilerFlag for this?
list(
APPEND WARNING_FLAGS
"-Wall"
"-Wextra"
"-Wconversion"
"-Wnon-virtual-dtor"
"-Woverloaded-virtual"
"-Wshadow"
"-Wsign-conversion"
"-Wundef"
"-Wunreachable-code"
"-Wunused"
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
list(
APPEND WARNING_FLAGS
"-Wcast-align"
"-Wpedantic"
)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
list(
APPEND WARNING_FLAGS
"-Wcast-align"
"-Wpedantic"
"-Wnoexcept"
"-Wsuggest-attribute=const"
"-Wsuggest-attribute=noreturn"
"-Wsuggest-override"
)
endif()
if(${PROJECT_NAME}_WARNINGS_ARE_ERRORS)
list(
APPEND WARNING_FLAGS
"-Werror"
)
endif()
target_compile_options(
"${PROJECT_NAME}_warnings" INTERFACE
$<BUILD_INTERFACE:${WARNING_FLAGS}>
)
# Populate some of the options to the source code
if (${PROJECT_NAME}_SIMULATE_FAILURES)
target_compile_definitions(${PROJECT_NAME}_compile_requirements INTERFACE SIMULATE_FAILURES)
endif()
if (${PROJECT_NAME}_USE_FTMPI)
target_compile_definitions(${PROJECT_NAME}_compile_requirements INTERFACE USE_FTMPI)
endif()
if (${PROJECT_NAME}_ID_RANDOMIZATION)
target_compile_definitions(${PROJECT_NAME}_compile_requirements INTERFACE ID_RANDOMIZATION)
target_compile_definitions(${PROJECT_NAME}_compile_requirements INTERFACE DENSE_ALL_TO_ALL_IN_SUBMIT_BLOCKS)
endif()
### Libraries ###
# Load and include cppitertools
if(NEEDS_CPPITERTOOLS)
if(NOT EXISTS "${${PROJECT_NAME}_CPPITERTOOLS_DIR}/CMakeLists.txt")
message(FATAL_ERROR "Could not find cppitertools in ${${PROJECT_NAME}_CPPITERTOOLS_DIR}")
endif()
message(STATUS "Configuring cppitertools...")
set("ENV{cppitertools_INSTALL_CMAKE_DIR}" "share") # default value; supress the warning message
add_subdirectory("${${PROJECT_NAME}_CPPITERTOOLS_DIR}")
message(STATUS "cppitertools configured.")
endif()
# Load and include cxxopts
if(NEEDS_CXXOPTS)
if(NOT EXISTS "${${PROJECT_NAME}_CXXOPTS_DIR}/CMakeLists.txt")
message(FATAL_ERROR "Could not find cxxopts in ${${PROJECT_NAME}_CXXOPTS_DIR}")
endif()
message(STATUS "Configuring cxxopts...")
set("ENV{cxxopts_INSTALL_CMAKE_DIR}" "share") # default value; supress the warning message
add_subdirectory("${${PROJECT_NAME}_CXXOPTS_DIR}")
message(STATUS "cxxopts configured.")
endif()
# Load and include googletest
if(NEEDS_GOOGLETEST)
if(${PROJECT_NAME}_SYSTEM_GTEST)
find_package(GTest REQUIRED)
else()
if(NOT EXISTS "${${PROJECT_NAME}_GTEST_DIR}/CMakeLists.txt")
message(FATAL_ERROR "Could not find googletest in ${${PROJECT_NAME}_GTEST_DIR}")
endif()
message(STATUS "Configuring googletest...")
add_subdirectory("${${PROJECT_NAME}_GTEST_DIR}" EXCLUDE_FROM_ALL)
list(APPEND CMAKE_MODULE_PATH "${${PROJECT_NAME}_GTEST_DIR}/contrib")
message(STATUS "googletest configured.")
endif()
include(GoogleTest)
set_target_properties(gtest gmock PROPERTIES FOLDER googletest)
endif()
# Load and include googlebenchmark
if(NEEDS_GOOGLEBENCHMARK)
message(STATUS "Configuring googlebenchmark...")
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Suppressing benchmark's tests" FORCE)
add_subdirectory("${${PROJECT_NAME}_GBENCHMARK_DIR}" EXCLUDE_FROM_ALL)
set_target_properties(benchmark PROPERTIES FOLDER googlebenchmark)
message(STATUS "googlebenchmark configured.")
endif()
# Load and include backward-cpp
if (NEEDS_BACKWARDCPP)
message(STATUS "Configuring backward-cpp...")
set(Backward_DIR "${PROJECT_SOURCE_DIR}/extern/backward-cpp")
find_package(Backward)
message(STATUS "backward-cpp configured.")
endif()
# Load and include xxHash
message(STATUS "Configuring xxHash...")
set(${PROJECT_NAME}_XXHASH_DIR "${CMAKE_CURRENT_LIST_DIR}/extern/xxHash" CACHE PATH "Path to the xxHash source directory")
set(BUILD_SHARED_LIBS OFF)
set(XXHASH_BUILD_ENABLE_INLINE_API ON)
set(XXHASH_BUILD_XXHSUM OFF)
add_subdirectory("${${PROJECT_NAME}_XXHASH_DIR}/cmake_unofficial" "${${PROJECT_NAME}_XXHASH_DIR/build}" EXCLUDE_FROM_ALL)
# Link xxHash with ReStore
target_link_libraries("${PROJECT_NAME}" INTERFACE xxhash)
### Subdirectories ###
# Build the unit tests
if(${PROJECT_NAME}_BUILD_TESTS)
message(STATUS "Building unit tests: YES")
set(TEST_RUNNER_PARAMS "" CACHE STRING "Options added to the test runner")
enable_testing()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests")
else()
message(STATUS "Building unit tests: NO")
endif()
# Build the benchmarks
if(${PROJECT_NAME}_BUILD_BENCHMARKS)
message(STATUS "Building benchmarks: YES")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/benchmark")
else()
message(STATUS "Building benchmarks: NO")
endif()