From 5268edf5811251a432fb5096aef6de4ef372f619 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 12 May 2021 09:42:41 +0200 Subject: [PATCH] CMake: Don't do plugin initialization for static libraries Q_IMPORT_PLUGIN generates a global static symbol that initializes a plugin. If this symbol is added to a static library and the library is then linked to an executable, the linker decides that the symbol is unused (because nothing references it) and discards it. This means there's no point to compile the Q_IMPORT_PLUGIN containing files into static libraries. Change the generator expression we use for plugin propagation via associated modules to not compile and link the plugin initialization object file into a static library. Pick-to: 6.1 Task-number: QTBUG-80863 Change-Id: Ide32c0124c1e313c352a72280ce32ce9fbe8fff1 Reviewed-by: Qt CI Bot Reviewed-by: Joerg Bornemann --- cmake/QtPublicPluginHelpers.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/QtPublicPluginHelpers.cmake b/cmake/QtPublicPluginHelpers.cmake index 889e764d40b..39143cecc33 100644 --- a/cmake/QtPublicPluginHelpers.cmake +++ b/cmake/QtPublicPluginHelpers.cmake @@ -90,10 +90,17 @@ function(__qt_internal_get_static_plugin_condition_genex ">" ) + # No point in linking the plugin initialization source file into static libraries. The + # initialization symbol will be discarded by the linker when the static lib is linked into an + # executable or shared library, because nothing is referencing the global static symbol. + set(type_genex "$") + set(no_static_genex "$>") + # Complete condition that defines whether a static plugin is linked string(CONCAT _plugin_condition "$