qmake: Resolve target suffix based on Qt build config for static plugins

The qtPlatformTargetSuffix() function is used in various places to
determine the suffix of targets based on the config, which for macOS
will result in a _debug suffix in debug mode.

This becomes tricky when one project built in debug mode tries to depend
on the libraries/plugins of another project (Qt) built in release, as
the qtPlatformTargetSuffix() function uses the current CONFIG as input,
which may be different than the QT_CONFIG (or CONFIG of whatever project
is being depended on).

For libraries this was fixed in 50e664835b
by iterating all known library paths, and trying the CONFIG suffix before
falling back to release version.

For plugins this was never solved, which becomes an issue when linking
to static plugins, either in a fully static build of Qt, or when some
of the plugins are static (permission plugins e.g.).

In this situation, the user project has to have the same configuration
as Qt was built with, to avoid errors like:

 error: no such file or directory: '~/6.x-static/qtbase/plugins/platforms/libqcocoa_debug.a'

To work around this, we assume that a plugin installed into the Qt
tree has the same build configuration as Qt itself, then then use
QT_CONFIG as the determining factor when linking to the plugin.

This still ties the build config of the plugin to the config of Qt,
but relaxes the relationship to the application, allowing it to be
built in either debug or release, which is an improvement to the
current state.

Pick-to: 6.5 6.5.0
Task-number: QTBUG-110356
Change-Id: Icee67fc01313a6c6f34178a6345ccae1b57429d7
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-02-23 15:50:23 +01:00
parent 0bbf817589
commit e2446afaa1
2 changed files with 13 additions and 4 deletions

View File

@ -156,13 +156,18 @@ import_plugins {
# the plugin path. Unknown plugins must rely on the default link path.
plug_type = $$eval(QT_PLUGIN.$${plug}.TYPE)
!isEmpty(plug_type) {
plug_name = $$QMAKE_PREFIX_STATICLIB$${plug}$$qtPlatformTargetSuffix().$$QMAKE_EXTENSION_STATICLIB
# Respect target config if Qt provides both debug and release versions
# of each plugin. Otherwise, respect what Qt was configured with.
qtConfig(debug_and_release): config_variable = CONFIG
else: config_variable = QT_CONFIG
plug_name = $$QMAKE_PREFIX_STATICLIB$${plug}$$qtPlatformTargetSuffix($$config_variable).$$QMAKE_EXTENSION_STATICLIB
plug_path = $$eval(QT_PLUGIN.$${plug}.PATH)
isEmpty(plug_path): \
plug_path = $$[QT_INSTALL_PLUGINS/get]
LIBS += $$plug_path/$$plug_type/$$plug_name
} else {
LIBS += -l$${plug}$$qtPlatformTargetSuffix()
LIBS += -l$${plug}$$qtPlatformTargetSuffix(CONFIG)
}
}

View File

@ -1,9 +1,13 @@
defineReplace(qtPlatformTargetSuffix) {
config_variable = $$1
isEmpty(config_variable): \
config_variable = CONFIG
suffix =
android: return($${suffix}_$${QT_ARCH})
win32 {
CONFIG(debug, debug|release) {
contains($$config_variable, debug, debug|release) {
mingw {
qtConfig(debug_and_release):build_pass: \
return($${suffix}d)
@ -14,7 +18,7 @@ defineReplace(qtPlatformTargetSuffix) {
}
}
darwin {
CONFIG(debug, debug|release) {
contains($$config_variable, debug, debug|release) {
!debug_and_release|build_pass: \
return($${suffix}_debug)
}