-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
250 lines (214 loc) · 9.02 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
cmake_minimum_required(VERSION 3.12)
project(Vulkan-CPPTemplate)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
############################################################################################
############################################################################################
############################################################################################
############################################################################################
# Copyright 2019 The VKB Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
enable_testing()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_DEBUG_POSTFIX "")
set(VKB_THIRD_PARTY "${CMAKE_CURRENT_SOURCE_DIR}/subprojects")
option(VKB_BUILD_TESTS "Build tests for projects" OFF)
option(VKB_BUILD_GLSLANG "Build GLSLang" ON)
option(VKB_BUILD_SHADERC "Build ShaderC" OFF)
option(VKB_BUILD_SPIRV_CROSS "Build SPIRV-Cross" ON)
option(VKB_BUILD_SPIRV_HEADERS "Build SPIRV-Headers" ON)
option(VKB_BUILD_SPIRV_TOOLS "Build SPIRV-Tools" ON)
option(VKB_BUILD_SPIRV_DOCS "Build SPIRV-Docs" OFF)
option(VKB_BUILD_VULKAN_DOCS "Build Vulkan-Docs" OFF)
option(VKB_BUILD_VULKAN_GUIDE "Build Vulkan-Guide" OFF)
option(VKB_BUILD_VULKAN_HEADERS "Build Vulkan-Headers" ON)
option(VKB_BUILD_VULKAN_HPP "Build Vulkan-Hpp" ON)
option(VKB_BUILD_VULKAN_LOADER "Build Vulkan-Loader" ON)
option(VKB_BUILD_VULKAN_VALIDATION_LAYERS "Build Vulkan-ValidationLayers" ON)
option(VKB_BUILD_VULKAN_EXTENSION_LAYER "Build Vulkan-ExtensionLayer" ON)
if (${VKB_BUILD_SHADERC})
set(VKB_BUILD_GLSLANG ON)
set(VKB_BUILD_SPIRV_TOOLS ON)
set(VKB_BUILD_SPIRV_CROSS ON)
endif()
if (${VKB_BUILD_GLSLANG})
set(VKB_BUILD_SPIRV_TOOLS ON)
endif()
if (${VKB_BUILD_SPIRV_TOOLS})
set(VKB_BUILD_SPIRV_HEADERS ON)
endif()
if (${VKB_BUILD_VULKAN_DOCS})
set(VKB_BUILD_VULKAN_HEADERS ON)
endif()
if (${VKB_BUILD_VULKAN_LOADER})
set(VKB_BUILD_VULKAN_HEADERS ON)
endif()
if (${VKB_BUILD_VULKAN_VALIDATION_LAYERS})
set(VKB_BUILD_VULKAN_HEADERS ON)
endif()
if (${VKB_BUILD_VULKAN_HPP})
set(VKB_BUILD_VULKAN_HEADERS ON)
set(VKB_TINYXML2_SOURCE_DIR "${VKB_THIRD_PARTY}/tinyxml2")
set(VKB_GLM_SOURCE_DIR "${VKB_THIRD_PARTY}/glm")
endif()
if (${VKB_BUILD_VULKAN_EXTENSION_LAYER})
set(VKB_BUILD_VULKAN_HEADERS ON)
endif()
set(VKB_EFFCEE_SOURCE_DIR "${VKB_THIRD_PARTY}/effcee")
set(VKB_GLSLANG_SOURCE_DIR "${VKB_THIRD_PARTY}/glslang")
set(VKB_GOOGLE_TEST_SOURCE_DIR "${VKB_THIRD_PARTY}/googletest")
set(VKB_RE2_SOURCE_DIR "${VKB_THIRD_PARTY}/re2")
set(VKB_SHADERC_SOURCE_DIR "${VKB_THIRD_PARTY}/shaderc")
set(VKB_SPIRV_DOCS_SOURCE_DIR "${VKB_THIRD_PARTY}/SPIRV-Docs")
set(VKB_SPIRV_CROSS_SOURCE_DIR "${VKB_THIRD_PARTY}/SPIRV-Cross")
set(VKB_SPIRV_HEADERS_SOURCE_DIR "${VKB_THIRD_PARTY}/SPIRV-Headers")
set(VKB_SPIRV_TOOLS_SOURCE_DIR "${VKB_THIRD_PARTY}/SPIRV-Tools")
set(VKB_VULKAN_DOCS_SOURCE_DIR "${VKB_THIRD_PARTY}/Vulkan-Docs")
set(VKB_VULKAN_GUIDE_SOURCE_DIR "${VKB_THIRD_PARTY}/Vulkan-Guide")
set(VKB_VULKAN_HEADERS_SOURCE_DIR "${VKB_THIRD_PARTY}/Vulkan-Headers")
set(VKB_VULKAN_HPP_SOURCE_DIR "${VKB_THIRD_PARTY}/Vulkan-Hpp")
set(VKB_VULKAN_LOADER_SOURCE_DIR "${VKB_THIRD_PARTY}/Vulkan-Loader")
set(VKB_VULKAN_VALIDATION_LAYERS_SOURCE_DIR "${VKB_THIRD_PARTY}/Vulkan-ValidationLayers")
set(VKB_VULKAN_EXTENSION_LAYER_SOURCE_DIR "${VKB_THIRD_PARTY}/Vulkan-ExtensionLayer")
find_package(PythonInterp 3 REQUIRED)
message(STATUS "VKB using Python3")
message(STATUS "VKB enable testing: ${VKB_BUILD_TESTS}")
message(STATUS "VKB enable SPIRV-Docs: ${VKB_BUILD_SPIRV_DOCS}")
message(STATUS "VKB enable SPIRV-Headers: ${VKB_BUILD_SPIRV_HEADERS}")
message(STATUS "VKB enable SPIRV-Tools: ${VKB_BUILD_SPIRV_TOOLS}")
message(STATUS "VKB enable SPIRV-Cross: ${VKB_BUILD_SPIRV_CROSS}")
message(STATUS "VKB enable GLSLang: ${VKB_BUILD_GLSLANG}")
message(STATUS "VKB enable ShaderC: ${VKB_BUILD_SHADERC}")
message(STATUS "VKB enable Vulkan-Docs: ${VKB_BUILD_VULKAN_DOCS}")
message(STATUS "VKB enable Vulkan-Guide: ${VKB_BUILD_VULKAN_GUIDE}")
message(STATUS "VKB enable Vulkan-Headers: ${VKB_BUILD_VULKAN_HEADERS}")
message(STATUS "VKB enable Vulkan-Hpp: ${VKB_BUILD_VULKAN_HPP}")
message(STATUS "VKB enable Vulkan-Loader: ${VKB_BUILD_VULKAN_LOADER}")
message(STATUS "VKB enable Vulkan-ValidationLayers: ${VKB_BUILD_VULKAN_VALIDATION_LAYERS}")
if(MSVC)
# By default compile code to assume the CRT is statically linked,
# i.e. use /MT* options. For debug builds use /MTd, and for release builds
# use /MT.
#
# Modify the project-wide options variables. This is ugly, but seems to be
# the state of the art.
message(STATUS "VKB: Static C runtime selected: replacing /MD* with /MT*")
foreach (flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endforeach()
endif()
# Support
if (${VKB_BUILD_TESTS})
include(cmake/googletest.cmake)
include(cmake/re2.cmake)
include(cmake/effcee.cmake)
endif()
# SPIR-V
if (${VKB_BUILD_SPIRV_HEADERS})
include(cmake/spirv-headers.cmake)
endif()
if (${VKB_BUILD_SPIRV_DOCS})
include(cmake/spirv-docs.cmake)
endif()
if (${VKB_BUILD_SPIRV_TOOLS})
include(cmake/spirv-tools.cmake)
endif()
# SPIR-V Compilers
if (${VKB_BUILD_GLSLANG})
include(cmake/glslang.cmake)
endif()
if (${VKB_BUILD_SHADERC})
include(cmake/shaderc.cmake)
endif()
# Must come after spirv-tools and glslang as it uses the generated binaries
# to setup testing.
if (${VKB_BUILD_SPIRV_CROSS})
include(cmake/spirv-cross.cmake)
endif()
# Vulkan
if (${VKB_BUILD_VULKAN_HEADERS})
include(cmake/vulkan-headers.cmake)
endif()
if (${VKB_BUILD_VULKAN_HPP})
include(cmake/vulkan-hpp.cmake)
endif()
if (${VKB_BUILD_VULKAN_DOCS})
include(cmake/vulkan-docs.cmake)
endif()
if (${VKB_BUILD_VULKAN_GUIDE})
include(cmake/vulkan-guide.cmake)
endif()
if (${VKB_BUILD_VULKAN_LOADER})
include(cmake/vulkan-loader.cmake)
endif()
if (${VKB_BUILD_VULKAN_VALIDATION_LAYERS})
include(cmake/vulkan-validation-layers.cmake)
endif()
if (${VKB_BUILD_VULKAN_EXTENSION_LAYER})
include(cmake/vulkan-extensionlayer.cmake)
endif()
############################################################################################
############################################################################################
############################################################################################
############################################################################################
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(executable
src/main.cpp
src/graphics/context.hpp
src/graphics/device.cpp
src/graphics/device.hpp
src/graphics/display.cpp
src/graphics/display.hpp
src/graphics/display_surface.cpp
src/graphics/display_surface.hpp
src/graphics/log.cpp
src/graphics/log.hpp
src/graphics/instance.cpp
src/graphics/instance.hpp
src/graphics/physical_device.cpp
src/graphics/physical_device.hpp
src/graphics/surface.cpp
src/graphics/surface.hpp
src/graphics/swapchain.cpp
src/graphics/swapchain.hpp
src/graphics/vulkan.cpp
src/graphics/vulkan.hpp
src/graphics/xcb_surface.cpp
src/graphics/xcb_surface.hpp
src/log/log.cpp
src/log/log.hpp
)
set_target_properties(executable PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED ON)
add_subdirectory(subprojects/fmt)
add_subdirectory(subprojects/GSL)
find_package(XCB REQUIRED)
target_include_directories(executable PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
# ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/Vulkan-Headers/include
${XCB_INCLUDE_DIRS}
)
target_link_libraries(executable PRIVATE
fmt::fmt
Microsoft.GSL::GSL
Vulkan::Vulkan
Vulkan::Headers
${XCB_LIBRARIES}
)