-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
296 lines (254 loc) · 10 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
cmake_minimum_required(VERSION 3.17)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR} CACHE INTERNAL "")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIGURATION>)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIGURATION>)
if(MSVC)
add_definitions(/MP)
endif()
if (LINUX)
find_package(X11)
endif()
project(RGL)
option(RGL_ENABLE_RGLC "Enable the separate compiler executable" ON)
option(RGL_DISABLE_VK "Force-disable the Vulkan backend" OFF)
option(RGL_DISABLE_DX "Force-disable the D3D12 backend" OFF)
option(RGL_DISABLE_WEBGPU "Force-disable the WebGPU backend" OFF)
option(RGL_ENABLE_WEBGPU "Force-enable the WebGPU backend" OFF)
option(RGL_RUNTIME_COMPILATION "Enable runtime shader compilation" OFF)
option(RGL_SKIP_BACKEND_CHECK "Skip the SDK check" OFF)
option(RGL_IDE_ROOT "IDE parent folder for targets" "RGL")
if (NOT RGL_IDE_ROOT)
set(RGL_IDE_ROOT "RGL") # CMake sets this to "OFF" for some insane reason
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT RGL_DISABLE_WEBGPU )
set(RGL_WEBGPU_AVAILABLE ON CACHE INTERNAL "RGL WebGPU")
else()
set(RGL_WEBGPU_AVAILABLE OFF CACHE INTERNAL "RGL WebGPU")
endif()
if (RGL_ENABLE_WEBGPU)
set(RGL_WEBGPU_AVAILABLE ON CACHE INTERNAL "RGL WebGPU")
endif()
if (CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64")
set(RGL_DISABLE_VK ON CACHE INTERNAL "")
endif()
#setup main library
if(APPLE)
file(GLOB_RECURSE MM_SOURCES "src/*.mm")
endif()
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.hpp" "include/*.hpp" "src/*.h" )
add_library(${PROJECT_NAME} ${SOURCES} ${MM_SOURCES})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
if (APPLE)
set_source_files_properties(${MM_SOURCES} PROPERTIES
COMPILE_FLAGS "-x objective-c++"
)
endif()
# setup compiler
if (RGL_WEBGPU_AVAILABLE)
set(ST_ENABLE_WGSL ON CACHE INTERNAL "")
else()
set(ST_ENABLE_WGSL OFF CACHE INTERNAL "")
endif()
set(ST_ENABLE_TEST OFF CACHE INTERNAL "")
if((WIN32 AND NOT WINDOWS_STORE) AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/deps/ShaderTranspiler/deps/DirectXShaderCompiler/CMakeLists.txt")
message("Building DXC from source")
set(ST_BUNDLED_DXC ON)
else()
message("Not building DXC from source")
set(ST_BUNDLED_DXC OFF)
endif()
add_subdirectory(deps/ShaderTranspiler EXCLUDE_FROM_ALL)
file(GLOB_RECURSE LIBRGLC_SOURCES "tools/librglc/*.cpp" "tools/librglc/*.hpp")
add_library(librglc ${LIBRGLC_SOURCES})
target_link_libraries(librglc PRIVATE ShaderTranspiler)
target_compile_features(librglc PRIVATE cxx_std_20)
target_include_directories(librglc
PRIVATE
"tools/librglc/include/"
PUBLIC
"tools/librglc/include/"
)
# setup command line compiler utility
if (RGL_ENABLE_RGLC)
file(GLOB RGLC_SOURCES "tools/rglc/*.cpp" "tools/rglc/*.hpp")
add_executable(rglc ${RGLC_SOURCES})
target_compile_features(rglc PRIVATE cxx_std_20)
target_link_libraries(rglc PRIVATE librglc)
target_include_directories(rglc PRIVATE "deps/cxxopts/include")
set(rglc_path "rglc" CACHE INTERNAL "rglc compiler path")
set(rglc_exe "rglc")
set_target_properties(rglc
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rglc"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rglc"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rglc"
)
endif()
if(WINDOWS_STORE OR RGL_DISABLE_VK OR APPLE OR CMAKE_SYSTEM_NAME MATCHES "Emscripten")
set(VK_FORCE_DISABLED ON)
else()
set(VK_FORCE_DISABLED OFF)
endif()
if (NOT VK_FORCE_DISABLED)
add_subdirectory(deps/volk EXCLUDE_FROM_ALL)
target_compile_definitions(volk PUBLIC NOMINMAX=1)
# Get our vendored headers
set(VK_INCLUDE deps/Vulkan-Headers/include deps/Vulkan-Utility-Libraries/include)
target_include_directories(volk PUBLIC ${VK_INCLUDE})
if (LINUX)
target_compile_definitions(volk PRIVATE VK_USE_PLATFORM_XLIB_KHR VK_USE_PLATFORM_WAYLAND_KHR)
elseif(ANDROID)
target_compile_definitions(volk PRIVATE VK_USE_PLATFORM_ANDROID_KHR)
elseif(WIN32 OR WINDOWS_STORE)
target_compile_definitions(volk PRIVATE VK_USE_PLATFORM_WIN32_KHR)
endif()
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_VK_AVAILABLE=1 )
set(RGL_VK_AVAILABLE ON CACHE INTERNAL "RGL Vulkan")
add_subdirectory(deps/VulkanMemoryAllocator EXCLUDE_FROM_ALL)
target_compile_definitions(VulkanMemoryAllocator INTERFACE VMA_STATIC_VULKAN_FUNCTIONS=0 VMA_DYNAMIC_VULKAN_FUNCTIONS=0)
target_link_libraries(${PROJECT_NAME}
PUBLIC
volk
PRIVATE
GPUOpen::VulkanMemoryAllocator
)
set_target_properties(VulkanMemoryAllocator volk PROPERTIES FOLDER "${RGL_IDE_ROOT}/Libraries")
if (TARGET loader-opt)
set_target_properties(loader-opt loader-unknown-chain PROPERTIES FOLDER "${RGL_IDE_ROOT}/Libraries")
endif()
if(RGL_USE_MINIVKSDK)
set_target_properties(vulkan vvl VkLayer_utils loader_asm_gen_files PROPERTIES FOLDER "${RGL_IDE_ROOT}/Libraries")
endif()
else()
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_VK_AVAILABLE=0)
set(RGL_VK_AVAILABLE OFF CACHE INTERNAL "RGL Vulkan")
endif()
if(MSVC AND NOT RGL_DISABLE_DX)
add_subdirectory(deps/DirectX-Headers EXCLUDE_FROM_ALL)
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_DX12_AVAILABLE=1)
set(RGL_DX12_AVAILABLE ON CACHE INTERNAL "RGL DX12")
add_subdirectory("deps/D3D12MemoryAllocator" EXCLUDE_FROM_ALL)
set(BUILD_XAUDIO_WIN10 OFF CACHE INTERNAL "")
add_subdirectory("deps/DirectXTK12" EXCLUDE_FROM_ALL)
target_include_directories(${PROJECT_NAME} PUBLIC "deps/DirectXTK12/Inc")
# PIX stuff
add_subdirectory(deps/PixEvents-cmake)
set_target_properties("WinPixEventRuntime" "WinPixEventRuntime_ETW" "PixDecoder" "DirectX-Guids" "DirectXTK12" DirectX-Headers PROPERTIES FOLDER "${RGL_IDE_ROOT}/Libraries/")
target_link_libraries(${PROJECT_NAME}
PRIVATE
d3d12.lib
DirectX-Headers
DirectX-Guids
dxgi.lib
d3dcompiler.lib
D3D12MemoryAllocator
DirectXTK12
$<$<NOT:$<CONFIG:release>>:WinPixEventRuntime>
)
set_target_properties(D3D12MemoryAllocator PROPERTIES FOLDER "${RGL_IDE_ROOT}/Libraries")
else()
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_DX12_AVAILABLE=0)
set(RGL_DX12_AVAILABLE OFF CACHE INTERNAL "RGL DX12")
endif()
if(APPLE)
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_MTL_AVAILABLE=1)
set(MTL_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/deps/metal-cpp" "${CMAKE_CURRENT_LIST_DIR}/deps/metal-cpp-extensions")
find_library(FOUNDATION_LIB Cocoa REQUIRED)
find_library(METAL_LIB Metal REQUIRED)
find_library(QZC_LIB QuartzCore REQUIRED)
set(RGL_MTL_AVAILABLE ON CACHE INTERNAL "RGL Metal")
target_link_libraries(${PROJECT_NAME}
PRIVATE
${FOUNDATION_LIB}
${METAL_LIB}
${QZC_LIB}
)
else()
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_MTL_AVAILABLE=0)
set(RGL_MTL_AVAILABLE OFF CACHE INTERNAL "RGL Metal")
endif()
if (RGL_WEBGPU_AVAILABLE)
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_WEBGPU_AVAILABLE=1)
else()
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_WEBGPU_AVAILABLE=0)
endif()
if (RGL_RUNTIME_COMPILATION)
target_link_libraries(${PROJECT_NAME} PRIVATE librglc)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE SPIRV-Reflect ${X11_LIBRARIES})
if (APPLE)
target_include_directories(${PROJECT_NAME} PRIVATE "tools/librglc/include/")
if (RGL_RUNTIME_COMPILATION)
target_compile_definitions(${PROJECT_NAME} PRIVATE "RGL_CAN_RUNTIME_COMPILE")
endif()
endif()
set(AFTERMATH_DIR "AftermathSDK")
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/deps/${AFTERMATH_DIR}")
target_include_directories(${PROJECT_NAME} PRIVATE "deps/${AFTERMATH_DIR}/include")
file(GLOB AFTERMATH_LIBS "deps/${AFTERMATH_DIR}/lib/x64/*.lib")
target_link_libraries(${PROJECT_NAME} PRIVATE ${AFTERMATH_LIBS})
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_AFTERMATH_AVAILABLE=1)
message("Aftermath SDK enabled")
else()
message("Aftermath SDK disabled")
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_AFTERMATH_AVAILABLE=0)
endif()
target_include_directories(${PROJECT_NAME}
PRIVATE
${X11_INCLUDE_DIR}
${MTL_INCLUDE}
"include/RGL"
PUBLIC
${VK_INCLUDE}
"${CMAKE_CURRENT_LIST_DIR}/deps/DirectX-Headers/include"
"include"
)
target_compile_definitions(${PROJECT_NAME} PUBLIC NOMINMAX=1)
set_target_properties("RGL" ${rglc_exe} "librglc" PROPERTIES
FOLDER "${RGL_IDE_ROOT}"
XCODE_GENERATE_SCHEME ON
)
set_target_properties("SPIRV-Reflect" "ShaderTranspiler" PROPERTIES
FOLDER "${RGL_IDE_ROOT}/Libraries"
)
if (RGL_WEBGPU_AVAILABLE)
set_target_properties("libtint" "tint_diagnostic_utils" PROPERTIES
FOLDER "${RGL_IDE_ROOT}/Libraries"
)
endif()
set_target_properties("GenericCodeGen" "glslang" "OGLCompiler" "MachineIndependent" "OSDependent" "SPIRV" "SPVRemapper" "glslang-default-resource-limits" PROPERTIES
FOLDER "${RGL_IDE_ROOT}/Libraries/glslang"
)
set_target_properties(
"SPIRV-Tools-opt" "SPIRV-Tools-reduce" "SPIRV-Tools-static" "SPIRV-Tools-shared" "SPIRV-Tools-lint" "SPIRV-Tools-diff" "SPIRV-Tools-link"
"spirv-tools-shared-pkg-config" "spirv-tools-pkg-config"
PROPERTIES
FOLDER "${RGL_IDE_ROOT}/Libraries/SPIRV-Tools Libraries"
)
set_target_properties(
"spirv-cross-core"
"spirv-cross-glsl" "spirv-cross-hlsl" "spirv-cross-msl" "spirv-cross-reflect" "spirv-cross-cpp" "spirv-cross-util"
PROPERTIES
FOLDER "${RGL_IDE_ROOT}/Libraries/SPIRV-Cross"
)
if(ST_BUNDLED_DXC AND NOT WINDOWS_STORE)
function(dxc_set_for_dir DIR)
get_property(TGTS DIRECTORY "${DIR}" PROPERTY BUILDSYSTEM_TARGETS)
set_target_properties(
${TGTS}
PROPERTIES
FOLDER "${RGL_IDE_ROOT}/Libraries/DirectXShaderCompiler"
)
get_property(SUBDIRS DIRECTORY "${DIR}" PROPERTY SUBDIRECTORIES)
foreach(SUBDIR IN LISTS SUBDIRS)
dxc_set_for_dir("${SUBDIR}")
endforeach()
endfunction()
dxc_set_for_dir("${CMAKE_CURRENT_LIST_DIR}/deps/ShaderTranspiler/deps/DirectXShaderCompiler")
endif()
if (NOT RGL_SKIP_BACKEND_CHECK)
if (RGL_VK_AVAILABLE OR RGL_DX12_AVAILABLE OR RGL_MTL_AVAILABLE OR RGL_WEBGPU_AVAILABLE)
else()
message(FATAL_ERROR "No backends are enabled! Check that all required SDKs are installed.")
endif()
endif()