forked from takiyu/VulkanWrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
251 lines (225 loc) · 10.9 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
message(STATUS "--------------------------------------------------------------")
message(STATUS "----------------------------- VKW ----------------------------")
message(STATUS "--------------------------------------------------------------")
cmake_minimum_required(VERSION 3.10)
# ------------------------------------------------------------------------------
# -------------------------------- Check parent --------------------------------
# ------------------------------------------------------------------------------
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if (HAS_PARENT)
message(STATUS "Build VKW as subdirectory mode")
else()
message(STATUS "Build VKW as independent mode")
endif()
# ------------------------------------------------------------------------------
# ----------------------------------- Options ----------------------------------
# ------------------------------------------------------------------------------
set(VKW_BUILD_EXAMPLES ON CACHE BOOL "Build examples")
set(VKW_LINK_DYNAMIC_VK ON CACHE BOOL "Dynamic link for vulkan.")
set(VKW_USE_VULKAN_LOADER ON CACHE BOOL "Use Vulkan-Loader when dynamic link.")
set(VKW_USE_VULKAN_VALIDATION OFF CACHE BOOL "Use Vulkan-ValidationLayers.")
set(VKW_USE_INTERNAL_GLFW ON CACHE BOOL "Use Internal GLFW.")
set(VKW_EXTERNAL_INCLUDE "" CACHE STRING "External include paths.")
set(VKW_EXTERNAL_LIBRARY "" CACHE STRING "External libraries.")
set(VKW_THIRD_PARTY_PATH "" CACHE STRING "Third party directory path.")
# Detect Android
if (ANDROID OR ANDROID_ABI OR ANDROID_TOOLCHAIN)
message(STATUS "Build for Android")
set(VKW_ANDROID TRUE)
endif()
# Handle flag dependency
if (NOT VKW_LINK_DYNAMIC_VK OR WIN32 OR VKW_ANDROID)
set(VKW_USE_VULKAN_LOADER OFF) # No vulkan-loader for static Vulkan
endif()
if (VKW_ANDROID)
set(VKW_USE_INTERNAL_GLFW OFF) # No GLFW for Android
endif()
if (NOT VKW_THIRD_PARTY_PATH)
set(VKW_THIRD_PARTY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
endif()
# External includes/libraries
list(APPEND VKW_INCLUDE ${VKW_EXTERNAL_INCLUDE})
list(APPEND VKW_LIBRARY ${VKW_EXTERNAL_LIBRARY})
# ------------------------------------------------------------------------------
# ----------------------------------- Common -----------------------------------
# ------------------------------------------------------------------------------
project(vkw CXX C)
set(CMAKE_CXX_STANDARD 14) # C++ 14
# Include CSC
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_scalable_conf.cmake)
# ------------------------------------------------------------------------------
# --------------------------- Third Party Libraries ----------------------------
# ------------------------------------------------------------------------------
list(APPEND VKW_INCLUDE ${VKW_THIRD_PARTY_PATH})
# Version Tags
set(VK_HEADERS_TAG "v1.3.204")
set(VK_LOADER_TAG "v1.3.204")
set(SPIRV_HEADERS_TAG "sdk-1.3.204")
set(SPIRV_TOOLS_TAG "sdk-1.3.204")
set(GLSLANG_TAG "sdk-1.3.204")
set(VK_VALIDATION_TAG "v1.3.204")
set(GLFW_TAG "3.3.6")
set(GLM_TAG "66062497b104ca7c297321bd0e970869b1e6ece5")
set(TINYOBJ_TAG "0ed6c38f20c63b996fbb9fa949569b2acb213a3d")
set(STB_TAG "c9064e317699d2e495f36ba4f9ac037e88ee371a")
if (VKW_LINK_DYNAMIC_VK)
# Vulkan (Dynamic)
message(STATUS "Build VKW as dynacmic-vk mode")
csc_clone_third_party("https://github.com/KhronosGroup/Vulkan-Headers"
${VK_HEADERS_TAG} TRUE ${VKW_THIRD_PARTY_PATH})
list(APPEND VKW_INCLUDE ${VKW_THIRD_PARTY_PATH}/Vulkan-Headers/include)
list(APPEND VKW_DEFINE -DVULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL=1 # dlopen
-DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) # dispatch
if (VKW_USE_VULKAN_LOADER)
# Vulkan-Loader
csc_clone_third_party("https://github.com/KhronosGroup/Vulkan-Loader"
${VK_LOADER_TAG} TRUE ${VKW_THIRD_PARTY_PATH})
endif()
else()
# Vulkan (Static)
message(STATUS "Build VKW as static-vk mode")
find_package(Vulkan REQUIRED)
list(APPEND VKW_INCLUDE ${Vulkan_INCLUDE_DIRS})
list(APPEND VKW_LIBRARY ${Vulkan_LIBRARY})
list(APPEND VKW_DEFINE -DVULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL=0 # dlopen
-DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=0) # dispatch
endif()
# SPIRV-Headers
set(SPIRV_HEADERS_SKIP_EXAMPLES ON CACHE BOOL "")
set(SPIRV_HEADERS_SKIP_INSTALL ON CACHE BOOL "")
csc_clone_third_party("https://github.com/KhronosGroup/SPIRV-Headers"
${SPIRV_HEADERS_TAG} TRUE ${VKW_THIRD_PARTY_PATH})
list(APPEND VKW_INCLUDE ${VKW_THIRD_PARTY_PATH}/SPIRV-Headers/include)
# SPIRV-Tools
set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE BOOL "")
set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "")
# set(SPIRV_CHECK_CONTEXT ON CACHE BOOL "")
csc_clone_third_party("https://github.com/KhronosGroup/SPIRV-Tools"
${SPIRV_TOOLS_TAG} TRUE ${VKW_THIRD_PARTY_PATH})
list(APPEND VKW_INCLUDE ${VKW_THIRD_PARTY_PATH}/SPIRV-Tools/include)
list(APPEND VKW_LIBRARY SPIRV-Tools-opt) # For "ENABLE_OPT=1" in GLSLang
# Overwrite for FetchContent variable
set(spirv-tools_SOURCE_DIR ${VKW_THIRD_PARTY_PATH}/SPIRV-Tools)
# GLSLang
set(ENABLE_GLSLANG_BINARIES ON CACHE BOOL "")
set(ENABLE_SPVREMAPPER OFF CACHE BOOL "")
set(ENABLE_HLSL OFF CACHE BOOL "")
set(SKIP_GLSLANG_INSTALL ON CACHE BOOL "")
csc_clone_third_party("https://github.com/KhronosGroup/glslang.git"
${GLSLANG_TAG} TRUE ${VKW_THIRD_PARTY_PATH})
list(APPEND VKW_INCLUDE ${VKW_THIRD_PARTY_PATH}/glslang)
list(APPEND VKW_LIBRARY glslang SPIRV glslang-default-resource-limits
OGLCompiler)
list(APPEND VKW_DEFINE -DENABLE_OPT=1) # Defined internally
# Validation Layer
if (VKW_USE_VULKAN_VALIDATION)
# Build Validation Layer
set(USE_ROBIN_HOOD_HASHING OFF CACHE BOOL "")
if (VKW_ANDROID)
set(BUILD_WSI_XCB_SUPPORT OFF CACHE BOOL "")
set(BUILD_WSI_XLIB_SUPPORT OFF CACHE BOOL "")
set(BUILD_WSI_WAYLAND_SUPPORT OFF CACHE BOOL "")
endif()
set(SPIRV_HEADERS_INCLUDE_DIR
"${VKW_THIRD_PARTY_PATH}/SPIRV-Headers/include" CACHE STRING "")
csc_clone_third_party("https://github.com/KhronosGroup/Vulkan-ValidationLayers"
${VK_VALIDATION_TAG} TRUE ${VKW_THIRD_PARTY_PATH})
endif()
# GLFW
if (VKW_USE_INTERNAL_GLFW)
message(STATUS "With VKW Internal GLFW")
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "")
set(GLFW_BUILD_TESTS OFF CACHE BOOL "")
set(GLFW_BUILD_DOCS OFF CACHE BOOL "")
set(GLFW_INSTALL OFF CACHE BOOL "")
csc_clone_third_party("https://github.com/glfw/glfw"
${GLFW_TAG} TRUE ${VKW_THIRD_PARTY_PATH})
list(APPEND VKW_INCLUDE ${VKW_THIRD_PARTY_PATH}/glfw/include)
list(APPEND VKW_LIBRARY glfw)
endif()
if (VKW_BUILD_EXAMPLES)
message(STATUS "With VKW Examples")
# GLM
csc_clone_third_party("https://github.com/g-truc/glm"
${GLM_TAG} FALSE ${VKW_THIRD_PARTY_PATH})
list(APPEND VKW_INCLUDE ${VKW_THIRD_PARTY_PATH}/glm)
# TinyObjLoader
csc_clone_third_party("https://github.com/syoyo/tinyobjloader"
${TINYOBJ_TAG} FALSE ${VKW_THIRD_PARTY_PATH})
add_library(tinyobjloader
${VKW_THIRD_PARTY_PATH}/tinyobjloader/tiny_obj_loader.cc
)
list(APPEND VKW_LIBRARY tinyobjloader)
# STB
csc_clone_third_party("https://github.com/nothings/stb"
${STB_TAG} FALSE ${VKW_THIRD_PARTY_PATH})
add_library(stb
${CMAKE_CURRENT_SOURCE_DIR}/example/utils/stb_impl.cpp
)
csc_setup_target(stb "${VKW_INCLUDE}" "${VKW_LIBRARY}" FALSE)
list(APPEND VKW_LIBRARY stb)
endif()
# ------------------------------------------------------------------------------
# ----------------------------- Internal Libraries -----------------------------
# ------------------------------------------------------------------------------
# VKW
list(APPEND VKW_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(vkw
${CMAKE_CURRENT_SOURCE_DIR}/src/vkw.cpp
)
csc_setup_target(vkw "${VKW_INCLUDE}" "${VKW_LIBRARY}" TRUE)
add_definitions(${VKW_DEFINE})
list(APPEND VKW_LIBRARY vkw)
# ------------------------------------------------------------------------------
# ----------------------------- Pass to the parent -----------------------------
# ------------------------------------------------------------------------------
if (HAS_PARENT)
set(VKW_INCLUDE ${VKW_INCLUDE} PARENT_SCOPE)
set(VKW_LIBRARY ${VKW_LIBRARY} PARENT_SCOPE)
set(VKW_DEFINE ${VKW_DEFINE} PARENT_SCOPE)
endif()
# ------------------------------------------------------------------------------
# ---------------------------------- Examples ----------------------------------
# ------------------------------------------------------------------------------
if (VKW_BUILD_EXAMPLES)
# Example application sources
set(EXAMPLE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/example/01_rotate_box/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/02_load_obj/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/03_load_obj_many/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/04_deferred_shading/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/05_instancing/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/06_raster_vtx_id/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/07_image_transfer/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/08_comp_shader/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/09_inverse_uv/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/10_glsl_optim/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/11_img_buf/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/example/12_comp_shader_atomic_float/app.cpp
)
if (VKW_ANDROID)
# ----------------------------------------------------------------------
# ------------------------------ Android -------------------------------
# ----------------------------------------------------------------------
find_library(log-lib log)
find_library(android-lib android)
list(APPEND VKW_LIBRARY ${log-lib} ${android-lib})
# Android example
add_library(native-lib SHARED
${EXAMPLE_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/android/app/src/main/cpp/native-lib.cpp)
csc_setup_target(native-lib "${VKW_INCLUDE}" "${VKW_LIBRARY}" TRUE)
else()
# ----------------------------------------------------------------------
# --------------------------------- PC ---------------------------------
# ----------------------------------------------------------------------
# PC example
add_executable(main
${EXAMPLE_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/pc/main.cpp)
csc_setup_target(main "${VKW_INCLUDE}" "${VKW_LIBRARY}" TRUE)
endif()
endif()
message(STATUS "--------------------------------------------------------------")
message(STATUS "--------------------------------------------------------------")
message(STATUS "--------------------------------------------------------------")