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