Fix linking of debug projects against release Qt on Darwin platforms

Consider a release-only, non-framework Qt build on macOS.  Building a
debug user project would fail, because qmake tried to link
against *_debug.dylib and *_debug.a libraries.

Building a debug user project that uses QtUiTools against a release-only
framework-build Qt posed the same problem.  QMake tried to link against
the libQt5UiTools_debug.a, which does not exist.

Fix this by maintaining a list of library file candidates, and use the
first existing one (or just the first one if none exists).  This favors
the library matching the user project's configuration but falls back to
the release version of the library if necessary.

Fixes: QTBUG-81251
Pick-to: 6.2
Change-Id: I8d641104718edb16500c6d6e3994e736fa5ddcf4
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2021-06-24 14:27:37 +02:00
parent ae2ef9dbf0
commit 50e664835b

View File

@ -218,28 +218,35 @@ for(ever) {
# Linking frameworks by absolute path does not work.
LIBS$$var_sfx += -framework $$framework
} else {
lib = $$MODULE_MODULE$$qtPlatformTargetSuffix()
lib_bases = $$MODULE_MODULE$$qtPlatformTargetSuffix()
darwin: lib_bases *= $$MODULE_MODULE
win32|contains(MODULE_CONFIG, staticlib) {
lib_missing = true
lib_extensions = $$QMAKE_EXTENSION_STATICLIB
lib_extensions *= $$QMAKE_LIB_EXTENSIONS
candidates =
for(ext, lib_extensions) {
candidate = $$MODULE_LIBS/$$QMAKE_PREFIX_STATICLIB$${lib}.$$ext
candidates += $$candidate
exists($$candidate) {
lib = $$candidate
lib_missing = false
break()
}
}
$$lib_missing {
lib = $$first(candidates)
}
PRE_TARGETDEPS += $$lib
lib_prefix = $$MODULE_LIBS/$$QMAKE_PREFIX_STATICLIB
lib_suffixes = $$QMAKE_EXTENSION_STATICLIB
lib_suffixes *= $$QMAKE_LIB_EXTENSIONS
add_lib_to_pretargetdeps = true
} else {
lib = $$MODULE_LIBS/$$QMAKE_PREFIX_SHLIB$${lib}.$$QMAKE_EXTENSION_SHLIB
lib_prefix = $$MODULE_LIBS/$$QMAKE_PREFIX_SHLIB
lib_suffixes = $$QMAKE_EXTENSION_SHLIB
add_lib_to_pretargetdeps = false
}
candidates =
for(lib_base, lib_bases) {
for(lib_suffix, lib_suffixes) {
candidates += $${lib_prefix}$${lib_base}.$${lib_suffix}
}
}
lib =
for(candidate, candidates) {
exists("$$candidate") {
lib = "$$candidate"
break()
}
}
isEmpty(lib): \
lib = $$first(candidates)
$$add_lib_to_pretargetdeps: \
PRE_TARGETDEPS += $$lib
LIBS$$var_sfx += $$lib
}
}