diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake index 2db9d4628a6..bc0f651b99c 100644 --- a/cmake/QtPluginHelpers.cmake +++ b/cmake/QtPluginHelpers.cmake @@ -211,6 +211,13 @@ function(qt_internal_add_plugin target) # This QT_PLUGINS assignment is only used by QtPostProcessHelpers to decide if a # QtModulePlugins.cmake file should be generated. set_property(TARGET "${qt_module_target}" APPEND PROPERTY QT_PLUGINS "${target}") + else() + # The _qt_plugins property is considered when collecting the plugins in + # deployment process. The usecase is following: + # QtModuleX is built separately and installed, so it's imported. + # The plugin is built in some application build tree and its PLUGIN_TYPE is associated + # with QtModuleX. + set_property(TARGET "${qt_module_target}" APPEND PROPERTY _qt_plugins "${target}") endif() set(plugin_target_versioned "${QT_CMAKE_EXPORT_NAMESPACE}::${target}") diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 90f52620ad0..707065f2826 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -392,3 +392,6 @@ endif() _qt_internal_test_expect_pass(test_config_expressions) _qt_internal_test_expect_pass(test_QTP0003) +if(NOT NO_GUI) + _qt_internal_test_expect_pass(test_collecting_plugins) +endif() diff --git a/tests/auto/cmake/test_collecting_plugins/CMakeLists.txt b/tests/auto/cmake/test_collecting_plugins/CMakeLists.txt new file mode 100644 index 00000000000..246acd4c717 --- /dev/null +++ b/tests/auto/cmake/test_collecting_plugins/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_collecting_plugins + VERSION + "${CMAKE_Core_MODULE_MAJOR_VERSION}.${CMAKE_Core_MODULE_MINOR_VERSION}.${CMAKE_Core_MODULE_PATCH_VERSION}") + +find_package(Qt6 COMPONENTS Core Gui BuildInternals REQUIRED) + +qt_prepare_standalone_project() + +qt_internal_add_plugin(QTestImagePlugin + SHARED + PLUGIN_TYPE imageformats + SOURCES + plugin.cpp + LIBRARIES + Qt6::Gui + SKIP_INSTALL # Make sure that we do not package this plugin +) + +qt_add_executable(TestExecutable main.cpp) +target_link_libraries(TestExecutable PRIVATE Qt6::Gui) + +__qt_internal_collect_plugin_targets_from_dependencies(TestExecutable plugin_targets) + +if(NOT "QTestImagePlugin" IN_LIST plugin_targets) + message(FATAL_ERROR "QTestImagePlugin plugin is missing") +endif() diff --git a/tests/auto/cmake/test_collecting_plugins/main.cpp b/tests/auto/cmake/test_collecting_plugins/main.cpp new file mode 100644 index 00000000000..09225de2053 --- /dev/null +++ b/tests/auto/cmake/test_collecting_plugins/main.cpp @@ -0,0 +1,7 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +int main(int, char *[]) +{ + return 0; +} diff --git a/tests/auto/cmake/test_collecting_plugins/plugin.cpp b/tests/auto/cmake/test_collecting_plugins/plugin.cpp new file mode 100644 index 00000000000..f844d86c4ef --- /dev/null +++ b/tests/auto/cmake/test_collecting_plugins/plugin.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include + +class TestImagePlugin : public QImageIOPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface") +public: + Capabilities capabilities(QIODevice *, const QByteArray &) const override { return {}; } + QImageIOHandler *create(QIODevice *, const QByteArray & = QByteArray()) const override + { + return nullptr; + } +}; + +#include "plugin.moc"