-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
297 lines (251 loc) · 8.37 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
# Copyright (C) 2022-2023 George Cave.
#
# SPDX-License-Identifier: Apache-2.0
# Modify CMake modules path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
cmake_minimum_required(VERSION 3.15)
include(afl-fuzzing)
project(FoE-Engine C CXX)
# Global Options
include(CMakeDependentOption)
option(BUILD_SHADERS "Build GLSL shaders to SPIR-V automatically" ON)
option(BUILD_TESTS "Build test programs" OFF)
option(BUILD_VULKAN_RUNTIME_TESTS
"Build tests that require an available Vulkan runtime" OFF)
# There are cases where it is easier to debug issues if dynamic plugin library
# content is still loaded into the application when it terminates, such as for
# tools that do post-analysis such as sanitizers.
option(DISABLE_PLUGIN_UNLOAD "Prevent plugins from unloading" OFF)
option(EDITOR_MODE "Build with the editor UI capability" OFF)
cmake_dependent_option(
IMGUI_DEMO "Build with the ImGui demo in the bringup app" OFF EDITOR_MODE OFF)
# WSI Loader/Implementation Settings
option(
WSI_LOADER
"Compile/link the WSI loader library (implementations are shared objects)" ON)
set(WSI_LIBRARY
"glfw3"
CACHE
STRING
"WSI library linked/loaded by default (passed via compile definitions)")
# XR Settings
if(APPLE)
option(XR_SUPPORT "Compile/link XR device support" OFF)
else()
option(XR_SUPPORT "Compile/link XR device support" ON)
endif()
# C11 standard, no extensions
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# C++20 standard, no extensions
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Code Coverage
include(code-coverage)
add_code_coverage_all_targets(EXCLUDE /usr/.* .*/test/.*
${CMAKE_CURRENT_SOURCE_DIR}/external/.*)
# Formatting
include(formatting)
file(
GLOB_RECURSE
CL_FILES
*.[hc]
*.[hc]pp
*.vert
*.tese
*.tesc
*.geom
*.frag
*.comp)
list(FILTER CL_FILES EXCLUDE REGEX ${CMAKE_CURRENT_SOURCE_DIR}/build)
list(FILTER CL_FILES EXCLUDE REGEX ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
list(FILTER CL_FILES EXCLUDE REGEX ${CMAKE_CURRENT_SOURCE_DIR}/external)
clang_format(format ${CL_FILES})
file(GLOB_RECURSE CM_FILES CMakeLists.txt *.cmake)
list(FILTER CM_FILES EXCLUDE REGEX ${CMAKE_CURRENT_SOURCE_DIR}/build)
list(FILTER CM_FILES EXCLUDE REGEX ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
list(FILTER CM_FILES EXCLUDE REGEX ${CMAKE_CURRENT_SOURCE_DIR}/external)
cmake_format(cmake-format ${CM_FILES})
# Dependency Graph
include(dependency-graph)
gen_dep_graph(png ADD_TO_DEP_GRAPH)
# clang-tidy
include(tools)
option(CLANG_TIDY "Run clang-tidy static analysis" OFF)
cmake_dependent_option(
CLANG_TIDY_FIX "Turns on fixes for found clang-tidy issues" OFF CLANG_TIDY
OFF)
option(CLANG_TIDY_FIX "" OFF)
if(CLANG_TIDY_FIX)
clang_tidy(-header-filter='${CMAKE_SOURCE_DIR}/*' -fix)
elseif(CLANG_TIDY)
clang_tidy(-header-filter='${CMAKE_SOURCE_DIR}/*')
endif()
# Header Exports
include(GenerateExportHeader)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
# Misc CMake
include(compiler-options)
include(glsl-shaders)
include(sanitizers)
if(WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
if(BUILD_TESTS)
enable_testing()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# GLFW/Vulkan
add_compile_definitions(GLFW_INCLUDE_VULKAN)
# Libraries
add_subdirectory(external)
add_subdirectory(libs)
# Engine Entrypoint
add_executable(foe_bringup)
target_link_libraries(foe_bringup PRIVATE foe_bringup_lib)
target_code_coverage(
foe_bringup
OBJECTS
foe_bringup_lib
EXCLUDE
${CMAKE_SOURCE_DIR}/external/.*
ARGS
--config
${CMAKE_CURRENT_SOURCE_DIR}/foe-settings.yml)
# Engine Library
set(CMAKE_C_VISIBILITY_PRESET default)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Delcarations
add_library(foe_bringup_lib)
add_library(foe_bringup_imgui)
add_library(foe_bringup_lib_eh)
add_library(foe_bringup_shared SHARED)
add_library(foe_bringup_binary SHARED)
add_library(foe_bringup_yaml SHARED)
# Sources
add_subdirectory(src)
# Engine Definition
target_link_libraries(foe_bringup_lib PUBLIC foe foe_ecs foe_bringup_lib_eh
foe_imex)
# These are plugins which are linked because the bringup library is using
# header/content directly
target_link_libraries(
foe_bringup_lib PUBLIC foe_bringup_shared foe_graphics_resource foe_physics
foe_position vk_value_serialization)
target_include_directories(foe_bringup_lib
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/public/)
target_compile_definitions(
foe_bringup_lib
PRIVATE
# Regular Plugins
BRINGUP_PLUGIN="$<TARGET_FILE:foe_bringup_shared>"
GRAPHICS_RESOURCE_PLUGIN="$<TARGET_FILE:foe_graphics_resource>"
PHYSICS_PLUGIN="$<TARGET_FILE:foe_physics>"
POSITION_PLUGIN="$<TARGET_FILE:foe_position>"
# Yaml Plugins
BRINGUP_YAML_PLUGIN="$<TARGET_FILE:foe_bringup_yaml>"
GRAPHICS_RESOURCE_YAML_PLUGIN="$<TARGET_FILE:foe_graphics_resource_yaml>"
IMEX_YAML_PLUGIN="$<TARGET_FILE:foe_imex_yaml>"
PHYSICS_YAML_PLUGIN="$<TARGET_FILE:foe_physics_yaml>"
POSITION_YAML_PLUGIN="$<TARGET_FILE:foe_position_yaml>"
# Binary Plugin
IMEX_BINARY_PLUGIN="$<TARGET_FILE:foe_imex_binary>"
PHYSICS_BINARY_PLUGIN="$<TARGET_FILE:foe_physics_binary>"
POSITION_BINARY_PLUGIN="$<TARGET_FILE:foe_position_binary>"
GRAPHICS_RESOURCE_BINARY_PLUGIN="$<TARGET_FILE:foe_graphics_resource_binary>"
BRINGUP_BINARY_PLUGIN="$<TARGET_FILE:foe_bringup_binary>")
if(MSVC)
target_compile_options(foe_bringup_lib PRIVATE /EHsc)
else()
target_compile_options(foe_bringup_lib PRIVATE -fno-exceptions)
endif()
if(EDITOR_MODE)
target_link_libraries(foe_bringup_lib PUBLIC foe_bringup_imgui)
endif()
target_code_coverage(
foe_bringup_lib
OBJECTS
foe
foe_ecs
foe_bringup_shared
foe_bringup_lib_eh
foe_graphics_resource
foe_graphics_vk
foe_imex
foe_model
foe_physics
foe_position
foe_simulation)
if(WSI_LOADER)
target_link_libraries(foe_bringup_lib PUBLIC foe_wsi_loader)
else()
target_link_libraries(foe_bringup_lib PUBLIC foe_wsi_${WSI_LIBRARY})
endif()
if(XR_SUPPORT)
target_link_libraries(foe_bringup_lib PUBLIC foe_xr_openxr foe_xr_openxr_vk)
else()
target_link_libraries(foe_bringup_lib PUBLIC foe_xr)
endif()
# Engine ImGUI Definition
target_compile_definitions(foe_bringup_imgui PUBLIC EDITOR_MODE)
target_link_libraries(
foe_bringup_imgui
PUBLIC foe_bringup_shared
foe_imgui
foe_imgui_vk
foe_graphics_resource_imgui
foe_position_imgui
foe_physics_imgui
foe_simulation_imgui
foe_wsi_imgui)
if(IMGUI_DEMO)
target_compile_definitions(foe_bringup_imgui PUBLIC IMGUI_SHOW_DEMO)
target_link_libraries(foe_bringup_imgui PRIVATE imgui_demo)
endif()
target_code_coverage(foe_bringup_imgui)
if(UNIX)
target_compile_options(foe_bringup_imgui PRIVATE -fPIC)
endif()
# Exception-handling Definition
target_link_libraries(foe_bringup_lib_eh PUBLIC CLI11 foe_simulation foe_yaml)
target_code_coverage(foe_bringup_lib_eh)
if(UNIX)
target_compile_options(foe_bringup_lib_eh PRIVATE -fPIC)
endif()
# Bringup Functionality
target_include_directories(foe_bringup_shared
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/public/)
target_link_libraries(
foe_bringup_shared PRIVATE foe_model foe_model_assimp foe_resource
foe_simulation foe_position foe_graphics_resource)
# Binary Definition
target_include_directories(foe_bringup_binary
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/public/)
target_link_libraries(foe_bringup_binary PRIVATE foe_bringup_shared
foe_imex_binary)
# Yaml Definition
target_include_directories(foe_bringup_yaml
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/public/)
target_link_libraries(foe_bringup_yaml PRIVATE foe_bringup_shared foe_ecs_yaml
foe_imex_yaml)
# Auxiliary Items
if(BUILD_SHADERS)
file(
GLOB_RECURSE
GLSL_FILES
data/*.vert
data/*.tese
data/*.tesc
data/*.geom
data/*.frag
data/*.comp)
target_glsl_shaders(foe_bringup PRIVATE ${GLSL_FILES})
clang_format(format_shaders ${GLSL_FILES})
endif()