From ededf3914297aca62e1d257175305cab5dbf6da2 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 7 Apr 2021 12:00:09 +0200 Subject: [PATCH] CMake: Fix duplicate symbol errors in Windows static super builds qt_internal_add_executable has some special logic to link static plugins in order to avoid issues with link cycles on exported Qt module targets. This logic does not take into account if a plugin is a default plugin. On windows this caused duplicate symbol linking issues in static super builds, because both qwindows and qdirect2d define a subset of the same symbols. Make sure to only link to default static plugins. This will skip linking to qdirect2d because it's not a default qpa plugin and thus avoid linker issues. Amends 5807e1ae8168a5702ad0f6890d2b35223cfebdee Pick-to: 6.1 6.1.0 Fixes: QTBUG-92451 Change-Id: I56df2ce0201625088417de53038642518c1d3bbd Reviewed-by: Alexey Edelev Reviewed-by: Craig Scott Reviewed-by: Alexandru Croitor --- cmake/QtPluginHelpers.cmake | 39 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake index d210d29cdc..5972d1419d 100644 --- a/cmake/QtPluginHelpers.cmake +++ b/cmake/QtPluginHelpers.cmake @@ -140,6 +140,23 @@ function(qt_internal_add_plugin target) unset(plugin_install_package_suffix) + # The generic plugins should be enabled by default. + # But platform plugins should always be disabled by default, and only one is enabled + # based on the platform (condition specified in arg_DEFAULT_IF). + if(plugin_type_escaped STREQUAL "platforms") + set(_default_plugin 0) + else() + set(_default_plugin 1) + endif() + + if (DEFINED arg_DEFAULT_IF) + if (NOT ${arg_DEFAULT_IF}) + set(_default_plugin 0) + else() + set(_default_plugin 1) + endif() + endif() + # Save the Qt module in the plug-in's properties and vice versa if(NOT plugin_type_escaped STREQUAL "qml_plugin") qt_internal_get_module_for_plugin("${target}" "${plugin_type_escaped}" qt_module) @@ -166,7 +183,10 @@ function(qt_internal_add_plugin target) DIRECTORY ${module_source_dir} DEFINITION PROJECT_NAME ) - if(module_project_name STREQUAL PROJECT_NAME) + + # When linking static plugins with the special logic in qt_internal_add_executable, + # make sure to skip non-default plugins. + if(module_project_name STREQUAL PROJECT_NAME AND _default_plugin) set_property(TARGET ${qt_module_target} APPEND PROPERTY _qt_repo_plugins "${target}") set_property(TARGET ${qt_module_target} APPEND PROPERTY _qt_repo_plugin_class_names "$" @@ -195,23 +215,6 @@ function(qt_internal_add_plugin target) _qt_plugin_install_package_suffix "${plugin_install_package_suffix}") endif() - # The generic plugins should be enabled by default. - # But platform plugins should always be disabled by default, and only one is enabled - # based on the platform (condition specified in arg_DEFAULT_IF). - if(plugin_type_escaped STREQUAL "platforms") - set(_default_plugin 0) - else() - set(_default_plugin 1) - endif() - - if (DEFINED arg_DEFAULT_IF) - if (NOT ${arg_DEFAULT_IF}) - set(_default_plugin 0) - else() - set(_default_plugin 1) - endif() - endif() - if(TARGET qt_plugins) add_dependencies(qt_plugins "${target}") endif()