This repository has been archived by the owner on Dec 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
506 lines (442 loc) · 17.8 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
cmake_minimum_required(VERSION 3.12)
project(nova-renderer)
############################################################
# Fix build type because of possible capitalization issues #
############################################################
if(NOT NOVA_PACKAGE AND CMAKE_BUILD_TYPE)
string(TOLOWER ${CMAKE_BUILD_TYPE} TMP_BUILD_TYPE)
set(BUILD_TYPE_FIXED_BY_NOVA FALSE)
if("${TMP_BUILD_TYPE}" STREQUAL "debug" AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(ORIGINAL_BUILD_TYPE ${CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Specifies the build type on single-configuration generators. (Fixed to Debug from '${TMP_BUILD_TYPE}' by nova-renderer)" FORCE)
set(BUILD_TYPE_FIXED_BY_NOVA TRUE)
elseif(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(ORIGINAL_BUILD_TYPE ${CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Specifies the build type on single-configuration generators. (Fixed to Release from '${TMP_BUILD_TYPE}' by nova-renderer)" FORCE)
set(BUILD_TYPE_FIXED_BY_NOVA TRUE)
endif()
if(BUILD_TYPE_FIXED_BY_NOVA)
message(WARNING "CMAKE_BUILD_TYPE build type has been fixed to ${CMAKE_BUILD_TYPE} from ${ORIGINAL_BUILD_TYPE}")
endif()
elseif(NOT CMAKE_BUILD_TYPE AND NOT MSVC)
set(CMAKE_BUILD_TYPE "Release")
endif()
#############################
# Options for nova's builds #
#############################
option(NOVA_TEST "Enable tests." OFF)
option(NOVA_ENABLE_EXPERIMENTAL "Enable experimental features, may be in code as well as in the CMake files" OFF)
option(NOVA_TREAT_WARNINGS_AS_ERRORS "Add -Werror flag or /WX for MSVC" OFF)
option(NOVA_PACKAGE "Build only the library, nothing else." OFF)
option(NOVA_ENABLE_VULKAN_RHI "Compile the Vulkan RHI backend" ON)
option(NOVA_ENABLE_D3D12_RHI "Compile the D3D12 RHI backend" ON)
option(NOVA_ENABLE_OPENGL_RHI "Compile the OpenGL 3 backend" ON)
if(NOVA_ENABLE_D3D12_API AND NOT WIN32)
message(WARNING "Nova can only compile its D3D12 RHI backend on Windows 10. You're now on Windows 10, so I'm disabling the D3D12 RHI backend")
set(NOVA_ENABLE_D3D12_RHI_BACKEND OFF)
endif()
if(NOT NOVA_ENABLE_VULKAN_RHI AND NOT VULKAN_ENABLE_D3D12_RHI AND NOT NOVA_ENABLE_OPENGL_RHI)
message(ERROR "You must enable at least one RHI backend")
endif()
if(NOVA_ENABLE_EXPERIMENTAL)
set(CMAKE_LINK_WHAT_YOU_USE TRUE) # Warn about unsued linked libraries
endif()
#########################################################
# Enable tests if not in submodule and debug or if MSVC #
#########################################################
if(NOT NOVA_PACKAGE)
message(STATUS "Enabling nova tests by default because Nova is not a package")
set(NOVA_TEST ON)
endif()
############################
# Initialize cmake options #
############################
set(3RD_PARTY_DIR ${CMAKE_CURRENT_LIST_DIR}/external)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools/cmake" "${3RD_PARTY_DIR}")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
if(NOT NOVA_PACKAGE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
#################################
# Setup our own cmake additions #
#################################
include(ClangFormat)
include(ClangTidy)
include(RemovePermissive)
include(CompilerOptionsUtils)
include(CheckCXXCompilerFlag)
include(CheckIncludeFileCXX)
set(BUILD_TESTING OFF CACHE BOOL "NO TESTING" FORCE)
#################################
# Setup 3rd party dependencies. #
#################################
include(external)
########################
# Add Nova source code #
########################
set(NOVA_SOURCE
include/nova_renderer/util/filesystem.hpp
include/nova_renderer/util/platform.hpp
include/nova_renderer/util/result.hpp
include/nova_renderer/util/utils.hpp
include/nova_renderer/command_list.hpp
include/nova_renderer/device_memory_resource.hpp
include/nova_renderer/nova_renderer.hpp
include/nova_renderer/nova_settings.hpp
include/nova_renderer/render_engine.hpp
include/nova_renderer/renderables.hpp
include/nova_renderer/renderdoc_app.h
include/nova_renderer/rhi_enums.hpp
include/nova_renderer/rhi_types.hpp
include/nova_renderer/shaderpack_data.hpp
include/nova_renderer/window.hpp
include/nova_renderer/bytes.hpp
include/nova_renderer/render_graph.hpp
include/nova_renderer/allocation_strategy.hpp
include/nova_renderer/allocation_structs.hpp
include/nova_renderer/bytes.hpp
include/nova_renderer/polyalloc.hpp
src/nova_renderer.cpp
src/render_engine/render_engine.cpp
src/loading/zip_folder_accessor.hpp
src/loading/regular_folder_accessor.hpp
src/loading/folder_accessor.hpp
src/loading/folder_accessor.cpp
src/loading/regular_folder_accessor.cpp
src/loading/zip_folder_accessor.cpp
src/loading/loading_utils.cpp
src/loading/loading_utils.hpp
src/loading/json_utils.hpp
src/settings/nova_settings.cpp
src/render_objects/uniform_structs.hpp
src/util/logger.cpp
src/util/logger.hpp
src/util/utils.cpp
src/util/result.cpp
src/loading/shaderpack/shaderpack_loading.cpp
src/loading/shaderpack/shaderpack_loading.hpp
src/loading/shaderpack/shaderpack_data.cpp
src/loading/shaderpack/json_interop.cpp
src/loading/shaderpack/json_interop.hpp
src/loading/shaderpack/shaderpack_validator.cpp
src/loading/shaderpack/shaderpack_validator.hpp
src/loading/shaderpack/render_graph_builder.cpp
src/loading/shaderpack/render_graph_builder.hpp
src/render_engine/command_list.cpp
src/render_engine/rhi_types.cpp
src/render_engine/render_engine.cpp
src/render_engine/swapchain.cpp
src/tasks/task_scheduler.cpp
src/tasks/task_scheduler.hpp
src/tasks/task_graph.hpp
src/tasks/wait_free_queue.hpp
src/tasks/condition_counter.cpp
src/tasks/condition_counter.hpp
src/debugging/renderdoc.cpp
src/debugging/renderdoc.hpp
src/memory/device_memory_resource.cpp
src/memory/block_allocation_strategy.hpp
src/memory/bump_point_allocation_strategy.hpp
src/memory/mallocator.hpp
src/memory/system_memory_allocator.hpp
src/memory/block_allocation_strategy.cpp
src/memory/bump_point_allocation_strategy.cpp
src/memory/bytes.cpp
src/memory/mallocator.cpp
src/memory/system_memory_allocator.cpp
)
#################################################################
# Add NTL source code - just until I get INTERFACE libs working #
#################################################################
set(NOVA_SOURCE ${NOVA_SOURCE} ${NTL_SOURCE})
####################
# Add Nova headers #
####################
set(NOVA_HEADERS
include/nova_renderer/util/platform.hpp
include/nova_renderer/nova_renderer.hpp
include/nova_renderer/shaderpack_data.hpp
include/nova_renderer/nova_settings.hpp
include/nova_renderer/render_engine.hpp
include/nova_renderer/window.hpp
include/nova_renderer/util/utils.hpp
include/nova_renderer/renderables.hpp
include/nova_renderer/renderdoc_app.h
include/nova_renderer/util/result.hpp
)
##################################
# Select platform dependent code #
##################################
set(WINDOWS_NOVA_SOURCE
src/util/windows_utils.cpp
src/util/windows_utils.hpp
src/windowing/win32_window.hpp
src/windowing/win32_window.cpp
)
set(UNIX_NOVA_SOURCE
src/windowing/x11_window.cpp
src/windowing/x11_window.hpp
src/util/linux_utils.cpp
src/util/linux_utils.hpp
)
#########################################
# Which RHI backends should we compile? #
#########################################
if(NOVA_ENABLE_VULKAN_RHI)
set(NOVA_SOURCE
${NOVA_SOURCE}
src/render_engine/vulkan/vulkan_command_list.cpp
src/render_engine/vulkan/vulkan_command_list.hpp
src/render_engine/vulkan/vulkan_render_engine.cpp
src/render_engine/vulkan/vulkan_render_engine.hpp
src/render_engine/vulkan/vk_structs.hpp
src/render_engine/vulkan/vulkan_utils.hpp
src/render_engine/vulkan/vulkan_utils.cpp
src/render_engine/vulkan/vulkan_swapchain.cpp
src/render_engine/vulkan/vulkan_swapchain.hpp
)
endif()
if(NOVA_ENABLE_D3D12_RHI)
set(WINDOWS_NOVA_SOURCE
${WINDOWS_NOVA_SOURCE}
src/render_engine/dx12/dx12_utils.cpp
src/render_engine/dx12/dx12_utils.hpp
src/render_engine/dx12/d3dx12.h
src/render_engine/dx12/dx12_command_list.cpp
src/render_engine/dx12/dx12_command_list.hpp
src/render_engine/dx12/dx12_structs.hpp
src/render_engine/dx12/dx12_swapchain.cpp
src/render_engine/dx12/dx12_swapchain.hpp
src/render_engine/dx12/dx12_render_engine.cpp
src/render_engine/dx12/dx12_render_engine.hpp
)
endif()
if(NOVA_ENABLE_OPENGL_RHI)
set(NOVA_SOURCE
${NOVA_SOURCE}
src/render_engine/gl3/gl3_render_engine.cpp
src/render_engine/gl3/gl3_render_engine.hpp
src/render_engine/gl3/gl3_command_list.cpp
src/render_engine/gl3/gl3_command_list.hpp
src/render_engine/gl3/gl3_swapchain.cpp
src/render_engine/gl3/gl3_swapchain.hpp
src/render_engine/gl3/KHR/khrplatform.h
src/render_engine/gl3/glad/glad.h
src/render_engine/gl3/glad.c
src/render_engine/gl3/gl3_structs.hpp
src/windowing/glfw_window.cpp
src/windowing/glfw_window.hpp
)
endif()
if(WIN32)
set(NOVA_SOURCE ${NOVA_SOURCE} ${WINDOWS_NOVA_SOURCE})
set(OTHER_NOVA_SOURCE ${UNIX_NOVA_SOURCE})
else()
set(NOVA_SOURCE ${NOVA_SOURCE} ${UNIX_NOVA_SOURCE})
set(OTHER_NOVA_SOURCE ${WINDOWS_NOVA_SOURCE})
endif()
##########################################
# Set platform dependent compile options #
##########################################
if (UNIX)
add_compile_options_if_supported(-g -fno-omit-frame-pointer -fPIC -fdiagnostics-color=always -Wpessimizing-move -Wredundant-move)
endif()
if(MSVC)
add_definitions(/D_CRT_SECURE_NO_WARNINGS=1)
endif()
if(NOVA_TREAT_WARNINGS_AS_ERRORS)
if(MSVC)
add_compile_options(/WX)
else()
# TODO: Consider removing the -Wno-error's when we are in a more complete state
add_compile_options(-Werror -Wno-error=unused-variable -Wno-error=unused-but-set-variable
-Wno-error=unused-parameter)
endif()
endif()
macro(add_coverage target)
if(NOVA_COVERAGE)
if(MSVC)
message(FATAL_ERROR "Coverage not supported on MSVC.")
else()
target_compile_options(${target} PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage)
target_link_libraries(${target} PRIVATE -g --coverage)
endif()
endif()
endmacro()
##########################################
# Setup required options for backtracing #
##########################################
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
add_compile_options_if_supported(-g -rdynamic)
message(STATUS "Enabling symbol output")
endif()
#################
# Organize code #
#################
# For now just put everthing in a single nova source group
# because there are several sub groups that would be extremely small
source_group("nova" FILES ${NOVA_NO_COMPILE} ${3RD_PARTY_SOURCE} ${NOVA_SOURCE} ${NOVA_HEADERS})
##########################
# Setup the nova library #
##########################
add_library(nova-renderer STATIC
${NOVA_HEADERS}
${NOVA_SOURCE}
${3RD_PARTY_SOURCE}
)
nova_format(nova-renderer "${OTHER_NOVA_SOURCE}")
# Add VULKAN_SDK to the include path
# TODO: Only add if the user is compiling the Vulkan backend
message(STATUS "FMT headers: ${FMT_HEADERS}")
message(STATUS "Miniz headers: ${INSTALL_HEADERS}")
set_target_properties(nova-renderer PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
target_compile_definitions(nova-renderer PUBLIC DUMP_NOVA_CALLS)
target_compile_definitions(nova-renderer PUBLIC MTR_ENABLED)
target_compile_definitions(nova-renderer PUBLIC FMT_STRING_ALIAS=1)
target_include_directories(nova-renderer PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$ENV{VULKAN_SDK}/Include
${FMT_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/external/miniz # Miniz doesn't export a MINIZ_HEADERS variable?
)
target_link_directories(nova-renderer PUBLIC $ENV{VULKAN_SDK}/Lib)
# Compilation definitions indicating enabled backends
if(NOVA_ENABLE_VULKAN_RHI)
target_compile_definitions(nova-renderer PUBLIC NOVA_VULKAN_RHI)
target_include_directories(nova-renderer PRIVATE Vulkan_INCLUDE_DIR)
endif()
if(NOVA_ENABLE_D3D12_RHI)
target_compile_definitions(nova-renderer PUBLIC NOVA_D3D12_RHI)
endif()
if(NOVA_ENABLE_OPENGL_RHI)
target_compile_definitions(nova-renderer PUBLIC NOVA_OPENGL_RHI)
endif()
include(GNUInstallDirs)
# TODO: Never care about CMake packages ever again
# install(
# TARGETS nova-renderer
# EXPORT nova-renderer-config
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/
# )
#
# install(
# EXPORT nova-renderer-config DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nova-renderer
# NAMESPACE nova-renderer::
# )
#
# install(
# DIRECTORY ${CMAKE_SOURCE_DIR}/src/
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nova-renderer
# FILES_MATCHING PATTERN "*.hpp*"
# )
##################################
# Add extra warnings if possible #
##################################
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
target_compile_options_if_supported(nova-renderer PUBLIC -Wall -Wextra -Wpedantic -Wconversion -Wdefaulted-function-deleted)
endif()
add_coverage(nova-renderer)
#########################
# Set libraries to link #
#########################
set(COMMON_LINK_LIBS
${CMAKE_DL_LIBS}
fmt
glm::glm
glslang
OGLCompiler
OSDependent
SPIRV
minitrace
miniz
nlohmann::json
vma::vma
SPIRV-Tools
spirv-cross-core
spirv-cross-glsl
spirv-cross-reflect
spirv-cross-util)
if(NOVA_ENABLE_VULKAN_RHI)
if(WIN32)
set(COMMON_LINK_LIBS ${COMMON_LINK_LIBS} vulkan-1)
else()
set(COMMON_LINK_LIBS ${COMMON_LINK_LIBS} vulkan)
endif()
endif()
if(NOVA_ENABLE_OPENGL_RHI)
if(TARGET glfw)
set(GLFW_TARGET_NAME glfw)
elseif(TARGET glfw3)
set(GLFW_TARGET_NAME glfw3)
else()
message(FATAL_ERROR "GLFW target name could not be found")
endif()
set(COMMON_LINK_LIBS ${COMMON_LINK_LIBS} ${GLFW_TARGET_NAME})
target_include_directories(nova-renderer PUBLIC external/glfw/include)
endif()
if(NOVA_ENABLE_D3D12_RHI)
set(COMMON_LINK_LIBS ${COMMON_LINK_LIBS} spirv-cross-hlsl)
endif()
##############################
# Find C++ filesystem header #
##############################
# On some toolchains its still <experimental/filesystem> while on others its already <filesystem>
check_include_file_cxx("filesystem" CXX_STD_FILESYSTEM)
if(NOT CXX_STD_FILESYSTEM)
check_include_file_cxx("experimental/filesystem" CXX_STD_FILESYSTEM_EXPERIMENTAL)
if(NOT CXX_STD_FILESYSTEM_EXPERIMENTAL)
message(FATAL_ERROR "Failed to find a filesystem header for C++")
endif()
target_compile_definitions(nova-renderer PUBLIC NOVA_STD_FILESYSTEM_EXPERIMENTAL=1)
else()
target_compile_definitions(nova-renderer PUBLIC NOVA_STD_FILESYSTEM=1)
endif()
############################
# Platform dependent fixes #
############################
if(WIN32)
find_package(WindowsSDK)
get_windowssdk_include_dirs(${WINDOWSSDK_LATEST_DIR} WinSDK_DIRS)
# MSVC 15.9 broke the Windows SDK by implementing two phase lookup. "/Zc:twoPhase-" disables it.
add_compile_options_if_supported(/Zc:twoPhase- /permissive /bigobj )
set_target_properties(nova-renderer PROPERTIES PREFIX "")
set(COMMON_LINK_LIBS ${COMMON_LINK_LIBS} d3d12 dxgi d3dcompiler spirv-cross-hlsl)
target_include_directories(nova-renderer PRIVATE ${WinSDK_DIRS})
target_compile_definitions(nova-renderer PUBLIC _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING NOMINMAX)
target_compile_definitions(nova-renderer PRIVATE NOVA_EXPORT)
# Visual Studio is stupid. Is it really that hard to use filesystem directories to organize code like literally
# everyone else?
foreach(source IN LISTS NOVA_SOURCE)
get_filename_component(source_path "${source}" PATH)
string(REPLACE "/" "\\" source_path_msvc "${source_path}")
source_group("${source_path_msvc}" FILES "${source}")
endforeach()
else()
# GCC and Clang complain loudly about the #pragma region stuff. This shuts them up.
target_compile_options_if_supported(nova-renderer PRIVATE -Wno-unknown-pragmas)
set(COMMON_LINK_LIBS ${COMMON_LINK_LIBS} stdc++fs X11)
endif()
###############################
# Link all required libraries #
###############################
target_link_libraries(nova-renderer PUBLIC ${COMMON_LINK_LIBS})
#############################
# Fix issue with permissive #
#############################
remove_permissive(nova-renderer)
##########################
# Add tests if requested #
##########################
if(NOVA_TEST)
add_subdirectory(tests)
endif()
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()