-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
85 lines (78 loc) · 2.69 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
cmake_minimum_required(VERSION 3.5)
project(json17)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
##################################################
# C++ standard version selection
##################################################
function(constexpr_if_std std_flag var)
try_compile(
worked
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/constexpr_if.cpp
COMPILE_DEFINITIONS ${std_flag} -Wall -Werror -DCHECK_CONSTEXPR_IF=1
)
set(${var} ${worked} PARENT_SCOPE)
endfunction ()
function(try_std_flag std_flag)
try_compile(
std_supported
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/constexpr_if.cpp
COMPILE_DEFINITIONS ${std_flag} -Wall -Werror -DCHECK_CONSTEXPR_IF=0
)
if (std_supported)
message("-- Checking compiler flag ${std_flag} -- success")
set(std_flag ${std_flag} PARENT_SCOPE)
constexpr_if_std(${std_flag} have_constexpr_if)
if (have_constexpr_if)
set(constexpr_if_define -DBOOST_NO_CONSTEXPR_IF=0 PARENT_SCOPE)
message("-- Checking constexpr if support -- success")
else ()
set(constexpr_if_define -DBOOST_NO_CONSTEXPR_IF=1 PARENT_SCOPE)
message("-- Checking constexpr if support -- failed to compile")
endif ()
else ()
message("-- Checking compiler flag ${std_flag} -- failed to compile")
endif ()
endfunction ()
if (NOT MSVC)
try_std_flag(-std=c++17)
if (NOT std_flag)
try_std_flag(-std=c++1z)
elseif (NOT std_flag)
try_std_flag(-std=c++14)
elseif (NOT std_flag)
message(FATAL_ERROR "Only Clang or GCC with -std=c++14 or later will work")
endif ()
endif ()
##################################################
# Clang+Linux support
##################################################
set(clang_on_linux false)
if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
add_definitions(${std_flag} -stdlib=libc++ -g -Wall)
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
set(clang_on_linux true)
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
add_definitions(${std_flag} -g -Wall)
else ()
if (NOT MSVC)
message(FATAL_ERROR "Only Clang or GCC with -std=c++14 or later will work")
endif()
endif ()
##################################################
# Dependencies
##################################################
include(dependencies)
include(flags)
##################################################
# Flags
##################################################
configure_msvc_runtime()
print_compile_flags()
##################################################
# Subdirectories
##################################################
add_subdirectory(json17)
add_subdirectory(unit-tests)