]> git.proxmox.com Git - ceph.git/blob - ceph/src/CMakeLists.txt
import ceph 16.2.7
[ceph.git] / ceph / src / CMakeLists.txt
1 include(GetGitRevisionDescription)
2 include(CheckCXXCompilerFlag)
3
4 # for erasure and compressor plugins
5 set(CEPH_INSTALL_PKGLIBDIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME})
6 set(CEPH_INSTALL_FULL_PKGLIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME})
7 # for mgr plugins
8 set(CEPH_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME})
9 # so libceph-common can be found
10 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
11 if(NOT CMAKE_INSTALL_RPATH)
12 set(CMAKE_INSTALL_RPATH "${CEPH_INSTALL_FULL_PKGLIBDIR}")
13 endif()
14
15 # to be compatible with configure_files shared with autoconfig
16 set(bindir ${CMAKE_INSTALL_FULL_BINDIR})
17 set(sbindir ${CMAKE_INSTALL_FULL_SBINDIR})
18 set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
19 set(sysconfdir ${CMAKE_INSTALL_FULL_SYSCONFDIR})
20 set(libexecdir ${CMAKE_INSTALL_FULL_LIBEXECDIR})
21 set(pkgdatadir ${CMAKE_INSTALL_FULL_DATADIR})
22 set(datadir ${CEPH_INSTALL_DATADIR})
23 set(prefix ${CMAKE_INSTALL_PREFIX})
24
25 add_definitions(
26 -DHAVE_CONFIG_H
27 -D__CEPH__
28 -D_REENTRANT
29 -D_THREAD_SAFE
30 -D__STDC_FORMAT_MACROS
31 -D_FILE_OFFSET_BITS=64
32 -DBOOST_ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
33 if(Boost_VERSION VERSION_GREATER_EQUAL 1.74)
34 add_definitions(-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
35 endif()
36
37 if(LINUX)
38 add_definitions("-D_GNU_SOURCE")
39 endif()
40
41 add_compile_options(
42 -Wall
43 -fno-strict-aliasing
44 -fsigned-char)
45
46 if(NOT MSVC)
47 add_compile_options(
48 -Wtype-limits
49 -Wignored-qualifiers
50 -Wpointer-arith
51 -Werror=format-security
52 -Winit-self
53 -Wno-unknown-pragmas)
54 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>)
55 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-ignored-qualifiers>)
56 endif()
57
58 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-ftemplate-depth-1024>)
59
60 CHECK_CXX_COMPILER_FLAG("-Wpessimizing-move" COMPILER_SUPPORTS_PESSIMIZING_MOVE)
61 if(COMPILER_SUPPORTS_PESSIMIZING_MOVE)
62 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wpessimizing-move>)
63 endif()
64 CHECK_CXX_COMPILER_FLAG("-Wredundant-move" COMPILER_SUPPORTS_REDUNDANT_MOVE)
65 if(COMPILER_SUPPORTS_REDUNDANT_MOVE)
66 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wredundant-move>)
67 endif()
68 if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
69 if(MINGW)
70 # The MINGW headers are missing some "const" qualifiers.
71 add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fpermissive>)
72 else()
73 string(APPEND CMAKE_EXE_LINKER_FLAGS " -rdynamic")
74 endif()
75 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wstrict-null-sentinel>)
76 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Woverloaded-virtual>)
77 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-new-ttp-matching>)
78 # cmake does not add '-pie' for executables even if
79 # CMAKE_POSITION_INDEPENDENT_CODE is TRUE.
80 if(EXE_LINKER_USE_PIE)
81 if (NOT WITH_OSD_INSTRUMENT_FUNCTIONS AND NOT HAVE_SEASTAR)
82 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
83 endif()
84 endif()
85 elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
86 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_EXPORTS_C_FLAG}")
87 string(APPEND CMAKE_LINKER_FLAGS " -rdynamic -export-dynamic ${CMAKE_EXE_EXPORTS_C_FLAG}")
88 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-inconsistent-missing-override>)
89 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-mismatched-tags>)
90 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-unused-private-field>)
91 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-address-of-packed-member>)
92 add_compile_options(
93 -Wno-unused-function
94 -Wno-unused-local-typedef
95 -Wno-varargs
96 -Wno-gnu-designator
97 -Wno-missing-braces
98 -Wno-parentheses
99 -Wno-deprecated-register)
100 if(FREEBSD)
101 # Need to use the GNU binutils linker to get versioning right.
102 string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=/usr/local/bin/ld -Wno-unused-command-line-argument")
103 string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=/usr/local/bin/ld -Wno-unused-command-line-argument")
104 endif()
105 if(APPLE)
106 string(APPEND CMAKE_SHARED_LINKER_FLAGS " -undefined dynamic_lookup")
107 endif()
108 endif(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
109
110 if(NOT CMAKE_BUILD_TYPE)
111 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
112 set(default_build_type "Debug")
113 else()
114 set(default_build_type "RelWithDebInfo")
115 endif()
116 set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
117 STRING "Default BUILD_TYPE is Debug, other options are: RelWithDebInfo, Release, and MinSizeRel." FORCE)
118 endif()
119
120 if(WITH_CEPH_DEBUG_MUTEX OR CMAKE_BUILD_TYPE STREQUAL Debug)
121 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-DCEPH_DEBUG_MUTEX>)
122 endif()
123
124 include(CheckCCompilerFlag)
125 if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
126 CHECK_C_COMPILER_FLAG("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" HAS_FORTIFY_SOURCE)
127 if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
128 if(HAS_FORTIFY_SOURCE)
129 add_definitions(
130 -U_FORTIFY_SOURCE
131 -D_FORTIFY_SOURCE=2)
132 endif()
133 endif()
134 if(NOT WIN32)
135 CHECK_C_COMPILER_FLAG(-fstack-protector-strong HAS_STACK_PROTECT)
136 if (HAS_STACK_PROTECT)
137 add_compile_options(-fstack-protector-strong)
138 endif()
139 endif(NOT WIN32)
140 endif(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
141
142 CHECK_C_COMPILER_FLAG("-D_GLIBCXX_ASSERTIONS" HAS_GLIBCXX_ASSERTIONS)
143 if(HAS_GLIBCXX_ASSERTIONS AND CMAKE_BUILD_TYPE STREQUAL Debug)
144 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-D_GLIBCXX_ASSERTIONS>)
145 endif()
146
147 include(SIMDExt)
148 if(HAVE_INTEL)
149 if(APPLE)
150 set(object_format "macho64")
151 else()
152 set(object_format "elf64")
153 endif()
154 set(CMAKE_ASM_FLAGS "-f ${object_format}")
155 set(CMAKE_ASM_COMPILER ${PROJECT_SOURCE_DIR}/src/nasm-wrapper)
156 if(NOT WIN32)
157 # The native tools might be located even when cross compiling, which
158 # might not work in this case (especially when targeting Windows).
159 include(CheckNasm)
160 check_nasm_support(${object_format}
161 HAVE_NASM_X64
162 HAVE_NASM_X64_AVX2
163 HAVE_NASM_X64_AVX512)
164 endif()
165 endif()
166
167 # require c++17
168 set(CMAKE_CXX_STANDARD 17)
169 set(CMAKE_CXX_EXTENSIONS OFF)
170 set(CMAKE_CXX_STANDARD_REQUIRED ON)
171 set(CMAKE_C_STANDARD 99)
172 # we use `asm()` to inline assembly, so enable the GNU extension
173 set(CMAKE_C_EXTENSIONS ON)
174 set(C_STANDARD_REQUIRED ON)
175
176 include(CheckCXXSourceCompiles)
177 CHECK_CXX_SOURCE_COMPILES("
178 #include <map>
179 using Map = std::map<int, int>;
180 int main() {
181 Map m;
182 m.merge(Map{});
183 }
184 " HAVE_STDLIB_MAP_SPLICING)
185
186 ## Handle diagnostics color if compiler supports them.
187 CHECK_C_COMPILER_FLAG("-fdiagnostics-color=always"
188 COMPILER_SUPPORTS_DIAGNOSTICS_COLOR)
189
190 set(DIAGNOSTICS_COLOR "auto"
191 CACHE STRING "Used if the C/C++ compiler supports the -fdiagnostics-color option. May have one of three values -- 'auto' (default), 'always', or 'never'. If set to 'always' and the compiler supports the option, 'make [...] | less -R' will make visible diagnostics colorization of compiler output.")
192
193 if(COMPILER_SUPPORTS_DIAGNOSTICS_COLOR)
194 add_compile_options(-fdiagnostics-color=${DIAGNOSTICS_COLOR})
195 endif()
196
197 set(EXTRALIBS ${CMAKE_DL_LIBS})
198 if(HAVE_POSIX_TIMERS)
199 list(APPEND EXTRALIBS ${RT_LIBRARY})
200 endif()
201 if(LINUX OR APPLE)
202 set(LIB_RESOLV resolv)
203 list(APPEND EXTRALIBS ${LIB_RESOLV})
204 endif()
205
206 if(${ENABLE_COVERAGE})
207 find_program(HAVE_GCOV gcov)
208 if(NOT HAVE_GCOV)
209 message(FATAL_ERROR "Coverage Enabled but gcov Not Found")
210 endif()
211 add_compile_options(
212 -fprofile-arcs
213 -ftest-coverage
214 -O0)
215 list(APPEND EXTRALIBS gcov)
216 endif(${ENABLE_COVERAGE})
217
218 set(GCOV_PREFIX_STRIP 4)
219
220 # the src/.git_version file may be written out by make-dist; otherwise
221 # we pull the git version from .git
222 option(ENABLE_GIT_VERSION "build Ceph with git version string" ON)
223 if(${ENABLE_GIT_VERSION})
224 get_git_head_revision(GIT_REFSPEC CEPH_GIT_VER)
225 git_describe(CEPH_GIT_NICE_VER_WITH_V --always)
226 # remove leading 'v'
227 string(SUBSTRING ${CEPH_GIT_NICE_VER_WITH_V} 1 -1 CEPH_GIT_NICE_VER)
228 #if building from a source tarball via make-dist
229 if(${CEPH_GIT_VER} STREQUAL "GITDIR-NOTFOUND")
230 message(STATUS "Ceph/.git directory not found, parsing ${CMAKE_CURRENT_SOURCE_DIR}/.git_version for CEPH_GIT_VER and CEPH_GIT_NICE_VER")
231 file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/.git_version CEPH_GIT_SHA_AND_TAG)
232 list(GET CEPH_GIT_SHA_AND_TAG 0 CEPH_GIT_VER)
233 list(GET CEPH_GIT_SHA_AND_TAG 1 CEPH_GIT_NICE_VER)
234 endif(${CEPH_GIT_VER} STREQUAL "GITDIR-NOTFOUND")
235 else(${ENABLE_GIT_VERSION})
236 set(CEPH_GIT_VER "no_version")
237 set(CEPH_GIT_NICE_VER "Development")
238 endif(${ENABLE_GIT_VERSION})
239
240 # the src/ceph_release file is 3 lines,
241 # <release number, e.g. '12' for luminous>
242 # <release name, e.g. 'luminous'>
243 # <release type: 'dev' for x.0.z, 'rc' or x.1.z, or 'stable' or x.2.z>
244 # note that the release name is semi-redundant and must match CEPH_RELEASE_*
245 # definitions in include/rados.h and common/ceph_strings.c.
246 file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/ceph_release CEPH_RELEASE_FILE)
247 list(GET CEPH_RELEASE_FILE 0 CEPH_RELEASE)
248 list(GET CEPH_RELEASE_FILE 1 CEPH_RELEASE_NAME)
249 list(GET CEPH_RELEASE_FILE 2 CEPH_RELEASE_TYPE)
250
251 option(WITH_OCF "build OCF-compliant cluster resource agent" OFF)
252 if(WITH_OCF)
253 add_subdirectory(ocf)
254 endif()
255
256 option(WITH_CEPHFS_JAVA "build libcephfs Java bindings" OFF)
257 if(WITH_CEPHFS_JAVA)
258 add_subdirectory(java)
259 endif()
260
261 # sort out which allocator to use
262 if(ALLOCATOR STREQUAL "tcmalloc")
263 set(ALLOC_LIBS gperftools::tcmalloc)
264 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-malloc>)
265 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-calloc>)
266 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-realloc>)
267 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-free>)
268 elseif(ALLOCATOR STREQUAL "tcmalloc_minimal")
269 set(ALLOC_LIBS gperftools::tcmalloc_minimal)
270 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-malloc>)
271 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-calloc>)
272 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-realloc>)
273 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-free>)
274 elseif(ALLOCATOR STREQUAL "jemalloc")
275 set(ALLOC_LIBS JeMalloc::JeMalloc)
276 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-malloc>)
277 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-calloc>)
278 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-realloc>)
279 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-free>)
280 endif()
281
282 if (WITH_BLKIN)
283 add_subdirectory(blkin/blkin-lib)
284 endif(WITH_BLKIN)
285
286 # Common infrastructure
287 configure_file(
288 ${CMAKE_SOURCE_DIR}/src/ceph_ver.h.in.cmake
289 ${CMAKE_BINARY_DIR}/src/include/ceph_ver.h
290 @ONLY)
291
292 set(mds_files)
293 list(APPEND mds_files
294 mds/MDSMap.cc
295 mds/FSMap.cc
296 mds/FSMapUser.cc
297 mds/inode_backtrace.cc
298 mds/mdstypes.cc
299 mds/flock.cc
300 mds/cephfs_features.cc)
301
302 add_subdirectory(json_spirit)
303
304 include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/xxHash")
305 include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/rapidjson/include")
306
307 option(WITH_FMT_HEADER_ONLY "use header-only version of fmt library" OFF)
308 find_package(fmt 6.0.0 QUIET)
309 if(fmt_FOUND)
310 include_directories(SYSTEM "${fmt_INCLUDE_DIR}")
311 else()
312 message(STATUS "Could not find fmt, will build it")
313 set(old_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
314 set(BUILD_SHARED_LIBS FALSE)
315 add_subdirectory(fmt)
316 set(BUILD_SHARED_LIBS ${old_BUILD_SHARED_LIBS})
317 unset(old_BUILD_SHARED_LIBS)
318 include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/fmt/include")
319 endif()
320
321 # in osd/PeeringState.h, the number of elements in PeeringState::Active::reactions
322 # is now 21 which exceeds the default value of BOOST_MPL_LIMIT_VECTOR_SIZE, which
323 # is 20. so we need to override it. see
324 # https://www.boost.org/doc/libs/1_74_0/libs/mpl/doc/refmanual/limit-list-size.html
325 # link with this library, if your code includes osd/PeeringState.h (indirectly)
326 add_library(Boost::MPL INTERFACE IMPORTED)
327 set_target_properties(Boost::MPL PROPERTIES
328 INTERFACE_COMPILE_DEFINITIONS
329 "BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS;BOOST_MPL_LIMIT_LIST_SIZE=30")
330
331 if(WITH_SEASTAR)
332 find_package(c-ares 1.13.0 QUIET)
333 if(NOT c-ares_FOUND)
334 message(STATUS "Could not find c-ares, will build it")
335 include(Buildc-ares)
336 build_c_ares()
337 endif()
338 macro(find_package name)
339 if(NOT TARGET ${name})
340 _find_package(${ARGV})
341 endif()
342 endmacro ()
343 set(Seastar_API_LEVEL "6" CACHE STRING "" FORCE)
344 set(Seastar_HWLOC OFF CACHE BOOL "" FORCE)
345 set(Seastar_STD_OPTIONAL_VARIANT_STRINGVIEW ON CACHE BOOL "" FORCE)
346 if(Seastar_DPDK)
347 find_package(dpdk QUIET)
348 if(NOT DPDK_FOUND)
349 include(BuildDPDK)
350 build_dpdk(${CMAKE_BINARY_DIR}/src/dpdk)
351 endif()
352 endif()
353 list(APPEND Seastar_CXX_FLAGS
354 "-Wno-error"
355 "-Wno-sign-compare"
356 "-Wno-attributes"
357 "-Wno-pessimizing-move"
358 "-Wno-address-of-packed-member"
359 "-Wno-non-virtual-dtor")
360 set(Seastar_CXX_FLAGS "${Seastar_CXX_FLAGS}" CACHE STRING "" FORCE)
361 add_subdirectory(seastar)
362 # create the directory so cmake won't complain when looking at the imported
363 # target: Seastar exports this directory created at build-time
364 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/seastar/gen/include")
365 add_subdirectory(crimson)
366 endif()
367
368 function(compile_with_fmt target)
369 get_target_property(fmt_compile_definitions
370 fmt::fmt INTERFACE_COMPILE_DEFINITIONS)
371 if(fmt_compile_definitions)
372 target_compile_definitions(${target} PUBLIC
373 ${fmt_compile_definitions})
374 endif()
375 endfunction()
376
377 set(libcommon_files
378 ${CMAKE_BINARY_DIR}/src/include/ceph_ver.h
379 ceph_ver.c
380 global/global_context.cc
381 xxHash/xxhash.c
382 common/error_code.cc
383 log/Log.cc
384 mon/MonCap.cc
385 mon/MonClient.cc
386 mon/MonMap.cc
387 mon/MonSub.cc
388 mon/error_code.cc
389 mgr/MgrClient.cc
390 mon/PGMap.cc
391 mgr/ServiceMap.cc
392 osd/ECMsgTypes.cc
393 osd/HitSet.cc
394 osd/OSDMap.cc
395 osd/OSDMapMapping.cc
396 osd/osd_types.cc
397 osd/error_code.cc
398 osd/PGPeeringEvent.cc
399 osd/OpRequest.cc
400 osd/ClassHandler.cc
401 osd/osd_op_util.cc
402 osdc/Striper.cc
403 osdc/Objecter.cc
404 osdc/error_code.cc
405 librbd/Features.cc
406 ${mds_files})
407 if(WITH_JAEGER)
408 list(APPEND libcommon_files common/tracer.cc)
409 endif()
410 set_source_files_properties(ceph_ver.c
411 APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_BINARY_DIR}/src/include/ceph_ver.h)
412 add_library(common-objs OBJECT ${libcommon_files})
413 compile_with_fmt(common-objs)
414
415 if(WITH_JAEGER)
416 find_package(yaml-cpp 0.6.0)
417 if(NOT yaml-cpp_FOUND)
418 set(jaeger_libs ${CMAKE_BINARY_DIR}/external/lib/libyaml-cpp.so
419 ${CMAKE_BINARY_DIR}/external/lib/libyaml-cpp.so.0.6
420 ${CMAKE_BINARY_DIR}/external/lib/libyaml-cpp.so.0.6.2)
421 #customize libjaeger.install
422 execute_process(COMMAND bash -c "sed -i 's/#//' debian/libjaeger.install"
423 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
424 execute_process(COMMAND bash -c "grep -q 'yaml-cpp' debian/libjaeger.install || echo 'usr/lib/libyaml-cpp.so.*' >> debian/libjaeger.install"
425 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
426 endif()
427 include(IncludeJaeger)
428 add_library(jaeger-base INTERFACE)
429 add_dependencies(common-objs
430 yaml-cpp::yaml-cpp
431 opentracing::libopentracing
432 thrift::libthrift
433 jaegertracing::libjaegertracing)
434 target_link_libraries(jaeger-base INTERFACE
435 yaml-cpp::yaml-cpp
436 opentracing::libopentracing
437 thrift::libthrift
438 jaegertracing::libjaegertracing)
439 include_directories(SYSTEM ${CMAKE_BINARY_DIR}/external/include)
440 #with CMake 3.12+ the following can be replaced by:
441 #target_link_libraries(common-objs jaeger-base)
442 list(APPEND jaeger_libs
443 ${CMAKE_BINARY_DIR}/external/lib/libjaegertracing.so.0
444 ${CMAKE_BINARY_DIR}/external/lib/libjaegertracing.so.0.6.1
445 ${CMAKE_BINARY_DIR}/external/lib/libopentracing.so.1
446 ${CMAKE_BINARY_DIR}/external/lib/libopentracing.so.1.6.0
447 ${CMAKE_BINARY_DIR}/external/lib/libthrift.so.0.13.0)
448 install(FILES ${jaeger_libs}
449 DESTINATION ${CMAKE_INSTALL_LIBDIR})
450 endif()
451
452 CHECK_C_COMPILER_FLAG("-fvar-tracking-assignments" HAS_VTA)
453 add_subdirectory(auth)
454 add_subdirectory(common)
455 add_subdirectory(crush)
456 add_subdirectory(msg)
457 add_subdirectory(arch)
458
459 set(ceph_common_objs
460 $<TARGET_OBJECTS:common-auth-objs>
461 $<TARGET_OBJECTS:common-common-objs>
462 $<TARGET_OBJECTS:common-msg-objs>
463 $<TARGET_OBJECTS:common_buffer_obj>
464 $<TARGET_OBJECTS:common_texttable_obj>
465 $<TARGET_OBJECTS:compressor_objs>
466 $<TARGET_OBJECTS:common-objs>
467 $<TARGET_OBJECTS:common_mountcephfs_objs>
468 $<TARGET_OBJECTS:crush_objs>)
469 set(ceph_common_deps
470 json_spirit erasure_code arch crc32
471 ${LIB_RESOLV}
472 Boost::thread
473 Boost::system
474 Boost::random
475 Boost::program_options
476 Boost::date_time
477 Boost::iostreams
478 fmt::fmt
479 StdFilesystem::filesystem
480 fmt::fmt
481 ${BLKID_LIBRARIES}
482 ${Backtrace_LIBRARIES}
483 ${BLKIN_LIBRARIES}
484 ${CRYPTO_LIBS}
485 ${GSSAPI_LIBRARIES}
486 ${CMAKE_THREAD_LIBS_INIT}
487 ${CMAKE_DL_LIBS})
488 if(HAVE_UDEV)
489 list(APPEND ceph_common_deps ${UDEV_LIBRARIES})
490 endif()
491
492 if(HAVE_VERBS)
493 list(APPEND ceph_common_deps IBVerbs::verbs)
494 endif()
495
496 if(HAVE_RDMACM)
497 list(APPEND ceph_common_deps RDMA::RDMAcm)
498 endif()
499
500 if(NOT WITH_SYSTEM_BOOST)
501 list(APPEND ceph_common_deps ${ZLIB_LIBRARIES})
502 endif()
503
504 if(HAVE_QATZIP)
505 list(APPEND ceph_common_deps ${QATZIP_LIBRARIES})
506 endif()
507
508 if(WITH_DPDK)
509 list(APPEND ceph_common_deps common_async_dpdk)
510 endif()
511
512 if(WITH_JAEGER)
513 list(APPEND ceph_common_deps jaeger-base)
514 endif()
515
516 if(WIN32)
517 list(APPEND ceph_common_deps ws2_32 mswsock iphlpapi bcrypt)
518 list(APPEND ceph_common_deps dlfcn_win32)
519 endif()
520
521 if(WITH_BLUESTORE_PMEM OR WITH_RBD_RWL)
522 if(WITH_SYSTEM_PMDK)
523 if(WITH_BLUESTORE_PMEM)
524 find_package(pmem REQUIRED COMPONENTS pmem)
525 endif()
526 if(WITH_RBD_RWL)
527 find_package(pmem REQUIRED COMPONENTS pmemobj)
528 endif()
529 find_package(pmem 1.10 REQUIRED COMPONENTS ${pmem_COMPONENTS})
530 else()
531 include(Buildpmem)
532 build_pmem()
533 endif()
534 endif()
535
536 add_library(common STATIC ${ceph_common_objs})
537 target_link_libraries(common ${ceph_common_deps})
538
539 add_library(ceph-common SHARED ${ceph_common_objs})
540 target_link_libraries(ceph-common ${ceph_common_deps})
541 # appease dpkg-shlibdeps
542 set_target_properties(ceph-common PROPERTIES
543 SOVERSION 2
544 SKIP_RPATH TRUE)
545 if(NOT APPLE AND NOT FREEBSD)
546 # Apple uses Mach-O, not ELF. so this option does not apply to APPLE.
547 #
548 # prefer the local symbol definitions when binding references to global
549 # symbols. otherwise we could reference the symbols defined by the application
550 # with the same name, instead of using the one defined in libceph-common.
551 # in other words, we require libceph-common to use local symbols, even if redefined
552 # in application".
553 set_property(
554 TARGET ceph-common
555 APPEND APPEND_STRING
556 PROPERTY LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions")
557 endif()
558
559 if(MINGW)
560 install(
561 TARGETS ceph-common
562 RUNTIME
563 DESTINATION ${CEPH_INSTALL_PKGLIBDIR})
564 else()
565 install(
566 TARGETS ceph-common
567 LIBRARY
568 DESTINATION ${CEPH_INSTALL_PKGLIBDIR}
569 NAMELINK_SKIP)
570 endif()
571
572 if(${WITH_LTTNG})
573 add_subdirectory(tracing)
574 add_dependencies(common-objs oprequest-tp)
575 endif(${WITH_LTTNG})
576
577 add_subdirectory(global)
578
579 if(NOT WIN32)
580 find_package(Lua 5.3 REQUIRED)
581 endif()
582
583 # rados object classes
584 add_subdirectory(cls)
585
586 # RADOS client/library
587 add_subdirectory(osdc)
588
589 # heal_profiler
590 add_subdirectory(perfglue)
591
592 add_library(rados_snap_set_diff_obj OBJECT librados/snap_set_diff.cc)
593
594 option(WITH_LIBRADOSSTRIPER "build with libradosstriper support" ON)
595
596 add_subdirectory(include)
597 add_subdirectory(librados)
598 add_subdirectory(neorados)
599
600 if(WITH_LIBRADOSSTRIPER)
601 add_subdirectory(libradosstriper)
602 endif()
603
604 add_subdirectory(mgr)
605
606 set(librados_config_srcs
607 librados-config.cc)
608 add_executable(librados-config ${librados_config_srcs})
609 target_link_libraries(librados-config librados Boost::program_options)
610
611 install(TARGETS librados-config DESTINATION bin)
612
613 # virtualenv base directory for ceph-disk and ceph-detect-init
614 set(CEPH_BUILD_VIRTUALENV $ENV{TMPDIR})
615 if(NOT CEPH_BUILD_VIRTUALENV)
616 set(CEPH_BUILD_VIRTUALENV ${CMAKE_BINARY_DIR})
617 endif()
618
619 if(NOT WIN32)
620 add_subdirectory(pybind)
621 add_subdirectory(ceph-volume)
622 add_subdirectory(python-common)
623 add_subdirectory(cephadm)
624 endif(NOT WIN32)
625
626 # Monitor
627 add_subdirectory(mon)
628 set(ceph_mon_srcs
629 ceph_mon.cc)
630 add_executable(ceph-mon ${ceph_mon_srcs}
631 $<TARGET_OBJECTS:common_texttable_obj>)
632 add_dependencies(ceph-mon erasure_code_plugins)
633 target_link_libraries(ceph-mon mon os global-static ceph-common
634 ${EXTRALIBS}
635 ${CMAKE_DL_LIBS} ${GSSAPI_LIBRARIES})
636 install(TARGETS ceph-mon DESTINATION bin)
637
638 # OSD/ObjectStore
639 # make rocksdb statically
640
641 if(NOT WITH_SYSTEM_ROCKSDB)
642 include(BuildRocksDB)
643 build_rocksdb()
644 endif(NOT WITH_SYSTEM_ROCKSDB)
645
646 include(TestBigEndian)
647 test_big_endian(CEPH_BIG_ENDIAN)
648 if(NOT CEPH_BIG_ENDIAN)
649 set(CEPH_LITTLE_ENDIAN 1)
650 endif()
651
652 add_subdirectory(kv)
653 add_subdirectory(os)
654
655 if(NOT WIN32)
656 add_subdirectory(blk)
657 add_subdirectory(osd)
658
659 set(ceph_osd_srcs
660 # Link the Object Class API implementation directly as intermediary
661 # static library (like libosd.a) nullifies the effect of `-rdynamic`.
662 osd/objclass.cc
663 objclass/class_api.cc
664 ceph_osd.cc)
665 if(WITH_JAEGER)
666 list(APPEND ceph_osd_srcs common/tracer.cc)
667 endif()
668 add_executable(ceph-osd ${ceph_osd_srcs})
669 add_dependencies(ceph-osd erasure_code_plugins)
670 target_link_libraries(ceph-osd osd os global-static common
671 ${BLKID_LIBRARIES})
672 if(WITH_FUSE)
673 target_link_libraries(ceph-osd FUSE::FUSE)
674 endif()
675 set_target_properties(ceph-osd PROPERTIES
676 POSITION_INDEPENDENT_CODE ${EXE_LINKER_USE_PIE}
677 INSTALL_RPATH "")
678 install(TARGETS ceph-osd DESTINATION bin)
679
680 endif(NOT WIN32)
681
682 if (WITH_CEPHFS)
683 add_subdirectory(mds)
684 set(ceph_mds_srcs
685 ceph_mds.cc)
686 add_executable(ceph-mds ${ceph_mds_srcs})
687 target_link_libraries(ceph-mds mds ${CMAKE_DL_LIBS} global-static ceph-common
688 Boost::thread)
689 install(TARGETS ceph-mds DESTINATION bin)
690 endif()
691
692 add_subdirectory(erasure-code)
693
694 # Support/Tools
695 if(WITH_TESTS)
696 option(WITH_SYSTEM_GTEST "require and build with system gtest and gmock" OFF)
697 if(WITH_SYSTEM_GTEST)
698 find_package(GTest REQUIRED)
699 find_package(GMock REQUIRED)
700 else()
701 set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
702 add_subdirectory(googletest)
703 add_library(GMock::GMock ALIAS gmock)
704 add_library(GMock::Main ALIAS gmock_main)
705 target_include_directories(gmock INTERFACE
706 $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>)
707 target_include_directories(gmock_main INTERFACE
708 $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>)
709 add_library(GTest::GTest ALIAS gtest)
710 add_library(GTest::Main ALIAS gtest_main)
711 endif()
712 endif(WITH_TESTS)
713
714 # dmClock (after gmock)
715 option(WITH_DMCLOCK_TESTS
716 "enable the build of dmclock-tests and dmclock-data-struct tests binaries"
717 OFF)
718 if(WITH_TESTS AND WITH_DMCLOCK_TESTS)
719 # note: add_test is not being called, so dmclock tests aren't part
720 # of ceph tests
721 set(dmclock_TEST ON CACHE BOOL "" FORCE)
722 endif()
723 add_subdirectory(dmclock)
724
725 add_subdirectory(compressor)
726
727 add_subdirectory(tools)
728
729 if(WITH_TESTS)
730 add_subdirectory(test)
731 endif()
732
733 add_subdirectory(crypto)
734
735 if(WITH_TESTS)
736 configure_file(${CMAKE_SOURCE_DIR}/src/ceph-coverage.in
737 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-coverage @ONLY)
738 configure_file(${CMAKE_SOURCE_DIR}/src/ceph-debugpack.in
739 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-debugpack @ONLY)
740 endif()
741
742 configure_file(${CMAKE_SOURCE_DIR}/src/ceph.in
743 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph @ONLY)
744
745 configure_file(${CMAKE_SOURCE_DIR}/src/init-ceph.in
746 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/init-ceph @ONLY)
747
748 configure_file(ceph-post-file.in
749 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-post-file @ONLY)
750
751 configure_file(ceph-crash.in
752 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-crash @ONLY)
753
754 if(WITH_TESTS)
755 install(PROGRAMS
756 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-debugpack
757 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-coverage
758 DESTINATION bin)
759 endif()
760
761 install(PROGRAMS
762 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph
763 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-post-file
764 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-crash
765 ${CMAKE_SOURCE_DIR}/src/ceph-run
766 ${CMAKE_SOURCE_DIR}/src/ceph-clsinfo
767 DESTINATION bin)
768 install(PROGRAMS
769 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/init-ceph
770 DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/init.d
771 RENAME ceph)
772
773 install(FILES
774 ${CMAKE_SOURCE_DIR}/share/id_rsa_drop.ceph.com
775 ${CMAKE_SOURCE_DIR}/share/id_rsa_drop.ceph.com.pub
776 ${CMAKE_SOURCE_DIR}/share/known_hosts_drop.ceph.com
777 DESTINATION ${CMAKE_INSTALL_DATADIR}/ceph)
778
779 install(PROGRAMS
780 ceph_common.sh
781 ceph-osd-prestart.sh
782 DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/ceph)
783
784 install(PROGRAMS
785 ${CMAKE_SOURCE_DIR}/src/ceph-create-keys
786 DESTINATION sbin)
787
788 add_subdirectory(bash_completion)
789 add_subdirectory(client)
790
791 if(WITH_LIBCEPHFS)
792 set(libcephfs_srcs libcephfs.cc)
793 add_library(cephfs ${CEPH_SHARED} ${libcephfs_srcs})
794 target_link_libraries(cephfs PRIVATE client ceph-common
795 ${CRYPTO_LIBS} ${EXTRALIBS})
796 if(ENABLE_SHARED)
797 set_target_properties(cephfs PROPERTIES
798 OUTPUT_NAME cephfs
799 VERSION 2.0.0
800 SOVERSION 2)
801 if(NOT APPLE)
802 foreach(name ceph-common client osdc)
803 set_property(TARGET cephfs APPEND_STRING PROPERTY
804 LINK_FLAGS " -Wl,--exclude-libs,lib${name}.a")
805 endforeach()
806 endif()
807 endif(ENABLE_SHARED)
808 install(TARGETS cephfs DESTINATION ${CMAKE_INSTALL_LIBDIR})
809 install(DIRECTORY
810 "${CMAKE_SOURCE_DIR}/src/include/cephfs"
811 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
812 set(ceph_syn_srcs
813 ceph_syn.cc
814 client/SyntheticClient.cc)
815 add_executable(ceph-syn ${ceph_syn_srcs})
816 target_link_libraries(ceph-syn client global-static ceph-common)
817 install(TARGETS ceph-syn DESTINATION bin)
818 if(LINUX)
819 add_subdirectory(mount)
820 endif()
821 endif(WITH_LIBCEPHFS)
822
823 if(WITH_LIBCEPHSQLITE)
824 set(cephsqlite_srcs libcephsqlite.cc SimpleRADOSStriper.cc)
825 add_library(cephsqlite ${CEPH_SHARED} ${cephsqlite_srcs})
826 target_link_libraries(cephsqlite PRIVATE cls_lock_client librados ceph-common SQLite3::SQLite3 ${EXTRALIBS})
827 set_target_properties(cephsqlite PROPERTIES
828 CXX_VISIBILITY_PRESET hidden
829 VISIBILITY_INLINES_HIDDEN ON)
830 if(NOT APPLE AND NOT WIN32)
831 set_property(TARGET cephsqlite APPEND_STRING PROPERTY
832 LINK_FLAGS " -Wl,--exclude-libs,ALL")
833 endif()
834 install(TARGETS cephsqlite DESTINATION ${CMAKE_INSTALL_LIBDIR})
835 endif(WITH_LIBCEPHSQLITE)
836
837 if(WITH_FUSE)
838 set(ceph_fuse_srcs
839 ceph_fuse.cc
840 client/fuse_ll.cc)
841 add_executable(ceph-fuse ${ceph_fuse_srcs})
842 target_link_libraries(ceph-fuse FUSE::FUSE
843 ${GSSAPI_LIBRARIES} client ceph-common global-static ${EXTRALIBS})
844 set_target_properties(ceph-fuse PROPERTIES
845 POSITION_INDEPENDENT_CODE ${EXE_LINKER_USE_PIE})
846 install(TARGETS ceph-fuse DESTINATION bin)
847 install(PROGRAMS mount.fuse.ceph DESTINATION ${CMAKE_INSTALL_SBINDIR})
848 endif(WITH_FUSE)
849
850 if(WITH_DOKAN)
851 add_subdirectory(dokan)
852 endif(WITH_DOKAN)
853
854 add_subdirectory(journal)
855
856 if(WITH_RBD)
857 if(WITH_KRBD)
858 add_library(krbd STATIC krbd.cc
859 $<TARGET_OBJECTS:parse_secret_objs>)
860 target_link_libraries(krbd keyutils::keyutils)
861 endif()
862 add_subdirectory(librbd)
863 if(WITH_FUSE)
864 add_subdirectory(rbd_fuse)
865 endif()
866
867 install(PROGRAMS
868 ${CMAKE_SOURCE_DIR}/src/ceph-rbdnamer
869 ${CMAKE_SOURCE_DIR}/src/rbd-replay-many
870 ${CMAKE_SOURCE_DIR}/src/rbdmap
871 DESTINATION ${CMAKE_INSTALL_BINDIR})
872 add_subdirectory(rbd_replay)
873 endif(WITH_RBD)
874
875 set(SPAWN_BUILD_TESTS OFF CACHE INTERNAL "disable building of spawn unit tests")
876 set(SPAWN_INSTALL OFF CACHE INTERNAL "disable installation of spawn headers")
877 add_subdirectory(spawn)
878
879 # RadosGW
880 if(WITH_KVS)
881 add_subdirectory(key_value_store)
882 endif(WITH_KVS)
883
884 if(WITH_RADOSGW)
885 add_subdirectory(libkmip)
886
887 set(civetweb_common_files civetweb/src/civetweb.c)
888 add_library(civetweb_common_objs OBJECT ${civetweb_common_files})
889 target_include_directories(civetweb_common_objs SYSTEM PRIVATE
890 "${CMAKE_SOURCE_DIR}/src/civetweb/include")
891 set_property(TARGET civetweb_common_objs
892 APPEND PROPERTY COMPILE_DEFINITIONS USE_IPV6=1)
893 if (LIBSSL_SONAME)
894 set_property(TARGET civetweb_common_objs
895 APPEND PROPERTY COMPILE_DEFINITIONS SSL_LIB="${LIBSSL_SONAME}")
896 set_property(TARGET civetweb_common_objs
897 APPEND PROPERTY COMPILE_DEFINITIONS CRYPTO_LIB="${LIBCRYPTO_SONAME}")
898 endif()
899
900 if (OPENSSL_FOUND)
901 # Use cmake to determine openssl version, a TODO is to make
902 # civetweb itself do this based on openssl_api_compat strings
903 if (NOT (OPENSSL_VERSION VERSION_LESS "1.1"))
904 message(STATUS "Setting civetweb to use OPENSSL >= 1.1")
905 set_property(TARGET civetweb_common_objs
906 APPEND PROPERTY COMPILE_DEFINITIONS OPENSSL_API_1_1=1)
907 endif()
908 endif(OPENSSL_FOUND)
909 add_subdirectory(rgw)
910
911 endif(WITH_RADOSGW)
912
913 install(FILES
914 sample.ceph.conf
915 DESTINATION ${CMAKE_INSTALL_DOCDIR})
916
917 # Now create a usable config.h
918 configure_file(
919 ${CMAKE_SOURCE_DIR}/src/include/config-h.in.cmake
920 ${CMAKE_BINARY_DIR}/include/acconfig.h
921 )
922
923 if(NOT WIN32)
924 # Everything you need to spin up a cluster with vstart.sh
925 add_custom_target(vstart-base DEPENDS
926 ceph-osd
927 ceph-mon
928 ceph-authtool
929 ceph-conf
930 monmaptool
931 crushtool
932 rados
933 cython_rados)
934 if (WITH_MGR)
935 add_dependencies(vstart-base ceph-mgr)
936 endif()
937
938 add_custom_target(vstart DEPENDS vstart-base)
939 if(WITH_RBD)
940 add_dependencies(vstart cython_rbd)
941 endif()
942 if (WITH_CEPHFS)
943 add_dependencies(vstart ceph-mds cephfs cython_cephfs)
944 endif()
945 if(WITH_RADOSGW)
946 add_dependencies(vstart radosgwd radosgw-admin)
947 endif()
948
949 if(WITH_LTTNG)
950 add_dependencies(vstart tracepoint_libraries)
951 endif(WITH_LTTNG)
952
953 if(WITH_MGR AND WITH_MGR_DASHBOARD_FRONTEND AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64")
954 add_dependencies(vstart mgr-dashboard-frontend-build)
955 endif()
956
957 if(WITH_MGR)
958 add_dependencies(vstart ceph-volume-venv-setup)
959 endif()
960 endif(NOT WIN32)
961
962 # Everything you need to run CephFS tests
963 add_custom_target(cephfs_testing DEPENDS
964 vstart
965 rados
966 cython_modules
967 cephfs
968 cls_cephfs
969 ceph-fuse
970 ceph-dencoder
971 cephfs-journal-tool
972 cephfs-meta-injection
973 cephfs-data-scan
974 cephfs-table-tool)
975
976 if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git")
977 add_custom_target(
978 git-update
979 COMMAND git submodule sync
980 COMMAND git submodule update --force --init --recursive
981 WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
982 endif()
983
984 add_subdirectory(script)
985
986 # add doxygen target
987 find_package(Doxygen)
988 if(DOXYGEN_FOUND)
989 set(DOXYGEN_FILE_PATTERNS *.cc *.c *.cpp *.C *.cxx *.c++ *.CC *.H *.h *.hh *.hpp)
990 set(DOXYGEN_SOURCE_BROWSER YES)
991 set(DOXYGEN_WARN_IF_UNDOCUMENTED NO)
992 # enabling clang slows down doxygen significantly
993 set(DOXYGEN_CLANG_ASSISTED_PARSING NO)
994 set(DOXYGEN_CLANG_DATABASE_PATH "${PROJECT_BINARY_DIR}")
995 set(DOXYGEN_BUILTIN_STL_SUPPORT YES)
996 set(DOXYGEN_RECURSIVE YES)
997 set(DOXYGEN_QUIET YES)
998 set(DOXYGEN_GENERATE_LATEX NO)
999 set(DOXYGEN_GENERATE_XML NO)
1000 set(DOXYGEN_GENERATE_HTML YES)
1001 set(DOXYGEN_PROJECT_NAME Ceph)
1002 set(DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/build-doc/doxygen")
1003 set(DOXYGEN_STRIP_FROM_PATH "src/")
1004 set(DOXYGEN_STRIP_FROM_INC_PATH "src/include")
1005 set(DOXYGEN_JAVADOC_AUTOBRIEF YES)
1006 set(DOXYGEN_HAVE_DOT NO)
1007 set(DOXYGEN_VERBATIM_HEADERS YES)
1008 doxygen_add_docs(doxygen
1009 auth
1010 client
1011 cls
1012 common
1013 compressor
1014 crimson
1015 crush
1016 crypto
1017 erasure-code
1018 global
1019 include
1020 journal
1021 json_spirit
1022 key_value_store
1023 kv
1024 librados
1025 libradosstriper
1026 librbd
1027 log
1028 mds
1029 messages
1030 mgr
1031 mon
1032 mount
1033 msg
1034 objclass
1035 objsync
1036 os
1037 osd
1038 osdc
1039 perfglue
1040 rbd_fuse
1041 rbd_replay
1042 rgw
1043 COMMENT "Generate C++ documentation")
1044 endif()
1045