From f417af638f5647e39682ec0e62311a96b2cf8584 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 1 Jul 2022 14:45:54 +0200 Subject: [PATCH] CMake: Create and include plugin packages in shared builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously QtModulePlugins.cmake files were only created and included in static library Qt builds. Having the targets available in shared library builds would be useful for custom project deployment purposes. One could query the location of the plugins or use various generator expressions referencing their location. Ensure we always generate and include the QtModulePlugins.cmake files regardless of the build type. Allow opting out of including the files by setting QT_SKIP_AUTO_PLUGIN_INCLUSION to ON, just like we allow for Qml plugins with QT_SKIP_AUTO_QML_PLUGIN_INCLUSION. Fixes: QTBUG-94066 Change-Id: I69a5dc17762a8e43265578fc33b82b5c4b7a1f5c Reviewed-by: Jörg Bornemann (cherry picked from commit 7d6f1ee5a75cae9d122a3f0c7b3a6d03f380535e) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtPlugins.cmake.in | 2 +- cmake/QtPostProcess.cmake | 2 +- cmake/QtPostProcessHelpers.cmake | 13 +++++-------- cmake/QtPublicPluginHelpers.cmake | 9 ++++++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmake/QtPlugins.cmake.in b/cmake/QtPlugins.cmake.in index 09a2f404144..405d5f37b92 100644 --- a/cmake/QtPlugins.cmake.in +++ b/cmake/QtPlugins.cmake.in @@ -1,6 +1,6 @@ include_guard(DIRECTORY) @QT_MODULE_PLUGIN_INCLUDES@ -if(NOT @BUILD_SHARED_LIBS@ AND NOT QT_NO_CREATE_TARGETS) +if(NOT QT_NO_CREATE_TARGETS AND NOT QT_SKIP_AUTO_PLUGIN_INCLUSION) __qt_internal_include_plugin_packages(@QT_MODULE@) endif() diff --git a/cmake/QtPostProcess.cmake b/cmake/QtPostProcess.cmake index 0cb0edf1c6a..77b226718b4 100644 --- a/cmake/QtPostProcess.cmake +++ b/cmake/QtPostProcess.cmake @@ -2,7 +2,7 @@ include(QtPostProcessHelpers) qt_internal_create_depends_files() qt_generate_build_internals_extra_cmake_code() -qt_internal_create_plugins_files() +qt_internal_create_plugins_auto_inclusion_files() qt_internal_create_config_file_for_standalone_tests() # Needs to run after qt_internal_create_depends_files. diff --git a/cmake/QtPostProcessHelpers.cmake b/cmake/QtPostProcessHelpers.cmake index a34d27a4bd3..518bfee580d 100644 --- a/cmake/QtPostProcessHelpers.cmake +++ b/cmake/QtPostProcessHelpers.cmake @@ -388,14 +388,11 @@ function(qt_internal_create_depends_files) endforeach() endfunction() -# This function creates the QtPlugins.cmake used to list all -# the plug-in target files. -function(qt_internal_create_plugins_files) - # The plugins cmake configuration is only needed for static builds. Dynamic builds don't need - # the application to link against plugins at build time. - if(QT_BUILD_SHARED_LIBS) - return() - endif() +# This function creates QtPlugins.cmake files used to include all +# the plugin Config files that belong to that module. +function(qt_internal_create_plugins_auto_inclusion_files) + # For static library builds, the plugin targets need to be available for linking. + # For shared library builds, the plugin targets are useful for deployment purposes. qt_internal_get_qt_repo_known_modules(repo_known_modules) set(modules_with_plugins "") diff --git a/cmake/QtPublicPluginHelpers.cmake b/cmake/QtPublicPluginHelpers.cmake index 90d784d88e8..6dfaead7553 100644 --- a/cmake/QtPublicPluginHelpers.cmake +++ b/cmake/QtPublicPluginHelpers.cmake @@ -461,9 +461,12 @@ function(__qt_internal_include_plugin_packages target) list(APPEND "QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}" "${plugin_target}") - __qt_internal_add_static_plugin_linkage("${plugin_target}" "${_module_target}") - __qt_internal_add_static_plugin_import_macro( - "${plugin_target}" ${_module_target} "${target}") + # Auto-linkage should be set up only for static library builds. + if(NOT QT6_IS_SHARED_LIBS_BUILD) + __qt_internal_add_static_plugin_linkage("${plugin_target}" "${_module_target}") + __qt_internal_add_static_plugin_import_macro( + "${plugin_target}" ${_module_target} "${target}") + endif() endforeach() set("QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}"