1 cmake_minimum_required(VERSION 3.5)
2 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
4 ##################################################
5 # C++ standard version selection
6 ##################################################
7 function(constexpr_if_std std_flag var)
11 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/constexpr_if.cpp
12 COMPILE_DEFINITIONS ${std_flag} -DCHECK_CONSTEXPR_IF=1
14 set(${var} ${worked} PARENT_SCOPE)
17 function(try_std_flag std_flag)
21 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/constexpr_if.cpp
22 COMPILE_DEFINITIONS ${std_flag} -DCHECK_CONSTEXPR_IF=0
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")
32 set(constexpr_if_define -DBOOST_NO_CONSTEXPR_IF=1 PARENT_SCOPE)
33 message("-- Checking constexpr if support -- failed to compile")
36 message("-- Checking compiler flag ${std_flag} -- failed to compile")
40 try_std_flag(-std=c++17)
42 try_std_flag(-std=c++1z)
44 try_std_flag(-std=c++14)
46 try_std_flag(/std:c++14)
48 message(FATAL_ERROR "Only c++14 or later will work")
51 ##################################################
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")
59 set(compile_flags -fsanitize=address)
60 set(link_flags -fsanitize=address)
61 message("-- Using -fsanitize=address")
63 set(compile_flags -fsanitize=undefined)
64 set(link_flags -fsanitize=undefined)
65 message("-- Using -fsanitize=undefined")
68 ##################################################
70 ##################################################
72 set(BUILD_COVERAGE false CACHE BOOL "Set to true to enable code coverage when building tests. Only Linux and Mac are supported.")
74 message("-- Building for code coverage; disabling any sanitizers")
76 set(compile_flags -fprofile-arcs -ftest-coverage)
77 set(CMAKE_BUILD_TYPE RelWithDebInfo)
78 set(link_flags --coverage)
80 set(compile_flags --coverage)
81 set(CMAKE_BUILD_TYPE RelWithDebInfo)
82 set(link_flags --coverage)
87 ##################################################
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)
96 elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
97 add_definitions(${std_flag} -g -Wall)
100 ##################################################
102 ##################################################
103 include(dependencies)
105 ##################################################
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)
113 target_link_libraries(yap INTERFACE ${link_flags})
114 target_compile_options(yap INTERFACE ${compile_flags})
117 add_subdirectory(test)
118 add_subdirectory(example)
119 add_subdirectory(perf)
120 add_subdirectory(doc) # Doesn't build docs, just the snippets files.