Commit c3394ca7 authored by Joerg Bornemann's avatar Joerg Bornemann Committed by Oswald Buddenhagen
Browse files

fix MSVC target architecture detection for amd64_x86

When using the cross-compiler toolchain for 32 bit on a 64 bit machine,
qmake generated a 64 bit VS project.
This was because qmake didn't know about the amd64_x86 cross-compiler,
and qmake did not use the first MSVC bin directory it found in PATH.

Task-number: QTBUG-43457
Change-Id: I50c6f7bb9afe44a58321c670d680dbcc7cd07223
Reviewed-by: default avatarOswald Buddenhagen <>
(cherry picked from qtbase/e01c8103e14371dab7660343aff058528a11d763)
(cherry picked from qtbase/b9ae324dc9c815c2326803da0a3d0414cf7a2903)
Reviewed-by: default avatarJoerg Bornemann <>
parent 8a6255d2
......@@ -985,6 +985,49 @@ void QMakeEvaluator::setTemplate()
#if defined(Q_CC_MSVC)
static ProString msvcBinDirToQMakeArch(QString subdir)
int idx = subdir.indexOf(QLatin1Char('\\'));
if (idx == -1)
return ProString("x86");
subdir.remove(0, idx + 1);
idx = subdir.indexOf(QLatin1Char('_'));
if (idx >= 0)
subdir.remove(0, idx + 1);
subdir = subdir.toLower();
if (subdir == QStringLiteral("amd64"))
return ProString("x86_64");
return ProString(subdir);
static ProString defaultMsvcArchitecture()
#if defined(Q_OS_WIN64)
return ProString("x86_64");
return ProString("x86");
static ProString msvcArchitecture(const QString &vcInstallDir, const QString &pathVar)
if (vcInstallDir.isEmpty())
return defaultMsvcArchitecture();
QString vcBinDir = vcInstallDir;
if (vcBinDir.endsWith(QLatin1Char('\\')))
foreach (const QString &dir, pathVar.split(QLatin1Char(';'))) {
if (!dir.startsWith(vcBinDir, Qt::CaseInsensitive))
const ProString arch = msvcBinDirToQMakeArch(dir.mid(vcBinDir.length() + 1));
if (!arch.isEmpty())
return arch;
return defaultMsvcArchitecture();
#endif // defined(Q_CC_MSVC)
void QMakeEvaluator::loadDefaults()
ProValueMap &vars =;
......@@ -1046,21 +1089,9 @@ void QMakeEvaluator::loadDefaults()
vars[ProKey("QMAKE_HOST.arch")] << archStr;
# if defined(Q_CC_MSVC) // ### bogus condition, but nobody x-builds for msvc with a different qmake
QLatin1Char backslash('\\');
QString paths = m_option->getEnv(QLatin1String("PATH"));
QString vcBin64 = m_option->getEnv(QLatin1String("VCINSTALLDIR"));
if (!vcBin64.endsWith(backslash))
QString vcBinX86_64 = m_option->getEnv(QLatin1String("VCINSTALLDIR"));
if (!vcBinX86_64.endsWith(backslash))
if (paths.contains(vcBin64, Qt::CaseInsensitive)
|| paths.contains(vcBinX86_64, Qt::CaseInsensitive))
vars[ProKey("QMAKE_TARGET.arch")] << ProString("x86_64");
vars[ProKey("QMAKE_TARGET.arch")] << ProString("x86");
vars[ProKey("QMAKE_TARGET.arch")] = msvcArchitecture(
# endif
#elif defined(Q_OS_UNIX)
struct utsname name;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment