summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-05-12 09:42:41 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-05-20 09:48:48 +0200
commit3adf4877a40299a3de6daeac09e81256e168e5bb (patch)
tree323687cb7a6f7b3b3a3efd834ca1e2d11e8230d9 /cmake
parentad6870a855a6d10ca2cc937f0743754a7c50cda6 (diff)
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)
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtPlugins.cmake.in7
1 files changed, 7 insertions, 0 deletions
diff --git a/cmake/QtPlugins.cmake.in b/cmake/QtPlugins.cmake.in
index 3e554a43ad..4859691c46 100644
--- a/cmake/QtPlugins.cmake.in
+++ b/cmake/QtPlugins.cmake.in
@@ -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},"