-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
339 lines (237 loc) · 8.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
# Copyright (c) 2022 Sapphire's Suite. All Rights Reserved.
cmake_minimum_required(VERSION 3.16)
# Sapphire Suite's CMake tools.
add_subdirectory(ThirdParty/SA/CMake)
# Project
project(SA_Render)
SA_ConfigureProject(SA_Render)
# Main Library
add_library(SA_Render INTERFACE)
SA_ConfigureTarget(SA_Render LINK INTERFACE)
# Main LowLevel lib.
add_library(SA_Render_LowLevel INTERFACE)
SA_ConfigureTarget(SA_Render_LowLevel LINK INTERFACE)
### Link to main lib.
target_link_libraries(SA_Render INTERFACE SA_Render_LowLevel)
# LowLevel Common
add_library(SA_Render_LowLevel_Common STATIC)
SA_ConfigureTarget(SA_Render_LowLevel_Common)
SA_TargetSources(SA_Render_LowLevel_Common
PUBLIC_SRC_DIR "Include/SA/Render/LowLevel/Common"
PRIVATE_SRC_DIR "Source/SA/Render/LowLevel/Common"
)
### Link dependencies.
target_link_libraries(SA_Render_LowLevel_Common PUBLIC SA_Logger SA_Maths)
### Link to main lib.
target_link_libraries(SA_Render_LowLevel INTERFACE SA_Render_LowLevel_Common)
### Validation layers
option(SA_RENDER_VALIDATION_LAYER_RELEASE_OPT "Enable render validation layers in release" OFF)
if(SA_RENDER_VALIDATION_LAYER_RELEASE_OPT)
target_compile_definitions(SA_Render_LowLevel_Common PUBLIC SA_RENDER_VALIDATION_LAYER_RELEASE=1)
endif()
### API Tracking
option(SA_RENDER_API_TRACKING_OPT "Enable API call tracking" OFF)
if(SA_RENDER_API_TRACKING_OPT)
target_compile_definitions(SA_Render_LowLevel_Common PUBLIC SA_RENDER_API_TRACKING=1)
endif()
# Main RHI libs.
option(SA_RENDER_RHI_OPT "Should compile RHI" ON)
if(SA_RENDER_RHI_OPT)
## Main RHI lib.
add_library(SA_Render_RHI INTERFACE)
SA_ConfigureTarget(SA_Render_RHI LINK INTERFACE)
## RHI Common lib
add_library(SA_Render_RHI_Common STATIC)
SA_ConfigureTarget(SA_Render_RHI_Common)
SA_TargetSources(SA_Render_RHI_Common
PUBLIC_SRC_DIR "Include/SA/Render/RHI/Common"
PUBLIC_INCL_DIR "OFF"
PRIVATE_SRC_DIR "Source/SA/Render/RHI/Common"
)
### Link dependencies.
target_link_libraries(SA_Render_RHI_Common
PUBLIC SA_Render_LowLevel SA_Render_ShaderCompiler
)
### Link to main lib.
target_link_libraries(SA_Render_RHI INTERFACE SA_Render_RHI_Common)
endif()
# Vulkan Wrapper
option(SA_RENDER_VULKAN_OPT "Should compile Vulkan wrapper" ON)
if(SA_RENDER_VULKAN_OPT)
find_package(Vulkan REQUIRED)
## LowLevel Vulkan
add_library(SA_Render_LowLevel_Vulkan STATIC)
SA_ConfigureTarget(SA_Render_LowLevel_Vulkan)
SA_TargetSources(SA_Render_LowLevel_Vulkan
PUBLIC_SRC_DIR "Include/SA/Render/LowLevel/Vulkan"
PUBLIC_INCL_DIR "OFF"
PRIVATE_SRC_DIR "Source/SA/Render/LowLevel/Vulkan"
)
#### Link dependencies.
target_link_libraries(SA_Render_LowLevel_Vulkan
PUBLIC SA_Render_LowLevel_Common
PUBLIC Vulkan::Vulkan # Set to public for easier wrapping.
)
#### Link to main lib.
target_link_libraries(SA_Render_LowLevel INTERFACE SA_Render_LowLevel_Vulkan)
## RHI Vulkan
if(SA_RENDER_RHI_OPT)
add_library(SA_Render_RHI_Vulkan STATIC)
SA_ConfigureTarget(SA_Render_RHI_Vulkan)
SA_TargetSources(SA_Render_RHI_Vulkan
PUBLIC_SRC_DIR "Include/SA/Render/RHI/Vulkan"
PUBLIC_INCL_DIR "OFF"
PRIVATE_SRC_DIR "Source/SA/Render/RHI/Vulkan"
)
#### Link dependencies.
target_link_libraries(SA_Render_RHI_Vulkan
PUBLIC SA_Render_RHI_Common
PUBLIC SA_Render_LowLevel_Vulkan # Set to public for easier wrapping.
)
#### Link to main lib.
target_link_libraries(SA_Render_RHI INTERFACE SA_Render_RHI_Vulkan)
endif()
endif()
# DX12 Wrapper
if(WIN32)
option(SA_RENDER_DX12_OPT "Should compile DirectX12 wrapper" ON)
else()
set(SA_RENDER_DX12_OPT OFF)
endif()
if(SA_RENDER_DX12_OPT)
## LowLevel DX12
add_library(SA_Render_LowLevel_DX12 STATIC)
SA_ConfigureTarget(SA_Render_LowLevel_DX12)
SA_TargetSources(SA_Render_LowLevel_DX12
PUBLIC_SRC_DIR "Include/SA/Render/LowLevel/DX12"
PUBLIC_INCL_DIR "OFF"
PRIVATE_SRC_DIR "Source/SA/Render/LowLevel/DX12"
)
### Link dependencies.
target_link_libraries(SA_Render_LowLevel_DX12
PUBLIC SA_Render_LowLevel_Common
PUBLIC d3d12.lib dxgi.lib # Set to public for easier wrapping.
PRIVATE dxguid.lib
)
### Link to main lib.
target_link_libraries(SA_Render_LowLevel INTERFACE SA_Render_LowLevel_DX12)
## RHI DX12
if(SA_RENDER_RHI_OPT)
add_library(SA_Render_RHI_DX12 STATIC)
SA_ConfigureTarget(SA_Render_RHI_DX12)
SA_TargetSources(SA_Render_RHI_DX12
PUBLIC_SRC_DIR "Include/SA/Render/RHI/DX12"
PUBLIC_INCL_DIR "OFF"
PRIVATE_SRC_DIR "Source/SA/Render/RHI/DX12"
)
#### Link dependencies.
target_link_libraries(SA_Render_RHI_DX12
PUBLIC SA_Render_RHI_Common
PUBLIC SA_Render_LowLevel_DX12 # Set to public for easier wrapping.
)
#### Link to main lib.
target_link_libraries(SA_Render_RHI INTERFACE SA_Render_RHI_DX12)
endif()
endif()
## OpenGL
option(SA_RENDER_OPENGL_OPT "Should compile OpenGL wrapper" OFF)
if(SA_RENDER_OPENGL_OPT)
find_package(OpenGL REQUIRED)
## LowLevel OpenGL
add_library(SA_Render_LowLevel_OpenGL STATIC)
SA_ConfigureTarget(SA_Render_LowLevel_OpenGL)
SA_TargetSources(SA_Render_LowLevel_OpenGL
PUBLIC_SRC_DIR "Include/SA/Render/LowLevel/OpenGL"
PUBLIC_INCL_DIR "OFF"
PRIVATE_SRC_DIR "Source/SA/Render/LowLevel/OpenGL"
)
### Link dependencies.
target_link_libraries(SA_Render_LowLevel_OpenGL
PUBLIC SA_Render_LowLevel_Common
PRIVATE OpenGL::GL
)
### Link to main lib.
target_link_libraries(SA_Render_LowLevel INTERFACE SA_Render_LowLevel_OpenGL)
## RHI OpenGL
if(SA_RENDER_RHI_OPT)
add_library(SA_Render_RHI_OpenGL STATIC)
SA_ConfigureTarget(SA_Render_RHI_OpenGL)
SA_TargetSources(SA_Render_RHI_OpenGL
PUBLIC_SRC_DIR "Include/SA/Render/RHI/OpenGL"
PUBLIC_INCL_DIR "OFF"
PRIVATE_SRC_DIR "Source/SA/Render/RHI/OpenGL"
)
#### Link dependencies.
target_link_libraries(SA_Render_RHI_OpenGL
PUBLIC SA_Render_RHI_Common
PUBLIC SA_Render_LowLevel_OpenGL # Set to public for easier wrapping.
)
#### Link to main lib.
target_link_libraries(SA_Render_RHI INTERFACE SA_Render_RHI_OpenGL)
endif()
endif()
## Renderer
option(SA_RENDER_RENDERER_OPT "Should compile Renderer" ON)
if(SA_RENDER_RENDERER_OPT AND SA_RENDER_RHI_OPT)
add_library(SA_Render_Renderer STATIC)
SA_ConfigureTarget(SA_Render_Renderer)
SA_TargetSources(SA_Render_Renderer
PUBLIC_SRC_DIR "Include/SA/Render/Renderer"
PUBLIC_INCL_DIR "OFF"
PRIVATE_SRC_DIR "Source/SA/Render/Renderer"
)
### Link dependencies.
target_link_libraries(SA_Render_Renderer
PUBLIC SA_Render_RHI
)
### Link to main lib.
target_link_libraries(SA_Render INTERFACE SA_Render_Renderer)
endif()
## ShaderCompiler
option(SA_RENDER_SHADER_COMPILER_OPT "Should compile shader compiler" ON)
if(SA_RENDER_SHADER_COMPILER_OPT)
add_library(SA_Render_ShaderCompiler STATIC)
SA_ConfigureTarget(SA_Render_ShaderCompiler)
SA_TargetSources(SA_Render_ShaderCompiler
PUBLIC_SRC_DIR "Include/SA/Render/ShaderCompiler"
PUBLIC_INCL_DIR "OFF"
PRIVATE_SRC_DIR "Source/SA/Render/ShaderCompiler"
)
### Link dependencies.
target_link_libraries(SA_Render_ShaderCompiler
PUBLIC SA_Logger SA_DirectXShaderCompiler SA_Render_RHI
)
if(SA_RENDER_VULKAN_OPT OR SA_RENDER_OPENGL_OPT)
target_link_libraries(SA_Render_ShaderCompiler PRIVATE spirv-reflect-static)
endif()
### Link to main lib.
target_link_libraries(SA_Render INTERFACE SA_Render_ShaderCompiler)
### Add source folder for shader include directory.
target_compile_definitions(SA_Render_ShaderCompiler PRIVATE SA_CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}")
if(WIN32)
### Fix dxcompiler.dll mUtils->CreateReflection.
add_custom_command(
TARGET SA_Render_ShaderCompiler POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/ThirdParty/DirectXShaderCompiler/bin/windows/dxcompiler.dll
$<TARGET_FILE_DIR:SA_Render_ShaderCompiler>/../
)
### Fix dxil.dll lookup.
add_custom_command(
TARGET SA_Render_ShaderCompiler POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/ThirdParty/DirectXShaderCompiler/bin/windows/dxil.dll
$<TARGET_FILE_DIR:SA_Render_ShaderCompiler>/../
)
endif()
endif()
# Options
## Add SA_Render's tests to build tree.
option(SA_RENDER_BUILD_TESTS_OPT "Should build SA_Render tests" OFF)
# Entrypoints
add_subdirectory(ThirdParty)
if(SA_RENDER_BUILD_TESTS_OPT)
### Enable testing for this directory and below.
enable_testing()
add_subdirectory(Tests)
endif()