-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
494 lines (402 loc) · 13.3 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
cmake_minimum_required(VERSION 3.10)
project(Atmos)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# If the build type hasn't been specified, defaulting it to Release
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif ()
######################
# Atmos - Executable #
######################
add_executable(Atmos)
# Using C++17
target_compile_features(Atmos PRIVATE cxx_std_17)
############################
# Atmos - Useful variables #
############################
# Detect whether Emscripten is being used
if (CMAKE_CXX_COMPILER MATCHES "/em\\+\\+.*$")
set(ATMOS_USE_EMSCRIPTEN ON)
else ()
set(ATMOS_USE_EMSCRIPTEN OFF)
endif ()
if (MSVC AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Finding exclusively MSVC, not clang-cl
set(ATMOS_COMPILER_MSVC ON)
target_compile_definitions(Atmos PUBLIC ATMOS_COMPILER_MSVC)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (MSVC)
# Using clang-cl, for which both MSVC & Clang are found
set(ATMOS_COMPILER_CLANG_CL ON)
endif ()
set(ATMOS_COMPILER_CLANG ON)
target_compile_definitions(Atmos PUBLIC ATMOS_COMPILER_CLANG)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(ATMOS_COMPILER_GCC ON)
target_compile_definitions(Atmos PUBLIC ATMOS_COMPILER_GCC)
endif ()
if (WIN32 OR CYGWIN)
set(ATMOS_PLATFORM_WINDOWS ON)
target_compile_definitions(Atmos PUBLIC ATMOS_PLATFORM_WINDOWS)
if (CYGWIN)
set(ATMOS_PLATFORM_CYGWIN ON)
target_compile_definitions(Atmos PUBLIC ATMOS_PLATFORM_CYGWIN)
endif ()
elseif (APPLE)
set(ATMOS_PLATFORM_MAC ON)
target_compile_definitions(Atmos PUBLIC ATMOS_PLATFORM_MAC)
elseif (ATMOS_USE_EMSCRIPTEN)
set(ATMOS_PLATFORM_EMSCRIPTEN ON)
target_compile_definitions(Atmos PUBLIC ATMOS_PLATFORM_EMSCRIPTEN USE_OPENGL_ES)
elseif (UNIX)
set(ATMOS_PLATFORM_LINUX ON)
target_compile_definitions(Atmos PUBLIC ATMOS_PLATFORM_LINUX)
endif ()
if (ATMOS_COMPILER_MSVC)
set(ATMOS_CONFIG_DEBUG "$<IF:$<CONFIG:Debug>,ON,OFF>")
set(ATMOS_CONFIG_RELEASE "$<IF:$<CONFIG:Debug>,OFF,ON>")
target_compile_definitions(Atmos PUBLIC $<IF:$<CONFIG:Debug>,ATMOS_CONFIG_DEBUG,ATMOS_CONFIG_RELEASE>)
else ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ATMOS_CONFIG_DEBUG ON)
set(ATMOS_CONFIG_RELEASE OFF)
target_compile_definitions(Atmos PUBLIC ATMOS_CONFIG_DEBUG)
else ()
set(ATMOS_CONFIG_DEBUG OFF)
set(ATMOS_CONFIG_RELEASE ON)
target_compile_definitions(Atmos PUBLIC ATMOS_CONFIG_RELEASE)
endif ()
endif ()
if (ATMOS_USE_EMSCRIPTEN)
target_compile_definitions(Atmos PUBLIC ATMOS_ROOT="/")
else ()
target_compile_definitions(Atmos PUBLIC ATMOS_ROOT="${CMAKE_CURRENT_SOURCE_DIR}/")
endif ()
##########################
# Atmos - Compiler flags #
##########################
if (ATMOS_COMPILER_GCC)
set(
ATMOS_COMPILER_FLAGS
-pedantic
-pedantic-errors
-Wall
-Wextra
-Warray-bounds
-Wcast-align
-Wcast-qual
-Wconditionally-supported
-Wconversion
-Wdisabled-optimization
-Wdouble-promotion
-Wfloat-conversion
-Wformat=2
-Wformat-security
-Wlogical-op
-Wmissing-declarations
-Wmissing-include-dirs
-Wnoexcept
-Wnon-virtual-dtor
-Wold-style-cast
-Wopenmp-simd
-Woverloaded-virtual
-Wpacked
-Wredundant-decls
-Wstrict-aliasing
-Wstrict-null-sentinel
#-Wsuggest-final-methods
#-Wsuggest-final-types
-Wtrampolines
-Wundef
-Wuninitialized
-Wunused-macros
-Wuseless-cast
-Wvector-operation-performance
-Wvla
-Wzero-as-null-pointer-constant
-Wno-comment
-Wno-format-nonliteral
)
# Enabling some other warnings available since GCC 5
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5)
set(
ATMOS_COMPILER_FLAGS
${ATMOS_COMPILER_FLAGS}
-fsized-deallocation
-Warray-bounds=2
-Wformat-signedness
-Wsized-deallocation
)
endif ()
# Enabling some other warnings available since GCC 6
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6)
set(
ATMOS_COMPILER_FLAGS
${ATMOS_COMPILER_FLAGS}
-Wduplicated-cond
-Wnull-dereference
)
endif ()
# Enabling some other warnings available since GCC 7
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7)
set(
ATMOS_COMPILER_FLAGS
${ATMOS_COMPILER_FLAGS}
-Waligned-new
-Walloca
-Walloc-zero
-Wformat-overflow
-Wshadow
)
endif ()
# Enabling code coverage
option(ATMOS_ENABLE_COVERAGE "Enable code coverage (GCC only)" OFF)
if (ATMOS_CONFIG_DEBUG AND ATMOS_ENABLE_COVERAGE)
set(
ATMOS_COMPILER_FLAGS
${ATMOS_COMPILER_FLAGS}
-g
-O0
-fno-inline
-fno-inline-small-functions
-fno-default-inline
-fprofile-arcs
-ftest-coverage
)
set(
ATMOS_LINKER_FLAGS
gcov
)
endif ()
elseif (ATMOS_COMPILER_CLANG)
set(
ATMOS_COMPILER_FLAGS
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-covered-switch-default
-Wno-documentation
-Wno-documentation-unknown-command
-Wno-exit-time-destructors
-Wno-float-equal
-Wno-format-nonliteral
-Wno-global-constructors
-Wno-mismatched-tags
-Wno-missing-braces
-Wno-padded
-Wno-reserved-id-macro
-Wno-sign-conversion
-Wno-switch-enum
-Wno-weak-vtables
)
if (ATMOS_COMPILER_CLANG_CL)
set(
ATMOS_COMPILER_FLAGS
${ATMOS_COMPILER_FLAGS}
# Disabling warnings triggered in externals
-Wno-language-extension-token
-Wno-nonportable-system-include-path
-Wno-zero-as-null-pointer-constant
)
else ()
set(
ATMOS_COMPILER_FLAGS
${ATMOS_COMPILER_FLAGS}
# Other warning flags not recognized by clang-cl
-pedantic
-pedantic-errors
)
endif ()
# Disabling some warnings available since Clang 5
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5)
set(
ATMOS_COMPILER_FLAGS
${ATMOS_COMPILER_FLAGS}
-Wno-unused-template
)
endif ()
elseif (ATMOS_COMPILER_MSVC)
set(
ATMOS_COMPILER_FLAGS
/Wall
/MP # Enabling multi-processes compilation
/wd4061 # Enum value in a switch not explicitly handled by a case label
/wd4571 # SEH exceptions aren't caught since Visual C++ 7.1
/wd5045 # Spectre mitigation
# Warnings triggered by MSVC's standard library
/wd4355 # 'this' used in base member initializing list
/wd4514 # Unreferenced inline function has been removed
/wd4548 # Expression before comma has no effect
/wd4668 # Preprocessor macro not defined
/wd4710 # Function not inlined
/wd4711 # Function inlined
/wd4774 # Format string is not a string literal
/wd4820 # Added padding to members
/wd5026 # Move constructor implicitly deleted
/wd5027 # Move assignment operator implicitly deleted
/wd5039 # Pointer/ref to a potentially throwing function passed to an 'extern "C"' function (with -EHc)
)
# To automatically export all the classes & functions
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
# CMake automatically appends /W3 to the standard flags, which produces a warning with MSVC when adding another level; this has to be removed
# TODO: if possible, this should be done per target, not globally
string(REGEX REPLACE "/W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif ()
if (ATMOS_COMPILER_MSVC OR ATMOS_COMPILER_CLANG_CL)
set(
ATMOS_COMPILER_FLAGS
${ATMOS_COMPILER_FLAGS}
/permissive- # Improving standard compliance
/EHsc # Enabling exceptions
/utf-8 # Forcing MSVC to actually handle files as UTF-8
)
target_compile_definitions(
Atmos
PRIVATE
NOMINMAX # Preventing definitions of min & max macros
_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING # Ignoring std::codecvt deprecation warnings
)
endif ()
if (ATMOS_USE_EMSCRIPTEN)
target_compile_options(Atmos PRIVATE "SHELL:-s USE_LIBPNG=1")
target_link_options(
Atmos
PUBLIC
"SHELL:-s USE_GLFW=3"
"SHELL:-s USE_LIBPNG=1"
)
target_link_libraries(Atmos PRIVATE glfw)
endif ()
########################
# Atmos - Source files #
########################
set(
ATMOS_SRC
main.cpp
src/Atmos/*.cpp
include/Atmos/*.hpp
include/Atmos/*.inl
)
# Adding every file to be compiled
file(
GLOB
ATMOS_FILES
${ATMOS_SRC}
)
#####################
# Atmos - RaZ usage #
#####################
# Finding RaZ
option(ATMOS_BUILD_RAZ "Build RaZ alongside Atmos (requires downloading the submodule)" OFF)
if (NOT ATMOS_BUILD_RAZ)
set(RAZ_ROOT "C:/RaZ" CACHE PATH "Path to the RaZ installation")
set(RAZ_LIB_DIR "${RAZ_ROOT}/lib")
# Visual Studio having all the configurations from within the project, CMAKE_BUILD_TYPE is unknown at generation time
# Adding a link directory automatically creates anoter path to which is appended the $(Configuration) macro, which contains the build type
if (NOT ATMOS_COMPILER_MSVC)
set(RAZ_LIB_DIR "${RAZ_LIB_DIR}/${CMAKE_BUILD_TYPE}")
endif ()
target_link_directories(Atmos PRIVATE "${RAZ_LIB_DIR}")
target_include_directories(Atmos PUBLIC "${RAZ_ROOT}/include")
target_compile_definitions(Atmos PRIVATE RAZ_USE_WINDOW) # Raz::Window is needed
# Additional linking flags
if (ATMOS_PLATFORM_WINDOWS)
set(
ATMOS_LINKER_FLAGS
${ATMOS_LINKER_FLAGS}
opengl32
)
elseif (ATMOS_PLATFORM_LINUX)
set(
ATMOS_LINKER_FLAGS
${ATMOS_LINKER_FLAGS}
dl
pthread
GL
X11
Xrandr
Xcursor
Xinerama
Xxf86vm
)
elseif (ATMOS_PLATFORM_MAC)
find_package(OpenGL REQUIRED)
set(
ATMOS_LINKER_FLAGS
${ATMOS_LINKER_FLAGS}
OpenGL::GL
"-framework OpenGL"
"-framework Cocoa"
"-framework IOKit"
"-framework CoreVideo"
)
endif ()
else ()
set(RAZ_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/extern/RaZ")
if (EXISTS "${RAZ_ROOT}")
# No need to keep the examples, unit tests & documentation generation
set(RAZ_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(RAZ_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(RAZ_GEN_DOC OFF CACHE BOOL "" FORCE)
add_subdirectory("${RAZ_ROOT}")
# Use RaZ's compiler flags' script
include("${RAZ_ROOT}/cmake/CompilerFlags.cmake")
add_compiler_flags(Atmos PRIVATE)
else ()
message(FATAL_ERROR "Failed to find RaZ; the submodule must be downloaded")
endif ()
endif ()
if (ATMOS_USE_EMSCRIPTEN)
target_compile_definitions(Atmos PRIVATE RAZ_ROOT="/")
else ()
target_compile_definitions(Atmos PRIVATE RAZ_ROOT="${RAZ_ROOT}/")
endif ()
target_link_libraries(Atmos PUBLIC RaZ)
#################
# Atmos - Build #
#################
if (ATMOS_USE_EMSCRIPTEN)
set_target_properties(Atmos PROPERTIES SUFFIX ".html")
target_link_options(
Atmos
PRIVATE
"SHELL:--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/shaders@shaders"
"SHELL:--preload-file ${RAZ_ROOT}/shaders@shaders"
)
set(
ATMOS_ASSETS
assets/textures/earth.png
assets/textures/earth_normal.png
assets/skyboxes/space_right.png
assets/skyboxes/space_left.png
assets/skyboxes/space_up.png
assets/skyboxes/space_down.png
assets/skyboxes/space_back.png
assets/skyboxes/space_front.png
)
foreach (ASSET_PATH ${ATMOS_ASSETS})
target_link_options(Atmos PRIVATE "SHELL:--preload-file ${CMAKE_SOURCE_DIR}/${ASSET_PATH}@${ASSET_PATH}")
endforeach ()
endif ()
target_include_directories(Atmos PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
if (NOT ATMOS_COMPILER_MSVC)
# Defining the compiler flags only for C++; this doesn't work with MSVC
set(ATMOS_COMPILER_FLAGS $<$<COMPILE_LANGUAGE:CXX>:${ATMOS_COMPILER_FLAGS}>)
endif ()
target_compile_options(Atmos PRIVATE ${ATMOS_COMPILER_FLAGS})
target_link_libraries(Atmos PRIVATE ${ATMOS_LINKER_FLAGS})
# Cygwin's Clang needs to use GCC's standard library
if (CYGWIN AND ATMOS_COMPILER_CLANG)
target_compile_options(Atmos PRIVATE -stdlib=libstdc++)
target_link_libraries(Atmos PRIVATE stdc++)
endif ()
# Compiling Atmos' sources
target_sources(Atmos PRIVATE ${ATMOS_FILES})
########################
# Atmos - Installation #
########################
# Installing the executable
if (ATMOS_PLATFORM_WINDOWS)
set(CMAKE_INSTALL_PREFIX "C:/Atmos")
endif ()
install(TARGETS Atmos DESTINATION "${CMAKE_INSTALL_PREFIX}")