-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
443 lines (420 loc) · 16.1 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
cmake_minimum_required(VERSION 3.27)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Spirit ----------------------------------------------------------------------------------------------------------------------------------
project(Spirit)
add_executable(Spirit
source/Application.hpp
source/Application.cpp
)
target_include_directories(Spirit
PRIVATE source
)
target_link_libraries(Spirit
PUBLIC System
PUBLIC Component
PUBLIC OpenGL
PUBLIC Platform
PUBLIC UI
PUBLIC Utility # Simulation loop runs in the header and uses Logger
)
target_compile_options(Spirit PRIVATE ${WARNING_COMPILE_FLAGS})
# Spirit end ------------------------------------------------------------------------------------------------------------------------------
# ------------------------ Test -----------------------------------------------------------------------------------------------------------
add_executable(Test
source/Test/TestMain.cpp
source/Test/MemoryCorrectnessItem.hpp
source/Test/MemoryCorrectnessItem.cpp
source/Test/TestManager.hpp
source/Test/TestManager.cpp
source/Test/Tests/CameraTester.hpp
source/Test/Tests/CameraTester.cpp
source/Test/Tests/ComponentSerialiseTester.hpp
source/Test/Tests/ComponentSerialiseTester.cpp
source/Test/Tests/ECSTester.hpp
source/Test/Tests/ECSTester.cpp
source/Test/Tests/GraphicsTester.hpp
source/Test/Tests/GraphicsTester.cpp
source/Test/Tests/ResourceManagerTester.hpp
source/Test/Tests/ResourceManagerTester.cpp
source/Test/Tests/GeometryTester.hpp
source/Test/Tests/GeometryTester.cpp
source/Test/Tests/QuadTreeTester.hpp
source/Test/Tests/QuadTreeTester.cpp
)
target_include_directories(Test
PRIVATE source/Test/Tests
PRIVATE source/Test
PRIVATE source
)
target_link_libraries(Test
PUBLIC Utility
PRIVATE ECS
PRIVATE OpenGL
PRIVATE Geometry
PRIVATE GLM
PRIVATE ImGui
)
target_compile_options(Test PRIVATE ${WARNING_COMPILE_FLAGS})
# Test end --------------------------------------------------------------------------------------------------------------------------------
# Set variables after project() so we can use CMAKE_CXX_COMPILER_ID -----------------------------------------------------------------------
set(SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) # TODO remove this and use CMAKE_CURRENT_SOURCE_DIR directly
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(OPENGL_VERSION_MAJOR 4)
set(OPENGL_VERSION_MINOR 6)
set(OPENGL_VERSION_STRING "${OPENGL_VERSION_MAJOR}.${OPENGL_VERSION_MINOR}")
set(GLSL_VERSION_STRING "#version ${OPENGL_VERSION_MAJOR}${OPENGL_VERSION_MINOR}0")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
set(IS_MSVC TRUE)
set(WARNING_COMPILE_FLAGS /W4; /WX; /external:W0;)
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set(IS_GCC TRUE)
set(WARNING_COMPILE_FLAGS -Wall; -Wextra; -Wpedantic; -Wformat; -Wformat-security; -Werror;)
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(IS_CLANG TRUE)
set(WARNING_COMPILE_FLAGS -Wall; -Wextra; -Wpedantic; -Wformat; -Wformat-security; -Werror;)
ELSE() # If we could not determine the compile ID match put warning message up
message(WARNING "Compiler: \"${CMAKE_CXX_COMPILER_ID}\" has not been tested with this project, compilation may fail")
ENDIF()
message (STATUS "Compiling with \"${CMAKE_CXX_COMPILER_ID}\" - Adding compiler flags to non-externals libs: \"${WARNING_COMPILE_FLAGS}\"")
# IF generator is Visual Studio set the startup project to Spirit -------------------------------------------------------------------------
if (CMAKE_GENERATOR MATCHES "Visual Studio")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Spirit) # Makes Spirit the startup project in VS .sln
endif ()
#------------------------------------------------------------------------------------------------------------------------------------------
# ECS -------------------------------------------------------------------------------------------------------------------------------------
add_library(ECS
source/ECS/Entity.hpp
source/ECS/Storage.hpp
source/ECS/Storage.cpp
source/ECS/Component.hpp
source/ECS/Meta.hpp
)
target_include_directories(ECS
PRIVATE source/ECS
PRIVATE source
)
target_link_libraries(ECS
PUBLIC Utility # Uses Logger in Storage.hpp
)
target_compile_options(ECS PRIVATE ${WARNING_COMPILE_FLAGS})
# ECS -------------------------------------------------------------------------------------------------------------------------------------
# Component -------------------------------------------------------------------------------------------------------------------------------
add_library(Component
source/Component/FirstPersonCamera.cpp
source/Component/FirstPersonCamera.hpp
source/Component/Collider.cpp
source/Component/Collider.hpp
source/Component/Input.cpp
source/Component/Input.hpp
source/Component/Label.hpp
source/Component/Label.cpp
source/Component/Mesh.cpp
source/Component/Mesh.hpp
source/Component/ParticleEmitter.hpp
source/Component/ParticleEmitter.cpp
source/Component/RigidBody.cpp
source/Component/RigidBody.hpp
source/Component/Lights.cpp
source/Component/Lights.hpp
source/Component/Terrain.cpp
source/Component/Terrain.hpp
source/Component/Texture.cpp
source/Component/Texture.hpp
source/Component/Transform.cpp
source/Component/Transform.hpp
source/Component/TwoAxisCamera.cpp
source/Component/TwoAxisCamera.hpp
source/Component/ViewInformation.hpp
)
target_include_directories(Component
PRIVATE source/Component
PRIVATE source
)
target_link_libraries(Component
PUBLIC Geometry
PUBLIC OpenGL
PUBLIC Data
PUBLIC GLM
PUBLIC Utility # Used in headers of Mesh, Texture, Input
PRIVATE System
PRIVATE Platform
PRIVATE ImGui
PRIVATE STB
)
target_compile_options(Component PRIVATE ${WARNING_COMPILE_FLAGS})
# Component end ---------------------------------------------------------------------------------------------------------------------------
# System ----------------------------------------------------------------------------------------------------------------------------------
add_library(System
source/System/AssetManager.cpp
source/System/AssetManager.hpp
source/System/CollisionSystem.cpp
source/System/CollisionSystem.hpp
source/System/PhysicsSystem.cpp
source/System/PhysicsSystem.hpp
source/System/InputSystem.hpp
source/System/InputSystem.cpp
source/System/SceneSystem.hpp
source/System/SceneSystem.cpp
)
target_include_directories(System
PRIVATE source/System
PRIVATE source
)
target_link_libraries(System
PUBLIC Component
PUBLIC Geometry
PUBLIC ECS #SceneSystem.hpp uses ECS storage
PUBLIC Utility
PRIVATE Platform
PRIVATE ImGui
)
target_compile_options(System PRIVATE ${WARNING_COMPILE_FLAGS})
# System end ------------------------------------------------------------------------------------------------------------------------------
# Geometry --------------------------------------------------------------------------------------------------------------------------------
add_library(Geometry
source/Geometry/AABB.cpp
source/Geometry/AABB.hpp
source/Geometry/Cylinder.hpp
source/Geometry/Cylinder.cpp
source/Geometry/Cone.hpp
source/Geometry/Cone.cpp
source/Geometry/Constants.hpp
source/Geometry/Cuboid.hpp
source/Geometry/Cuboid.cpp
source/Geometry/Geometry.hpp
source/Geometry/Geometry.cpp
source/Geometry/GJK.hpp
source/Geometry/GJK.cpp
source/Geometry/Frustrum.hpp
source/Geometry/Frustrum.cpp
source/Geometry/Intersect.cpp
source/Geometry/Intersect.hpp
source/Geometry/Line.cpp
source/Geometry/Line.hpp
source/Geometry/LineSegment.cpp
source/Geometry/LineSegment.hpp
source/Geometry/Plane.cpp
source/Geometry/Plane.hpp
source/Geometry/Point.hpp
source/Geometry/Quad.hpp
source/Geometry/Quad.cpp
source/Geometry/QuadTree.hpp
source/Geometry/Ray.hpp
source/Geometry/Sphere.hpp
source/Geometry/Sphere.cpp
source/Geometry/Triangle.hpp
source/Geometry/Triangle.cpp
source/Geometry/TriTri.hpp
source/Geometry/TriTri.cpp
)
target_include_directories(Geometry
PRIVATE source/Geometry
PRIVATE source
)
target_link_libraries(Geometry
PUBLIC GLM
PRIVATE Utility
PRIVATE ImGui
)
target_compile_options(Geometry PRIVATE ${WARNING_COMPILE_FLAGS})
# Geometry end ----------------------------------------------------------------------------------------------------------------------------
# UI --------------------------------------------------------------------------------------------------------------------------------------
add_library(UI
source/UI/Console.hpp
source/UI/Console.cpp
source/UI/Editor.hpp
source/UI/Editor.cpp
source/UI/Visualisers.hpp
source/UI/Visualisers.cpp
)
target_include_directories(UI
PRIVATE source/UI
PRIVATE source
)
target_link_libraries(UI
PUBLIC GLM
PUBLIC ECS
PRIVATE Geometry
PRIVATE System
PRIVATE Platform
PRIVATE OpenGL
PRIVATE Utility
PRIVATE ImGui
)
target_compile_options(UI PRIVATE ${WARNING_COMPILE_FLAGS})
# UI end ----------------------------------------------------------------------------------------------------------------------------------
# Data ----------------------------------------------------------------------------------------------------------------------------------
add_library(Data
source/Data/Image.hpp
source/Data/Image.cpp
source/Data/Vertex.hpp
)
target_include_directories(Data
PRIVATE source/Data
PRIVATE source
)
target_link_libraries(Data
PUBLIC STB
PUBLIC GLM
)
# Platform --------------------------------------------------------------------------------------------------------------------------------
add_library(Platform
source/Platform/Window.hpp
source/Platform/Window.cpp
source/Platform/Core.hpp
source/Platform/Core.cpp
source/Platform/Input.hpp
source/Platform/Input.cpp
)
target_include_directories(Platform
PRIVATE source/Platform
PRIVATE source
)
target_link_libraries(Platform
PUBLIC GLM
PUBLIC Utility # EventDispatcher in Window and Input hpps.
PRIVATE Data # Image in Window.cpp for icon
PRIVATE glfw
PRIVATE glad
PRIVATE ImGui
)
target_compile_options(Platform PRIVATE ${WARNING_COMPILE_FLAGS})
# Platform end ----------------------------------------------------------------------------------------------------------------------------
# OpenGL ----------------------------------------------------------------------------------------------------------------------------------
add_library(OpenGL
source/OpenGL/DrawCall.hpp
source/OpenGL/DrawCall.cpp
source/OpenGL/OpenGLRenderer.hpp
source/OpenGL/OpenGLRenderer.cpp
source/OpenGL/GridRenderer.hpp
source/OpenGL/GridRenderer.cpp
source/OpenGL/DebugRenderer.hpp
source/OpenGL/DebugRenderer.cpp
source/OpenGL/ParticleRenderer.cpp
source/OpenGL/ParticleRenderer.hpp
source/OpenGL/ShadowMapper.hpp
source/OpenGL/ShadowMapper.cpp
source/OpenGL/GLState.hpp
source/OpenGL/GLState.cpp
source/OpenGL/PhongRenderer.hpp
source/OpenGL/PhongRenderer.cpp
source/OpenGL/Types.hpp
source/OpenGL/Types.cpp
source/OpenGL/Shader.hpp
source/OpenGL/Shader.cpp
)
target_include_directories(OpenGL
PRIVATE source/OpenGL
PRIVATE source
)
target_link_libraries(OpenGL
PUBLIC Utility # Uses MeshBuilder, Logger in headers
PUBLIC GLM
PRIVATE Geometry
PRIVATE System
PRIVATE Platform
PRIVATE Component
PRIVATE ECS
PRIVATE ImGui
PRIVATE glad
)
target_compile_options(OpenGL PRIVATE ${WARNING_COMPILE_FLAGS})
# OpenGL end ------------------------------------------------------------------------------------------------------------------------------
# Utility ---------------------------------------------------------------------------------------------------------------------------------
configure_file(source/Utility/Config.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/source/Utility/Config.hpp)
add_library(Utility
source/Utility/EventDispatcher.hpp
source/Utility/ResourceManager.hpp
source/Utility/FunctionTraits.hpp
source/Utility/File.cpp
source/Utility/File.hpp
source/Utility/Logger.hpp
source/Utility/Logger.cpp
source/Utility/MeshBuilder.hpp
source/Utility/PerlinNoise.hpp
source/Utility/Serialise.hpp
source/Utility/Stopwatch.hpp
source/Utility/Utility.cpp
source/Utility/Utility.hpp
)
target_include_directories(Utility
PRIVATE source/Utility
PRIVATE source
)
target_link_libraries(Utility
PUBLIC GLM
PUBLIC Geometry
PUBLIC OpenGL
PRIVATE UI # Logger.cpp uses Editor for output
)
target_compile_options(Utility PRIVATE ${WARNING_COMPILE_FLAGS})
# Utility end -----------------------------------------------------------------------------------------------------------------------------
# EXTERNAL LIBRARIES ***********************************************************************************************************************
# ImGui --------------------------------------------------------------------------------------------------------------------------------
# ImGui has no cMakeLists.txt file so need to generate a library for it
add_library(ImGui
source/External/ImGui/imgui_demo.cpp
source/External/ImGui/imgui_draw.cpp
source/External/ImGui/imgui_tables.cpp
source/External/ImGui/imgui_widgets.cpp
source/External/ImGui/imgui.cpp
source/External/ImGui/backends/imgui_impl_opengl3.cpp
source/External/ImGui/backends/imgui_impl_glfw.cpp
source/External/ImGuizmo/ImGuizmo.h
source/External/ImGuizmo/ImGuizmo.cpp
source/External/ImGuiUser/imgui_user.h
source/External/ImGuiUser/imgui_user_config.h
)
target_include_directories(ImGui SYSTEM
PUBLIC source/External/ImGui
PUBLIC source/External/ImGuizmo
PUBLIC source/External/ImGuiUser # Seperate folder to avoid comitting to ImGui
PRIVATE source/External/GLFW/include
)
target_compile_definitions(ImGui
INTERFACE IMGUI_USER_CONFIG="imgui_user_config.h")
target_link_libraries(ImGui
PUBLIC GLM
PUBLIC Utility # imgui_user_config uses logger
)
# ImGui end ---------------------------------------------------------------------------------------------------------------------------
# GLFW --------------------------------------------------------------------------------------------------------------------------------
# Dont build any examples, tests or documentation
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
add_subdirectory(source/External/GLFW source/External/GLFW SYSTEM)
# GLFW end ----------------------------------------------------------------------------------------------------------------------------
# GLAD --------------------------------------------------------------------------------------------------------------------------------
add_subdirectory(source/External/GLAD)
# GLAD end ----------------------------------------------------------------------------------------------------------------------------
# GLM ---------------------------------------------------------------------------------------------------------------------------------
add_library(GLM INTERFACE)
target_include_directories(GLM SYSTEM
INTERFACE source/External/GLM)
# GLM end -----------------------------------------------------------------------------------------------------------------------------
# STB ---------------------------------------------------------------------------------------------------------------------------------
add_library(STB INTERFACE)
target_include_directories(STB SYSTEM
INTERFACE source/External/stb)
# STB end -----------------------------------------------------------------------------------------------------------------------------
# ASSIMP ------------------------------------------------------------------------------------------------------------------------------
set(ASSIMP_BUILD_ZLIB ON CACHE BOOL "" FORCE)
if (WIN32)
# Remove all supported filetypes for import and export.
# Enable only OBJ files for import.
set(ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT OFF CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT OFF CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_OBJ_IMPORTER ON CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
else()
set(ASSIMP_WARNINGS_AS_ERRORS OFF CACHE BOOL "" FORCE)
endif (WIN32)
add_subdirectory(source/External/ASSIMP source/External/ASSIMP SYSTEM)
# ASSIMP end --------------------------------------------------------------------------------------------------------------------------
# EXTERNAL LIBRARIES ***********************************************************************************************************************