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 <oswald.buddenhagen@theqtcompany.com>
(cherry picked from qtbase/e01c8103e14371dab7660343aff058528a11d763)
(cherry picked from qtbase/b9ae324dc9c815c2326803da0a3d0414cf7a2903)
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
parent 8a6255d2
...@@ -985,6 +985,49 @@ void QMakeEvaluator::setTemplate() ...@@ -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");
#else
return ProString("x86");
#endif
}
static ProString msvcArchitecture(const QString &vcInstallDir, const QString &pathVar)
{
if (vcInstallDir.isEmpty())
return defaultMsvcArchitecture();
QString vcBinDir = vcInstallDir;
if (vcBinDir.endsWith(QLatin1Char('\\')))
vcBinDir.chop(1);
foreach (const QString &dir, pathVar.split(QLatin1Char(';'))) {
if (!dir.startsWith(vcBinDir, Qt::CaseInsensitive))
continue;
const ProString arch = msvcBinDirToQMakeArch(dir.mid(vcBinDir.length() + 1));
if (!arch.isEmpty())
return arch;
}
return defaultMsvcArchitecture();
}
#endif // defined(Q_CC_MSVC)
void QMakeEvaluator::loadDefaults() void QMakeEvaluator::loadDefaults()
{ {
ProValueMap &vars = m_valuemapStack.top(); ProValueMap &vars = m_valuemapStack.top();
...@@ -1046,21 +1089,9 @@ void QMakeEvaluator::loadDefaults() ...@@ -1046,21 +1089,9 @@ void QMakeEvaluator::loadDefaults()
vars[ProKey("QMAKE_HOST.arch")] << archStr; vars[ProKey("QMAKE_HOST.arch")] << archStr;
# if defined(Q_CC_MSVC) // ### bogus condition, but nobody x-builds for msvc with a different qmake # if defined(Q_CC_MSVC) // ### bogus condition, but nobody x-builds for msvc with a different qmake
QLatin1Char backslash('\\'); vars[ProKey("QMAKE_TARGET.arch")] = msvcArchitecture(
QString paths = m_option->getEnv(QLatin1String("PATH")); m_option->getEnv(QLatin1String("VCINSTALLDIR")),
QString vcBin64 = m_option->getEnv(QLatin1String("VCINSTALLDIR")); m_option->getEnv(QLatin1String("PATH")));
if (!vcBin64.endsWith(backslash))
vcBin64.append(backslash);
vcBin64.append(QLatin1String("bin\\amd64"));
QString vcBinX86_64 = m_option->getEnv(QLatin1String("VCINSTALLDIR"));
if (!vcBinX86_64.endsWith(backslash))
vcBinX86_64.append(backslash);
vcBinX86_64.append(QLatin1String("bin\\x86_amd64"));
if (paths.contains(vcBin64, Qt::CaseInsensitive)
|| paths.contains(vcBinX86_64, Qt::CaseInsensitive))
vars[ProKey("QMAKE_TARGET.arch")] << ProString("x86_64");
else
vars[ProKey("QMAKE_TARGET.arch")] << ProString("x86");
# endif # endif
#elif defined(Q_OS_UNIX) #elif defined(Q_OS_UNIX)
struct utsname name; struct utsname name;
......
Markdown is supported
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