-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
111 lines (94 loc) · 3.34 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
project(VulkanLightBakery)
cmake_minimum_required(VERSION 3.21)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_COMPILER g++)
set(GLSL_VALIDATOR "glslangValidator")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=1")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nullability-completeness -pthread -O0 -g")
else()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nullability-completeness -pthread -O3 -DNDEBUG")
message("Building in release mode")
endif()
find_package(Vulkan REQUIRED)
find_package(glfw3 REQUIRED)
find_package(glm REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(imgui REQUIRED)
include_directories(/usr/include/tinygltf REQUIRED)
set(VENDOR_LIBS
${Vulkan_LIBRARIES}
${glm_LIBRARIES}
glfw
imgui
${nlohmann_json_LIBRARIES})
include_directories(src src/vendor src/vendor/tqdm/include src/baker shaders)
add_library(core SHARED
src/application.cpp
src/scene_manager.cpp
src/skybox_manager.cpp
src/camera.cpp
src/vendor/define_implementations.cpp
)
add_executable(rtrt
src/realtime_raytracer/main.cpp
src/realtime_raytracer/renderer.cpp
src/realtime_raytracer/raytracer.cpp
src/realtime_raytracer/ui.cpp
src/vendor/imgui_impl_glfw.cpp
src/vendor/imgui_impl_vulkan.cpp
src/vendor/imgui_stdlib.cpp
)
add_executable(baker
src/baker/main.cpp
src/baker/env_map_generator.cpp
src/baker/light_baker.cpp
)
target_link_libraries(rtrt ${VENDOR_LIBS} -ldl core)
target_link_libraries(baker ${VENDOR_LIBS} -ldl core)
##################
## ASSETS ########
##################
set(ASSETS_URL http://vulkan.gpuinfo.org/downloads/vulkan_asset_pack_gltf.zip)
set(ASSETS_ZIP assets.zip)
file(COPY_FILE src/vendor/default_blender_cube.gltf ${CMAKE_BINARY_DIR}/default_blender_cube.gltf)
if (NOT EXISTS ${CMAKE_BINARY_DIR}/assets)
message(CHECK_START "Downloading assets")
file(DOWNLOAD ${ASSETS_URL} ${ASSETS_ZIP} TLS_VERIFY ON)
file(ARCHIVE_EXTRACT INPUT ${ASSETS_ZIP} DESTINATION ${CMAKE_BINARY_DIR})
file(RENAME ${CMAKE_BINARY_DIR}/data ${CMAKE_BINARY_DIR}/assets)
file(REMOVE ${CMAKE_BINARY_DIR}/${ASSETS_ZIP})
message(CHECK_PASS "done")
endif()
##################
## SHADERS #######
##################
message(CHECK_START "Detecting ${GLSL_VALIDATOR}")
find_program(KERNEL_COMPILER "${GLSL_VALIDATOR}" ${CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH})
if (KERNEL_COMPILER)
message(CHECK_PASS "done")
file(GLOB_RECURSE GLSL_SOURCE_FILES
"shaders/*.rgen"
"shaders/*.rchit"
"shaders/*.rmiss"
"shaders/*.rahit"
"shaders/*.rcall"
"shaders/*.comp"
)
foreach(GLSL ${GLSL_SOURCE_FILES})
get_filename_component(FILE_NAME ${GLSL} NAME)
set(SPIRV "${PROJECT_BINARY_DIR}/shaders/${FILE_NAME}.spv")
add_custom_command(
OUTPUT ${SPIRV}
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/shaders/"
COMMAND ${GLSL_VALIDATOR} --target-env vulkan1.2 -V ${GLSL} -o ${SPIRV}
DEPENDS ${GLSL})
list(APPEND SPIRV_BINARY_FILES ${SPIRV})
endforeach(GLSL)
add_custom_target(shaders DEPENDS ${SPIRV_BINARY_FILES})
add_dependencies(rtrt shaders)
add_dependencies(baker shaders)
else()
message(CHECK_FAIL "missing")
message(WARNING "MAKE SURE TO COMPILE SHADERS YOURSELF")
endif()