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 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread -fPIC")
31 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
33 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
34 set(CMAKE_CXX_STANDARD 11)
36 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
38 if(NOT DEFINED VULKAN_CXX_INCLUDE)
39 set(VULKAN_CXX_INCLUDE ${VULKAN_PKG_CONFIG_INCLUDEDIR})
42 if(DEFINED VULKAN_CXX_INCLUDE)
43 message(STATUS "Using Vulkan include directories: ${VULKAN_CXX_INCLUDE}")
44 separate_arguments(VULKAN_CXX_INCLUDE)
46 message(FATAL_ERROR "Either vulkan.pc must be available or VULKAN_CXX_INCLUDE must be defined")
49 # Build Configuration options
50 option(BUILD_WSI_WAYLAND "Build with support for VK_KHR_wayland_surface" OFF)
51 set(SELECT_EXTERNAL_ALLOCATOR "none" CACHE STRING "Select an external system allocator (none, ion)")
53 option(BUILD_WSI_TIZEN "Build with support for VK_KHR_wayland_surface(For Tizen platform)" OFF)
56 if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "none")
57 message(FATAL_ERROR "Wayland only supported with an external allocator.")
59 set(BUILD_DRM_UTILS True)
64 add_library(drm_utils STATIC util/drm/drm_utils.cpp)
66 pkg_check_modules(LIBDRM REQUIRED libdrm)
67 message(STATUS "Using libdrm include directories: ${LIBDRM_INCLUDE_DIRS}")
68 message(STATUS "Using libdrm cflags: ${LIBDRM_CFLAGS}")
70 target_sources(drm_utils PRIVATE util/drm/format_table.c)
71 target_include_directories(drm_utils PRIVATE ${VULKAN_CXX_INCLUDE})
72 target_include_directories(drm_utils PUBLIC ${LIBDRM_INCLUDE_DIRS})
73 target_compile_options(drm_utils PUBLIC ${LIBDRM_CFLAGS})
76 # External WSI Alloctator
77 if(NOT SELECT_EXTERNAL_ALLOCATOR STREQUAL "none")
78 add_library(wsialloc STATIC)
79 set_target_properties(wsialloc PROPERTIES C_STANDARD 99)
81 if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "ion")
82 target_sources(wsialloc PRIVATE util/wsialloc/wsialloc_ion.c)
83 target_link_libraries(wsialloc drm_utils)
84 if(DEFINED KERNEL_DIR)
85 target_include_directories(wsialloc PRIVATE "${KERNEL_DIR}/drivers/staging/android/uapi")
87 message(FATAL_ERROR "KERNEL_DIR must be defined as the root of the Linux kernel source.")
90 message(FATAL_ERROR "Invalid external allocator selected: ${SELECT_EXTERNAL_ALLOCATOR}")
93 target_include_directories(wsialloc PRIVATE ${VULKAN_CXX_INCLUDE})
94 target_include_directories(wsialloc PRIVATE util/drm)
99 add_library(wayland_wsi STATIC
100 wsi/wayland/surface_properties.cpp
101 wsi/wayland/swapchain_wl_helpers.cpp
102 wsi/wayland/swapchain.cpp)
104 pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client)
105 message(STATUS "Using Wayland client include directories: ${WAYLAND_CLIENT_INCLUDE_DIRS}")
106 message(STATUS "Using Wayland client cflags: ${WAYLAND_CLIENT_CFLAGS}")
107 message(STATUS "Using Wayland client ldflags: ${WAYLAND_CLIENT_LDFLAGS}")
109 pkg_check_modules(WAYLAND_SCANNER REQUIRED wayland-scanner)
110 pkg_get_variable(WAYLAND_SCANNER_EXEC wayland-scanner wayland_scanner)
111 message(STATUS "Using wayland-scanner : ${WAYLAND_SCANNER_EXEC}")
113 pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
114 pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
115 message(STATUS "Using wayland protocols dir : ${WAYLAND_PROTOCOLS_DIR}")
117 add_custom_target(wayland_generated_files
118 COMMAND ${WAYLAND_SCANNER_EXEC} client-header
119 ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
120 ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-client-protocol.h
121 COMMAND ${WAYLAND_SCANNER_EXEC} code
122 ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
123 ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-protocol.c
124 BYPRODUCTS linux-dmabuf-unstable-v1-protocol.c linux-dmabuf-unstable-v1-client-protocol.h)
126 target_sources(wayland_wsi PRIVATE
127 ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-protocol.c
128 ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-client-protocol.h)
129 add_dependencies(wayland_wsi wayland_generated_files)
131 target_include_directories(wayland_wsi PRIVATE
132 ${PROJECT_SOURCE_DIR}
133 ${VULKAN_CXX_INCLUDE}
134 ${WAYLAND_CLIENT_INCLUDE_DIRS}
135 ${CMAKE_CURRENT_BINARY_DIR})
137 target_compile_options(wayland_wsi PRIVATE ${WAYLAND_CLIENT_CFLAGS})
138 target_compile_options(wayland_wsi INTERFACE "-DBUILD_WSI_WAYLAND=1")
139 target_link_libraries(wayland_wsi drm_utils wsialloc ${WAYLAND_CLIENT_LDFLAGS})
140 list(APPEND LINK_WSI_LIBS wayland_wsi)
141 elseif(BUILD_WSI_TIZEN)
142 add_library(tizen_wsi STATIC
143 wsi/tizen/surface_properties.cpp
144 wsi/tizen/swapchain.cpp)
146 pkg_check_modules(LIBDRM REQUIRED libdrm)
147 message(STATUS "Using libdrm include directories: ${LIBDRM_INCLUDE_DIRS}")
149 target_include_directories(tizen_wsi PRIVATE
150 ${PROJECT_SOURCE_DIR}
151 ${VULKAN_CXX_INCLUDE}
152 ${CMAKE_CURRENT_BINARY_DIR}
153 ${LIBDRM_INCLUDE_DIRS})
155 target_compile_options(tizen_wsi INTERFACE "-DBUILD_WSI_TIZEN=1")
156 target_link_libraries(tizen_wsi dlog tbm tpl-egl)
157 list(APPEND LINK_WSI_LIBS tizen_wsi)
159 list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_KHR_wayland_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json)
164 set(WSI_PLATFORM_SPECIFIED wsi/swapchain_base_tizen.cpp)
166 set(WSI_PLATFORM_SPECIFIED wsi/swapchain_base.cpp wsi/headless/surface_properties.cpp wsi/headless/swapchain.cpp)
168 add_library(${PROJECT_NAME} SHARED
170 layer/private_data.cpp
171 layer/surface_api.cpp
172 layer/swapchain_api.cpp
173 util/timed_semaphore.cpp
174 util/custom_allocator.cpp
175 util/extension_list.cpp
177 ${WSI_PLATFORM_SPECIFIED})
178 target_compile_definitions(${PROJECT_NAME} PRIVATE ${WSI_DEFINES})
179 target_include_directories(${PROJECT_NAME} PRIVATE
180 ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${VULKAN_CXX_INCLUDE})
182 target_link_libraries(${PROJECT_NAME} ${LINK_WSI_LIBS})
184 add_custom_target(manifest_json ALL COMMAND
185 cp ${PROJECT_SOURCE_DIR}/layer/VkLayer_window_system_integration.json ${CMAKE_CURRENT_BINARY_DIR}