Fix needless resolution of -l LIBS entries on Windows

Do not resolve -l entries to absolute file paths for libraries in the
default search paths.

This restores behavior from 5.12.0 (commit 2327944d) for Windows
system libraries.

Fixes: QTBUG-78827
Change-Id: Ic2d4626df87308dd635afc1ab5c4b8191d3d2831
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
This commit is contained in:
Joerg Bornemann 2019-09-30 10:51:59 +02:00
parent 85f9fa7fab
commit ce5dc31932

View File

@ -38,6 +38,8 @@
#include <qdir.h>
#include <stdlib.h>
#include <algorithm>
QT_BEGIN_NAMESPACE
ProString Win32MakefileGenerator::fixLibFlag(const ProString &lib)
@ -73,16 +75,37 @@ Win32MakefileGenerator::parseLibFlag(const ProString &flag, ProString *arg)
return LibFlagFile;
}
class LibrarySearchPath : public QMakeLocalFileName
{
public:
LibrarySearchPath() = default;
LibrarySearchPath(const QString &s)
: QMakeLocalFileName(s)
{
}
LibrarySearchPath(QString &&s, bool isDefault = false)
: QMakeLocalFileName(std::move(s)), _default(isDefault)
{
}
bool isDefault() const { return _default; }
private:
bool _default = false;
};
bool
Win32MakefileGenerator::findLibraries(bool linkPrl, bool mergeLflags)
{
ProStringList impexts = project->values("QMAKE_LIB_EXTENSIONS");
if (impexts.isEmpty())
impexts = project->values("QMAKE_EXTENSION_STATICLIB");
QVector<QMakeLocalFileName> dirs;
QVector<LibrarySearchPath> dirs;
int libidx = 0;
for (const ProString &dlib : project->values("QMAKE_DEFAULT_LIBDIRS"))
dirs.append(QMakeLocalFileName(dlib.toQString()));
dirs.append(LibrarySearchPath(dlib.toQString(), true));
static const char * const lflags[] = { "LIBS", "LIBS_PRIVATE",
"QMAKE_LIBS", "QMAKE_LIBS_PRIVATE", nullptr };
for (int i = 0; lflags[i]; i++) {
@ -92,12 +115,20 @@ Win32MakefileGenerator::findLibraries(bool linkPrl, bool mergeLflags)
ProString arg;
LibFlagType type = parseLibFlag(opt, &arg);
if (type == LibFlagPath) {
QMakeLocalFileName lp(arg.toQString());
int idx = dirs.indexOf(lp);
const QString argqstr = arg.toQString();
auto dit = std::find_if(dirs.cbegin(), dirs.cend(),
[&argqstr](const LibrarySearchPath &p)
{
return p.real() == argqstr;
});
int idx = dit == dirs.cend()
? -1
: std::distance(dirs.cbegin(), dit);
if (idx >= 0 && idx < libidx) {
it = l.erase(it);
continue;
}
const LibrarySearchPath lp(argqstr);
dirs.insert(libidx++, lp);
(*it) = "-L" + lp.real();
} else if (type == LibFlagLib) {
@ -114,7 +145,8 @@ Win32MakefileGenerator::findLibraries(bool linkPrl, bool mergeLflags)
for (ProStringList::ConstIterator extit = impexts.cbegin();
extit != impexts.cend(); ++extit) {
if (exists(libBase + '.' + *extit)) {
(*it) = cand + verovr + '.' + *extit;
*it = (dir_it->isDefault() ? lib : cand)
+ verovr + '.' + *extit;
goto found;
}
}