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.

Task-number: QTBUG-80863
Change-Id: Ide32c0124c1e313c352a72280ce32ce9fbe8fff1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
(cherry picked from commit 5268edf5811251a432fb5096aef6de4ef372f619)
This commit is contained in:
Alexandru Croitor 2021-05-12 09:42:41 +02:00
parent ad6870a855
commit 3adf4877a4

View File

@ -101,10 +101,17 @@ function(__qt_internal_add_static_plugins_once)
">"
)
# 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 "$<TARGET_PROPERTY:TYPE>")
set(no_static_genex "$<NOT:$<STREQUAL:${type_genex},STATIC_LIBRARY>>")
# Complete condition that defines whether a static plugin is linked
string(CONCAT _plugin_condition
"$<BOOL:$<AND:"
"${_is_plugin_marker_genex},"
"${no_static_genex},"
"$<OR:"
"${_plugin_is_whitelisted},"
"${_plugin_versionless_is_whitelisted},"