CMake: Create and include plugin packages in shared builds

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.

Pick-to: 6.4
Fixes: QTBUG-94066
Change-Id: I69a5dc17762a8e43265578fc33b82b5c4b7a1f5c
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2022-07-01 14:45:54 +02:00
parent ff4be4cf30
commit 7d6f1ee5a7
4 changed files with 13 additions and 13 deletions

View File

@ -1,6 +1,6 @@
include_guard(DIRECTORY) include_guard(DIRECTORY)
@QT_MODULE_PLUGIN_INCLUDES@ @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@) __qt_internal_include_plugin_packages(@QT_MODULE@)
endif() endif()

View File

@ -2,7 +2,7 @@ include(QtPostProcessHelpers)
qt_internal_create_depends_files() qt_internal_create_depends_files()
qt_generate_build_internals_extra_cmake_code() 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() qt_internal_create_config_file_for_standalone_tests()
# Needs to run after qt_internal_create_depends_files. # Needs to run after qt_internal_create_depends_files.

View File

@ -401,14 +401,11 @@ function(qt_internal_create_depends_files)
endforeach() endforeach()
endfunction() endfunction()
# This function creates the Qt<Module>Plugins.cmake used to list all # This function creates Qt<Module>Plugins.cmake files used to include all
# the plug-in target files. # the plugin Config files that belong to that module.
function(qt_internal_create_plugins_files) function(qt_internal_create_plugins_auto_inclusion_files)
# The plugins cmake configuration is only needed for static builds. Dynamic builds don't need # For static library builds, the plugin targets need to be available for linking.
# the application to link against plugins at build time. # For shared library builds, the plugin targets are useful for deployment purposes.
if(QT_BUILD_SHARED_LIBS)
return()
endif()
qt_internal_get_qt_repo_known_modules(repo_known_modules) qt_internal_get_qt_repo_known_modules(repo_known_modules)
set(modules_with_plugins "") set(modules_with_plugins "")

View File

@ -461,9 +461,12 @@ function(__qt_internal_include_plugin_packages target)
list(APPEND "QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}" "${plugin_target}") list(APPEND "QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}" "${plugin_target}")
__qt_internal_add_static_plugin_linkage("${plugin_target}" "${_module_target}") # Auto-linkage should be set up only for static library builds.
__qt_internal_add_static_plugin_import_macro( if(NOT QT6_IS_SHARED_LIBS_BUILD)
"${plugin_target}" ${_module_target} "${target}") __qt_internal_add_static_plugin_linkage("${plugin_target}" "${_module_target}")
__qt_internal_add_static_plugin_import_macro(
"${plugin_target}" ${_module_target} "${target}")
endif()
endforeach() endforeach()
set("QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}" set("QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}"