From b41b27352d59b85cdf5f8c2cd8e24fc8e2a85d85 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 6 Jan 2023 16:12:34 +0100 Subject: [PATCH] CMake: Add switch for allowing missing Qt6*Tools packages Consider a cross build of Qt with qtbase, qtshadertools and qtdeclarative. If a user projects only links against QtQml without creating an actual QtQuick module, no host tools from qtdeclarative are needed. Normally, find_package(Qt6Qml) pulls in Qt6QmlTools and errors out if it's not found. By setting QT_ALLOW_MISSING_TOOLS_PACKAGES when configuring Qt, one can disable the error and build a user project such as the one outlined above. Fixes: QTBUG-109547 Change-Id: I45e727713912d19e6007a7fbf3d61533f82b71d9 Reviewed-by: Alexey Edelev Reviewed-by: Jaeyoon Jung (cherry picked from commit 94e474b48e9d3c6434339afe166c2329f8c36ea2) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtModuleHelpers.cmake | 5 +++++ cmake/QtPublicDependencyHelpers.cmake | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake index a7315550e2a..196c6a316f1 100644 --- a/cmake/QtModuleHelpers.cmake +++ b/cmake/QtModuleHelpers.cmake @@ -669,6 +669,11 @@ set(QT_VISIBILITY_AVAILABLE TRUE)") set(QT_LIBINFIX \"${QT_LIBINFIX}\")") endif() + # Store whether find_package(Qt6Foo) should succeed if Qt6FooTools is missing. + if(QT_ALLOW_MISSING_TOOLS_PACKAGES) + string(APPEND qtcore_extra_cmake_code " +set(QT_ALLOW_MISSING_TOOLS_PACKAGES TRUE)") + endif() endif() configure_file("${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigExtras.cmake.in" diff --git a/cmake/QtPublicDependencyHelpers.cmake b/cmake/QtPublicDependencyHelpers.cmake index 803cb73e637..7fca0fa66dc 100644 --- a/cmake/QtPublicDependencyHelpers.cmake +++ b/cmake/QtPublicDependencyHelpers.cmake @@ -67,7 +67,7 @@ macro(_qt_internal_find_tool_dependencies target target_dep_list) "${_qt_cmake_dir}" ${_qt_additional_packages_prefix_paths} ) - if (NOT ${__qt_${target}_pkg}_FOUND) + if (NOT ${__qt_${target}_pkg}_FOUND AND NOT QT_ALLOW_MISSING_TOOLS_PACKAGES) set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency \