iOS: Add C toolchain

To fix kits complaining about incorrect C compiler and ABI
incompatibility

Task-number: QTCREATORBUG-17135
Change-Id: I69ece613453463b97d193bb1740044d16f62172f
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Vikas Pachdha
2016-11-16 14:59:10 +01:00
parent 38753d06a2
commit 9f0bb3c93a
3 changed files with 145 additions and 85 deletions

View File

@@ -116,17 +116,26 @@ void IosProbe::setupDefaultToolchains(const QString &devPath, const QString &xco
qCDebug(probeLog) << QString::fromLatin1("Setting up platform \"%1\".").arg(xcodeName);
QString indent = QLatin1String(" ");
auto getClangInfo = [devPath, indent](const QString &compiler) {
QFileInfo compilerInfo(devPath
+ QLatin1String("/Toolchains/XcodeDefault.xctoolchain/usr/bin/")
+ compiler);
if (!compilerInfo.exists())
qCWarning(probeLog) << indent << QString::fromLatin1("Default toolchain %1 not found.")
.arg(compilerInfo.canonicalFilePath());
return compilerInfo;
};
// detect clang (default toolchain)
QFileInfo clangFileInfo(devPath
+ QLatin1String("/Toolchains/XcodeDefault.xctoolchain/usr/bin")
+ QLatin1String("/clang++"));
bool hasClang = clangFileInfo.exists();
if (!hasClang)
qCWarning(probeLog) << indent << QString::fromLatin1("Default toolchain %1 not found.")
.arg(clangFileInfo.canonicalFilePath());
const QFileInfo clangCppInfo = getClangInfo("clang++");
const bool hasClangCpp = clangCppInfo.exists();
const QFileInfo clangCInfo = getClangInfo("clang");
const bool hasClangC = clangCInfo.exists();
// Platforms
QDir platformsDir(devPath + QLatin1String("/Platforms"));
QFileInfoList platforms = platformsDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
const QDir platformsDir(devPath + QLatin1String("/Platforms"));
const QFileInfoList platforms = platformsDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach (const QFileInfo &fInfo, platforms) {
if (fInfo.isDir() && fInfo.suffix() == QLatin1String("platform")) {
qCDebug(probeLog) << indent << QString::fromLatin1("Setting up %1").arg(fInfo.fileName());
@@ -159,14 +168,20 @@ void IosProbe::setupDefaultToolchains(const QString &devPath, const QString &xco
defaultProp[i.key()] = i.value();
}
QString clangFullName = name + QLatin1String("-clang") + xcodeName;
QString clang11FullName = name + QLatin1String("-clang11") + xcodeName;
const QString clangFullName = name + QLatin1String("-clang") + xcodeName;
const QString clang11FullName = name + QLatin1String("-clang11") + xcodeName;
// detect gcc
QFileInfo gccFileInfo(fInfo.absoluteFilePath() + QLatin1String("/Developer/usr/bin/g++"));
QString gccFullName = name + QLatin1String("-gcc") + xcodeName;
if (!gccFileInfo.exists())
gccFileInfo = QFileInfo(devPath + QLatin1String("/usr/bin/g++"));
bool hasGcc = gccFileInfo.exists();
QFileInfo gccCppInfo(fInfo.absoluteFilePath() + QLatin1String("/Developer/usr/bin/g++"));
if (!gccCppInfo.exists())
gccCppInfo = QFileInfo(devPath + QLatin1String("/usr/bin/g++"));
const bool hasGccCppCompiler = gccCppInfo.exists();
QFileInfo gccCInfo(fInfo.absoluteFilePath() + QLatin1String("/Developer/usr/bin/gcc"));
if (!gccCInfo.exists())
gccCInfo = QFileInfo(devPath + QLatin1String("/usr/bin/gcc"));
const bool hasGccCCompiler = gccCInfo.exists();
const QString gccFullName = name + QLatin1String("-gcc") + xcodeName;
QStringList extraFlags;
if (defaultProp.contains(QLatin1String("NATIVE_ARCH"))) {
@@ -178,45 +193,58 @@ void IosProbe::setupDefaultToolchains(const QString &devPath, const QString &xco
// don't generate a toolchain for 64 bit (to fix when we support that)
extraFlags << QLatin1String("-arch") << QLatin1String("i386");
}
if (hasClang) {
Platform clangProfile;
clangProfile.developerPath = Utils::FileName::fromString(devPath);
clangProfile.platformKind = 0;
clangProfile.name = clangFullName;
clangProfile.platformPath = Utils::FileName(fInfo);
clangProfile.compilerPath = Utils::FileName(clangFileInfo);
auto getArch = [extraFlags](const QFileInfo &compiler) {
QStringList flags = extraFlags;
flags << QLatin1String("-dumpmachine");
QString compilerTriplet = qsystem(clangFileInfo.canonicalFilePath(), flags)
.simplified();
QStringList compilerTripletl = compilerTriplet.split(QLatin1Char('-'));
clangProfile.architecture = compilerTripletl.value(0);
const QStringList compilerTriplet = qsystem(compiler.canonicalFilePath(), flags)
.simplified().split(QLatin1Char('-'));
return compilerTriplet.value(0);
};
if (hasClangCpp || hasClangC) {
Platform clangProfile;
clangProfile.type = Platform::CLang;
clangProfile.developerPath = Utils::FileName::fromString(devPath);
clangProfile.platformKind = 0;
clangProfile.platformPath = Utils::FileName(fInfo);
clangProfile.architecture = getArch(hasClangCpp ? clangCppInfo : clangCInfo);
clangProfile.backendFlags = extraFlags;
qCDebug(probeLog) << indent << QString::fromLatin1("* adding profile %1").arg(clangProfile.name);
m_platforms[clangProfile.name] = clangProfile;
clangProfile.platformKind |= Platform::Cxx11Support;
clangProfile.backendFlags.append(QLatin1String("-std=c++11"));
clangProfile.backendFlags.append(QLatin1String("-stdlib=libc++"));
clangProfile.name = clang11FullName;
m_platforms[clangProfile.name] = clangProfile;
clangProfile.name = clangFullName;
if (hasClangC) {
clangProfile.cCompilerPath = Utils::FileName(clangCInfo);
m_platforms[clangFullName] = clangProfile;
}
if (hasClangCpp) {
clangProfile.cxxCompilerPath = Utils::FileName(clangCppInfo);
m_platforms[clangFullName] = clangProfile;
clangProfile.platformKind |= Platform::Cxx11Support;
clangProfile.backendFlags.append(QLatin1String("-std=c++11"));
clangProfile.backendFlags.append(QLatin1String("-stdlib=libc++"));
clangProfile.name = clang11FullName;
m_platforms[clang11FullName] = clangProfile;
}
}
if (hasGcc) {
if (hasGccCppCompiler || hasGccCCompiler) {
Platform gccProfile;
gccProfile.type = Platform::GCC;
gccProfile.developerPath = Utils::FileName::fromString(devPath);
gccProfile.name = gccFullName;
gccProfile.platformKind = 0;
// use the arm-apple-darwin10-llvm-* variant and avoid the extraFlags if available???
gccProfile.platformPath = Utils::FileName(fInfo);
gccProfile.compilerPath = Utils::FileName(gccFileInfo);
QStringList flags = extraFlags;
flags << QLatin1String("-dumpmachine");
QString compilerTriplet = qsystem(gccFileInfo.canonicalFilePath(), flags)
.simplified();
QStringList compilerTripletl = compilerTriplet.split(QLatin1Char('-'));
gccProfile.architecture = compilerTripletl.value(0);
gccProfile.architecture = getArch(hasGccCppCompiler ? gccCppInfo : gccCInfo);
gccProfile.backendFlags = extraFlags;
qCDebug(probeLog) << indent << QString::fromLatin1("* adding profile %1").arg(gccProfile.name);
m_platforms[gccProfile.name] = gccProfile;
if (hasGccCppCompiler) {
gccProfile.cxxCompilerPath = Utils::FileName(gccCppInfo);
}
if (hasGccCCompiler) {
gccProfile.cCompilerPath = Utils::FileName(gccCInfo);
}
m_platforms[gccFullName] = gccProfile;
}
// set SDKs/sysroot
@@ -262,15 +290,18 @@ void IosProbe::setupDefaultToolchains(const QString &devPath, const QString &xco
if (sysRoot.isEmpty() && !sdkName.isEmpty())
qCDebug(probeLog) << indent << QString::fromLatin1("Failed to find sysroot %1").arg(sdkName);
}
if (hasClang && !sysRoot.isEmpty()) {
m_platforms[clangFullName].platformKind |= Platform::BasePlatform;
m_platforms[clangFullName].sdkPath = Utils::FileName::fromString(sysRoot);
m_platforms[clang11FullName].platformKind |= Platform::BasePlatform;
m_platforms[clang11FullName].sdkPath = Utils::FileName::fromString(sysRoot);
}
if (hasGcc && !sysRoot.isEmpty()) {
m_platforms[gccFullName].platformKind |= Platform::BasePlatform;
m_platforms[gccFullName].sdkPath = Utils::FileName::fromString(sysRoot);
if (!sysRoot.isEmpty()) {
auto itr = m_platforms.begin();
while (itr != m_platforms.end()) {
if (itr.key() == clangFullName ||
itr.key() == clang11FullName ||
itr.key() == gccFullName) {
itr.value().platformKind |= Platform::BasePlatform;
itr.value().sdkPath = Utils::FileName::fromString(sysRoot);
}
++itr;
}
}
}
indent = QLatin1String(" ");
@@ -293,7 +324,8 @@ QDebug operator<<(QDebug debug, const Platform &platform)
{
QDebugStateSaver saver(debug); Q_UNUSED(saver)
debug.nospace() << "(name=" << platform.name
<< ", compiler=" << platform.compilerPath.toString()
<< ", C++ compiler=" << platform.cxxCompilerPath.toString()
<< ", C compiler=" << platform.cCompilerPath.toString()
<< ", flags=" << platform.backendFlags
<< ")";
return debug;