From ce5dc3193279cdbcc34b583151ba05464444dd5a Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 30 Sep 2019 10:51:59 +0200 Subject: [PATCH] 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 Reviewed-by: Kai Koehne --- qmake/generators/win32/winmakefile.cpp | 42 +++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/qmake/generators/win32/winmakefile.cpp b/qmake/generators/win32/winmakefile.cpp index 27d2a7c0a5..86d10c213c 100644 --- a/qmake/generators/win32/winmakefile.cpp +++ b/qmake/generators/win32/winmakefile.cpp @@ -38,6 +38,8 @@ #include #include +#include + 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 dirs; + QVector 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; } }