-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
153 lines (125 loc) · 6.82 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
cmake_minimum_required(VERSION 3.20)
project(KWA)
set(CMAKE_CXX_STANDARD 17)
set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT "unittest")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "cmake")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DKW_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNICODE -D_UNICODE")
find_program(
vulkan_dxc_executable
NAMES dxc
HINTS "$ENV{VULKAN_SDK}/bin"
REQUIRED
)
function(target_add_shaders target shaders)
set(vertex_shaders ${shaders})
list(FILTER vertex_shaders INCLUDE REGEX ".+_vertex\\.hlsl$")
foreach(absolute_path_hlsl ${vertex_shaders})
cmake_path(RELATIVE_PATH absolute_path_hlsl BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE relative_path_hlsl)
cmake_path(REPLACE_EXTENSION relative_path_hlsl ".cso" OUTPUT_VARIABLE relative_path_cso)
cmake_path(REPLACE_EXTENSION relative_path_hlsl ".spv" OUTPUT_VARIABLE relative_path_spv)
cmake_path(REMOVE_FILENAME relative_path_hlsl OUTPUT_VARIABLE relative_path_dir)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_cso}" "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_spv}"
MAIN_DEPENDENCY ${absolute_path_hlsl}
COMMAND ${CMAKE_COMMAND} -E make_directory "\"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_dir}\""
COMMAND ${vulkan_dxc_executable} -T vs_6_0 -Fo "\"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_cso}\"" "$<$<CONFIG:Debug>:-Od;-Zi;-O0;-Qembed_debug>" -Wno-ignored-attributes "\"${absolute_path_hlsl}\""
COMMAND ${vulkan_dxc_executable} -T vs_6_0 -Fo "\"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_spv}\"" "$<$<CONFIG:Debug>:-Od;-Zi;-O0;-Qembed_debug;-fspv-debug=line>" -fspv-reflect -fvk-invert-y -fvk-use-dx-layout -spirv "\"${absolute_path_hlsl}\""
COMMAND_EXPAND_LISTS
)
endforeach()
set(fragment_shaders ${shaders})
list(FILTER fragment_shaders INCLUDE REGEX ".+_fragment\\.hlsl$")
foreach(absolute_path_hlsl ${fragment_shaders})
cmake_path(RELATIVE_PATH absolute_path_hlsl BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE relative_path_hlsl)
cmake_path(REPLACE_EXTENSION relative_path_hlsl ".cso" OUTPUT_VARIABLE relative_path_cso)
cmake_path(REPLACE_EXTENSION relative_path_hlsl ".spv" OUTPUT_VARIABLE relative_path_spv)
cmake_path(REMOVE_FILENAME relative_path_hlsl OUTPUT_VARIABLE relative_path_dir)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_cso}" "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_spv}"
COMMAND ${CMAKE_COMMAND} -E make_directory "\"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_dir}\""
COMMAND ${vulkan_dxc_executable} -T ps_6_0 -Fo "\"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_cso}\"" "$<$<CONFIG:Debug>:-Od;-Zi;-O0;-Qembed_debug>" -Wno-ignored-attributes "\"${absolute_path_hlsl}\""
COMMAND ${vulkan_dxc_executable} -T ps_6_0 -Fo "\"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_spv}\"" "$<$<CONFIG:Debug>:-Od;-Zi;-O0;-Qembed_debug;-fspv-debug=line>" -fspv-reflect -fvk-use-dx-position-w -fvk-use-dx-layout -spirv "\"${absolute_path_hlsl}\""
MAIN_DEPENDENCY ${absolute_path_hlsl}
COMMAND_EXPAND_LISTS
)
endforeach()
target_sources(${target} PRIVATE ${shaders})
source_group(
TREE "${CMAKE_CURRENT_SOURCE_DIR}/resource"
PREFIX "Resource Files"
FILES ${shaders}
)
set_source_files_properties(${shaders} PROPERTIES VS_TOOL_OVERRIDE "None")
endfunction()
function(target_add_textures target textures)
foreach(absolute_path_dds ${textures})
cmake_path(RELATIVE_PATH absolute_path_dds BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE relative_path_dds)
cmake_path(REPLACE_EXTENSION relative_path_dds LAST_ONLY "kwt" OUTPUT_VARIABLE relative_path_kwt)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_kwt}"
COMMAND $<TARGET_FILE:texture_converter> "\"${absolute_path_dds}\"" "\"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_kwt}\""
MAIN_DEPENDENCY ${absolute_path_dds}
#DEPENDS texture_converter
COMMAND_EXPAND_LISTS
)
endforeach()
target_sources(${target} PRIVATE ${textures})
source_group(
TREE "${CMAKE_CURRENT_SOURCE_DIR}/resource"
PREFIX "Resource Files"
FILES ${textures}
)
endfunction()
function(target_add_geometries target geometries)
foreach(absolute_path_glb ${geometries})
cmake_path(RELATIVE_PATH absolute_path_glb BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE relative_path_glb)
cmake_path(REPLACE_EXTENSION relative_path_glb LAST_ONLY "kwg" OUTPUT_VARIABLE relative_path_kwg)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_kwg}"
COMMAND $<TARGET_FILE:geometry_converter> "\"${absolute_path_glb}\"" "\"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path_kwg}\""
MAIN_DEPENDENCY ${absolute_path_glb}
#DEPENDS geometry_converter
COMMAND_EXPAND_LISTS
)
endforeach()
target_sources(${target} PRIVATE ${geometries})
source_group(
TREE "${CMAKE_CURRENT_SOURCE_DIR}/resource"
PREFIX "Resource Files"
FILES ${geometries}
)
endfunction()
function(target_add_materials target materials)
foreach(absolute_path ${materials})
cmake_path(RELATIVE_PATH absolute_path BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE relative_path)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path}"
COMMAND ${CMAKE_COMMAND} -E copy "\"${absolute_path}\"" "\"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${relative_path}\""
MAIN_DEPENDENCY ${absolute_path}
COMMAND_EXPAND_LISTS
)
endforeach()
target_sources(${target} PRIVATE ${materials})
source_group(
TREE "${CMAKE_CURRENT_SOURCE_DIR}/resource"
PREFIX "Resource Files"
FILES ${materials}
)
endfunction()
function(target_add_resources target)
file(GLOB_RECURSE shaders "resource/*.hlsl")
target_add_shaders(${target} "${shaders}")
file(GLOB_RECURSE textures "resource/*.dds")
target_add_textures(${target} "${textures}")
file(GLOB_RECURSE geometries "resource/*.glb")
target_add_geometries(${target} "${geometries}")
file(GLOB_RECURSE materials "resource/*.kwm")
target_add_materials(${target} "${materials}")
endfunction()
add_subdirectory("thirdparty")
add_subdirectory("engine")
add_subdirectory("tools")
add_subdirectory("examples")