-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
523 lines (389 loc) · 15.2 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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
cmake_minimum_required(VERSION 3.9.0)
Project(Asciir VERSION 0.3.5)
set(CMAKE_CXX_STANDARD 17)
include(CheckIPOSupported)
include("${CMAKE_CURRENT_SOURCE_DIR}/scripts/ConanInstall.cmake")
# place all predefined target projects into a filter
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(PREDEFINED_TARGETS_FOLDER "CustomTargets")
check_ipo_supported(RESULT ipo_supported OUTPUT error)
if(${MSVC})
set(CMAKE_CONFIGURATION_TYPES "Debug;InlineDebug;Release;MinSizeRel;RelWithDebInfo;DeployRel" CACHE STRING "" FORCE)
if(NOT CMAKE_CXX_FLAGS_INLINEDEBUG)
set(CMAKE_CXX_FLAGS_INLINEDEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Ob2" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_EXE_FLAGS_INLINEDEBUG)
set(CMAKE_EXE_FLAGS_INLINEDEBUG "${CMAKE_EXE_FLAGS_DEBUG}" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_LINKER_FLAGS_INLINEDEBUG)
set(CMAKE_LINKER_FLAGS_INLINEDEBUG "${CMAKE_LINKER_FLAGS_DEBUG}" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_SHARED_LINKER_FLAGS_INLINEDEBUG)
set(CMAKE_SHARED_LINKER_FLAGS_INLINEDEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_EXE_LINKER_FLAGS_INLINEDEBUG)
set(CMAKE_EXE_LINKER_FLAGS_INLINEDEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_CXX_FLAGS_DEPLOYREL)
set(CMAKE_CXX_FLAGS_DEPLOYREL "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_EXE_FLAGS_DEPLOYREL)
set(CMAKE_EXE_FLAGS_DEPLOYREL "${CMAKE_EXE_FLAGS_RELEASE}" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_LINKER_FLAGS_DEPLOYREL)
set(CMAKE_LINKER_FLAGS_DEPLOYREL "${CMAKE_LINKER_FLAGS_RELEASE}" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_SHARED_LINKER_FLAGS_DEPLOYREL)
set(CMAKE_SHARED_LINKER_FLAGS_DEPLOYREL "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" CACHE STRING "" FORCE)
endif()
if(NOT CMAKE_EXE_LINKER_FLAGS_DEPLOYREL)
set(CMAKE_EXE_LINKER_FLAGS_DEPLOYREL "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "" FORCE)
endif()
endif()
# the /ZI option is incompatible with whole program optimization, and as this is not modifyable directly by cmake,
# as well as it being on by default, whole program optimization will need to be enabled manually,
# whilst overriding the /ZI option with /Zi.
#
# this does create a bunch of warnings because of overriding the /ZI option.
if(ipo_supported AND ${MSVC})
add_compile_options("$<$<CONFIG:DEPLOYREL,RELEASE,RELWITHDEBINFO>:/Zi /GL>")
endif()
# options
option(ASCIIR_LOG_VIEWER "builds an executable to view log files" ON)
option(ASCIIR_EXAMPLES "build example projects" OFF)
option(ASCIIR_HIGH_PRECISSION_FLOAT "uses double instead of float as floating point data type (uses more memory)" OFF)
option(ASCIIR_AUTO_INSTALL_DEPS "Automaticly installs the required packages using conan (requires conan)" OFF)
option(ASCIIR_PARALLEL_BUILD "Builds the Asciir project using multiple threads" ON)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH "x64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH "x86")
else()
message(STATUS "unknown architecture")
endif()
define_property(
TARGET
PROPERTY FOLDER
INHERITED
BRIEF_DOCS "Set the folder name."
FULL_DOCS "Use to organize targets in an IDE."
)
# organize folders and files into general variables
set(EXAMPLES
AsciirBanner
BasicInputExample
MouseInputExample
TriangleExample
TextureExample
SuperAsciirBros
)
set(INCLUDE_DIRS
src/pch
src
)
set(SRC_DIR_CORE
src/Asciir/Core/Application.cpp
src/Asciir/Core/Layer.cpp
src/Asciir/Core/EntryPoint.cpp
src/Asciir/Core/LayerStack.cpp
src/Asciir/Core/Terminal.cpp
src/Asciir/Core/Timing.cpp
src/Asciir/Core/AsciirLiterals.cpp
)
set(HEADER_DIR_CORE
src/Asciir/Core/Core.h
src/Asciir/Core/Application.h
src/Asciir/Core/EntryPoint.h
src/Asciir/Core/Layer.h
src/Asciir/Core/LayerStack.h
src/Asciir/Core/MacroArguments.h
src/Asciir/Core/Terminal.h
src/Asciir/Core/Timing.h
src/Asciir/Core/AsciirLiterals.h
)
set(HEADER_DIR_ENTITIES
src/Asciir/Entities/ECS.h
src/Asciir/Entities/Systems.h
src/Asciir/Entities/Components.h
)
set(SRC_DIR_ENTITIES
src/Asciir/Entities/ECS.cpp
src/Asciir/Entities/ECS.ipp
src/Asciir/Entities/Systems.cpp
src/Asciir/Entities/Components.cpp
)
set(DIR_EVENT
src/Asciir/Event/Event.h
src/Asciir/Event/KeyEvent.h
src/Asciir/Event/MouseEvent.h
src/Asciir/Event/TerminalEvent.h
)
set(SRC_DIR_INPUT
src/Asciir/Input/Input.cpp
)
set(HEADER_DIR_INPUT
src/Asciir/Input/Input.h
src/Asciir/Input/KeyCodes.h
src/Asciir/Input/EventListener.h
)
set(SRC_DIR_AUDIO
src/Asciir/Audio/Audio.cpp
)
set(HEADER_DIR_AUDIO
src/Asciir/Audio/Audio.h
)
set(SRC_DIR_LOGGING
src/Asciir/Logging/FileLog.cpp
src/Asciir/Logging/FileLog.ipp
src/Asciir/Logging/ErrLog.ipp
src/Asciir/Logging/Log.cpp
)
set(HEADER_DIR_LOGGING
src/Asciir/Logging/FileLog.h
src/Asciir/Logging/Log.h
)
set(SRC_DIR_MATHS
src/Asciir/Maths/Maths.cpp
src/Asciir/Maths/Lines.cpp
src/Asciir/Maths/Lines.ipp
src/Asciir/Maths/Vertices.ipp
src/Asciir/Maths/Vector.ipp
src/Asciir/Maths/Matrix.ipp
src/Asciir/Maths/Tensor.ipp
)
set(HEADER_DIR_MATHS
src/Asciir/Maths/Maths.h
src/Asciir/Maths/Lines.h
src/Asciir/Maths/Vertices.h
src/Asciir/Maths/Vector.h
src/Asciir/Maths/Matrix.h
src/Asciir/Maths/Tensor.h
)
set(SRC_DIR_RENDERING
src/Asciir/Rendering/AsciiAttributes.cpp
src/Asciir/Rendering/Mesh.cpp
src/Asciir/Rendering/Primitives.cpp
src/Asciir/Rendering/TerminalRenderer.cpp
src/Asciir/Rendering/Renderer.cpp
src/Asciir/Rendering/Renderer.ipp
src/Asciir/Rendering/Shader.cpp
src/Asciir/Rendering/Texture.cpp
src/Asciir/Rendering/Texture.ipp
)
set(HEADER_DIR_RENDERING
src/Asciir/Rendering/AsciiAttributes.h
src/Asciir/Rendering/Mesh.h
src/Asciir/Rendering/Primitives.h
src/Asciir/Rendering/TerminalRenderer.h
src/Asciir/Rendering/Renderer.h
src/Asciir/Rendering/RenderConsts.h
src/Asciir/Rendering/Shader.h
src/Asciir/Rendering/Texture.h
)
set(SRC_DIR_TOOLS
src/Asciir/Tools/ProfileLayer.cpp
)
set(HEADER_DIR_TOOLS
src/Asciir/Tools/ProfileLayer.h
)
# platform specific files
if(WIN32)
set(SRC_DIR_PLATFORM
# core
src/Asciir/Platform/Windows/WinInit.cpp
# rendering
src/Asciir/Platform/Windows/WindowsARAttributes.cpp
src/Asciir/Platform/Windows/WinTermRenderer.cpp
# input
src/Asciir/Platform/Windows/WinEventListener.cpp
)
set(HEADER_DIR_PLATFORM
# core
src/Asciir/Platform/Windows/KeyCodeMap.h
src/Asciir/Platform/Windows/WinInit.h
#rendering
src/Asciir/Platform/Windows/WindowsARAttributes.h
src/Asciir/Platform/Windows/WinTermRenderer.h
# input
src/Asciir/Platform/Windows/WinEventListener.h
)
elseif(UNIX)
set(SRC_DIR_PLATFORM
# rendering
src/Asciir/Platform/Unix/UnixARAttributes.cpp
)
set(HEADER_DIR_PLATFORM
# core
src/Asciir/Platform/Unix/KeyCodeMap.h
#rendering
src/Asciir/Platform/Unix/UnixARAttributes.h
)
else()
message(SEND_ERROR "Platform not supported")
endif()
# add the main Asciir library
add_library(${PROJECT_NAME} STATIC
src/Asciir.h
src/pch/arpch.h
src/pch/arpch.cpp
src/Asciir/Platform/PlatformMacros.h
${HEADER_DIR_CORE}
${SRC_DIR_CORE}
${HEADER_DIR_ENTITIES}
${SRC_DIR_ENTITIES}
${DIR_EVENT}
${HEADER_DIR_INPUT}
${SRC_DIR_INPUT}
${HEADER_DIR_AUDIO}
${SRC_DIR_AUDIO}
${HEADER_DIR_LOGGING}
${SRC_DIR_LOGGING}
${HEADER_DIR_MATHS}
${SRC_DIR_MATHS}
${HEADER_DIR_RENDERING}
${SRC_DIR_RENDERING}
${SRC_DIR_PLATFORM}
${HEADER_DIR_PLATFORM}
${SRC_DIR_TOOLS}
${HEADER_DIR_TOOLS}
)
# setup alias library
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
if(ipo_supported AND NOT ${MSVC})
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION_DEPLOYREL TRUE)
endif()
# compile options
if(MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES test "$<$<CONFIG:INLINEDEB>:DEBUG> $<$<CONFIG:DEPLOYREL>:RELEASE>")
# set conformance mode ot permissive (sfml requires this)
target_compile_options(${PROJECT_NAME} PUBLIC /permissive)
# set warning level
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /external:anglebrackets /external:W0 $<$<CONFIG:DEPLOYREL>:/WX> /permissive)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
# parallel build setup
if(${ASCIIR_PARALLEL_BUILD} AND MSVC)
# the CMAKE_BUILD_PARALLEL_LEVEL does not do anything for MSVC, so enable it manually here
add_compile_options(/MP)
target_compile_options(${PROJECT_NAME} PRIVATE /MP)
elseif(${ASCIIR_PARALLEL_BUILD})
include(ProcessorCount)
ProcessorCount(p_count)
message(${p_count})
set(CMAKE_BUILD_PARALLEL_LEVEL ${p_count})
endif()
# organize the source files in the generated project
source_group("core/header" FILES ${HEADER_DIR_CORE})
source_group("core/src" FILES ${SRC_DIR_CORE})
source_group("entities/header" FILES ${HEADER_DIR_ENTITIES})
source_group("entities/src" FILES ${SRC_DIR_ENTITIES})
source_group("event" FILES ${DIR_EVENT})
source_group("input/header" FILES ${HEADER_DIR_INPUT})
source_group("input/src" FILES ${SRC_DIR_INPUT})
source_group("audio/header" FILES ${HEADER_DIR_AUDIO})
source_group("audio/src" FILES ${SRC_DIR_AUDIO})
source_group("logging/header" FILES ${HEADER_DIR_LOGGING})
source_group("logging/src" FILES ${SRC_DIR_LOGGING})
source_group("maths/header" FILES ${HEADER_DIR_MATHS})
source_group("maths/src" FILES ${SRC_DIR_MATHS})
source_group("rendering/header" FILES ${HEADER_DIR_RENDERING})
source_group("rendering/src" FILES ${SRC_DIR_RENDERING})
source_group("tools/header" FILES ${HEADER_DIR_TOOLS})
source_group("tools/src" FILES ${SRC_DIR_TOOLS})
source_group("platform/" FILES src/Asciir/Platform/PlatformMacros.h)
if(WIN32)
source_group("platform/windows/header" FILES ${HEADER_DIR_PLATFORM})
source_group("platform/windows/src" FILES ${SRC_DIR_PLATFORM})
endif()
target_include_directories(${PROJECT_NAME} PUBLIC ${INCLUDE_DIRS})
target_precompile_headers(${PROJECT_NAME} PRIVATE "src/pch/arpch.h")
# set compile definitions depending on configuration
target_compile_definitions(${PROJECT_NAME} PUBLIC
$<$<CONFIG:DEBUG,INLINEDEBUG>:AR_DEBUG>
$<$<CONFIG:RELEASE>:AR_SAFE_RELEASE AR_CORE_VERBOSITY=2 AR_CLIENT_VERBOSITY=4>
$<$<CONFIG:RELEASE,DEBUG,INLINEDEBUG>:AR_CORE_LOG_DIR="../../logs/core_log.log" AR_CLIENT_LOG_DIR="../../logs/client_log.log">
$<$<CONFIG:DEPLOYREL>:AR_CORE_LOG_DIR="./logs/core_log.log" AR_CLIENT_LOG_DIR="./logs/client_log.log">
$<$<BOOL:${ASCIIR_HIGH_PRECISSION_FLOAT}>:AR_HIGH_PRECISSION_FLOAT>)
# packages
# install trhough conan
if(${ASCIIR_AUTO_INSTALL_DEPS})
ConanInstall("${CMAKE_CURRENT_BINARY_DIR}/conan")
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}/conan")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/conan")
if(${UNIX})
find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${X11_LIBRARIES})
find_package(Threads REQUIRED)
include_directories(${THREADS_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads)
endif()
set_target_properties(${PROJECT_NAME}
PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}
ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/bin/Debug-${ARCH}
ARCHIVE_OUTPUT_DIRECTORY_INLINEDEBUG ${CMAKE_CURRENT_BINARY_DIR}/bin/InlineDebug-${ARCH}
ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/bin/Release-${ARCH}
ARCHIVE_OUTPUT_DIRECTORY_DEPLOYREL ${CMAKE_CURRENT_BINARY_DIR}/bin/DeployRelease-${ARCH}
)
# Eigen 3
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/modules/eigen)
# SFML
set(BUILD_SHARED_LIBS FALSE CACHE BOOL "ASCIIR specific default value" FORCE)
set(SFML_BUILD_GRAPHICS FALSE CACHE BOOL "ASCIIR specific default value" FORCE)
set(SFML_BUILD_WINDOW FALSE CACHE BOOL "ASCIIR specific default value" FORCE)
set(SFML_BUILD_NETWORK FALSE CACHE BOOL "ASCIIR specific default value" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules/SFML SFML)
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/modules/SFML/include)
set_property(TARGET sfml-audio PROPERTY FOLDER "modules/SFML")
set_property(TARGET sfml-main PROPERTY FOLDER "modules/SFML")
set_property(TARGET sfml-system PROPERTY FOLDER "modules/SFML")
target_link_libraries(${PROJECT_NAME} SFML::Audio)
# CImg
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/modules/CImg")
# enable png and jpeg support
target_compile_definitions(${PROJECT_NAME} PUBLIC cimg_use_png cimg_use_jpeg cimg_verbosity=0)
# libpng, zlib and libjpeg
find_package(JPEG REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${JPEG_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${JPEG_LIBRARIES})
message(STATUS ${JPEG_LIBRARIES})
find_package(PNG REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${PNG_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES})
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/modules/zlib" "${CMAKE_CURRENT_BINARY_DIR}/zlib")
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/modules/zlib" "${CMAKE_CURRENT_BINARY_DIR}/zlib")
target_link_libraries(${PROJECT_NAME} zlibstatic)
# Entt
find_package(EnTT REQUIRED)
target_link_libraries(${PROJECT_NAME} EnTT::EnTT)
# FastNoise2
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/modules/FastNoise2")
set(FASTNOISE2_NOISETOOL OFF CACHE BOOL INTERNAL "")
target_link_libraries(${PROJECT_NAME} FastNoise)
# EThread
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules/EThread EThread)
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/modules/ETHread/include)
set_property(TARGET EThread PROPERTY FOLDER "modules/EThread")
target_link_libraries(${PROJECT_NAME} EThread)
# ChrTrcProfiler
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules/ChrTrcProfiler ChrTrcProfiler)
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/modules/ChrTrcProfiler/include)
set_property(TARGET ChrTrcProfiler PROPERTY FOLDER "modules/ChrTrcProfiler")
target_link_libraries(${PROJECT_NAME} ChrTrcProfiler)
if(ASCIIR_LOG_VIEWER)
add_subdirectory(${PROJECT_SOURCE_DIR}/ARLogViewer ARLogViewer)
endif()
# add all the examples programmatically
if(ASCIIR_EXAMPLES)
foreach(EXAMPLE IN ITEMS ${EXAMPLES})
add_subdirectory(${PROJECT_SOURCE_DIR}/Examples/${EXAMPLE} ${EXAMPLE})
endforeach()
set_target_properties(${EXAMPLES} PROPERTIES
FOLDER "Examples"
)
endif()