-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
269 lines (219 loc) · 7.16 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
cmake_minimum_required(VERSION 3.16...3.29)
set(CMAKE_POLICY_DEFAULT_CMP0091 NEW) # Respect CMAKE_MSVC_RUNTIME_LIBRARY
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(GitVersion)
gitversion_set_version(DUNE_VERSION v)
project(dunelegacy
VERSION 0.96.4
LANGUAGES CXX C
)
if(APPLE)
enable_language(OBJC)
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
if(CMAKE_BUILD_TYPE)
message(STATUS "CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}")
set(build_list ${CMAKE_BUILD_TYPE})
elseif(CMAKE_CONFIGURATION_TYPES)
message(STATUS "CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES}")
set(build_list ${CMAKE_CONFIGURATION_TYPES})
endif()
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
option(DUNE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
if(DUNE_PRECOMPILED_HEADERS)
message(STATUS "Enabling precompiled headers")
endif()
option(DUNE_ASAN "Enable ASAN")
if(DUNE_ASAN)
include(setup/asan-setup)
endif()
option(DUNE_ASAN "Enable UBSAN")
if(DUNE_UBSAN)
include(setup/ubsan-setup)
endif()
if(WIN32)
include(setup/win32-setup)
endif()
if(MSVC)
include(setup/msvc-setup)
endif()
if(APPLE)
include(setup/macos-setup)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
include(setup/clang-gcc-setup)
endif()
include(create-harden-interface)
include(CheckSymbolExists)
include(CheckCXXSourceCompiles)
check_symbol_exists(strerror_s "string.h" HAVE_STRERROR_S)
check_cxx_source_compiles(
"#include <time.h>
int main(int argc, char* argv[]) {
time_t rawtime{};
tm timeinfo{};
int error = localtime_s(&timeinfo, &rawtime);
return 0;
}"
HAVE_MS_LOCALTIME_S)
check_cxx_source_compiles(
"#include <time.h>
int main(int argc, char* argv[]) {
time_t rawtime{};
tm timeinfo{};
tm* result = localtime_r(&rawtime, &timeinfo);
return 0;
}"
HAVE_MS_LOCALTIME_R)
check_cxx_source_compiles(
"#include <string.h>
char buffer[64];
int main(int argc, char* argv[]) {
int error = strerror_r(7, buffer, sizeof(buffer));
return 0;
}"
HAVE_STRERROR_R)
check_cxx_source_compiles(
"#include <string.h>
char buffer[64];
int main(int argc, char* argv[]) {
char* error = strerror_r(7, buffer, sizeof(buffer));
return 0;
}"
HAVE_GNU_STRERROR_R)
check_cxx_source_compiles(
"#include <charconv>
char buffer[64];
int main(int argc, char* argv[]) {
auto [ptr, ec] = std::to_chars(&buffer[0], &buffer[sizeof(buffer)], 1.0f);
return 0;
}"
HAVE_FLOAT_TO_CHARS)
check_cxx_source_compiles(
"#include <charconv>
char buffer[64];
int main(int argc, char* argv[]) {
auto [ptr, ec] = std::to_chars(&buffer[0], &buffer[sizeof(buffer)], 1.0);
return 0;
}"
HAVE_DOUBLE_TO_CHARS)
check_cxx_source_compiles(
"#include <charconv>
const char number[] = \"1.0\";
int main(int argc, char* argv[]) {
float value;
auto [ptr, ec] = std::from_chars(&number[0], &number[sizeof(number) - 1], value);
return 0;
}"
HAVE_FLOAT_FROM_CHARS)
check_cxx_source_compiles(
"#include <charconv>
const char number[] = \"1.0\";
int main(int argc, char* argv[]) {
double value;
auto [ptr, ec] = std::from_chars(&number[0], &number[sizeof(number) - 1], value);
return 0;
}"
HAVE_DOUBLE_FROM_CHARS)
check_cxx_source_compiles(
"#include <vector>
struct Foo { int a; double b; bool c; };
int main(int argc, char* argv[]) {
std::vector<Foo> v;
v.emplace_back(123, -3.456, false);
return 0;
}"
HAVE_PARENTHESIZED_INITIALIZATION_OF_AGGREGATES)
check_cxx_source_compiles(
"#include <future>
int main(int argc, char* argv[]) {
auto fut = std::async(std::launch::async | std::launch::deferred, [] { return 42; });
return fut.get();
}"
HAVE_STD_ASYNC)
if(DUNE_TARGET_ARCHITECTURE)
if (DUNE_TARGET_ARCHITECTURE STREQUAL "x64" OR DUNE_TARGET_ARCHITECTURE STREQUAL "x86_64")
check_cxx_source_compiles(
"#if !defined(__x86_64__) && !defined(_M_X64)
#error \"Invalid architecture\"
#endif
int main(int argc, const char* argv[]) { }
"
DUNE_TARGET_MATCHES)
elseif(DUNE_TARGET_ARCHITECTURE STREQUAL "x86")
check_cxx_source_compiles(
"#if !defined(__i386__) && !defined(_M_IX86)
#error \"Invalid architecture\"
#endif
int main(int argc, const char* argv[]) { }
"
DUNE_TARGET_MATCHES)
elseif(DUNE_TARGET_ARCHITECTURE STREQUAL "arm64")
check_cxx_source_compiles(
"#if !defined(__aarch64__) && !defined(_M_ARM64)
#error \"Invalid architecture\"
#endif
int main(int argc, const char* argv[]) { }
"
DUNE_TARGET_MATCHES)
endif()
if(DUNE_TARGET_MATCHES)
else()
message(FATAL_ERROR "Target architecture \"${DUNE_TARGET_ARCHITECTURE}\" doesn't match the compiler output.")
endif()
endif()
include(AddSources)
# googletest and the #define "new" used for heap debugging don't get along.
if(DUNE_CRT_HEAP_DEBUG)
set(ENABLE_TESTS OFF)
else()
set(ENABLE_TESTS ON)
endif()
option(DUNE_ENABLE_TESTS "Enable tests" "${ENABLE_TESTS}")
if(DUNE_ENABLE_TESTS)
message(STATUS "Enabling tests")
enable_testing()
else()
message(STATUS "Skipping tests")
endif()
if(COMMAND gitversion_create_target)
gitversion_create_target(dune_gitversion)
endif()
add_subdirectory(external)
add_subdirectory(src)
add_subdirectory(data)
if(DUNE_ENABLE_TESTS)
add_subdirectory(tests)
endif()
install(FILES README DESTINATION .)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
if(WIN32)
if(TARGET_MSI_NAME)
set(CPACK_PACKAGE_FILE_NAME "${TARGET_MSI_NAME}")
else()
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${DUNE_TARGET_ARCHITECTURE}")
endif()
endif()
include(CPack)
message(STATUS " CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS " CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS " CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS " VCPKG_TARGET_TRIPLET: ${VCPKG_TARGET_TRIPLET}")
if(CMAKE_MSVC_RUNTIME_LIBRARY)
message(STATUS " MSVC Runtime: ${CMAKE_MSVC_RUNTIME_LIBRARY}")
endif()
foreach(config ${build_list})
string(TOUPPER "${config}" config)
message(STATUS " CMAKE_C_FLAGS_${config}: ${CMAKE_C_FLAGS_${config}}")
message(STATUS " CMAKE_CXX_FLAGS_${config}: ${CMAKE_CXX_FLAGS_${config}}")
message(STATUS " CMAKE_EXE_LINKER_FLAGS_${config}: ${CMAKE_EXE_LINKER_FLAGS_${config}}")
endforeach()
get_directory_property(COMPILE_OPTIONS COMPILE_OPTIONS)
get_directory_property(LINK_OPTIONS LINK_OPTIONS)
message(STATUS " COMPILE_OPTIONS: ${COMPILE_OPTIONS}")
message(STATUS " LINK_OPTIONS: ${LINK_OPTIONS}")
message(STATUS " DUNE_TARGET_COMPILE_FLAGS: ${DUNE_TARGET_COMPILE_FLAGS}")