Remove DEBUG build option
[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 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
38 set(CMAKE_CXX_STANDARD 11)
39
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)
43
44 if(NOT DEFINED VULKAN_CXX_INCLUDE)
45    set(VULKAN_CXX_INCLUDE ${VULKAN_PKG_CONFIG_INCLUDEDIR})
46 endif()
47
48 if(DEFINED VULKAN_CXX_INCLUDE)
49    message(STATUS "Using Vulkan include directories: ${VULKAN_CXX_INCLUDE}")
50    separate_arguments(VULKAN_CXX_INCLUDE)
51 else()
52    message(FATAL_ERROR "Either vulkan.pc must be available or VULKAN_CXX_INCLUDE must be defined")
53 endif()
54
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")
60
61 if(BUILD_WSI_WAYLAND)
62    if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "none")
63       message(FATAL_ERROR "Wayland only supported with an external allocator.")
64    endif()
65    set(BUILD_DRM_UTILS True)
66 endif()
67
68 # DRM Utilities
69 if(BUILD_DRM_UTILS)
70    add_library(drm_utils STATIC util/drm/drm_utils.cpp)
71
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}")
75
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})
81 endif()
82
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)
87
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")
93       else()
94          message(FATAL_ERROR "KERNEL_DIR must be defined as the root of the Linux kernel source.")
95       endif()
96    else()
97       message(FATAL_ERROR "Invalid external allocator selected: ${SELECT_EXTERNAL_ALLOCATOR}")
98    endif()
99
100    target_include_directories(wsialloc PRIVATE ${VULKAN_CXX_INCLUDE})
101    target_include_directories(wsialloc PRIVATE util/drm)
102 endif()
103
104 # Wayland WSI
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)
111
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}")
116
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}")
120
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}")
124
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)
140
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)
147
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})
153
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})
158    else()
159       target_link_libraries(wayland_wsi wsialloc)
160    endif()
161    target_link_libraries(wayland_wsi drm_utils ${WAYLAND_CLIENT_LDFLAGS})
162    list(APPEND LINK_WSI_LIBS wayland_wsi)
163 else()
164    list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_KHR_wayland_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json)
165 endif()
166
167 # Headless
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)
173
174    target_include_directories(wsi_headless PRIVATE
175       ${PROJECT_SOURCE_DIR}
176       ${VULKAN_CXX_INCLUDE}
177       ${CMAKE_CURRENT_BINARY_DIR})
178
179    target_compile_options(wsi_headless INTERFACE "-DBUILD_WSI_HEADLESS=1")
180    list(APPEND LINK_WSI_LIBS wsi_headless)
181 else()
182    list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_EXT_headless_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json)
183 endif()
184
185 # Layer
186 add_library(${PROJECT_NAME} SHARED
187    layer/layer.cpp
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
194    util/log.cpp
195    wsi/swapchain_base.cpp
196    wsi/synchronization.cpp
197    wsi/wsi_factory.cpp)
198
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})
202
203 target_link_libraries(${PROJECT_NAME} ${LINK_WSI_LIBS})
204
205 add_custom_target(manifest_json ALL COMMAND
206    cp ${PROJECT_SOURCE_DIR}/layer/VkLayer_window_system_integration.json ${CMAKE_CURRENT_BINARY_DIR}
207    ${JSON_COMMANDS})