]> git.proxmox.com Git - ceph.git/blob - ceph/src/CMakeLists.txt
import ceph 16.2.6
[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 else()
530 include(Buildpmem)
531 build_pmem()
532 endif()
533 endif()
534
535 add_library(common STATIC ${ceph_common_objs})
536 target_link_libraries(common ${ceph_common_deps})
537
538 add_library(ceph-common SHARED ${ceph_common_objs})
539 target_link_libraries(ceph-common ${ceph_common_deps})
540 # appease dpkg-shlibdeps
541 set_target_properties(ceph-common PROPERTIES
542 SOVERSION 2
543 SKIP_RPATH TRUE)
544 if(NOT APPLE AND NOT FREEBSD)
545 # Apple uses Mach-O, not ELF. so this option does not apply to APPLE.
546 #
547 # prefer the local symbol definitions when binding references to global
548 # symbols. otherwise we could reference the symbols defined by the application
549 # with the same name, instead of using the one defined in libceph-common.
550 # in other words, we require libceph-common to use local symbols, even if redefined
551 # in application".
552 set_property(
553 TARGET ceph-common
554 APPEND APPEND_STRING
555 PROPERTY LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions")
556 endif()
557
558 if(MINGW)
559 install(
560 TARGETS ceph-common
561 RUNTIME
562 DESTINATION ${CEPH_INSTALL_PKGLIBDIR})
563 else()
564 install(
565 TARGETS ceph-common
566 LIBRARY
567 DESTINATION ${CEPH_INSTALL_PKGLIBDIR}
568 NAMELINK_SKIP)
569 endif()
570
571 if(${WITH_LTTNG})
572 add_subdirectory(tracing)
573 add_dependencies(common-objs oprequest-tp)
574 endif(${WITH_LTTNG})
575
576 add_subdirectory(global)
577
578 if(NOT WIN32)
579 find_package(Lua 5.3 REQUIRED)
580 endif()
581
582 # rados object classes
583 add_subdirectory(cls)
584
585 # RADOS client/library
586 add_subdirectory(osdc)
587
588 # heal_profiler
589 add_subdirectory(perfglue)
590
591 add_library(rados_snap_set_diff_obj OBJECT librados/snap_set_diff.cc)
592
593 option(WITH_LIBRADOSSTRIPER "build with libradosstriper support" ON)
594
595 add_subdirectory(include)
596 add_subdirectory(librados)
597 add_subdirectory(neorados)
598
599 if(WITH_LIBRADOSSTRIPER)
600 add_subdirectory(libradosstriper)
601 endif()
602
603 add_subdirectory(mgr)
604
605 set(librados_config_srcs
606 librados-config.cc)
607 add_executable(librados-config ${librados_config_srcs})
608 target_link_libraries(librados-config librados Boost::program_options)
609
610 install(TARGETS librados-config DESTINATION bin)
611
612 # virtualenv base directory for ceph-disk and ceph-detect-init
613 set(CEPH_BUILD_VIRTUALENV $ENV{TMPDIR})
614 if(NOT CEPH_BUILD_VIRTUALENV)
615 set(CEPH_BUILD_VIRTUALENV ${CMAKE_BINARY_DIR})
616 endif()
617
618 if(NOT WIN32)
619 add_subdirectory(pybind)
620 add_subdirectory(ceph-volume)
621 add_subdirectory(python-common)
622 add_subdirectory(cephadm)
623 endif(NOT WIN32)
624
625 # Monitor
626 add_subdirectory(mon)
627 set(ceph_mon_srcs
628 ceph_mon.cc)
629 add_executable(ceph-mon ${ceph_mon_srcs}
630 $<TARGET_OBJECTS:common_texttable_obj>)
631 add_dependencies(ceph-mon erasure_code_plugins)
632 target_link_libraries(ceph-mon mon os global-static ceph-common
633 ${EXTRALIBS}
634 ${CMAKE_DL_LIBS} ${GSSAPI_LIBRARIES})
635 install(TARGETS ceph-mon DESTINATION bin)
636
637 # OSD/ObjectStore
638 # make rocksdb statically
639
640 if(NOT WITH_SYSTEM_ROCKSDB)
641 include(BuildRocksDB)
642 build_rocksdb()
643 endif(NOT WITH_SYSTEM_ROCKSDB)
644
645 include(TestBigEndian)
646 test_big_endian(CEPH_BIG_ENDIAN)
647 if(NOT CEPH_BIG_ENDIAN)
648 set(CEPH_LITTLE_ENDIAN 1)
649 endif()
650
651 add_subdirectory(kv)
652 add_subdirectory(os)
653
654 if(NOT WIN32)
655 add_subdirectory(blk)
656 add_subdirectory(osd)
657
658 set(ceph_osd_srcs
659 # Link the Object Class API implementation directly as intermediary
660 # static library (like libosd.a) nullifies the effect of `-rdynamic`.
661 osd/objclass.cc
662 objclass/class_api.cc
663 ceph_osd.cc)
664 if(WITH_JAEGER)
665 list(APPEND ceph_osd_srcs common/tracer.cc)
666 endif()
667 add_executable(ceph-osd ${ceph_osd_srcs})
668 add_dependencies(ceph-osd erasure_code_plugins)
669 target_link_libraries(ceph-osd osd os global-static common
670 ${BLKID_LIBRARIES})
671 if(WITH_FUSE)
672 target_link_libraries(ceph-osd FUSE::FUSE)
673 endif()
674 set_target_properties(ceph-osd PROPERTIES
675 POSITION_INDEPENDENT_CODE ${EXE_LINKER_USE_PIE}
676 INSTALL_RPATH "")
677 install(TARGETS ceph-osd DESTINATION bin)
678
679 endif(NOT WIN32)
680
681 if (WITH_CEPHFS)
682 add_subdirectory(mds)
683 set(ceph_mds_srcs
684 ceph_mds.cc)
685 add_executable(ceph-mds ${ceph_mds_srcs})
686 target_link_libraries(ceph-mds mds ${CMAKE_DL_LIBS} global-static ceph-common
687 Boost::thread)
688 install(TARGETS ceph-mds DESTINATION bin)
689 endif()
690
691 add_subdirectory(erasure-code)
692
693 # Support/Tools
694 if(WITH_TESTS)
695 option(WITH_SYSTEM_GTEST "require and build with system gtest and gmock" OFF)
696 if(WITH_SYSTEM_GTEST)
697 find_package(GTest REQUIRED)
698 find_package(GMock REQUIRED)
699 else()
700 set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
701 add_subdirectory(googletest)
702 add_library(GMock::GMock ALIAS gmock)
703 add_library(GMock::Main ALIAS gmock_main)
704 target_include_directories(gmock INTERFACE
705 $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>)
706 target_include_directories(gmock_main INTERFACE
707 $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>)
708 add_library(GTest::GTest ALIAS gtest)
709 add_library(GTest::Main ALIAS gtest_main)
710 endif()
711 endif(WITH_TESTS)
712
713 # dmClock (after gmock)
714 option(WITH_DMCLOCK_TESTS
715 "enable the build of dmclock-tests and dmclock-data-struct tests binaries"
716 OFF)
717 if(WITH_TESTS AND WITH_DMCLOCK_TESTS)
718 # note: add_test is not being called, so dmclock tests aren't part
719 # of ceph tests
720 set(dmclock_TEST ON CACHE BOOL "" FORCE)
721 endif()
722 add_subdirectory(dmclock)
723
724 add_subdirectory(compressor)
725
726 add_subdirectory(tools)
727
728 if(WITH_TESTS)
729 add_subdirectory(test)
730 endif()
731
732 add_subdirectory(crypto)
733
734 if(WITH_TESTS)
735 configure_file(${CMAKE_SOURCE_DIR}/src/ceph-coverage.in
736 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-coverage @ONLY)
737 configure_file(${CMAKE_SOURCE_DIR}/src/ceph-debugpack.in
738 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-debugpack @ONLY)
739 endif()
740
741 configure_file(${CMAKE_SOURCE_DIR}/src/ceph.in
742 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph @ONLY)
743
744 configure_file(${CMAKE_SOURCE_DIR}/src/init-ceph.in
745 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/init-ceph @ONLY)
746
747 configure_file(ceph-post-file.in
748 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-post-file @ONLY)
749
750 configure_file(ceph-crash.in
751 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-crash @ONLY)
752
753 if(WITH_TESTS)
754 install(PROGRAMS
755 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-debugpack
756 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-coverage
757 DESTINATION bin)
758 endif()
759
760 install(PROGRAMS
761 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph
762 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-post-file
763 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ceph-crash
764 ${CMAKE_SOURCE_DIR}/src/ceph-run
765 ${CMAKE_SOURCE_DIR}/src/ceph-clsinfo
766 DESTINATION bin)
767 install(PROGRAMS
768 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/init-ceph
769 DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/init.d
770 RENAME ceph)
771
772 install(FILES
773 ${CMAKE_SOURCE_DIR}/share/id_rsa_drop.ceph.com
774 ${CMAKE_SOURCE_DIR}/share/id_rsa_drop.ceph.com.pub
775 ${CMAKE_SOURCE_DIR}/share/known_hosts_drop.ceph.com
776 DESTINATION ${CMAKE_INSTALL_DATADIR}/ceph)
777
778 install(PROGRAMS
779 ceph_common.sh
780 ceph-osd-prestart.sh
781 DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/ceph)
782
783 install(PROGRAMS
784 ${CMAKE_SOURCE_DIR}/src/ceph-create-keys
785 DESTINATION sbin)
786
787 add_subdirectory(bash_completion)
788 add_subdirectory(client)
789
790 if(WITH_LIBCEPHFS)
791 set(libcephfs_srcs libcephfs.cc)
792 add_library(cephfs ${CEPH_SHARED} ${libcephfs_srcs})
793 target_link_libraries(cephfs PRIVATE client ceph-common
794 ${CRYPTO_LIBS} ${EXTRALIBS})
795 if(ENABLE_SHARED)
796 set_target_properties(cephfs PROPERTIES
797 OUTPUT_NAME cephfs
798 VERSION 2.0.0
799 SOVERSION 2)
800 if(NOT APPLE)
801 foreach(name ceph-common client osdc)
802 set_property(TARGET cephfs APPEND_STRING PROPERTY
803 LINK_FLAGS " -Wl,--exclude-libs,lib${name}.a")
804 endforeach()
805 endif()
806 endif(ENABLE_SHARED)
807 install(TARGETS cephfs DESTINATION ${CMAKE_INSTALL_LIBDIR})
808 install(DIRECTORY
809 "${CMAKE_SOURCE_DIR}/src/include/cephfs"
810 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
811 set(ceph_syn_srcs
812 ceph_syn.cc
813 client/SyntheticClient.cc)
814 add_executable(ceph-syn ${ceph_syn_srcs})
815 target_link_libraries(ceph-syn client global-static ceph-common)
816 install(TARGETS ceph-syn DESTINATION bin)
817 if(LINUX)
818 add_subdirectory(mount)
819 endif()
820 endif(WITH_LIBCEPHFS)
821
822 if(WITH_LIBCEPHSQLITE)
823 set(cephsqlite_srcs libcephsqlite.cc SimpleRADOSStriper.cc)
824 add_library(cephsqlite ${CEPH_SHARED} ${cephsqlite_srcs})
825 target_link_libraries(cephsqlite PRIVATE cls_lock_client librados ceph-common SQLite3::SQLite3 ${EXTRALIBS})
826 set_target_properties(cephsqlite PROPERTIES
827 CXX_VISIBILITY_PRESET hidden
828 VISIBILITY_INLINES_HIDDEN ON)
829 if(NOT APPLE AND NOT WIN32)
830 set_property(TARGET cephsqlite APPEND_STRING PROPERTY
831 LINK_FLAGS " -Wl,--exclude-libs,ALL")
832 endif()
833 install(TARGETS cephsqlite DESTINATION ${CMAKE_INSTALL_LIBDIR})
834 endif(WITH_LIBCEPHSQLITE)
835
836 if(WITH_FUSE)
837 set(ceph_fuse_srcs
838 ceph_fuse.cc
839 client/fuse_ll.cc)
840 add_executable(ceph-fuse ${ceph_fuse_srcs})
841 target_link_libraries(ceph-fuse FUSE::FUSE
842 ${GSSAPI_LIBRARIES} client ceph-common global-static ${EXTRALIBS})
843 set_target_properties(ceph-fuse PROPERTIES
844 POSITION_INDEPENDENT_CODE ${EXE_LINKER_USE_PIE})
845 install(TARGETS ceph-fuse DESTINATION bin)
846 install(PROGRAMS mount.fuse.ceph DESTINATION ${CMAKE_INSTALL_SBINDIR})
847 endif(WITH_FUSE)
848
849 if(WITH_DOKAN)
850 add_subdirectory(dokan)
851 endif(WITH_DOKAN)
852
853 add_subdirectory(journal)
854
855 if(WITH_RBD)
856 if(WITH_KRBD)
857 add_library(krbd STATIC krbd.cc
858 $<TARGET_OBJECTS:parse_secret_objs>)
859 target_link_libraries(krbd keyutils::keyutils)
860 endif()
861 add_subdirectory(librbd)
862 if(WITH_FUSE)
863 add_subdirectory(rbd_fuse)
864 endif()
865
866 install(PROGRAMS
867 ${CMAKE_SOURCE_DIR}/src/ceph-rbdnamer
868 ${CMAKE_SOURCE_DIR}/src/rbd-replay-many
869 ${CMAKE_SOURCE_DIR}/src/rbdmap
870 DESTINATION ${CMAKE_INSTALL_BINDIR})
871 add_subdirectory(rbd_replay)
872 endif(WITH_RBD)
873
874 set(SPAWN_BUILD_TESTS OFF CACHE INTERNAL "disable building of spawn unit tests")
875 set(SPAWN_INSTALL OFF CACHE INTERNAL "disable installation of spawn headers")
876 add_subdirectory(spawn)
877
878 # RadosGW
879 if(WITH_KVS)
880 add_subdirectory(key_value_store)
881 endif(WITH_KVS)
882
883 if(WITH_RADOSGW)
884 add_subdirectory(libkmip)
885
886 set(civetweb_common_files civetweb/src/civetweb.c)
887 add_library(civetweb_common_objs OBJECT ${civetweb_common_files})
888 target_include_directories(civetweb_common_objs SYSTEM PRIVATE
889 "${CMAKE_SOURCE_DIR}/src/civetweb/include")
890 set_property(TARGET civetweb_common_objs
891 APPEND PROPERTY COMPILE_DEFINITIONS USE_IPV6=1)
892 if (LIBSSL_SONAME)
893 set_property(TARGET civetweb_common_objs
894 APPEND PROPERTY COMPILE_DEFINITIONS SSL_LIB="${LIBSSL_SONAME}")
895 set_property(TARGET civetweb_common_objs
896 APPEND PROPERTY COMPILE_DEFINITIONS CRYPTO_LIB="${LIBCRYPTO_SONAME}")
897 endif()
898
899 if (OPENSSL_FOUND)
900 # Use cmake to determine openssl version, a TODO is to make
901 # civetweb itself do this based on openssl_api_compat strings
902 if (NOT (OPENSSL_VERSION VERSION_LESS "1.1"))
903 message(STATUS "Setting civetweb to use OPENSSL >= 1.1")
904 set_property(TARGET civetweb_common_objs
905 APPEND PROPERTY COMPILE_DEFINITIONS OPENSSL_API_1_1=1)
906 endif()
907 endif(OPENSSL_FOUND)
908 add_subdirectory(rgw)
909
910 endif(WITH_RADOSGW)
911
912 install(FILES
913 sample.ceph.conf
914 DESTINATION ${CMAKE_INSTALL_DOCDIR})
915
916 # Now create a usable config.h
917 configure_file(
918 ${CMAKE_SOURCE_DIR}/src/include/config-h.in.cmake
919 ${CMAKE_BINARY_DIR}/include/acconfig.h
920 )
921
922 if(NOT WIN32)
923 # Everything you need to spin up a cluster with vstart.sh
924 add_custom_target(vstart-base DEPENDS
925 ceph-osd
926 ceph-mon
927 ceph-authtool
928 ceph-conf
929 monmaptool
930 crushtool
931 rados
932 cython_rados)
933 if (WITH_MGR)
934 add_dependencies(vstart-base ceph-mgr)
935 endif()
936
937 add_custom_target(vstart DEPENDS vstart-base)
938 if(WITH_RBD)
939 add_dependencies(vstart cython_rbd)
940 endif()
941 if (WITH_CEPHFS)
942 add_dependencies(vstart ceph-mds cephfs cython_cephfs)
943 endif()
944 if(WITH_RADOSGW)
945 add_dependencies(vstart radosgwd radosgw-admin)
946 endif()
947
948 if(WITH_LTTNG)
949 add_dependencies(vstart tracepoint_libraries)
950 endif(WITH_LTTNG)
951
952 if(WITH_MGR AND WITH_MGR_DASHBOARD_FRONTEND AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64")
953 add_dependencies(vstart mgr-dashboard-frontend-build)
954 endif()
955
956 if(WITH_MGR)
957 add_dependencies(vstart ceph-volume-venv-setup)
958 endif()
959 endif(NOT WIN32)
960
961 # Everything you need to run CephFS tests
962 add_custom_target(cephfs_testing DEPENDS
963 vstart
964 rados
965 cython_modules
966 cephfs
967 cls_cephfs
968 ceph-fuse
969 ceph-dencoder
970 cephfs-journal-tool
971 cephfs-meta-injection
972 cephfs-data-scan
973 cephfs-table-tool)
974
975 if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git")
976 add_custom_target(
977 git-update
978 COMMAND git submodule sync
979 COMMAND git submodule update --force --init --recursive
980 WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
981 endif()
982
983 add_subdirectory(script)
984
985 # add doxygen target
986 find_package(Doxygen)
987 if(DOXYGEN_FOUND)
988 set(DOXYGEN_FILE_PATTERNS *.cc *.c *.cpp *.C *.cxx *.c++ *.CC *.H *.h *.hh *.hpp)
989 set(DOXYGEN_SOURCE_BROWSER YES)
990 set(DOXYGEN_WARN_IF_UNDOCUMENTED NO)
991 # enabling clang slows down doxygen significantly
992 set(DOXYGEN_CLANG_ASSISTED_PARSING NO)
993 set(DOXYGEN_CLANG_DATABASE_PATH "${PROJECT_BINARY_DIR}")
994 set(DOXYGEN_BUILTIN_STL_SUPPORT YES)
995 set(DOXYGEN_RECURSIVE YES)
996 set(DOXYGEN_QUIET YES)
997 set(DOXYGEN_GENERATE_LATEX NO)
998 set(DOXYGEN_GENERATE_XML NO)
999 set(DOXYGEN_GENERATE_HTML YES)
1000 set(DOXYGEN_PROJECT_NAME Ceph)
1001 set(DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/build-doc/doxygen")
1002 set(DOXYGEN_STRIP_FROM_PATH "src/")
1003 set(DOXYGEN_STRIP_FROM_INC_PATH "src/include")
1004 set(DOXYGEN_JAVADOC_AUTOBRIEF YES)
1005 set(DOXYGEN_HAVE_DOT NO)
1006 set(DOXYGEN_VERBATIM_HEADERS YES)
1007 doxygen_add_docs(doxygen
1008 auth
1009 client
1010 cls
1011 common
1012 compressor
1013 crimson
1014 crush
1015 crypto
1016 erasure-code
1017 global
1018 include
1019 journal
1020 json_spirit
1021 key_value_store
1022 kv
1023 librados
1024 libradosstriper
1025 librbd
1026 log
1027 mds
1028 messages
1029 mgr
1030 mon
1031 mount
1032 msg
1033 objclass
1034 objsync
1035 os
1036 osd
1037 osdc
1038 perfglue
1039 rbd_fuse
1040 rbd_replay
1041 rgw
1042 COMMENT "Generate C++ documentation")
1043 endif()
1044