00019331f03c940bd488cab53ef5fa1dedbeecda
[platform/core/uifw/vulkan-wsi-tizen.git] / CMakeLists.txt
1 # Copyright (c) 2019-2021 Arm Limited.
2 #
3 # SPDX-License-Identifier: MIT
4 #
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:
11 #
12 # The above copyright notice and this permission notice shall be included in all
13 # copies or substantial portions of the Software.
14 #
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
21 # SOFTWARE.
22
23 cmake_minimum_required(VERSION 3.4.3)
24 project(VkLayer_window_system_integration)
25
26 find_package(PkgConfig REQUIRED)
27 pkg_check_modules(VULKAN_PKG_CONFIG vulkan)
28
29 find_program(CLANG_TIDY clang-tidy-8)
30
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-*)
34 endif()
35
36 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread -fPIC")
37 if (DEFINED DEBUG)
38    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
39    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0")
40 endif()
41 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
42 set(CMAKE_CXX_STANDARD 11)
43
44 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
45 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
46 set(CMAKE_C_VISIBILITY_PRESET hidden)
47
48 if(NOT DEFINED VULKAN_CXX_INCLUDE)
49    set(VULKAN_CXX_INCLUDE ${VULKAN_PKG_CONFIG_INCLUDEDIR})
50 endif()
51
52 if(DEFINED VULKAN_CXX_INCLUDE)
53    message(STATUS "Using Vulkan include directories: ${VULKAN_CXX_INCLUDE}")
54    separate_arguments(VULKAN_CXX_INCLUDE)
55 else()
56    message(FATAL_ERROR "Either vulkan.pc must be available or VULKAN_CXX_INCLUDE must be defined")
57 endif()
58
59 # Build Configuration options
60 option(BUILD_WSI_HEADLESS "Build with support for VK_EXT_headless_surface" ON)
61 option(BUILD_WSI_WAYLAND "Build with support for VK_KHR_wayland_surface" OFF)
62 set(SELECT_EXTERNAL_ALLOCATOR "none" CACHE STRING "Select an external system allocator (none, ion)")
63 set(EXTERNAL_WSIALLOC_LIBRARY "" CACHE STRING "External implementation of the wsialloc interface to use")
64
65 if(BUILD_WSI_WAYLAND)
66    if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "none")
67       message(FATAL_ERROR "Wayland only supported with an external allocator.")
68    endif()
69    set(BUILD_DRM_UTILS True)
70 endif()
71
72 # DRM Utilities
73 if(BUILD_DRM_UTILS)
74    add_library(drm_utils STATIC util/drm/drm_utils.cpp)
75
76    pkg_check_modules(LIBDRM REQUIRED libdrm)
77    message(STATUS "Using libdrm include directories: ${LIBDRM_INCLUDE_DIRS}")
78    message(STATUS "Using libdrm cflags: ${LIBDRM_CFLAGS}")
79
80    target_sources(drm_utils PRIVATE util/drm/format_table.c)
81    target_include_directories(drm_utils PRIVATE ${VULKAN_CXX_INCLUDE})
82    target_include_directories(drm_utils PUBLIC ${LIBDRM_INCLUDE_DIRS})
83    target_include_directories(drm_utils PUBLIC util/wsialloc)
84    target_compile_options(drm_utils PUBLIC ${LIBDRM_CFLAGS})
85 endif()
86
87 # External WSI Allocator
88 if(NOT SELECT_EXTERNAL_ALLOCATOR STREQUAL "none" AND EXTERNAL_WSIALLOC_LIBRARY STREQUAL "")
89    add_library(wsialloc STATIC)
90    set_target_properties(wsialloc PROPERTIES C_STANDARD 99)
91
92    if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "ion")
93       target_sources(wsialloc PRIVATE util/wsialloc/wsialloc_ion.c)
94       target_link_libraries(wsialloc drm_utils)
95       if(DEFINED KERNEL_DIR)
96          target_include_directories(wsialloc PRIVATE "${KERNEL_DIR}/drivers/staging/android/uapi")
97       else()
98          message(FATAL_ERROR "KERNEL_DIR must be defined as the root of the Linux kernel source.")
99       endif()
100    else()
101       message(FATAL_ERROR "Invalid external allocator selected: ${SELECT_EXTERNAL_ALLOCATOR}")
102    endif()
103
104    target_include_directories(wsialloc PRIVATE ${VULKAN_CXX_INCLUDE})
105    target_include_directories(wsialloc PRIVATE util/drm)
106 endif()
107
108 # Wayland WSI
109 if(BUILD_WSI_WAYLAND)
110    add_library(wayland_wsi STATIC
111       wsi/wayland/surface_properties.cpp
112       wsi/wayland/surface.cpp
113       wsi/wayland/wl_helpers.cpp
114       wsi/wayland/swapchain.cpp)
115
116    pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client)
117    message(STATUS "Using Wayland client include directories: ${WAYLAND_CLIENT_INCLUDE_DIRS}")
118    message(STATUS "Using Wayland client cflags: ${WAYLAND_CLIENT_CFLAGS}")
119    message(STATUS "Using Wayland client ldflags: ${WAYLAND_CLIENT_LDFLAGS}")
120
121    pkg_check_modules(WAYLAND_SCANNER REQUIRED wayland-scanner)
122    pkg_get_variable(WAYLAND_SCANNER_EXEC wayland-scanner wayland_scanner)
123    message(STATUS "Using wayland-scanner : ${WAYLAND_SCANNER_EXEC}")
124
125    pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
126    pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
127    message(STATUS "Using wayland protocols dir : ${WAYLAND_PROTOCOLS_DIR}")
128
129    add_custom_target(wayland_generated_files
130       COMMAND ${WAYLAND_SCANNER_EXEC} client-header
131       ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
132       ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-client-protocol.h
133       COMMAND ${WAYLAND_SCANNER_EXEC} code
134       ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
135       ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-protocol.c
136       COMMAND ${WAYLAND_SCANNER_EXEC} client-header
137       ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
138       ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.h
139       COMMAND ${WAYLAND_SCANNER_EXEC} code
140       ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
141       ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.c
142       BYPRODUCTS linux-dmabuf-unstable-v1-protocol.c linux-dmabuf-unstable-v1-client-protocol.h
143                  linux-explicit-synchronization-unstable-v1-protocol.c linux-explicit-synchronization-unstable-v1-protocol.h)
144
145    target_sources(wayland_wsi PRIVATE
146       ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-protocol.c
147       ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-client-protocol.h
148       ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.c
149       ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.h)
150    add_dependencies(wayland_wsi wayland_generated_files)
151
152    target_include_directories(wayland_wsi PRIVATE
153       ${PROJECT_SOURCE_DIR}
154       ${VULKAN_CXX_INCLUDE}
155       ${WAYLAND_CLIENT_INCLUDE_DIRS}
156       ${CMAKE_CURRENT_BINARY_DIR})
157
158    target_compile_options(wayland_wsi PRIVATE ${WAYLAND_CLIENT_CFLAGS})
159    target_compile_options(wayland_wsi INTERFACE "-DBUILD_WSI_WAYLAND=1")
160    if(NOT EXTERNAL_WSIALLOC_LIBRARY STREQUAL "")
161       target_link_libraries(wayland_wsi ${EXTERNAL_WSIALLOC_LIBRARY})
162    else()
163       target_link_libraries(wayland_wsi wsialloc)
164    endif()
165    target_link_libraries(wayland_wsi drm_utils ${WAYLAND_CLIENT_LDFLAGS})
166    list(APPEND LINK_WSI_LIBS wayland_wsi)
167 else()
168    list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_KHR_wayland_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json)
169 endif()
170
171 # Headless
172 if(BUILD_WSI_HEADLESS)
173    add_library(wsi_headless STATIC
174       wsi/headless/surface_properties.cpp
175       wsi/headless/surface.cpp
176       wsi/headless/swapchain.cpp)
177
178    target_include_directories(wsi_headless PRIVATE
179       ${PROJECT_SOURCE_DIR}
180       ${VULKAN_CXX_INCLUDE}
181       ${CMAKE_CURRENT_BINARY_DIR})
182
183    target_compile_options(wsi_headless INTERFACE "-DBUILD_WSI_HEADLESS=1")
184    list(APPEND LINK_WSI_LIBS wsi_headless)
185 else()
186    list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_EXT_headless_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json)
187 endif()
188
189 # Layer
190 add_library(${PROJECT_NAME} SHARED
191    layer/layer.cpp
192    layer/private_data.cpp
193    layer/surface_api.cpp
194    layer/swapchain_api.cpp
195    util/timed_semaphore.cpp
196    util/custom_allocator.cpp
197    util/extension_list.cpp
198    util/log.cpp
199    wsi/swapchain_base.cpp
200    wsi/synchronization.cpp
201    wsi/wsi_factory.cpp)
202
203 target_compile_definitions(${PROJECT_NAME} PRIVATE ${WSI_DEFINES})
204 target_include_directories(${PROJECT_NAME} PRIVATE
205         ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${VULKAN_CXX_INCLUDE})
206
207 target_link_libraries(${PROJECT_NAME} ${LINK_WSI_LIBS})
208
209 add_custom_target(manifest_json ALL COMMAND
210    cp ${PROJECT_SOURCE_DIR}/layer/VkLayer_window_system_integration.json ${CMAKE_CURRENT_BINARY_DIR}
211    ${JSON_COMMANDS})