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 5807e1ae81

Pick-to: 6.1 6.1.0
Fixes: QTBUG-92451
Change-Id: I56df2ce0201625088417de53038642518c1d3bbd
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Craig Scott <craig.scott@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexandru Croitor 2021-04-07 12:00:09 +02:00
parent 8115219407
commit ededf39142

View File

@ -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
"$<TARGET_PROPERTY:${target},QT_PLUGIN_CLASS_NAME>"
@ -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()