From bb25536a3db657b41ae31e1690d230ef8722b57d Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 30 Jun 2021 12:37:14 +0200 Subject: [PATCH] CMake: Fix Vulkan to be found when targeting Android Introduce two new packages WrapVulkanHeaders and WrapVulkan similar to the OpenSSL wrapper packages. WrapVulkanHeaders uses FindVulkan and is marked as found if Vulkan headers are found (that's the only part the Qt build requires). The WrapVulkan package is currently not used, but is there for symmetry. The Vulkan feature is now disabled by default on QNX, because the QNX toolchain file in the CI does not set CMAKE_FIND_ROOT_PATH_MODE-like variables and CMake ends up finding host Vulkan headers causing the build to break. Pick-to: 6.2 Fixes: QTBUG-92157 Change-Id: I05309821f866456cd42e7f85bf8b76ba099df656 Reviewed-by: Alexey Edelev Reviewed-by: Assam Boudjelthia Reviewed-by: Alexandru Croitor --- cmake/FindWrapVulkan.cmake | 20 ++++++++++++++++++++ cmake/FindWrapVulkanHeaders.cmake | 23 +++++++++++++++++++++++ src/gui/CMakeLists.txt | 2 +- src/gui/configure.cmake | 5 +++-- src/opengl/CMakeLists.txt | 2 +- util/cmake/helper.py | 2 +- 6 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 cmake/FindWrapVulkan.cmake create mode 100644 cmake/FindWrapVulkanHeaders.cmake diff --git a/cmake/FindWrapVulkan.cmake b/cmake/FindWrapVulkan.cmake new file mode 100644 index 0000000000..38cf3ea417 --- /dev/null +++ b/cmake/FindWrapVulkan.cmake @@ -0,0 +1,20 @@ +# We can't create the same interface imported target multiple times, CMake will complain if we do +# that. This can happen if the find_package call is done in multiple different subdirectories. +if(TARGET WrapVulkan::WrapVulkan) + set(WrapVulkan_FOUND ON) + return() +endif() + +set(WrapVulkan_FOUND OFF) + +find_package(Vulkan ${WrapVulkan_FIND_VERSION} QUIET) + +if(Vulkan_FOUND) + set(WrapVulkan_FOUND ON) + + add_library(WrapVulkan::WrapVulkan INTERFACE IMPORTED) + target_link_libraries(WrapVulkan::WrapVulkan INTERFACE Vulkan::Vulkan) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(WrapVulkan DEFAULT_MSG Vulkan_LIBRARY Vulkan_INCLUDE_DIR) diff --git a/cmake/FindWrapVulkanHeaders.cmake b/cmake/FindWrapVulkanHeaders.cmake new file mode 100644 index 0000000000..a079e07300 --- /dev/null +++ b/cmake/FindWrapVulkanHeaders.cmake @@ -0,0 +1,23 @@ +# We can't create the same interface imported target multiple times, CMake will complain if we do +# that. This can happen if the find_package call is done in multiple different subdirectories. +if(TARGET WrapVulkanHeaders::WrapVulkanHeaders) + set(WrapVulkanHeaders_FOUND ON) + return() +endif() + +set(WrapVulkanHeaders_FOUND OFF) + +find_package(Vulkan ${WrapVulkanHeaders_FIND_VERSION} QUIET) + +# We are interested only in include headers. The libraries might be missing, so we can't check the +# _FOUND variable. +if(Vulkan_INCLUDE_DIR) + set(WrapVulkanHeaders_FOUND ON) + + add_library(WrapVulkanHeaders::WrapVulkanHeaders INTERFACE IMPORTED) + target_include_directories(WrapVulkanHeaders::WrapVulkanHeaders INTERFACE + ${Vulkan_INCLUDE_DIR}) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(WrapVulkanHeaders DEFAULT_MSG Vulkan_INCLUDE_DIR) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index d2be239d84..84cf5229f6 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -870,7 +870,7 @@ qt_internal_extend_target(Gui CONDITION QT_FEATURE_vulkan vulkan/qvulkaninstance.cpp vulkan/qvulkaninstance.h vulkan/qvulkanwindow.cpp vulkan/qvulkanwindow.h vulkan/qvulkanwindow_p.h PUBLIC_LIBRARIES - Vulkan::Vulkan_nolink + WrapVulkanHeaders::WrapVulkanHeaders ) #### Keys ignored in scope 111:.:vulkan:vulkan/vulkan.pri:QT_FEATURE_vkgen: diff --git a/src/gui/configure.cmake b/src/gui/configure.cmake index 20c5b9624b..67fc7fd25d 100644 --- a/src/gui/configure.cmake +++ b/src/gui/configure.cmake @@ -50,7 +50,7 @@ qt_find_package(Mtdev PROVIDED_TARGETS PkgConfig::Mtdev MODULE_NAME gui QMAKE_LI qt_find_package(WrapOpenGL PROVIDED_TARGETS WrapOpenGL::WrapOpenGL MODULE_NAME gui QMAKE_LIB opengl) qt_find_package(GLESv2 PROVIDED_TARGETS GLESv2::GLESv2 MODULE_NAME gui QMAKE_LIB opengl_es2) qt_find_package(Tslib PROVIDED_TARGETS PkgConfig::Tslib MODULE_NAME gui QMAKE_LIB tslib) -qt_find_package(Vulkan PROVIDED_TARGETS Vulkan::Vulkan MODULE_NAME gui QMAKE_LIB vulkan MARK_OPTIONAL) # special case +qt_find_package(WrapVulkanHeaders PROVIDED_TARGETS WrapVulkanHeaders::WrapVulkanHeaders MODULE_NAME gui QMAKE_LIB vulkan MARK_OPTIONAL) # special case if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS) qt_find_package(Wayland PROVIDED_TARGETS Wayland::Server MODULE_NAME gui QMAKE_LIB wayland_server) endif() @@ -751,7 +751,8 @@ qt_feature("vkgen" PRIVATE ) qt_feature("vulkan" PUBLIC LABEL "Vulkan" - CONDITION QT_FEATURE_library AND QT_FEATURE_vkgen AND Vulkan_FOUND + AUTODETECT NOT QNX # FIXME: CI QNX toolchain is broken and finds host vulkan QTQAINFRA-4502 + CONDITION QT_FEATURE_library AND QT_FEATURE_vkgen AND WrapVulkanHeaders_FOUND ) qt_feature("vkkhrdisplay" PRIVATE SECTION "Platform plugins" diff --git a/src/opengl/CMakeLists.txt b/src/opengl/CMakeLists.txt index 1d92e89998..11345b5dc1 100644 --- a/src/opengl/CMakeLists.txt +++ b/src/opengl/CMakeLists.txt @@ -91,7 +91,7 @@ qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_vulkan SOURCES qvkconvenience.cpp qvkconvenience_p.h PUBLIC_LIBRARIES - Vulkan::Vulkan_nolink + WrapVulkanHeaders::WrapVulkanHeaders ) qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_egl diff --git a/util/cmake/helper.py b/util/cmake/helper.py index f286161866..dcb2b611b5 100644 --- a/util/cmake/helper.py +++ b/util/cmake/helper.py @@ -500,7 +500,7 @@ _library_map = [ LibraryMapping("tslib", "Tslib", "PkgConfig::Tslib"), LibraryMapping("udev", "Libudev", "PkgConfig::Libudev"), LibraryMapping("udev", "Libudev", "PkgConfig::Libudev"), # see also libudev! - LibraryMapping("vulkan", "Vulkan", "Vulkan::Vulkan"), + LibraryMapping("vulkan", "WrapVulkanHeaders", "WrapVulkanHeaders::WrapVulkanHeaders"), LibraryMapping("wayland_server", "Wayland", "Wayland::Server"), # used in qtbase/src/gui LibraryMapping("wayland-server", "Wayland", "Wayland::Server"), # used in qtwayland LibraryMapping("wayland-client", "Wayland", "Wayland::Client"),