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 <alexey.edelev@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexandru Croitor 2021-06-30 12:37:14 +02:00
parent 6d59e1e088
commit bb25536a3d
6 changed files with 49 additions and 5 deletions

View File

@ -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)

View File

@ -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)

View File

@ -870,7 +870,7 @@ qt_internal_extend_target(Gui CONDITION QT_FEATURE_vulkan
vulkan/qvulkaninstance.cpp vulkan/qvulkaninstance.h vulkan/qvulkaninstance.cpp vulkan/qvulkaninstance.h
vulkan/qvulkanwindow.cpp vulkan/qvulkanwindow.h vulkan/qvulkanwindow_p.h vulkan/qvulkanwindow.cpp vulkan/qvulkanwindow.h vulkan/qvulkanwindow_p.h
PUBLIC_LIBRARIES PUBLIC_LIBRARIES
Vulkan::Vulkan_nolink WrapVulkanHeaders::WrapVulkanHeaders
) )
#### Keys ignored in scope 111:.:vulkan:vulkan/vulkan.pri:QT_FEATURE_vkgen: #### Keys ignored in scope 111:.:vulkan:vulkan/vulkan.pri:QT_FEATURE_vkgen:

View File

@ -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(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(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(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) if((LINUX) OR QT_FIND_ALL_PACKAGES_ALWAYS)
qt_find_package(Wayland PROVIDED_TARGETS Wayland::Server MODULE_NAME gui QMAKE_LIB wayland_server) qt_find_package(Wayland PROVIDED_TARGETS Wayland::Server MODULE_NAME gui QMAKE_LIB wayland_server)
endif() endif()
@ -751,7 +751,8 @@ qt_feature("vkgen" PRIVATE
) )
qt_feature("vulkan" PUBLIC qt_feature("vulkan" PUBLIC
LABEL "Vulkan" 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 qt_feature("vkkhrdisplay" PRIVATE
SECTION "Platform plugins" SECTION "Platform plugins"

View File

@ -91,7 +91,7 @@ qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_vulkan
SOURCES SOURCES
qvkconvenience.cpp qvkconvenience_p.h qvkconvenience.cpp qvkconvenience_p.h
PUBLIC_LIBRARIES PUBLIC_LIBRARIES
Vulkan::Vulkan_nolink WrapVulkanHeaders::WrapVulkanHeaders
) )
qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_egl qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_egl

View File

@ -500,7 +500,7 @@ _library_map = [
LibraryMapping("tslib", "Tslib", "PkgConfig::Tslib"), LibraryMapping("tslib", "Tslib", "PkgConfig::Tslib"),
LibraryMapping("udev", "Libudev", "PkgConfig::Libudev"), LibraryMapping("udev", "Libudev", "PkgConfig::Libudev"),
LibraryMapping("udev", "Libudev", "PkgConfig::Libudev"), # see also 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 qtbase/src/gui
LibraryMapping("wayland-server", "Wayland", "Wayland::Server"), # used in qtwayland LibraryMapping("wayland-server", "Wayland", "Wayland::Server"), # used in qtwayland
LibraryMapping("wayland-client", "Wayland", "Wayland::Client"), LibraryMapping("wayland-client", "Wayland", "Wayland::Client"),