forked from LunarG/VulkanTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
233 lines (189 loc) · 9.87 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
cmake_minimum_required(VERSION 2.8.11)
project (VULKAN_TOOLS)
set(API_NAME "Vulkan" CACHE STRING "API name")
add_definitions(-DAPI_NAME="${API_NAME}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Define GNU standard installation directories.
include(GNUInstallDirs)
# Set a better default install location for Windows only if the user did not provide one.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
endif()
# Find Vulkan Headers, Loader, and ValidationLayers
# Search order:
# User-supplied CMAKE_PREFIX_PATH containing paths to the header and/or loader install dirs
# CMake options VULKAN_HEADERS_INSTALL_DIR, VULKAN_LOADER_INSTALL_DIR, and/or VULKAN_VALIDATIONLAYERS_INSTALL_DIR
# Env vars VULKAN_HEADERS_INSTALL_DIR, VULKAN_LOADER_INSTALL_DIR, and/or VULKAN_VALIDATIONLAYERS_INSTALL_DIR
# Fallback to FindVulkan operation using SDK install or system installed components.
set(VULKAN_HEADERS_INSTALL_DIR "HEADERS-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Headers install directory")
set(VULKAN_LOADER_INSTALL_DIR "LOADER-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Loader install directory")
set(VULKAN_VALIDATIONLAYERS_INSTALL_DIR "VALIDATIONLAYERS-NOTFOUND" CACHE PATH "Absolute path to Vulkan-ValidationLayers directory")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};${VULKAN_HEADERS_INSTALL_DIR};${VULKAN_LOADER_INSTALL_DIR};${VULKAN_VALIDATIONLAYERS_INSTALL_DIR};$ENV{VULKAN_HEADERS_INSTALL_DIR};$ENV{VULKAN_LOADER_INSTALL_DIR};$ENV{VULKAN_VALIDATIONLAYERS_INSTALL_DIR})
message(STATUS "Using find_package to locate Vulkan")
find_package(Vulkan)
message(STATUS "Vulkan FOUND = ${Vulkan_FOUND}")
message(STATUS "Vulkan Include = ${Vulkan_INCLUDE_DIR}")
message(STATUS "Vulkan Lib = ${Vulkan_LIBRARY}")
if(NOT VULKAN_HEADERS_INSTALL_DIR AND NOT DEFINED ENV{VULKAN_HEADERS_INSTALL_DIR})
message(FATAL_ERROR "Must define location of Vulkan-Headers install -- see BUILD.md")
endif()
# Cmake command line option overrides environment variable
if(NOT VULKAN_HEADERS_INSTALL_DIR)
set(VULKAN_HEADERS_INSTALL_DIR $ENV{VULKAN_HEADERS_INSTALL_DIR})
endif()
message(STATUS "Using Vulkan-Headers install located at ${VULKAN_HEADERS_INSTALL_DIR}")
if(NOT VULKAN_LOADER_INSTALL_DIR AND NOT DEFINED ENV{VULKAN_LOADER_INSTALL_DIR})
message(FATAL_ERROR "Must define location of Vulkan-Loader install -- see BUILD.md")
endif()
# Cmake command line option overrides environment variable
if(NOT VULKAN_LOADER_INSTALL_DIR)
set(VULKAN_LOADER_INSTALL_DIR $ENV{VULKAN_LOADER_INSTALL_DIR})
endif()
message(STATUS "Using Vulkan-Loader install located at ${VULKAN_LOADER_INSTALL_DIR}")
if(NOT VULKAN_VALIDATIONLAYERS_INSTALL_DIR AND NOT DEFINED ENV{VULKAN_VALIDATIONLAYERS_INSTALL_DIR})
message(FATAL_ERROR "Must define location of Vulkan-ValidationLayers install -- see BUILD.md")
endif()
# Cmake command line option overrides environment variable
if(NOT VULKAN_VALIDATIONLAYERS_INSTALL_DIR)
set(VULKAN_VALIDATIONLAYERS_INSTALL_DIR $ENV{VULKAN_VALIDATIONLAYERS_INSTALL_DIR})
endif()
message(STATUS "Using Vulkan-ValidationLayers install located at ${VULKAN_VALIDATIONLAYERS_INSTALL_DIR}")
set(Vulkan-ValidationLayers_INCLUDE_DIR "${VULKAN_VALIDATIONLAYERS_INSTALL_DIR}/include")
set(Vulkan-ValidationLayers_LIBRARY_DIR "${VULKAN_VALIDATIONLAYERS_INSTALL_DIR}/lib")
find_library(VkLayer_utils_LIBRARY VkLayer_utils HINTS ${Vulkan-ValidationLayers_LIBRARY_DIR})
find_package(PythonInterp 3 REQUIRED)
set (PYTHON_CMD ${PYTHON_EXECUTABLE})
# Enable cmake folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(VULKANTOOLS_TARGET_FOLDER vt_cmake_targets)
option(USE_CCACHE "Use ccache" OFF)
if (USE_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(FALLBACK_CONFIG_DIRS "/etc/xdg" CACHE STRING
"Search path to use when XDG_CONFIG_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant.")
set(FALLBACK_DATA_DIRS "/usr/local/share:/usr/share" CACHE STRING
"Search path to use when XDG_DATA_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant.")
include(FindPkgConfig)
option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
option(BUILD_WSI_MIR_SUPPORT "Build Mir WSI support" OFF)
set(DEMOS_WSI_SELECTION "XCB" CACHE STRING "Select WSI target for demos (XCB, XLIB, WAYLAND, MIR, DISPLAY)")
set(VKREPLAY_WSI_SELECTION "XCB" CACHE STRING "Select WSI target for vkreplay (XCB, WAYLAND, DISPLAY)")
if (BUILD_WSI_XCB_SUPPORT)
find_package(XCB REQUIRED)
endif()
if (BUILD_WSI_XLIB_SUPPORT)
find_package(X11 REQUIRED)
endif()
if (BUILD_WSI_WAYLAND_SUPPORT)
find_package(Wayland REQUIRED)
include_directories(${WAYLAND_CLIENT_INCLUDE_DIR})
endif()
if(BUILD_WSI_MIR_SUPPORT)
find_package(Mir REQUIRED)
endif()
endif()
set (VULKAN_SDK $ENV{VULKAN_SDK})
# NOTE: jsoncpp is located in SUBPROJECTS_DIR.
set (SUBPROJECTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/submodules)
set(VULKANTOOLS_SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
# Header file for CMake settings
find_package(VulkanHeaders)
include_directories(${VulkanHeaders_INCLUDE_DIR} ${PROJECT_BINARY_DIR}/${VALIDATION_LAYERS_RELATIVE_LOCATION})
# The vulkan loader search is:
# User-supplied setting of CMAKE_PREFIX_PATH
# VULKAN_LOADER_INSTALL_DIR defined via cmake option
# VULKAN_LOADER_INSTALL_DIR defined via environment variable
# Default findVulkan operation if the VULKAN_SDK environment variable is defined
set(VULKAN_LOADER_INSTALL_DIR "LOADER-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Loader install directory")
if (VULKAN_LOADER_INSTALL_DIR)
message(STATUS "VULKAN_LOADER_INSTALL_DIR specified, using find_package to locate Vulkan")
elseif(ENV{VULKAN_LOADER_INSTALL_DIR})
message(STATUS "VULKAN_LOADER_INSTALL_DIR environment variable specified, using find_package to locate Vulkan")
endif()
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};${VULKAN_LOADER_INSTALL_DIR};${VULKAN_HEADERS_INSTALL_DIR};$ENV{VULKAN_LOADER_INSTALL_DIR};$ENV{VULKAN_HEADERS_INSTALL_DIR})
find_package(Vulkan)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR
CMAKE_SYSTEM_NAME STREQUAL "Linux")
option(BUILD_TESTS "Build tests" ON)
option(BUILD_LAYERSVT "Build layersvt" ON)
option(BUILD_VLF "Build layer_factory" ON)
option(BUILD_VKTRACE "Build VkTrace" ON)
option(BUILD_VIA "Build via" ON)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT (BUILD_WSI_XCB_SUPPORT OR BUILD_WSI_WAYLAND_SUPPORT))
option(BUILD_VKTRACE_REPLAY "Build VkReplay" OFF)
else()
option(BUILD_VKTRACE_REPLAY "Build VkReplay" ON)
endif()
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Only vktrace enable for macOS
option(BUILD_VKTRACE ON)
option(BUILD_LOADER OFF)
option(BUILD_TESTS OFF)
option(BUILD_LAYERS OFF)
option(BUILD_LAYERSVT OFF)
option(BUILD_VLF OFF)
option(BUILD_VKTRACEVIEWER OFF)
option(BUILD_DEMOS OFF)
option(BUILD_VKJSON OFF)
option(BUILD_VIA OFF)
option(BUILD_VKTRACE_LAYER OFF)
option(BUILD_VKTRACE_REPLAY OFF)
endif()
find_path(JSONCPP_INCLUDE_DIR json/json.h HINTS "${SUBPROJECTS_DIR}/jsoncpp/dist"
"${SUBPROJECTS_DIR}/JsonCpp/dist"
"${SUBPROJECTS_DIR}/JsonCPP/dist"
"${SUBPROJECTS_DIR}/JSONCPP/dist"
"${CMAKE_SOURCE_DIR}/../jsoncpp/dist"
DOC "Path to jsoncpp/dist/json/json.h")
find_path(JSONCPP_SOURCE_DIR jsoncpp.cpp HINTS "${SUBPROJECTS_DIR}/jsoncpp/dist"
"${SUBPROJECTS_DIR}/JsonCpp/dist"
"${SUBPROJECTS_DIR}/JsonCPP/dist"
"${SUBPROJECTS_DIR}/JSONCPP/dist"
"${CMAKE_SOURCE_DIR}/../jsoncpp/dist"
DOC "Path to jsoncpp/dist/json.cpp")
find_library(JSONCPP_LIB NAMES jsoncpp HINTS ${JSONCPP_SEARCH_PATH} )
if (WIN32)
add_library(jsoncpp STATIC IMPORTED)
find_library(JSONCPP_DLIB NAMES jsoncpp
HINTS ${JSONCPP_DEBUG_SEARCH_PATH} )
set_target_properties(jsoncpp PROPERTIES
IMPORTED_LOCATION "${JSONCPP_LIB}"
IMPORTED_LOCATION_DEBUG "${JSONCPP_DLIB}")
endif()
# Define macro used for building vkxml generated files
macro(run_vulkantools_vk_xml_generate dependency output)
add_custom_command(OUTPUT ${output}
COMMAND ${PYTHON_CMD} ${VULKANTOOLS_SCRIPTS_DIR}/vt_genvk.py -registry ${VulkanRegistry_DIR}/vk.xml -scripts ${VulkanRegistry_DIR} ${output}
DEPENDS ${VulkanRegistry_DIR}/vk.xml ${VulkanRegistry_DIR}/generator.py ${VULKANTOOLS_SCRIPTS_DIR}/${dependency} ${VULKANTOOLS_SCRIPTS_DIR}/vt_genvk.py ${VulkanRegistry_DIR}/reg.py
)
endmacro()
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
if(BUILD_VLF)
add_subdirectory(layer_factory)
endif()
if(BUILD_LAYERSVT)
add_subdirectory(layersvt)
endif()
if(BUILD_VKTRACE)
add_subdirectory(vktrace)
endif()
if(BUILD_VIA)
add_subdirectory(via)
endif()
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)