-
Notifications
You must be signed in to change notification settings - Fork 500
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
285 lines (248 loc) · 11.1 KB
/
Copy pathCMakeLists.txt
File metadata and controls
285 lines (248 loc) · 11.1 KB
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
# ~~~
# Copyright (c) 2014-2026 Valve Corporation
# Copyright (c) 2014-2026 LunarG, Inc.
#
# 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.
# ~~~
cmake_minimum_required(VERSION 3.22.1)
# The VERSION field is generated with the "--generated-version" flag in the generate_source.py script
#
# If working with unreleased extensions, make sure the header and validation version are all on the same header version
project(VVL VERSION 1.4.362 LANGUAGES CXX)
# This variable enables downstream users to customize the target API
# variant (e.g. Vulkan SC)
set(API_TYPE "vulkan")
add_subdirectory(scripts)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
set(CMAKE_VISIBILITY_INLINES_HIDDEN "YES")
include(GNUInstallDirs)
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Remove when min is 3.26, see CMP0143
add_compile_definitions(VK_ENABLE_BETA_EXTENSIONS)
if(WIN32)
add_compile_definitions(VK_USE_PLATFORM_WIN32_KHR)
# Allow usage of unsafe CRT functions and minimize what Windows.h leaks
add_compile_definitions(_CRT_SECURE_NO_WARNINGS NOMINMAX WIN32_LEAN_AND_MEAN)
elseif(ANDROID)
add_compile_definitions(VK_USE_PLATFORM_ANDROID_KHR)
elseif(APPLE)
add_compile_definitions(VK_USE_PLATFORM_METAL_EXT)
if (IOS)
add_compile_definitions(VK_USE_PLATFORM_IOS_MVK)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_definitions(VK_USE_PLATFORM_MACOS_MVK)
endif()
else()
option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
option(BUILD_WSI_XLIB_XRANDR_SUPPORT "Build X11 Xrandr WSI support" ON)
option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
if (BUILD_WSI_XCB_SUPPORT OR BUILD_WSI_XLIB_SUPPORT OR BUILD_WSI_WAYLAND_SUPPORT)
find_package(PkgConfig REQUIRED QUIET)
endif()
if(BUILD_WSI_XCB_SUPPORT)
pkg_check_modules(XCB REQUIRED QUIET IMPORTED_TARGET xcb)
add_compile_definitions(VK_USE_PLATFORM_XCB_KHR)
endif()
if(BUILD_WSI_XLIB_SUPPORT)
pkg_check_modules(X11 REQUIRED QUIET IMPORTED_TARGET x11)
add_compile_definitions(VK_USE_PLATFORM_XLIB_KHR)
if(BUILD_WSI_XLIB_XRANDR_SUPPORT)
pkg_check_modules(XRANDR REQUIRED QUIET IMPORTED_TARGET xrandr)
add_compile_definitions(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
endif()
endif()
if(BUILD_WSI_WAYLAND_SUPPORT)
pkg_check_modules(WAYlAND_CLIENT QUIET REQUIRED IMPORTED_TARGET wayland-client)
add_compile_definitions(VK_USE_PLATFORM_WAYLAND_KHR)
endif()
endif()
# Tracy
option(VVL_ENABLE_TRACY "Enable profiling with Tracy" OFF)
option(VVL_ENABLE_TRACY_CPU_MEMORY "Enable profiling memory with Tracy" OFF)
option(VVL_TRACY_CALLSTACK "Size of the collected collected call stacks" 48)
if (VVL_ENABLE_TRACY)
if(VVL_ENABLE_TRACY_CPU_MEMORY AND USE_MIMALLOC)
message(FATAL_ERROR "Tracy cannot be used with mimalloc")
endif()
if (VVL_TRACY_CALLSTACK STREQUAL "OFF")
set(VVL_TRACY_CALLSTACK 48)
endif()
add_compile_definitions(
TRACY_ENABLE
TRACY_CALLSTACK=${VVL_TRACY_CALLSTACK}
TRACY_DELAYED_INIT
TRACY_MANUAL_LIFETIME
)
if(VVL_ENABLE_TRACY_CPU_MEMORY)
add_compile_definitions(VVL_TRACY_CPU_MEMORY)
endif()
if(VVL_ENABLE_TRACY_GPU)
add_compile_definitions(
VVL_TRACY_GPU
TRACY_VK_USE_SYMBOL_TABLE
)
endif()
endif()
find_package(VulkanHeaders ${PROJECT_VERSION} CONFIG QUIET)
find_package(VulkanUtilityLibraries CONFIG QUIET)
find_package(SPIRV-Headers CONFIG QUIET)
find_package(SPIRV-Tools-opt CONFIG QUIET)
# Workaround AppleClang using the wrong headers when there are headers in /usr/local/include
if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang AND TARGET Vulkan::Headers AND TARGET Vulkan::LayerSettings
AND TARGET SPIRV-Headers::SPIRV-Headers AND TARGET SPIRV-Tools-static AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.25)
get_target_property(vulkan_headers_aliased Vulkan::Headers ALIASED_TARGET)
if (NOT vulkan_headers_aliased)
set_target_properties(Vulkan::Headers PROPERTIES SYSTEM OFF)
endif()
get_target_property(vulkan_utilities_aliased Vulkan::LayerSettings ALIASED_TARGET)
if (NOT vulkan_utilities_aliased)
set_target_properties(Vulkan::LayerSettings PROPERTIES SYSTEM OFF)
set_target_properties(Vulkan::SafeStruct PROPERTIES SYSTEM OFF)
set_target_properties(Vulkan::UtilityHeaders PROPERTIES SYSTEM OFF)
endif()
get_target_property(spirv_headers_aliased SPIRV-Headers::SPIRV-Headers ALIASED_TARGET)
if (NOT spirv_headers_aliased)
set_target_properties(SPIRV-Headers::SPIRV-Headers PROPERTIES SYSTEM OFF)
endif()
get_target_property(spirv_tools_opt_aliased SPIRV-Tools-opt ALIASED_TARGET)
if (NOT spirv_tools_opt_aliased)
set_target_properties(SPIRV-Tools-static PROPERTIES SYSTEM OFF)
set_target_properties(SPIRV-Tools-opt PROPERTIES SYSTEM OFF)
endif()
endif()
# NOTE: Our custom code generation target isn't desirable for system package managers or add_subdirectory users.
# So this target needs to be off by default to avoid obtuse build errors or patches.
option(VVL_CODEGEN "Enable vulkan validation layer code generation")
if (VVL_CODEGEN)
find_package(Python3 REQUIRED)
add_custom_target(vvl_codegen
COMMAND Python3::Interpreter "${VVL_SOURCE_DIR}/scripts/generate_source.py"
"${VULKAN_HEADERS_INSTALL_DIR}/${CMAKE_INSTALL_DATADIR}/vulkan/registry"
"${SPIRV_HEADERS_INSTALL_DIR}/include/spirv/unified1"
--incremental --generated-version ${VulkanHeaders_VERSION} --api ${API_TYPE}
WORKING_DIRECTORY ${VVL_SOURCE_DIR}/layers/${API_TYPE}/generated
)
endif()
if (ANNOTATED_SPEC_LINK)
message("ANNOTATED_SPEC_LINK is ${ANNOTATED_SPEC_LINK}")
add_compile_definitions(ANNOTATED_SPEC_LINK=${ANNOTATED_SPEC_LINK})
endif()
# The idiom for open source projects is to NOT enable warnings as errors.
# System/language package managers have to build on multiple different platforms and compilers.
# By defaulting to `ON` we cause issues for package managers since there is no standard way to disable warnings until CMake 3.24
option(BUILD_WERROR "Treat compiler warnings as errors")
if (BUILD_WERROR)
add_compile_options("$<IF:$<CXX_COMPILER_ID:MSVC>,/WX,-Werror>")
# MSVC only: turns link.exe warnings (e.g. LNK4098, mismatched Debug/Release runtimes) into
# build failures too. There's no cross-platform link.exe/ld equivalent to add here.
# TODO: replace with CMAKE_LINK_WARNING_AS_ERROR once the minimum CMake version is >= 4.0.
#
# LNK4099 (PDB for a prebuilt dependency .lib not found) is ignored: it's a pre-existing,
# benign issue independent of this fix - our dependencies' static libraries don't carry
# their compiler-generated PDBs (CMake's COMPILE_PDB_NAME isn't installable for STATIC_LIBRARY
# targets via $<TARGET_PDB_FILE:...>), so the linker always falls back to no debug info for
# those objects. It was already happening before /WX was added to the linker; /WX would just
# newly turn it into a hard failure. Fixing it for real means installing each dependency's own
# PDB, which requires patching that dependency's CMakeLists.txt, not something to do here.
add_link_options("$<$<CXX_COMPILER_ID:MSVC>:/WX;/IGNORE:4099>")
endif()
option(VVL_ENABLE_ASAN "Use address sanitization")
if (VVL_ENABLE_ASAN)
add_compile_options(-fsanitize=address)
if (NOT MSVC)
add_link_options(-fsanitize=address)
endif()
endif()
option(VVL_ENABLE_UBSAN "Use undefined behavior sanitization")
if (VVL_ENABLE_UBSAN)
if (NOT MSVC)
add_compile_options(-fsanitize=undefined)
add_link_options(-fsanitize=undefined)
# VVL's test-suites deliberately use invalid enum values.
# This creates a lot of false positives.
add_compile_options(-fno-sanitize=enum)
endif()
endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU|Clang)")
add_compile_options(
-Wall
-Wextra
-Wpointer-arith
)
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options(
-Wconversion
-Wimplicit-fallthrough
-Wstring-conversion
# When using tools such as lldb, strings will produce "error: summary string parsing error"
$<$<CONFIG:Debug>:-fstandalone-debug>
)
endif()
elseif(MSVC)
add_compile_options(
/W4
/we5038 # Enable warning about MIL ordering in constructors
)
# Enforce stricter ISO C++
add_compile_options(/permissive-)
add_compile_options(/utf-8)
# PDBs aren't generated on Release builds by default.
add_compile_options("$<$<CONFIG:Release>:/Zi>")
add_link_options("$<$<CONFIG:Release>:/DEBUG:FULL>")
# Enable /LTCG (Link-time code generation)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
# Remove unreferenced code/data.
add_link_options("$<$<CONFIG:Release>:/OPT:REF>")
# Merge duplicate data/functions
add_link_options("$<$<CONFIG:Release>:/OPT:ICF>")
add_compile_options($<$<BOOL:${MSVC_IDE}>:/MP>) # Speed up Visual Studio builds
endif()
add_subdirectory(layers)
if(MSVC AND UPDATE_DEPS)
set(SCRIPTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/scripts")
file(GLOB_RECURSE SCRIPTS
"${SCRIPTS_DIR}/*.py"
"${SCRIPTS_DIR}/*.json"
)
add_custom_target(Scripts SOURCES ${SCRIPTS})
source_group(TREE ${SCRIPTS_DIR} PREFIX "Scripts" FILES ${SCRIPTS})
set(EXTERNAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external")
file(GLOB_RECURSE EXTERNAL_HEADER_FILES
"${GLSLANG_INSTALL_DIR}/*.h"
"${GLSLANG_INSTALL_DIR}/*.hpp"
"${VULKAN_HEADERS_INSTALL_DIR}/*.h"
"${VULKAN_HEADERS_INSTALL_DIR}/*.hpp"
"${VULKAN_UTILITY_LIBRARIES_INSTALL_DIR}/*.h"
"${VULKAN_UTILITY_LIBRARIES_INSTALL_DIR}/*.hpp"
"${SPIRV_HEADERS_INSTALL_DIR}/*.h"
"${SPIRV_HEADERS_INSTALL_DIR}/*.hpp"
"${SPIRV_TOOLS_INSTALL_DIR}/*.h"
"${SPIRV_TOOLS_INSTALL_DIR}/*.hpp"
"${GOOGLETEST_INSTALL_DIR}/*.h"
"${MIMALLOC_INSTALL_DIR}/*.h"
)
add_custom_target(External SOURCES ${EXTERNAL_HEADER_FILES})
source_group(TREE ${EXTERNAL_DIR} PREFIX "External" FILES ${EXTERNAL_HEADER_FILES})
endif()
option(BUILD_TESTS "Build the tests")
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
# Set tests as Visual Studio startup project
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT vk_layer_validation_tests)
endif()