1 # Copyright (c) 2019-2021 Arm Limited.
3 # SPDX-License-Identifier: MIT
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to
7 # deal in the Software without restriction, including without limitation the
8 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 # sell copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in all
13 # copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 cmake_minimum_required(VERSION 3.4.3)
24 project(VkLayer_window_system_integration)
26 find_package(PkgConfig REQUIRED)
27 pkg_check_modules(VULKAN_PKG_CONFIG vulkan)
29 find_program(CLANG_TIDY clang-tidy-8)
31 if (NOT CLANG_TIDY STREQUAL "CLANG_TIDY-NOTFOUND")
32 message(STATUS "Using clang-tidy: ${CLANG_TIDY}")
33 set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY} -checks=bugprone-*,modernize-*)
36 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread -fPIC")
37 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
38 set(CMAKE_CXX_STANDARD 11)
40 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
41 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
42 set(CMAKE_C_VISIBILITY_PRESET hidden)
44 if(NOT DEFINED VULKAN_CXX_INCLUDE)
45 set(VULKAN_CXX_INCLUDE ${VULKAN_PKG_CONFIG_INCLUDEDIR})
48 if(DEFINED VULKAN_CXX_INCLUDE)
49 message(STATUS "Using Vulkan include directories: ${VULKAN_CXX_INCLUDE}")
50 separate_arguments(VULKAN_CXX_INCLUDE)
52 message(FATAL_ERROR "Either vulkan.pc must be available or VULKAN_CXX_INCLUDE must be defined")
55 # Build Configuration options
56 option(BUILD_WSI_HEADLESS "Build with support for VK_EXT_headless_surface" ON)
57 option(BUILD_WSI_WAYLAND "Build with support for VK_KHR_wayland_surface" OFF)
58 set(SELECT_EXTERNAL_ALLOCATOR "none" CACHE STRING "Select an external system allocator (none, ion)")
59 set(EXTERNAL_WSIALLOC_LIBRARY "" CACHE STRING "External implementation of the wsialloc interface to use")
62 if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "none")
63 message(FATAL_ERROR "Wayland only supported with an external allocator.")
65 set(BUILD_DRM_UTILS True)
70 add_library(drm_utils STATIC util/drm/drm_utils.cpp)
72 pkg_check_modules(LIBDRM REQUIRED libdrm)
73 message(STATUS "Using libdrm include directories: ${LIBDRM_INCLUDE_DIRS}")
74 message(STATUS "Using libdrm cflags: ${LIBDRM_CFLAGS}")
76 target_sources(drm_utils PRIVATE util/drm/format_table.c)
77 target_include_directories(drm_utils PRIVATE ${VULKAN_CXX_INCLUDE})
78 target_include_directories(drm_utils PUBLIC ${LIBDRM_INCLUDE_DIRS})
79 target_include_directories(drm_utils PUBLIC util/wsialloc)
80 target_compile_options(drm_utils PUBLIC ${LIBDRM_CFLAGS})
83 # External WSI Allocator
84 if(NOT SELECT_EXTERNAL_ALLOCATOR STREQUAL "none" AND EXTERNAL_WSIALLOC_LIBRARY STREQUAL "")
85 add_library(wsialloc STATIC)
86 set_target_properties(wsialloc PROPERTIES C_STANDARD 99)
88 if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "ion")
89 target_sources(wsialloc PRIVATE util/wsialloc/wsialloc_ion.c)
90 target_link_libraries(wsialloc drm_utils)
91 if(DEFINED KERNEL_DIR)
92 target_include_directories(wsialloc PRIVATE "${KERNEL_DIR}/drivers/staging/android/uapi")
94 message(FATAL_ERROR "KERNEL_DIR must be defined as the root of the Linux kernel source.")
97 message(FATAL_ERROR "Invalid external allocator selected: ${SELECT_EXTERNAL_ALLOCATOR}")
100 target_include_directories(wsialloc PRIVATE ${VULKAN_CXX_INCLUDE})
101 target_include_directories(wsialloc PRIVATE util/drm)
105 if(BUILD_WSI_WAYLAND)
106 add_library(wayland_wsi STATIC
107 wsi/wayland/surface_properties.cpp
108 wsi/wayland/surface.cpp
109 wsi/wayland/wl_helpers.cpp
110 wsi/wayland/swapchain.cpp)
112 pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client)
113 message(STATUS "Using Wayland client include directories: ${WAYLAND_CLIENT_INCLUDE_DIRS}")
114 message(STATUS "Using Wayland client cflags: ${WAYLAND_CLIENT_CFLAGS}")
115 message(STATUS "Using Wayland client ldflags: ${WAYLAND_CLIENT_LDFLAGS}")
117 pkg_check_modules(WAYLAND_SCANNER REQUIRED wayland-scanner)
118 pkg_get_variable(WAYLAND_SCANNER_EXEC wayland-scanner wayland_scanner)
119 message(STATUS "Using wayland-scanner : ${WAYLAND_SCANNER_EXEC}")
121 pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
122 pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
123 message(STATUS "Using wayland protocols dir : ${WAYLAND_PROTOCOLS_DIR}")
125 add_custom_target(wayland_generated_files
126 COMMAND ${WAYLAND_SCANNER_EXEC} client-header
127 ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
128 ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-client-protocol.h
129 COMMAND ${WAYLAND_SCANNER_EXEC} code
130 ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
131 ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-protocol.c
132 COMMAND ${WAYLAND_SCANNER_EXEC} client-header
133 ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
134 ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.h
135 COMMAND ${WAYLAND_SCANNER_EXEC} code
136 ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
137 ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.c
138 BYPRODUCTS linux-dmabuf-unstable-v1-protocol.c linux-dmabuf-unstable-v1-client-protocol.h
139 linux-explicit-synchronization-unstable-v1-protocol.c linux-explicit-synchronization-unstable-v1-protocol.h)
141 target_sources(wayland_wsi PRIVATE
142 ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-protocol.c
143 ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-client-protocol.h
144 ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.c
145 ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.h)
146 add_dependencies(wayland_wsi wayland_generated_files)
148 target_include_directories(wayland_wsi PRIVATE
149 ${PROJECT_SOURCE_DIR}
150 ${VULKAN_CXX_INCLUDE}
151 ${WAYLAND_CLIENT_INCLUDE_DIRS}
152 ${CMAKE_CURRENT_BINARY_DIR})
154 target_compile_options(wayland_wsi PRIVATE ${WAYLAND_CLIENT_CFLAGS})
155 target_compile_options(wayland_wsi INTERFACE "-DBUILD_WSI_WAYLAND=1")
156 if(NOT EXTERNAL_WSIALLOC_LIBRARY STREQUAL "")
157 target_link_libraries(wayland_wsi ${EXTERNAL_WSIALLOC_LIBRARY})
159 target_link_libraries(wayland_wsi wsialloc)
161 target_link_libraries(wayland_wsi drm_utils ${WAYLAND_CLIENT_LDFLAGS})
162 list(APPEND LINK_WSI_LIBS wayland_wsi)
164 list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_KHR_wayland_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json)
168 if(BUILD_WSI_HEADLESS)
169 add_library(wsi_headless STATIC
170 wsi/headless/surface_properties.cpp
171 wsi/headless/surface.cpp
172 wsi/headless/swapchain.cpp)
174 target_include_directories(wsi_headless PRIVATE
175 ${PROJECT_SOURCE_DIR}
176 ${VULKAN_CXX_INCLUDE}
177 ${CMAKE_CURRENT_BINARY_DIR})
179 target_compile_options(wsi_headless INTERFACE "-DBUILD_WSI_HEADLESS=1")
180 list(APPEND LINK_WSI_LIBS wsi_headless)
182 list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_EXT_headless_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json)
186 add_library(${PROJECT_NAME} SHARED
188 layer/private_data.cpp
189 layer/surface_api.cpp
190 layer/swapchain_api.cpp
191 util/timed_semaphore.cpp
192 util/custom_allocator.cpp
193 util/extension_list.cpp
195 wsi/swapchain_base.cpp
196 wsi/synchronization.cpp
199 target_compile_definitions(${PROJECT_NAME} PRIVATE ${WSI_DEFINES})
200 target_include_directories(${PROJECT_NAME} PRIVATE
201 ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${VULKAN_CXX_INCLUDE})
203 target_link_libraries(${PROJECT_NAME} ${LINK_WSI_LIBS})
205 add_custom_target(manifest_json ALL COMMAND
206 cp ${PROJECT_SOURCE_DIR}/layer/VkLayer_window_system_integration.json ${CMAKE_CURRENT_BINARY_DIR}