]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/yap/CMakeLists.txt
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / yap / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.5)
2 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
3
4 ##################################################
5 # C++ standard version selection
6 ##################################################
7 function(constexpr_if_std std_flag var)
8 try_compile(
9 worked
10 ${CMAKE_BINARY_DIR}
11 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/constexpr_if.cpp
12 COMPILE_DEFINITIONS ${std_flag} -DCHECK_CONSTEXPR_IF=1
13 )
14 set(${var} ${worked} PARENT_SCOPE)
15 endfunction ()
16
17 function(try_std_flag std_flag)
18 try_compile(
19 std_supported
20 ${CMAKE_BINARY_DIR}
21 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/constexpr_if.cpp
22 COMPILE_DEFINITIONS ${std_flag} -DCHECK_CONSTEXPR_IF=0
23 )
24 if (std_supported)
25 message("-- Checking compiler flag ${std_flag} -- success")
26 set(std_flag ${std_flag} PARENT_SCOPE)
27 constexpr_if_std(${std_flag} have_constexpr_if)
28 if (have_constexpr_if)
29 set(constexpr_if_define -DBOOST_NO_CONSTEXPR_IF=0 PARENT_SCOPE)
30 message("-- Checking constexpr if support -- success")
31 else ()
32 set(constexpr_if_define -DBOOST_NO_CONSTEXPR_IF=1 PARENT_SCOPE)
33 message("-- Checking constexpr if support -- failed to compile")
34 endif ()
35 else ()
36 message("-- Checking compiler flag ${std_flag} -- failed to compile")
37 endif ()
38 endfunction ()
39
40 try_std_flag(-std=c++17)
41 if (NOT std_flag)
42 try_std_flag(-std=c++1z)
43 elseif (NOT std_flag)
44 try_std_flag(-std=c++14)
45 elseif (NOT std_flag)
46 try_std_flag(/std:c++14)
47 elseif (NOT std_flag)
48 message(FATAL_ERROR "Only c++14 or later will work")
49 endif ()
50
51 ##################################################
52 # Sanitizers
53 ##################################################
54 set(USE_ASAN false CACHE BOOL "Set to true to enable -fsanitize=address when building tests.")
55 set(USE_UBSAN false CACHE BOOL "Set to true to enable -fsanitize=undefined when building tests.")
56 if (USE_ASAN AND USE_UBSAN)
57 message(FATAL_ERROR "USE_ASAN and USE_UBSAN must not be enabled at the same time")
58 elseif (USE_ASAN)
59 set(compile_flags -fsanitize=address)
60 set(link_flags -fsanitize=address)
61 message("-- Using -fsanitize=address")
62 elseif (USE_UBSAN)
63 set(compile_flags -fsanitize=undefined)
64 set(link_flags -fsanitize=undefined)
65 message("-- Using -fsanitize=undefined")
66 endif()
67
68 ##################################################
69 # Code coverage
70 ##################################################
71 if (UNIX)
72 set(BUILD_COVERAGE false CACHE BOOL "Set to true to enable code coverage when building tests. Only Linux and Mac are supported.")
73 if (BUILD_COVERAGE)
74 message("-- Building for code coverage; disabling any sanitizers")
75 if (APPLE)
76 set(compile_flags -fprofile-arcs -ftest-coverage)
77 set(CMAKE_BUILD_TYPE RelWithDebInfo)
78 set(link_flags --coverage)
79 else ()
80 set(compile_flags --coverage)
81 set(CMAKE_BUILD_TYPE RelWithDebInfo)
82 set(link_flags --coverage)
83 endif ()
84 endif ()
85 endif ()
86
87 ##################################################
88 # Clang+Linux support
89 ##################################################
90 set(clang_on_linux false)
91 if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
92 add_definitions(${std_flag} -stdlib=libc++ -g -Wall)
93 if (CMAKE_SYSTEM_NAME STREQUAL Linux)
94 set(clang_on_linux true)
95 endif ()
96 elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
97 add_definitions(${std_flag} -g -Wall)
98 endif ()
99
100 ##################################################
101 # Dependencies
102 ##################################################
103 include(dependencies)
104
105 ##################################################
106 # yap library
107 ##################################################
108 add_library(yap INTERFACE)
109 target_include_directories(yap INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
110 target_link_libraries(yap INTERFACE boost)
111 target_compile_definitions(yap INTERFACE ${constexpr_if_define} BOOST_ALL_NO_LIB=1)
112 if (link_flags)
113 target_link_libraries(yap INTERFACE ${link_flags})
114 target_compile_options(yap INTERFACE ${compile_flags})
115 endif ()
116
117 add_subdirectory(test)
118 add_subdirectory(example)
119 add_subdirectory(perf)
120 add_subdirectory(doc) # Doesn't build docs, just the snippets files.