diff options
-rw-r--r-- | src/app/qbs-setup-toolchains/msvcprobe.cpp | 21 | ||||
-rw-r--r-- | src/lib/corelib/tools/msvcinfo.cpp | 21 | ||||
-rw-r--r-- | src/lib/corelib/tools/msvcinfo.h | 1 | ||||
-rw-r--r-- | src/lib/corelib/tools/vsenvironmentdetector.cpp | 3 | ||||
-rw-r--r-- | src/lib/corelib/tools/vsenvironmentdetector.h | 3 |
5 files changed, 41 insertions, 8 deletions
diff --git a/src/app/qbs-setup-toolchains/msvcprobe.cpp b/src/app/qbs-setup-toolchains/msvcprobe.cpp index 19da1e25a..00aedaaab 100644 --- a/src/app/qbs-setup-toolchains/msvcprobe.cpp +++ b/src/app/qbs-setup-toolchains/msvcprobe.cpp @@ -58,7 +58,7 @@ #include <QtCore/qstringlist.h> #include <algorithm> -#include <unordered_set> +#include <set> #include <vector> using namespace qbs; @@ -183,14 +183,21 @@ void msvcProbe(Settings *settings, std::vector<Profile> &profiles) } } - std::unordered_set<QString> seenNames; + // we want the same MSVC version share the same suffix in profiles, thus use + // a set to know the number of versions processed so far + std::map<QString /*VS*/, std::set<QString /*vcInstallPath*/>> msvcCounters; for (MSVC &msvc : msvcs) { - const QString name = QLatin1String("MSVC") + msvc.version + QLatin1Char('-') + // each VS needs its own counter + auto &msvcVersions = msvcCounters[msvc.version]; + // vcInstallPath is "Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.16.27023/bin" + // Since msvcs are sorted by version, when the new vcInstallPath is inserted, we start + // a new group of compilers of the same version incrementing the set size + msvcVersions.insert(msvc.vcInstallPath); + // index is the number of specific vcInstallPaths (e.g. compiler versions) seen so far + const qsizetype index = msvcVersions.size() - 1; + const QString suffix = index == 0 ? QString() : QStringLiteral("-%1").arg(index); + const QString name = QLatin1String("MSVC") + msvc.version + suffix + QLatin1Char('-') + msvc.architecture; - // TODO: Qbs currently does not support multiple versions of installed MSVCs - // so we stop at the first (the newest) one - if (!seenNames.insert(name).second) - continue; try { msvc.init(); addMSVCPlatform(settings, profiles, name, &msvc); diff --git a/src/lib/corelib/tools/msvcinfo.cpp b/src/lib/corelib/tools/msvcinfo.cpp index ed94613d9..58cd458c3 100644 --- a/src/lib/corelib/tools/msvcinfo.cpp +++ b/src/lib/corelib/tools/msvcinfo.cpp @@ -510,11 +510,32 @@ QString MSVC::architectureFromClPath(const QString &clPath) { const auto parentDir = QFileInfo(clPath).absolutePath(); const auto parentDirName = QFileInfo(parentDir).fileName().toLower(); + // can be the case when cl.exe is present within the Windows SDK installation... but can it? if (parentDirName == QLatin1String("bin")) return QStringLiteral("x86"); return parentDirName; } +QString MSVC::vcVariablesVersionFromBinPath(const QString &binPath) +{ + const auto binDirName = QFileInfo(binPath).fileName().toLower(); + // the case when cl.exe is present within the Windows SDK installation + if (binDirName == QLatin1String("bin")) + return {}; + // binPath is something like + // Microsoft Visual Studio 14.0/VC/bin/amd64_x86 + // or + // Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64 + QDir dir(binPath); + dir.cdUp(); + // older Visual Studios do not support multiple compiler versions + if (dir.dirName().toLower() == QLatin1String("bin")) + return {}; + dir.cdUp(); + dir.cdUp(); + return dir.dirName(); +} + QString MSVC::canonicalArchitecture(const QString &arch) { if (arch == QLatin1String("x64") || arch == QLatin1String("amd64")) diff --git a/src/lib/corelib/tools/msvcinfo.h b/src/lib/corelib/tools/msvcinfo.h index d081e5c15..efaf0b6c2 100644 --- a/src/lib/corelib/tools/msvcinfo.h +++ b/src/lib/corelib/tools/msvcinfo.h @@ -100,6 +100,7 @@ public: QBS_EXPORT void init(); QBS_EXPORT static QString architectureFromClPath(const QString &clPath); + QBS_EXPORT static QString vcVariablesVersionFromBinPath(const QString &binPath); QBS_EXPORT static QString canonicalArchitecture(const QString &arch); QBS_EXPORT static std::pair<QString, QString> getHostTargetArchPair(const QString &arch); QBS_EXPORT QString binPathForArchitecture(const QString &arch) const; diff --git a/src/lib/corelib/tools/vsenvironmentdetector.cpp b/src/lib/corelib/tools/vsenvironmentdetector.cpp index a11934d52..82dff578f 100644 --- a/src/lib/corelib/tools/vsenvironmentdetector.cpp +++ b/src/lib/corelib/tools/vsenvironmentdetector.cpp @@ -244,6 +244,9 @@ void VsEnvironmentDetector::writeBatchFile(QIODevice *device, const QString &vcv s << "call \"" << vcvarsallbat << "\" " << vcArchitecture(msvc); if (!msvc->sdkVersion.isEmpty()) s << " " << msvc->sdkVersion; + const auto vcVarsVer = MSVC::vcVariablesVersionFromBinPath(msvc->binPath); + if (!vcVarsVer.isEmpty()) + s << " -vcvars_ver=" << vcVarsVer; s << " || exit /b 1" << endl; batPrintVars(s, varnames); s << "endlocal" << endl; diff --git a/src/lib/corelib/tools/vsenvironmentdetector.h b/src/lib/corelib/tools/vsenvironmentdetector.h index 7fa152cb6..39bea07d6 100644 --- a/src/lib/corelib/tools/vsenvironmentdetector.h +++ b/src/lib/corelib/tools/vsenvironmentdetector.h @@ -57,7 +57,7 @@ class MSVC; class QBS_EXPORT VsEnvironmentDetector { public: - explicit VsEnvironmentDetector(QString vcvarsallPath = QString()); + explicit VsEnvironmentDetector(QString vcvarsallPath = {}); bool start(MSVC *msvc); bool start(std::vector<MSVC *> msvcs); @@ -71,6 +71,7 @@ private: const QString m_windowsSystemDirPath; const QString m_vcvarsallPath; + const QString m_vcVariablesVersion; QString m_errorString; }; |