Skip to content

Commit

Permalink
Avoid creating Plugin targets if the dependencies are missing
Browse files Browse the repository at this point in the history
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 <plugin>_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.5
Change-Id: I8685163df0dee3a728c724901f69780569ffcad5
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
(cherry picked from commit 8d0283a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 8f1438b)
  • Loading branch information
semlanik authored and Qt Cherry-pick Bot committed Dec 21, 2024
1 parent 45f39ab commit b2dcce1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cmake/QtPluginConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,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()
6 changes: 5 additions & 1 deletion cmake/QtPluginDependencies.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 6 additions & 1 deletion cmake/QtPublicDependencyHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand All @@ -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()
Expand Down

0 comments on commit b2dcce1

Please sign in to comment.