From 8d0283ad2cae3d8fbd4b1b7ee5c6454f7fcc079c Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Tue, 17 Dec 2024 18:41:32 +0100 Subject: [PATCH] Avoid creating Plugin targets if the dependencies are missing The plugin lookup mechanism doesn't handle the situation, when the plugin is available but it's private dependency(static plugin case) is missing. In this case we currently silently bypass the dependency lookup and create targets. So users see the confusing message about missing linked target, like: Qt6QSQLiteDriverPluginTargets.cmake:61 (set_target_properties): The link interface of target "Qt6::QSQLiteDriverPlugin" contains: SQLite::SQLite3 but the target was not found. Possible reasons include: * There is a typo in the target name. * A find_package call is missing for an IMPORTED target. * An ALIAS target is missing. This indeed should be handled properly and we should omit creating targets especially if users don't really use the plugin directly. Also if dependencies are not satisfied it looks logically to set the _FOUND to false as this will be yet another indicator for user that the plugin is not found. Task-number: QTBUG-132244 Pick-to: 6.8 6.9 6.5 Change-Id: I8685163df0dee3a728c724901f69780569ffcad5 Reviewed-by: Joerg Bornemann --- cmake/QtPluginConfig.cmake.in | 8 ++++++-- cmake/QtPluginDependencies.cmake.in | 6 +++++- cmake/QtPublicDependencyHelpers.cmake | 7 ++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmake/QtPluginConfig.cmake.in b/cmake/QtPluginConfig.cmake.in index 4b589cb4477..1ec7663ac6f 100644 --- a/cmake/QtPluginConfig.cmake.in +++ b/cmake/QtPluginConfig.cmake.in @@ -26,8 +26,12 @@ if (NOT QT_NO_CREATE_TARGETS) # Find required dependencies, if any. if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Dependencies.cmake") include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Dependencies.cmake") + else() + set(@target@_FOUND TRUE) endif() - include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@AdditionalTargetInfo.cmake") + if(@target@_FOUND) + include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@AdditionalTargetInfo.cmake") + endif() endif() diff --git a/cmake/QtPluginDependencies.cmake.in b/cmake/QtPluginDependencies.cmake.in index bcbb9bb5db3..800576f521a 100644 --- a/cmake/QtPluginDependencies.cmake.in +++ b/cmake/QtPluginDependencies.cmake.in @@ -18,4 +18,8 @@ set(__qt_@target@_find_dependency_paths "@find_dependency_paths@") _qt_internal_find_qt_dependencies("@target@" __qt_@target@_target_deps __qt_@target@_find_dependency_paths) -set(@target@_FOUND TRUE) +if(__qt_${target}_missing_deps) + set(@target@_FOUND FALSE) +else() + set(@target@_FOUND TRUE) +endif() diff --git a/cmake/QtPublicDependencyHelpers.cmake b/cmake/QtPublicDependencyHelpers.cmake index e797e5cc736..feeec07fff8 100644 --- a/cmake/QtPublicDependencyHelpers.cmake +++ b/cmake/QtPublicDependencyHelpers.cmake @@ -34,6 +34,9 @@ macro(_qt_internal_find_third_party_dependencies target target_dep_list) find_package(${__qt_${target}_find_package_args}) else() find_dependency(${__qt_${target}_find_package_args}) + if(NOT ${__qt_${target}_pkg}_FOUND) + list(APPEND __qt_${target}_missing_deps "${__qt_${target}_pkg}") + endif() endif() _qt_internal_get_package_components_id( @@ -129,7 +132,6 @@ macro(_qt_internal_find_qt_dependencies target target_dep_list find_dependency_p list(GET __qt_${target}_target_dep 1 __qt_${target}_version) if (NOT ${__qt_${target}_pkg}_FOUND) - # TODO: Remove Private handling once sufficient time has passed, aka all developers # updated their builds not to contain stale FooDependencies.cmake files without the # _qt_package_name property. @@ -149,6 +151,9 @@ macro(_qt_internal_find_qt_dependencies target target_dep_list find_dependency_p ${_qt_additional_packages_prefix_paths} ${__qt_use_no_default_path_for_qt_packages} ) + if(NOT ${__qt_${target}_pkg}_FOUND) + list(APPEND __qt_${target}_missing_deps "${__qt_${target}_pkg}") + endif() endif() endforeach() endmacro()