Merge pull request #22599 from anthonyeleven/patch-2
[ceph.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.5.1)
2
3 project(ceph CXX C ASM)
4 set(VERSION 13.1.0)
5
6 if(POLICY CMP0028)
7   cmake_policy(SET CMP0028 NEW)
8 endif()
9 if(POLICY CMP0046)
10   cmake_policy(SET CMP0046 NEW)
11 endif()
12 if(POLICY CMP0054)
13   cmake_policy(SET CMP0054 NEW)
14 endif()
15 if(POLICY CMP0056)
16   cmake_policy(SET CMP0056 NEW)
17 endif()
18 if(POLICY CMP0065)
19   cmake_policy(SET CMP0065 NEW)
20 endif()
21 if(POLICY CMP0051)
22   cmake_policy(SET CMP0051 NEW)
23 endif()
24 if(POLICY CMP0075)
25   cmake_policy(SET CMP0075 NEW)
26 endif()
27 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
28
29 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
30   set(LINUX ON)
31   FIND_PACKAGE(Threads)
32 elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
33   set(FREEBSD ON)
34   FIND_PACKAGE(Threads)
35 endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
36
37 if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
38   if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7)
39     message(FATAL_ERROR "GCC 7+ required due to C++17 requirements")
40   endif()
41 endif()
42
43 option(WITH_CCACHE "Build with ccache.")
44 if(WITH_CCACHE)
45   find_program(CCACHE_FOUND ccache)
46   if(CCACHE_FOUND)
47     message(STATUS "Building with ccache: ${CCACHE_FOUND}, CCACHE_DIR=$ENV{CCACHE_DIR}")
48     set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
49     # ccache does not accelerate link (ld), but let it handle it. by passing it
50     # along with cc to python's distutils, we are able to workaround
51     # https://bugs.python.org/issue8027.
52     set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
53   else(CCACHE_FOUND)
54     message(FATAL_ERROR "Can't find ccache. Is it installed?")
55   endif(CCACHE_FOUND)
56 endif(WITH_CCACHE)
57
58 option(WITH_MANPAGE "Build man pages." ON)
59 if(WITH_MANPAGE)
60   find_program(SPHINX_BUILD
61     sphinx-build)
62   if(NOT SPHINX_BUILD)
63     message(FATAL_ERROR "Can't find sphinx-build.")
64   endif(NOT SPHINX_BUILD)
65 endif(WITH_MANPAGE)
66
67 include_directories(
68   ${PROJECT_BINARY_DIR}/src/include
69   ${PROJECT_SOURCE_DIR}/src)
70
71 if(OFED_PREFIX)
72   include_directories(SYSTEM ${OFED_PREFIX}/include)
73   link_directories(${OFED_PREFIX}/lib)
74 endif()
75
76 if(FREEBSD)
77   include_directories(SYSTEM /usr/local/include)
78   link_directories(/usr/local/lib)
79   list(APPEND CMAKE_REQUIRED_INCLUDES /usr/local/include)
80 endif(FREEBSD)
81
82 #Check Includes
83 include(CheckIncludeFiles)
84 include(CheckIncludeFileCXX)
85 include(CheckFunctionExists)
86
87 #put all the libs and binaries in one place
88 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
89 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
90 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
91
92
93 CHECK_FUNCTION_EXISTS(fallocate CEPH_HAVE_FALLOCATE)
94 CHECK_FUNCTION_EXISTS(posix_fadvise HAVE_POSIX_FADVISE)
95 CHECK_FUNCTION_EXISTS(posix_fallocate HAVE_POSIX_FALLOCATE)
96 CHECK_FUNCTION_EXISTS(syncfs HAVE_SYS_SYNCFS)
97 CHECK_FUNCTION_EXISTS(sync_file_range HAVE_SYNC_FILE_RANGE)
98 CHECK_FUNCTION_EXISTS(pwritev HAVE_PWRITEV)
99 CHECK_FUNCTION_EXISTS(splice CEPH_HAVE_SPLICE)
100 CHECK_FUNCTION_EXISTS(getgrouplist HAVE_GETGROUPLIST)
101 if(NOT APPLE)
102   CHECK_FUNCTION_EXISTS(fdatasync HAVE_FDATASYNC)
103 endif()
104 CHECK_FUNCTION_EXISTS(strerror_r HAVE_Strerror_R)
105 CHECK_FUNCTION_EXISTS(name_to_handle_at HAVE_NAME_TO_HANDLE_AT)
106 CHECK_FUNCTION_EXISTS(pipe2 HAVE_PIPE2)
107 CHECK_FUNCTION_EXISTS(accept4 HAVE_ACCEPT4)
108
109 include(CMakePushCheckState)
110 cmake_push_check_state(RESET)
111 set(CMAKE_REQUIRED_LIBRARIES pthread)
112 CHECK_FUNCTION_EXISTS(pthread_spin_init HAVE_PTHREAD_SPINLOCK)
113 CHECK_FUNCTION_EXISTS(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
114 CHECK_FUNCTION_EXISTS(pthread_get_name_np HAVE_PTHREAD_GET_NAME_NP)
115 CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
116 CHECK_FUNCTION_EXISTS(pthread_getname_np HAVE_PTHREAD_GETNAME_NP)
117 CHECK_FUNCTION_EXISTS(pthread_rwlockattr_setkind_np HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP)
118 cmake_pop_check_state()
119
120 CHECK_FUNCTION_EXISTS(eventfd HAVE_EVENTFD)
121 CHECK_FUNCTION_EXISTS(getprogname HAVE_GETPROGNAME)
122
123 CHECK_INCLUDE_FILES("linux/types.h" HAVE_LINUX_TYPES_H)
124 CHECK_INCLUDE_FILES("linux/version.h" HAVE_LINUX_VERSION_H)
125 CHECK_INCLUDE_FILES("arpa/nameser_compat.h" HAVE_ARPA_NAMESER_COMPAT_H)
126 CHECK_INCLUDE_FILES("sys/mount.h" HAVE_SYS_MOUNT_H)
127 CHECK_INCLUDE_FILES("sys/param.h" HAVE_SYS_PARAM_H)
128 CHECK_INCLUDE_FILES("sys/types.h" HAVE_SYS_TYPES_H)
129 CHECK_INCLUDE_FILES("sys/vfs.h" HAVE_SYS_VFS_H)
130 CHECK_INCLUDE_FILES("sys/prctl.h" HAVE_SYS_PRCTL_H)
131 CHECK_INCLUDE_FILES("execinfo.h" HAVE_EXECINFO_H)
132 if(LINUX)
133   CHECK_INCLUDE_FILES("sched.h" HAVE_SCHED)
134 endif(LINUX)
135 CHECK_INCLUDE_FILES("valgrind/helgrind.h" HAVE_VALGRIND_HELGRIND_H)
136
137 include(CheckTypeSize)
138 set(CMAKE_EXTRA_INCLUDE_FILES "linux/types.h")
139 CHECK_TYPE_SIZE(__be16 __BE16) 
140 CHECK_TYPE_SIZE(__be32 __BE32) 
141 CHECK_TYPE_SIZE(__be64 __BE64) 
142 CHECK_TYPE_SIZE(__le16 __LE16) 
143 CHECK_TYPE_SIZE(__le32 __LE32) 
144 CHECK_TYPE_SIZE(__le64 __LE64) 
145 CHECK_TYPE_SIZE(__u8 __U8) 
146 CHECK_TYPE_SIZE(__u16 __U16) 
147 CHECK_TYPE_SIZE(__u32 __U32) 
148 CHECK_TYPE_SIZE(__u64 __U64) 
149 CHECK_TYPE_SIZE(__s8 __S8) 
150 CHECK_TYPE_SIZE(__s16 __S16) 
151 CHECK_TYPE_SIZE(__s32 __S32) 
152 CHECK_TYPE_SIZE(__s64 __S64) 
153 unset(CMAKE_EXTRA_INCLUDE_FILES)
154
155 include(CheckSymbolExists)
156 CHECK_SYMBOL_EXISTS(res_nquery "resolv.h" HAVE_RES_NQUERY)
157 CHECK_SYMBOL_EXISTS(F_SETPIPE_SZ "linux/fcntl.h" CEPH_HAVE_SETPIPE_SZ)
158 CHECK_SYMBOL_EXISTS(__func__ "" HAVE_FUNC)
159 CHECK_SYMBOL_EXISTS(__PRETTY_FUNCTION__ "" HAVE_PRETTY_FUNC)
160 CHECK_SYMBOL_EXISTS(getentropy "unistd.h" HAVE_GETENTROPY)
161
162 include(CheckCXXSourceCompiles)
163 CHECK_CXX_SOURCE_COMPILES("
164   #include <string.h>
165   int main() { char x = *strerror_r(0, &x, sizeof(x)); return 0; }
166   " STRERROR_R_CHAR_P)
167
168 include(CheckStructHasMember)
169 CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
170   HAVE_STAT_ST_MTIM_TV_NSEC LANGUAGE C)
171 CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h
172   HAVE_STAT_ST_MTIMESPEC_TV_NSEC LANGUAGE C)
173
174 set(CEPH_MAN_DIR "share/man" CACHE STRING "Install location for man pages (relative to prefix).")
175
176 option(ENABLE_SHARED "build shared libraries" ON)
177 if(ENABLE_SHARED)
178   set(CEPH_SHARED SHARED)
179 else(ENABLE_SHARED)
180   set(CEPH_SHARED STATIC)
181 endif(ENABLE_SHARED)
182 set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_SHARED})
183
184 option(WITH_STATIC_LIBSTDCXX "Link against libstdc++ statically" OFF)
185 if(WITH_STATIC_LIBSTDCXX)
186   if(CMAKE_COMPILER_IS_GNUCXX)
187     set(static_linker_flags "-static-libstdc++ -static-libgcc")
188     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${static_linker_flags}")
189     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${static_linker_flags}")
190     unset(static_linker_flags)
191     set(GPERFTOOLS_USE_STATIC_LIBS TRUE)
192   else()
193     message(FATAL_ERROR "Please use GCC to enable WITH_STATIC_LIBSTDCXX")
194   endif()
195 endif()
196 include(CheckCxxAtomic)
197 if(NOT HAVE_CXX11_ATOMIC)
198   set(CMAKE_CXX_STANDARD_LIBRARIES
199     "${CMAKE_CXX_STANDARD_LIBRARIES} ${LIBATOMIC_LINK_FLAGS}")
200 endif()
201
202 option(WITH_RDMA "Enable RDMA in async messenger" ON)
203 if(WITH_RDMA)
204   find_package(verbs REQUIRED)
205   set(HAVE_VERBS ${VERBS_FOUND})
206   find_package(rdmacm REQUIRED)
207   set(HAVE_RDMACM ${RDMACM_FOUND})
208   set(HAVE_RDMA TRUE)
209 endif()
210
211 find_package(Backtrace)
212
213 if(LINUX)
214   find_package(udev REQUIRED)
215   set(HAVE_UDEV ${UDEV_FOUND})
216   find_package(blkid REQUIRED)
217   set(HAVE_BLKID ${BLKID_FOUND})
218 elseif(FREEBSD)
219   set(HAVE_UDEV OFF)
220   set(HAVE_LIBAIO OFF)
221   set(HAVE_BLKID OFF)
222 else()
223   set(HAVE_UDEV OFF)
224   message(STATUS "Not using udev")
225   set(HAVE_BLKID OFF)
226   message(STATUS "Not using BLKID")
227 endif(LINUX)
228
229 option(WITH_OPENLDAP "OPENLDAP is here" ON)
230 if(WITH_OPENLDAP)
231   find_package(OpenLdap REQUIRED)
232   set(HAVE_OPENLDAP ${OPENLDAP_FOUND})
233 endif()
234
235 option(WITH_FUSE "Fuse is here" ON)
236 if(WITH_FUSE)
237   find_package(fuse)
238   set(HAVE_LIBFUSE ${FUSE_FOUND})
239 endif()
240
241 option(WITH_XFS "XFS is here" ON)
242 if(WITH_XFS)
243   find_package(xfs)
244   set(HAVE_LIBXFS ${XFS_FOUND})
245 endif()
246
247 option(WITH_ZFS "enable LibZFS if found" OFF)
248 if(WITH_ZFS)
249   find_package(zfs)
250   set(HAVE_LIBZFS ${ZFS_FOUND})
251 endif()
252
253 option(WITH_BLUESTORE "Bluestore OSD backend" ON)
254 if(WITH_BLUESTORE)
255   find_package(aio)
256   set(HAVE_LIBAIO ${AIO_FOUND})
257 endif()
258
259 if(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|amd64|x86_64|AMD64|aarch64")
260   option(WITH_SPDK "Enable SPDK" ON)
261 else()
262   option(WITH_SPDK "Enable SPDK" OFF)
263 endif()
264 if(WITH_SPDK)
265   if(NOT WITH_BLUESTORE)
266     message(SEND_ERROR "Please enable WITH_BLUESTORE for using SPDK")
267   endif()
268   include(BuildSPDK)
269   build_spdk()
270   set(HAVE_SPDK TRUE)
271 endif(WITH_SPDK)
272
273 option(WITH_PMEM "Enable PMEM" OFF)
274 if(WITH_PMEM)
275   set(HAVE_PMEM ON)
276   if(NOT WITH_BLUESTORE)
277     message(SEND_ERROR "Please enable WITH_BLUESTORE for using PMEM")
278   endif()
279 endif()
280
281 if(WITH_BLUESTORE)
282   if(NOT AIO_FOUND AND NOT WITH_SPDK AND NOT WITH_PMEM)
283     message(SEND_ERROR "WITH_BLUESTORE is ON, "
284       "but none of the bluestore backends is enabled. "
285       "Please install libaio, or enable WITH_SPDK or WITH_PMEM (experimental)")
286   endif()
287 endif()
288
289 option(WITH_BLUEFS "libbluefs library" OFF)
290
291 option(WITH_QATZIP "Enable QATZIP" OFF)
292 if(WITH_QATZIP)
293   find_package(qatzip REQUIRED)
294   set(HAVE_QATZIP ${QATZIP_FOUND})
295 endif(WITH_QATZIP)
296
297 # needs mds and? XXX
298 option(WITH_LIBCEPHFS "libcephfs client library" ON)
299
300 # key-value store
301 option(WITH_KVS "Key value store is here" ON)
302
303 # remote block storage
304 option(WITH_RBD "Remote block storage is here" ON)
305
306 # KERNEL remote block storage
307 option(WITH_KRBD "Kernel Remote block storage is here" ON)
308
309 if(WITH_KRBD AND WITHOUT_RBD)
310   message(FATAL_ERROR "Cannot have WITH_KRBD with WITH_RBD.")
311 endif()
312
313 option(WITH_LEVELDB "LevelDB is here" ON)
314 if(WITH_LEVELDB)
315   if(LEVELDB_PREFIX)
316     include_directories(SYSTEM ${LEVELDB_PREFIX}/include)
317     link_directories(${LEVELDB_PREFIX}/lib)
318   endif()
319   find_package(leveldb REQUIRED)
320   find_file(HAVE_LEVELDB_FILTER_POLICY leveldb/filter_policy.h PATHS ${LEVELDB_INCLUDE_DIR})
321 endif(WITH_LEVELDB)
322
323 find_package(snappy REQUIRED)
324
325 option(WITH_BROTLI "Brotli compression support" OFF)
326 if(WITH_BROTLI)
327   set(HAVE_BROTLI TRUE)
328 endif()
329
330 option(WITH_LZ4 "LZ4 compression support" ON)
331 if(WITH_LZ4)
332   find_package(LZ4 1.7 REQUIRED)
333   set(HAVE_LZ4 ${LZ4_FOUND})
334 endif(WITH_LZ4)
335
336 option(WITH_CEPH_DEBUG_MUTEX "Use debug ceph::mutex with lockdep" OFF)
337
338 #if allocator is set on command line make sure it matches below strings
339 set(ALLOCATOR "" CACHE STRING
340   "specify memory allocator to use. currently tcmalloc, tcmalloc_minimal, \
341 jemalloc, and libc is supported. if not specified, will try to find tcmalloc, \
342 and then jemalloc. If neither of then is found. use the one in libc.")
343 if(ALLOCATOR)
344   if(${ALLOCATOR} MATCHES "tcmalloc(_minimal)?")
345     find_package(gperftools REQUIRED)
346     set(HAVE_LIBTCMALLOC ON)
347   elseif(${ALLOCATOR} STREQUAL "jemalloc")
348     find_package(JeMalloc REQUIRED)
349     set(HAVE_JEMALLOC 1)
350   elseif(NOT ALLOCATOR STREQUAL "libc")
351     message(FATAL_ERROR "Unsupported allocator selected: ${ALLOCATOR}")
352   endif()
353 else(ALLOCATOR)
354   find_package(gperftools)
355   set(HAVE_LIBTCMALLOC ${gperftools_FOUND})
356   if(NOT gperftools_FOUND)
357     find_package(JeMalloc)
358   endif()
359   if(gperftools_FOUND)
360     set(ALLOCATOR tcmalloc)
361   elseif(JeMalloc_FOUND)
362     set(ALLOCATOR jemalloc)
363   else()
364     if(NOT FREEBSD)
365       # FreeBSD already has jemalloc as its default allocator
366       message(WARNING "tcmalloc and jemalloc not found, falling back to libc")
367     endif()
368     set(ALLOCATOR "libc")
369   endif(gperftools_FOUND)
370 endif(ALLOCATOR)
371
372 if(HAVE_LIBTCMALLOC AND WITH_STATIC_LIBSTDCXX)
373   set(EXE_LINKER_USE_PIE FALSE)
374 else()
375   set(EXE_LINKER_USE_PIE ${ENABLE_SHARED})
376 endif()
377
378 if(WITH_LIBCEPHFS OR WITH_KRBD)
379   find_package(keyutils REQUIRED)
380 endif()
381
382 find_package(CURL REQUIRED)
383 set(CMAKE_REQUIRED_INCLUDES ${CURL_INCLUDE_DIRS})
384 set(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBRARIES})
385 CHECK_SYMBOL_EXISTS(curl_multi_wait curl/curl.h HAVE_CURL_MULTI_WAIT)
386
387 find_package(NSS REQUIRED)
388 find_package(NSPR REQUIRED)
389 find_package(OpenSSL REQUIRED)
390 # TODO: use NSS only for validation of the OpenSSL-based implementations
391 set(USE_NSS 1)
392 set(USE_OPENSSL 1)
393 set(CRYPTO_LIBS ${NSS_LIBRARIES} ${NSPR_LIBRARIES} OpenSSL::Crypto)
394
395 option(WITH_XIO "Enable XIO messaging" OFF)
396 if(WITH_XIO)
397   find_package(xio REQUIRED)
398   set(HAVE_XIO ${XIO_FOUND})
399 endif()
400
401 option(WITH_DPDK "Enable DPDK messaging" OFF)
402 if(WITH_DPDK)
403   find_package(dpdk)
404   if(NOT DPDK_FOUND AND NOT TARGET dpdk-ext)
405     include(BuildDPDK)
406     build_dpdk(${CMAKE_BINARY_DIR}/src/dpdk)
407   endif()
408   set(HAVE_DPDK TRUE)
409 endif()
410
411 option(WITH_BLKIN "Use blkin to emit LTTng tracepoints for Zipkin" OFF)
412 if(WITH_BLKIN)
413   set(BLKIN_LIBRARIES blkin ${LTTNGUST_LIBRARIES} lttng-ust-fork)
414   include_directories(SYSTEM src/blkin/blkin-lib)
415 endif(WITH_BLKIN)
416
417 option(WITH_BOOST_CONTEXT "Enable boost::asio stackful coroutines" ON)
418 if(WITH_BOOST_CONTEXT)
419   set(HAVE_BOOST_CONTEXT ON)
420 endif()
421
422 #option for RGW
423 option(WITH_RADOSGW "Rados Gateway is enabled" ON)
424 option(WITH_RADOSGW_FCGI_FRONTEND "Rados Gateway's FCGI frontend is enabled" OFF)
425 option(WITH_RADOSGW_BEAST_FRONTEND "Rados Gateway's Beast frontend is enabled" ON)
426 option(WITH_RADOSGW_BEAST_OPENSSL "Rados Gateway's Beast frontend uses OpenSSL" ON)
427
428 if(WITH_RADOSGW)
429   find_package(EXPAT REQUIRED)
430   if(WITH_RADOSGW_FCGI_FRONTEND)
431     find_package(fcgi REQUIRED)
432   endif()
433   if(WITH_RADOSGW_BEAST_FRONTEND AND NOT WITH_BOOST_CONTEXT)
434     message(WARNING "disabling WITH_RADOSGW_BEAST_FRONTEND, which depends on WITH_BOOST_CONTEXT")
435     set(WITH_RADOSGW_BEAST_FRONTEND OFF)
436   endif()
437   find_package(OATH REQUIRED)
438
439 # https://curl.haxx.se/docs/install.html mentions the
440 # configure flags for various ssl backends
441   execute_process(
442     COMMAND
443   "sh" "-c"
444   "curl-config --configure | grep with-ssl"
445   RESULT_VARIABLE NO_CURL_SSL_LINK
446   ERROR_VARIABLE CURL_CONFIG_ERRORS
447   )
448   if (CURL_CONFIG_ERRORS)
449     message(WARNING "unable to run curl-config; rgw cannot make ssl requests to external systems reliably")
450   endif()
451
452   if (WITH_RADOSGW_BEAST_FRONTEND AND WITH_RADOSGW_BEAST_OPENSSL)
453     find_package(OpenSSL REQUIRED)
454   else()
455     find_package(OpenSSL)
456   endif()
457
458   if (OPENSSL_FOUND)
459     if (NOT NO_CURL_SSL_LINK)
460       message(STATUS "libcurl is linked with openssl: explicitly setting locks")
461       set(WITH_CURL_OPENSSL ON)
462     endif() # CURL_SSL_LINK
463     execute_process(
464       COMMAND
465         "sh" "-c"
466         "objdump -p ${OPENSSL_SSL_LIBRARY} | sed -n 's/^  SONAME  *//p'"
467       OUTPUT_VARIABLE LIBSSL_SONAME
468       ERROR_VARIABLE OBJDUMP_ERRORS
469       RESULT_VARIABLE OBJDUMP_RESULTS
470       OUTPUT_STRIP_TRAILING_WHITESPACE)
471     if (OBJDUMP_RESULTS)
472       message(FATAL_ERROR "can't run objdump: ${OBJDUMP_RESULTS}")
473     endif()
474     if (NOT OBJDUMP_ERRORS STREQUAL "")
475       message(WARNING "message from objdump: ${OBJDUMP_ERRORS}")
476     endif()
477     execute_process(
478       COMMAND
479         "sh" "-c"
480         "objdump -p ${OPENSSL_CRYPTO_LIBRARY} | sed -n 's/^  SONAME  *//p'"
481       OUTPUT_VARIABLE LIBCRYPTO_SONAME
482       ERROR_VARIABLE OBJDUMP_ERRORS
483       RESULT_VARIABLE OBJDUMP_RESULTS
484       OUTPUT_STRIP_TRAILING_WHITESPACE)
485     if (OBJDUMP_RESULTS)
486       message(FATAL_ERROR "can't run objdump: ${OBJDUMP_RESULTS}")
487     endif()
488     if (NOT OBJDUMP_ERRORS STREQUAL "")
489       message(WARNING "message from objdump: ${OBJDUMP_ERRORS}")
490     endif()
491     message(STATUS "ssl soname: ${LIBSSL_SONAME}")
492     message(STATUS "crypto soname: ${LIBCRYPTO_SONAME}")
493   else()
494     message(WARNING "ssl not found: rgw civetweb may fail to dlopen libssl libcrypto")
495   endif()  # OPENSSL_FOUND
496 endif (WITH_RADOSGW)
497
498 #option for CephFS
499 option(WITH_CEPHFS "CephFS is enabled" ON)
500
501 #option for Mgr
502 option(WITH_MGR "ceph-mgr is enabled" ON)
503 if(WITH_MGR)
504   # Please specify 3 or 3.[0-7] if you want to build with python3 support.
505   # FindPyhonInterp and FindPythonLibs think they belong to different families.
506   set(MGR_PYTHON_VERSION "2.7" CACHE
507     STRING "minimal required version of python runtime for running mgr plugins. ")
508   find_package(PythonInterp ${MGR_PYTHON_VERSION} REQUIRED)
509   find_package(PythonLibs ${MGR_PYTHON_VERSION} REQUIRED)
510   set(MGR_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
511   set(MGR_PYTHON_LIBRARIES ${PYTHON_LIBRARIES})
512   set(MGR_PYTHON_VERSION_MAJOR ${PYTHON_VERSION_MAJOR})
513   set(MGR_PYTHON_VERSION_MINOR ${PYTHON_VERSION_MINOR})
514   # Boost dependency check deferred to Boost section
515 endif(WITH_MGR)
516
517 option(WITH_THREAD_SAFE_RES_QUERY "res_query is thread safe" OFF)
518 if(WITH_THREAD_SAFE_RES_QUERY)
519   set(HAVE_THREAD_SAFE_RES_QUERY 1 CACHE INTERNAL "Thread safe res_query supported.")
520 endif()
521
522 option(WITH_REENTRANT_STRSIGNAL "strsignal is reentrant" OFF)
523 if(WITH_REENTRANT_STRSIGNAL)
524   set(HAVE_REENTRANT_STRSIGNAL 1 CACHE INTERNAL "Reentrant strsignal is supported.")
525 endif()
526
527 set(HAVE_LIBROCKSDB 1)
528
529 # -lz link into kv
530 find_package(ZLIB REQUIRED)
531
532 #option for EventTrace
533 option(WITH_EVENTTRACE "Event tracing support" OFF)
534
535 #option for LTTng
536 option(WITH_LTTNG "LTTng tracing is enabled" ON)
537 if(${WITH_LTTNG})
538   find_package(LTTngUST REQUIRED)
539   find_program(LTTNG_GEN_TP
540     lttng-gen-tp)
541   if(NOT LTTNG_GEN_TP)
542     message(FATAL_ERROR "Can't find lttng-gen-tp.")
543   endif()
544 endif(${WITH_LTTNG})
545
546 option(WITH_OSD_INSTRUMENT_FUNCTIONS OFF)
547
548 #option for Babeltrace
549 option(WITH_BABELTRACE "Babeltrace libraries are enabled" ON)
550 if(WITH_BABELTRACE)
551   set(HAVE_BABELTRACE ON)
552   find_package(babeltrace REQUIRED)
553   set(HAVE_BABELTRACE_BABELTRACE_H ${BABELTRACE_FOUND})
554   set(HAVE_BABELTRACE_CTF_EVENTS_H ${BABELTRACE_FOUND})
555   set(HAVE_BABELTRACE_CTF_ITERATOR_H ${BABELTRACE_FOUND})
556 endif(WITH_BABELTRACE)
557
558 option(DEBUG_GATHER "C_Gather debugging is enabled" ON)
559 option(ENABLE_COVERAGE "Coverage is enabled" OFF)
560 option(PG_DEBUG_REFS "PG Ref debugging is enabled" OFF)
561
562 option(WITH_TESTS "enable the build of ceph-test package scripts/binaries" ON)
563
564 # fio
565 option(WITH_FIO "build with fio plugin enabled" OFF)
566 option(WITH_SYSTEM_FIO "require and build with system fio" OFF)
567 if(WITH_SYSTEM_FIO)
568   find_package(fio REQUIRED)
569 elseif(WITH_FIO)
570   set(FIO_INCLUDE_DIR ${CMAKE_BINARY_DIR}/src/fio)
571   include(BuildFIO)
572   build_fio()
573 endif()
574
575 if(LINUX)
576   add_definitions(-D__linux__)
577 endif(LINUX)
578
579 # ASAN and friends
580 option(WITH_ASAN "build with ASAN" OFF)
581 if(WITH_ASAN)
582   list(APPEND sanitizers "address")
583 endif()
584
585 option(WITH_ASAN_LEAK "explicitly enable ASAN leak detection" OFF)
586 if(WITH_ASAN_LEAK)
587   list(APPEND sanitizers "leak")
588 endif()
589
590 option(WITH_TSAN "build with TSAN" OFF)
591 if(WITH_TSAN)
592   list(APPEND sanitizers "thread")
593 endif()
594
595 option(WITH_UBSAN "build with UBSAN" OFF)
596 if(WITH_UBSAN)
597   list(APPEND sanitizers "undefined-behavior")
598 endif()
599
600 if(sanitizers)
601   find_package(Sanitizers REQUIRED ${sanitizers})
602   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${Sanitizers_COMPILE_OPTIONS}")
603   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Sanitizers_COMPILE_OPTIONS}")
604   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Sanitizers_COMPILE_OPTIONS}")
605   set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${Sanitizers_COMPILE_OPTIONS}")
606 endif()
607
608 # Rocksdb
609 option(WITH_SYSTEM_ROCKSDB "require and build with system rocksdb" OFF)
610 if (WITH_SYSTEM_ROCKSDB)
611   find_package(RocksDB 5.8 REQUIRED)
612 endif()
613
614 option(WITH_SEASTAR "Build seastar components")
615 set(HAVE_SEASTAR ${WITH_SEASTAR})
616
617 # Boost
618 option(WITH_SYSTEM_BOOST "require and build with system Boost" OFF)
619
620 # Boost::thread depends on Boost::atomic, so list it explicitly.
621 set(BOOST_COMPONENTS
622   atomic chrono thread system regex random program_options date_time
623   iostreams)
624 set(BOOST_HEADER_COMPONENTS container)
625
626 if(WITH_MGR)
627   list(APPEND BOOST_COMPONENTS
628     python${MGR_PYTHON_VERSION_MAJOR}${MGR_PYTHON_VERSION_MINOR})
629 endif()
630 if(WITH_BOOST_CONTEXT)
631   list(APPEND BOOST_COMPONENTS context coroutine)
632 endif()
633 if(WITH_SEASTAR)
634   list(APPEND BOOST_COMPONENTS filesystem timer)
635 endif()
636
637 set(Boost_USE_MULTITHREADED ON)
638 # require minimally the bundled version
639 if(WITH_SYSTEM_BOOST)
640   if(ENABLE_SHARED)
641     set(Boost_USE_STATIC_LIBS OFF)
642   else()
643     set(Boost_USE_STATIC_LIBS ON)
644   endif()
645   if(BOOST_ROOT AND CMAKE_LIBRARY_ARCHITECTURE)
646     set(BOOST_LIBRARYDIR "${BOOST_ROOT}/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
647   endif()
648   find_package(Boost 1.67 COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
649 else()
650   set(BOOST_J 1 CACHE STRING
651     "max jobs for Boost build") # override w/-DBOOST_J=<n>
652   set(Boost_USE_STATIC_LIBS ON)
653   include(BuildBoost)
654   build_boost(1.67
655     COMPONENTS ${BOOST_COMPONENTS} ${BOOST_HEADER_COMPONENTS})
656 endif()
657 include_directories(BEFORE SYSTEM ${Boost_INCLUDE_DIRS})
658 set(Boost_USE_MULTITHREADED ON)
659
660 # dashboard angular2 frontend
661 option(WITH_MGR_DASHBOARD_FRONTEND "Build the mgr/dashboard frontend using `npm`" ON)
662 option(WITH_SYSTEM_NPM "Assume that dashboard build tools already installed through packages" OFF)
663 if(WITH_SYSTEM_NPM)
664   find_program(NPM npm)
665   if(NOT NPM)
666     message(FATAL_ERROR "Can't find npm.")
667   endif()
668 endif()
669
670 include_directories(SYSTEM ${PROJECT_BINARY_DIR}/include)
671
672 find_package(Threads REQUIRED)
673
674
675 option(WITH_SELINUX "build SELinux policy" OFF)
676 if(WITH_SELINUX)
677   find_file(SELINUX_MAKEFILE selinux/devel/Makefile
678     PATH /usr/share)
679   if(NOT SELINUX_MAKEFILE)
680     message(FATAL_ERROR "Can't find selinux's Makefile")
681   endif()
682   add_subdirectory(selinux)
683 endif(WITH_SELINUX)
684
685 # enables testing and creates Make check command
686 add_custom_target(tests
687   COMMENT "Building tests")
688 enable_testing()
689 set(CMAKE_CTEST_COMMAND ctest)
690 add_custom_target(check
691   COMMAND ${CMAKE_CTEST_COMMAND}
692   DEPENDS tests)
693
694 add_subdirectory(src)
695
696 add_subdirectory(doc)
697 if(WITH_MANPAGE)
698   add_subdirectory(man)
699 endif(WITH_MANPAGE)
700
701 option(WITH_SYSTEMD "install systemd target and service files" ON)
702 if(WITH_SYSTEMD)
703   add_subdirectory(systemd)
704 endif()
705
706 if(LINUX)
707   add_subdirectory(etc/sysctl)
708 endif()
709
710 option(WITH_GRAFANA "install grafana dashboards" OFF)
711 if(WITH_GRAFANA)
712   add_subdirectory(monitoring/grafana/dashboards)
713 endif()
714
715 include(CTags)
716 option(CTAG_EXCLUDES "Exclude files/directories when running ctag.")
717 add_tags(ctags
718   SRC_DIR src
719   TAG_FILE tags
720   EXCLUDE_OPTS ${CTAG_EXCLUDES}
721   EXCLUDES "*.js" "*.css")
722 add_custom_target(tags DEPENDS ctags)