forked from qt-creator/qt-creator
GCC: Detect multiple versions of gcc/g++ on linux
Debian/ubuntu systems can have /usr/bin/g++ which is GCC6, /usr/bin/g++-5 and /usr/bin/g++-7. The same applies for cross-compilers. Detect them all. Change-Id: Ia7b403efbfab60b05c4f27a9011d054d52c3aa1a Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
efa5a7b6d7
commit
131a796f9f
@@ -44,9 +44,9 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -66,6 +66,7 @@ static const char compilerPlatformLinkerFlagsKeyC[] = "ProjectExplorer.GccToolCh
|
|||||||
static const char targetAbiKeyC[] = "ProjectExplorer.GccToolChain.TargetAbi";
|
static const char targetAbiKeyC[] = "ProjectExplorer.GccToolChain.TargetAbi";
|
||||||
static const char originalTargetTripleKeyC[] = "ProjectExplorer.GccToolChain.OriginalTargetTriple";
|
static const char originalTargetTripleKeyC[] = "ProjectExplorer.GccToolChain.OriginalTargetTriple";
|
||||||
static const char supportedAbisKeyC[] = "ProjectExplorer.GccToolChain.SupportedAbis";
|
static const char supportedAbisKeyC[] = "ProjectExplorer.GccToolChain.SupportedAbis";
|
||||||
|
static const char binaryRegexp[] = "(?:^|-|\\b)(?:gcc|g\\+\\+)(?:-([\\d.]+))?$";
|
||||||
|
|
||||||
static const int CACHE_SIZE = 16;
|
static const int CACHE_SIZE = 16;
|
||||||
|
|
||||||
@@ -363,10 +364,15 @@ void GccToolChain::setOriginalTargetTriple(const QString &targetTriple)
|
|||||||
|
|
||||||
QString GccToolChain::defaultDisplayName() const
|
QString GccToolChain::defaultDisplayName() const
|
||||||
{
|
{
|
||||||
|
QString type = typeDisplayName();
|
||||||
|
const QRegularExpression regexp(binaryRegexp);
|
||||||
|
const QRegularExpressionMatch match = regexp.match(m_compilerCommand.fileName());
|
||||||
|
if (match.hasMatch())
|
||||||
|
type += ' ' + match.captured(1);
|
||||||
if (!m_targetAbi.isValid())
|
if (!m_targetAbi.isValid())
|
||||||
return typeDisplayName();
|
return type;
|
||||||
return QCoreApplication::translate("ProjectExplorer::GccToolChain",
|
return QCoreApplication::translate("ProjectExplorer::GccToolChain",
|
||||||
"%1 (%2, %3 %4 in %5)").arg(typeDisplayName(),
|
"%1 (%2, %3 %4 in %5)").arg(type,
|
||||||
ToolChainManager::displayNameOfLanguageId(language()),
|
ToolChainManager::displayNameOfLanguageId(language()),
|
||||||
Abi::toString(m_targetAbi.architecture()),
|
Abi::toString(m_targetAbi.architecture()),
|
||||||
Abi::toString(m_targetAbi.wordWidth()),
|
Abi::toString(m_targetAbi.wordWidth()),
|
||||||
@@ -928,20 +934,28 @@ QList<ToolChain *> GccToolChainFactory::autoDetect(const QList<ToolChain *> &alr
|
|||||||
Constants::GCC_TOOLCHAIN_TYPEID, alreadyKnown));
|
Constants::GCC_TOOLCHAIN_TYPEID, alreadyKnown));
|
||||||
known.append(tcs);
|
known.append(tcs);
|
||||||
if (HostOsInfo::isLinuxHost()) {
|
if (HostOsInfo::isLinuxHost()) {
|
||||||
|
const QRegularExpression regexp(binaryRegexp);
|
||||||
for (const QString &dir : QStringList({ "/usr/bin", "/usr/local/bin" })) {
|
for (const QString &dir : QStringList({ "/usr/bin", "/usr/local/bin" })) {
|
||||||
QDir binDir(dir);
|
QDir binDir(dir);
|
||||||
for (const QString &entry : binDir.entryList({"*-g++"}, QDir::Files | QDir::Executable)) {
|
auto gccProbe = [&](const QString &name, Core::Id language) {
|
||||||
tcs.append(autoDetectToolchains(entry, Abi(), Constants::CXX_LANGUAGE_ID,
|
for (const QString &entry : binDir.entryList(
|
||||||
Constants::GCC_TOOLCHAIN_TYPEID, known));
|
{"*-" + name, name + "-*", "*-" + name + "-*"},
|
||||||
known.append(tcs);
|
QDir::Files | QDir::Executable)) {
|
||||||
}
|
const QString fileName = FileName::fromString(entry).fileName();
|
||||||
for (const QString &entry : binDir.entryList({"*-gcc"}, QDir::Files | QDir::Executable)) {
|
if (fileName == "c89-gcc" || fileName == "c99-gcc")
|
||||||
if (entry.endsWith("c89-gcc") || entry.endsWith("c99-gcc"))
|
continue;
|
||||||
continue;
|
const QRegularExpressionMatch match = regexp.match(fileName);
|
||||||
tcs.append(autoDetectToolchains(entry, Abi(), Constants::C_LANGUAGE_ID,
|
if (!match.hasMatch())
|
||||||
Constants::GCC_TOOLCHAIN_TYPEID, known));
|
continue;
|
||||||
known.append(tcs);
|
const bool isNative = fileName.startsWith(name);
|
||||||
}
|
const Abi abi = isNative ? Abi::hostAbi() : Abi();
|
||||||
|
tcs.append(autoDetectToolchains(entry, abi, language,
|
||||||
|
Constants::GCC_TOOLCHAIN_TYPEID, known));
|
||||||
|
known.append(tcs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
gccProbe("g++", Constants::CXX_LANGUAGE_ID);
|
||||||
|
gccProbe("gcc", Constants::C_LANGUAGE_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user