-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
502 lines (432 loc) · 15 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
cmake_minimum_required(VERSION 3.16)
project(ceph
VERSION 18.1.0
LANGUAGES CXX C ASM)
cmake_policy(SET CMP0028 NEW)
cmake_policy(SET CMP0046 NEW)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0051 NEW)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0056 NEW)
cmake_policy(SET CMP0065 NEW)
cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0075 NEW)
cmake_policy(SET CMP0093 NEW)
foreach(policy CMP0127 CMP0135)
if(POLICY ${policy})
cmake_policy(SET ${policy} NEW)
endif()
endforeach()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
if(NOT CMAKE_BUILD_TYPE AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(default_build_type "Debug")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Default BUILD_TYPE is Debug, other options are: RelWithDebInfo, Release, and MinSizeRel." FORCE)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(LINUX ON)
FIND_PACKAGE(Threads)
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(FREEBSD ON)
FIND_PACKAGE(Threads)
endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(WIN32)
# The Windows headers (e.g. coming from mingw or the Windows SDK) check
# the targeted Windows version. The availability of certain functions and
# structures will depend on it.
set(WIN32_WINNT "0x0A00" CACHE STRING "Targeted Windows version.")
# In order to avoid known winpthread issues, we're using the boost
# shared mutex implementation.
# https://github.com/msys2/MINGW-packages/issues/3319
add_definitions(
-D_WIN32_WINNT=${WIN32_WINNT}
-DBOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
-DBOOST_THREAD_V2_SHARED_MUTEX
)
set(Boost_THREADAPI "win32")
endif()
if(MINGW)
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,-allow-multiple-definition")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-allow-multiple-definition")
# By default, cmake generates import libs for executables. The issue is that
# for rados and rbd, the executable import lib overrides the library import lib.
# For example, for rados.exe, it will end up generating a librados.dll.a import lib.
# We're providing custom rules to disable import libs for executables.
set(CMAKE_C_LINK_EXECUTABLE
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>")
set(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>")
link_directories(${MINGW_LINK_DIRECTORIES})
endif()
option(WITH_CCACHE "Build with ccache.")
if(WITH_CCACHE)
if(CMAKE_C_COMPILER_LAUNCHER OR CMAKE_CXX_COMPILER_LAUNCHER)
message(WARNING "Compiler launcher already set. stop configuring ccache")
else()
find_program(CCACHE_EXECUTABLE ccache)
if(NOT CCACHE_EXECUTABLE)
message(FATAL_ERROR "Can't find ccache. Is it installed?")
endif()
message(STATUS "Building with ccache: ${CCACHE_EXECUTABLE}, CCACHE_DIR=$ENV{CCACHE_DIR}")
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
endif()
endif(WITH_CCACHE)
option(WITH_MANPAGE "Build man pages." OFF)
if(WITH_MANPAGE)
find_program(SPHINX_BUILD
NAMES sphinx-build sphinx-build-3)
if(NOT SPHINX_BUILD)
message(FATAL_ERROR "Can't find sphinx-build.")
endif(NOT SPHINX_BUILD)
endif(WITH_MANPAGE)
include_directories(
${PROJECT_BINARY_DIR}/src/include
${PROJECT_SOURCE_DIR}/src)
if(WIN32)
include_directories(
${PROJECT_SOURCE_DIR}/src/include/win32)
# Boost complains if winsock2.h (or windows.h) is included before asio.hpp.
add_compile_options("SHELL:-include winsock_wrapper.h")
# Boost is also defining some of the errno values, we'll have
# to avoid mismatches.
add_compile_options("SHELL:-include win32_errno.h")
endif()
if(FREEBSD)
include_directories(SYSTEM /usr/local/include)
link_directories(/usr/local/lib)
list(APPEND CMAKE_REQUIRED_INCLUDES /usr/local/include)
endif(FREEBSD)
#put all the libs and binaries in one place
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
include(GNUInstallDirs)
include(CephChecks)
if(CMAKE_GENERATOR MATCHES Ninja)
include(LimitJobs)
endif()
set(CEPH_MAN_DIR "share/man" CACHE STRING "Install location for man pages (relative to prefix).")
option(ENABLE_SHARED "build shared libraries" ON)
if(ENABLE_SHARED)
set(CEPH_SHARED SHARED)
else(ENABLE_SHARED)
set(CEPH_SHARED STATIC)
endif(ENABLE_SHARED)
set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_SHARED})
option(WITH_STATIC_LIBSTDCXX "Link against libstdc++ statically" OFF)
if(WITH_STATIC_LIBSTDCXX)
if(NOT CMAKE_COMPILER_IS_GNUCXX)
message(FATAL_ERROR "Please use GCC to enable WITH_STATIC_LIBSTDCXX")
endif()
set(static_linker_flags "-static-libstdc++ -static-libgcc")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " ${static_linker_flags}")
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${static_linker_flags}")
unset(static_linker_flags)
set(GPERFTOOLS_USE_STATIC_LIBS TRUE)
endif()
include(CheckCxxAtomic)
if(NOT HAVE_CXX11_ATOMIC)
string(APPEND CMAKE_CXX_STANDARD_LIBRARIES
" ${LIBATOMIC_LINK_FLAGS}")
endif()
find_package(Backtrace)
find_package(cap REQUIRED)
if(LINUX)
find_package(udev REQUIRED)
set(HAVE_UDEV ${UDEV_FOUND})
find_package(blkid REQUIRED)
set(HAVE_BLKID ${BLKID_FOUND})
set(HAVE_KEYUTILS OFF)
#find_package(keyutils REQUIRED)
#set(HAVE_KEYUTILS ${KEYUTILS_FOUND})
elseif(FREEBSD)
set(HAVE_UDEV OFF)
set(HAVE_LIBAIO OFF)
set(HAVE_LIBDML OFF)
set(HAVE_BLKID OFF)
set(HAVE_KEYUTILS OFF)
else()
set(HAVE_UDEV OFF)
set(HAVE_BLKID OFF)
endif(LINUX)
option(WITH_BLUESTORE "Bluestore OSD backend" ON)
if(WITH_BLUESTORE)
if(LINUX)
find_package(aio)
set(HAVE_LIBAIO ${AIO_FOUND})
elseif(FREEBSD)
# POSIX AIO is integrated into FreeBSD kernel, and exposed by libc.
set(HAVE_POSIXAIO ON)
endif()
endif()
include(CMakeDependentOption)
CMAKE_DEPENDENT_OPTION(WITH_ZBD "Enable libzbd bluestore backend" OFF
"WITH_BLUESTORE" OFF)
if(WITH_ZBD)
find_package(zbd REQUIRED)
set(HAVE_LIBZBD ${ZBD_FOUND})
endif()
CMAKE_DEPENDENT_OPTION(WITH_LIBURING "Enable io_uring bluestore backend" OFF
"WITH_BLUESTORE;HAVE_LIBAIO" OFF)
set(HAVE_LIBURING ${WITH_LIBURING})
CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_LIBURING "Require and build with system liburing" OFF
"HAVE_LIBAIO;WITH_BLUESTORE" OFF)
CMAKE_DEPENDENT_OPTION(WITH_BLUESTORE_PMEM "Enable PMDK libraries" OFF
"WITH_BLUESTORE" OFF)
if(WITH_BLUESTORE_PMEM)
find_package(dml)
set(HAVE_LIBDML ${DML_FOUND})
endif()
CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_PMDK "Require and build with system PMDK" OFF
"WITH_RBD_RWL OR WITH_BLUESTORE_PMEM" OFF)
if(WITH_BLUESTORE_PMEM)
set(HAVE_BLUESTORE_PMEM ON)
endif()
CMAKE_DEPENDENT_OPTION(WITH_SPDK "Enable SPDK" OFF
"CMAKE_SYSTEM_PROCESSOR MATCHES i386|i686|amd64|x86_64|AMD64|aarch64" OFF)
if(WITH_SPDK)
if(NOT WITH_BLUESTORE)
message(SEND_ERROR "Please enable WITH_BLUESTORE for using SPDK")
endif()
include(BuildSPDK)
build_spdk()
set(HAVE_SPDK TRUE)
endif(WITH_SPDK)
if(WITH_BLUESTORE)
if(NOT AIO_FOUND AND NOT HAVE_POSIXAIO AND NOT WITH_SPDK AND NOT WITH_BLUESTORE_PMEM)
message(SEND_ERROR "WITH_BLUESTORE is ON, "
"but none of the bluestore backends is enabled. "
"Please install libaio, or enable WITH_SPDK or WITH_BLUESTORE_PMEM (experimental)")
endif()
endif()
option(WITH_BLUEFS "libbluefs library" OFF)
option(WITH_QAT "Enable Qat driver" OFF)
if(WITH_QAT)
find_package(QatDrv REQUIRED COMPONENTS qat_s usdm_drv_s)
set(HAVE_QATDRV $(QatDrv_FOUND))
endif()
option(WITH_QATZIP "Enable QATZIP" OFF)
if(WITH_QATZIP)
find_package(qatzip REQUIRED)
set(HAVE_QATZIP ${qatzip_FOUND})
endif(WITH_QATZIP)
find_package(snappy REQUIRED)
option(WITH_BROTLI "Brotli compression support" OFF)
if(WITH_BROTLI)
set(HAVE_BROTLI TRUE)
endif()
option(WITH_LZ4 "LZ4 compression support" OFF)
if(WITH_LZ4)
find_package(LZ4 1.7 REQUIRED)
set(HAVE_LZ4 ${LZ4_FOUND})
endif(WITH_LZ4)
CMAKE_DEPENDENT_OPTION(WITH_CEPH_DEBUG_MUTEX "Use debug ceph::mutex with lockdep" ON
"CMAKE_BUILD_TYPE STREQUAL Debug" OFF)
#if allocator is set on command line make sure it matches below strings
set(ALLOCATOR "" CACHE STRING
"specify memory allocator to use. currently tcmalloc, tcmalloc_minimal, \
jemalloc, and libc is supported. if not specified, will try to find tcmalloc, \
and then jemalloc. If neither of then is found. use the one in libc.")
if(ALLOCATOR)
if(${ALLOCATOR} MATCHES "tcmalloc(_minimal)?")
find_package(gperftools 2.6.2 REQUIRED)
set(ALLOC_LIBS gperftools::${ALLOCATOR})
set(HAVE_LIBTCMALLOC ON)
elseif(${ALLOCATOR} STREQUAL "jemalloc")
find_package(JeMalloc REQUIRED)
set(ALLOC_LIBS JeMalloc::JeMalloc)
set(HAVE_JEMALLOC 1)
elseif(NOT ALLOCATOR STREQUAL "libc")
message(FATAL_ERROR "Unsupported allocator selected: ${ALLOCATOR}")
endif()
else(ALLOCATOR)
find_package(gperftools 2.6.2)
set(HAVE_LIBTCMALLOC ${gperftools_FOUND})
if(NOT gperftools_FOUND)
find_package(JeMalloc)
endif()
if(gperftools_FOUND)
set(ALLOCATOR tcmalloc)
set(ALLOC_LIBS gperftools::tcmalloc)
elseif(JeMalloc_FOUND)
set(ALLOCATOR jemalloc)
set(ALLOC_LIBS JeMalloc::JeMalloc)
else()
if(NOT FREEBSD)
# FreeBSD already has jemalloc as its default allocator
message(WARNING "tcmalloc and jemalloc not found, falling back to libc")
endif()
set(ALLOCATOR "libc")
endif(gperftools_FOUND)
endif(ALLOCATOR)
if(NOT ALLOCATOR STREQUAL "libc")
add_compile_options(
$<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-malloc>
$<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-calloc>
$<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-realloc>
$<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-free>)
endif()
# Mingw generates incorrect entry points when using "-pie".
if(WIN32 OR (HAVE_LIBTCMALLOC AND WITH_STATIC_LIBSTDCXX))
set(EXE_LINKER_USE_PIE FALSE)
else()
set(EXE_LINKER_USE_PIE ${ENABLE_SHARED})
endif()
find_package(OpenSSL REQUIRED)
set(CRYPTO_LIBS OpenSSL::Crypto)
option(WITH_DPDK "Enable DPDK messaging" OFF)
if(WITH_DPDK)
find_package(dpdk)
if(NOT DPDK_FOUND)
include(BuildDPDK)
build_dpdk(${CMAKE_BINARY_DIR}/src/dpdk)
endif()
set(HAVE_DPDK TRUE)
endif()
option(WITH_BLKIN "Use blkin to emit LTTng tracepoints for Zipkin" OFF)
if(WITH_BLKIN)
find_package(LTTngUST REQUIRED)
set(BLKIN_LIBRARIES blkin ${LTTNGUST_LIBRARIES} lttng-ust-fork)
include_directories(SYSTEM src/blkin/blkin-lib)
endif(WITH_BLKIN)
option(WITH_THREAD_SAFE_RES_QUERY "res_query is thread safe" OFF)
if(WITH_THREAD_SAFE_RES_QUERY)
set(HAVE_THREAD_SAFE_RES_QUERY 1 CACHE INTERNAL "Thread safe res_query supported.")
endif()
option(WITH_REENTRANT_STRSIGNAL "strsignal is reentrant" OFF)
if(WITH_REENTRANT_STRSIGNAL)
set(HAVE_REENTRANT_STRSIGNAL 1 CACHE INTERNAL "Reentrant strsignal is supported.")
endif()
# -lz link into kv
find_package(ZLIB REQUIRED)
#option for EventTrace
CMAKE_DEPENDENT_OPTION(
WITH_EVENTTRACE "Event tracing support, requires WITH_LTTNG"
OFF "USE_LTTNG" OFF)
#option for LTTng
option(WITH_LTTNG "LTTng tracing is enabled" OFF)
if(${WITH_LTTNG})
find_package(LTTngUST REQUIRED)
find_program(LTTNG_GEN_TP
lttng-gen-tp)
if(NOT LTTNG_GEN_TP)
message(FATAL_ERROR "Can't find lttng-gen-tp.")
endif()
endif(${WITH_LTTNG})
option(WITH_OSD_INSTRUMENT_FUNCTIONS OFF)
#option for Babeltrace
option(WITH_BABELTRACE "Babeltrace libraries are enabled" OFF)
if(WITH_BABELTRACE)
set(HAVE_BABELTRACE ON)
find_package(babeltrace REQUIRED)
set(HAVE_BABELTRACE_BABELTRACE_H ${BABELTRACE_FOUND})
set(HAVE_BABELTRACE_CTF_EVENTS_H ${BABELTRACE_FOUND})
set(HAVE_BABELTRACE_CTF_ITERATOR_H ${BABELTRACE_FOUND})
endif(WITH_BABELTRACE)
option(DEBUG_GATHER "C_Gather debugging is enabled" OFF)
option(ENABLE_COVERAGE "Coverage is enabled" OFF)
option(WITH_TESTS "enable the build of ceph-test package scripts/binaries" OFF)
set(UNIT_TESTS_BUILT ${WITH_TESTS})
set(CEPH_TEST_TIMEOUT 3600 CACHE STRING
"Maximum time before a CTest gets killed" )
# fio
option(WITH_FIO "build with fio plugin enabled" OFF)
if(WITH_FIO)
include(BuildFIO)
build_fio()
endif()
if(LINUX)
add_definitions(-D__linux__)
endif(LINUX)
# ASAN and friends
option(WITH_ASAN "build with ASAN" OFF)
if(WITH_ASAN)
list(APPEND sanitizers "address")
endif()
option(WITH_ASAN_LEAK "explicitly enable ASAN leak detection" OFF)
if(WITH_ASAN_LEAK)
list(APPEND sanitizers "leak")
endif()
option(WITH_TSAN "build with TSAN" OFF)
if(WITH_TSAN)
list(APPEND sanitizers "thread")
endif()
option(WITH_UBSAN "build with UBSAN" OFF)
if(WITH_UBSAN)
list(APPEND sanitizers "undefined_behavior")
endif()
if(sanitizers)
find_package(Sanitizers REQUIRED ${sanitizers})
add_compile_options(${Sanitizers_COMPILE_OPTIONS})
string(REPLACE ";" " " sanitiers_compile_flags "${Sanitizers_COMPILE_OPTIONS}")
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${sanitiers_compile_flags}")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " ${sanitiers_compile_flags}")
endif()
# Rocksdb
option(WITH_SYSTEM_ROCKSDB "require and build with system rocksdb" OFF)
if (WITH_SYSTEM_ROCKSDB)
find_package(RocksDB 5.14 REQUIRED)
endif()
# Boost
option(WITH_SYSTEM_BOOST "require and build with system Boost" OFF)
# Boost::thread depends on Boost::atomic, so list it explicitly.
set(BOOST_COMPONENTS
atomic chrono thread system regex random program_options date_time
iostreams context coroutine)
set(BOOST_HEADER_COMPONENTS container)
set(Boost_USE_MULTITHREADED ON)
CMAKE_DEPENDENT_OPTION(WITH_BOOST_VALGRIND "Boost support for valgrind" OFF
"NOT WITH_SYSTEM_BOOST" OFF)
# require minimally the bundled version
if(WITH_SYSTEM_BOOST)
if(ENABLE_SHARED)
set(Boost_USE_STATIC_LIBS OFF)
else()
set(Boost_USE_STATIC_LIBS ON)
endif()
if(BOOST_ROOT AND CMAKE_LIBRARY_ARCHITECTURE)
set(BOOST_LIBRARYDIR "${BOOST_ROOT}/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
endif()
find_package(Boost 1.79 COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
if(NOT ENABLE_SHARED)
set_property(TARGET Boost::iostreams APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ZLIB::ZLIB)
endif()
else()
include(ProcessorCount)
ProcessorCount(DEFAULT_BOOST_J)
if(DEFAULT_BOOST_J EQUAL 0)
set(DEFAULT_BOOST_J 1)
endif()
set(BOOST_J ${DEFAULT_BOOST_J} CACHE STRING "max jobs for Boost build") # override w/-DBOOST_J=<n>
set(Boost_USE_STATIC_LIBS ON)
include(BuildBoost)
build_boost(1.79
COMPONENTS ${BOOST_COMPONENTS} ${BOOST_HEADER_COMPONENTS})
endif()
include_directories(BEFORE SYSTEM ${Boost_INCLUDE_DIRS})
include_directories(SYSTEM ${PROJECT_BINARY_DIR}/include)
find_package(Threads REQUIRED)
find_package(StdFilesystem REQUIRED)
# enables testing and creates Make check command
if (FALSE)
add_custom_target(tests
COMMENT "Building tests")
enable_testing()
set(CMAKE_CTEST_COMMAND ctest)
add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND}
DEPENDS tests)
endif(FALSE)
add_subdirectory(src)
if (FALSE)
include(CTags)
option(CTAG_EXCLUDES "Exclude files/directories when running ctag.")
add_tags(ctags
SRC_DIR src
TAG_FILE tags
EXCLUDE_OPTS ${CTAG_EXCLUDES}
EXCLUDES "*.js" "*.css" ".tox" "python-common/build")
add_custom_target(tags DEPENDS ctags)
endif(FALSE)