-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
144 lines (130 loc) · 5.12 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
cmake_minimum_required(VERSION 3.13)
#########################
# Configuration Options #
#########################
project(rpp LANGUAGES CXX VERSION 0.0.1)
option(RPP_ENABLE_WALL OFF)
option(RPP_ENABLE_WERROR OFF)
option(RPP_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS OFF)
option(RPP_ENABLE_TESTING OFF)
option(RPP_ENABLE_STATIC_STDLIB ON)
option(RPP_ENABLE_EXCEPTIONS OFF)
option(RPP_ENABLE_RTTI OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# configure custom Standard Library selection
if(DEFINED RPP_STDLIB AND NOT RPP_STDLIB STREQUAL "default")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=${RPP_STDLIB}")
else()
message(FATAL_ERROR "RPP_STDLIB must be \"default\" unless using Clang")
endif()
endif()
# configure custom Standard Library link paths
if(DEFINED RPP_STDLIB_PATH AND EXISTS ${RPP_STDLIB_PATH})
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L ${RPP_STDLIB_PATH}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rpath ${RPP_STDLIB_PATH}")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath -Wl,${RPP_STDLIB_PATH}")
else()
message(SEND_ERROR "option : RPP_STDLIB_PATH")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "setting the Standard Library link path on this compiler unsupported")
endif()
endif()
# configure custom Standard Library include paths
if(DEFINED RPP_STDLIB_INCLUDE AND EXISTS ${RPP_STDLIB_INCLUDE})
if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${RPP_STDLIB_INCLUDE}")
else()
message(SEND_ERROR "option : RPP_STDLIB_INCLUDE")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "setting the Standard Library link path on this compiler unsupported")
endif()
endif()
# configure static Standard Library linkage
if(RPP_ENABLE_STATIC_STDLIB)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
else()
message(FATAL_ERROR "RPP_ENABLE_STATIC_STDLIB must be \"OFF\" unless using Clang")
endif()
endif()
# concepts requires C++20
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()
if(CMAKE_CXX_STANDARD LESS 20)
message(FATAL_ERROR "This project requires C++20")
endif()
# handle enable-all-warnings
if(RPP_ENABLE_WALL)
if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
else()
message(SEND_ERROR "option : RPP_ENABLE_WALL")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "enabling all warning on this compiler unsupported")
endif()
endif()
# handle treat-warnings-as-errors
if(RPP_ENABLE_WERROR)
if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
else()
message(SEND_ERROR "option : RPP_ENABLE_WERROR")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "warnings as errors on this compiler unsupported")
endif()
endif()
# handle detailed-concepts-diagnostics
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(RPP_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fconcepts-diagnostics-depth=9")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(RPP_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-backtrace-limit=0")
endif()
else()
if(RPP_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS)
message(SEND_ERROR "option : RPP_ENABLE_DETAILED_CONCEPTS_DIAGNOSTICS")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "concepts diagnostics on this compiler unsupported")
endif()
endif()
# handle exception disabling
if(NOT RPP_ENABLE_EXCEPTIONS)
if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
else()
message(SEND_ERROR "option : RPP_ENABLE_EXCEPTIONS")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "disabling exceptions on this compiler unsupported")
endif()
endif()
# handle exception disabling
if(NOT RPP_ENABLE_RTTI)
if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
else()
message(SEND_ERROR "option : RPP_ENABLE_RTTI")
message(SEND_ERROR "compiler: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "disabling RTTI on this compiler unsupported")
endif()
endif()