2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-02-01 18:36:00 +01:00
|
|
|
**
|
2017-10-24 14:36:11 +02:00
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
2016-01-15 14:57:40 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-02-01 18:36:00 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-01 18:36:00 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-02-01 18:36:00 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-02-01 18:36:00 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-02-01 18:36:00 +01:00
|
|
|
|
|
|
|
|
#include "gcctoolchain.h"
|
2011-05-18 18:38:58 +02:00
|
|
|
#include "clangparser.h"
|
2011-02-28 16:50:14 +01:00
|
|
|
#include "gcctoolchainfactories.h"
|
2011-02-01 18:36:00 +01:00
|
|
|
#include "gccparser.h"
|
|
|
|
|
#include "linuxiccparser.h"
|
2017-02-07 15:00:38 +01:00
|
|
|
#include "projectmacro.h"
|
2011-03-31 10:13:35 +02:00
|
|
|
#include "toolchainmanager.h"
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2018-08-06 12:30:32 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
2014-07-07 19:02:26 +02:00
|
|
|
#include <utils/algorithm.h>
|
2011-02-01 18:36:00 +01:00
|
|
|
#include <utils/environment.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2011-02-01 18:36:00 +01:00
|
|
|
#include <utils/synchronousprocess.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
#include <utils/pathchooser.h>
|
2013-07-25 15:18:23 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2013-04-22 23:03:45 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2016-04-29 16:52:58 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QBuffer>
|
|
|
|
|
#include <QCoreApplication>
|
2017-07-14 15:47:03 +03:00
|
|
|
#include <QDir>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QFormLayout>
|
2017-07-17 22:35:06 +03:00
|
|
|
#include <QLineEdit>
|
2017-10-27 16:02:06 +02:00
|
|
|
#include <QLoggingCategory>
|
2017-07-17 22:35:06 +03:00
|
|
|
#include <QRegularExpression>
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
#include <algorithm>
|
2017-02-07 13:05:12 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
2017-10-27 16:02:06 +02:00
|
|
|
namespace {
|
2018-10-12 09:33:30 +03:00
|
|
|
Q_LOGGING_CATEGORY(gccLog, "qtc.projectexplorer.toolchain.gcc", QtWarningMsg);
|
2017-10-27 16:02:06 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
2012-08-21 13:29:16 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
using namespace Internal;
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// Helpers:
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2012-02-01 14:39:11 +01:00
|
|
|
static const char compilerCommandKeyC[] = "ProjectExplorer.GccToolChain.Path";
|
2013-04-22 23:03:45 +02:00
|
|
|
static const char compilerPlatformCodeGenFlagsKeyC[] = "ProjectExplorer.GccToolChain.PlatformCodeGenFlags";
|
|
|
|
|
static const char compilerPlatformLinkerFlagsKeyC[] = "ProjectExplorer.GccToolChain.PlatformLinkerFlags";
|
2011-03-10 14:44:49 +01:00
|
|
|
static const char targetAbiKeyC[] = "ProjectExplorer.GccToolChain.TargetAbi";
|
2016-03-04 15:33:16 +01:00
|
|
|
static const char originalTargetTripleKeyC[] = "ProjectExplorer.GccToolChain.OriginalTargetTriple";
|
2011-06-21 13:26:22 +02:00
|
|
|
static const char supportedAbisKeyC[] = "ProjectExplorer.GccToolChain.SupportedAbis";
|
2018-07-11 00:16:44 +03:00
|
|
|
static const char binaryRegexp[] = "(?:^|-|\\b)(?:gcc|g\\+\\+|clang(?:\\+\\+)?)(?:-([\\d.]+))?$";
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2012-08-21 13:29:16 +02:00
|
|
|
static QByteArray runGcc(const FileName &gcc, const QStringList &arguments, const QStringList &env)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2012-01-30 13:07:51 +01:00
|
|
|
if (gcc.isEmpty() || !gcc.toFileInfo().isExecutable())
|
2011-02-01 18:36:00 +01:00
|
|
|
return QByteArray();
|
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess cpp;
|
2011-07-29 08:53:00 +00:00
|
|
|
QStringList environment(env);
|
2016-04-07 13:06:01 +02:00
|
|
|
Utils::Environment::setupEnglishOutput(&environment);
|
2011-07-29 08:53:00 +00:00
|
|
|
|
|
|
|
|
cpp.setEnvironment(environment);
|
2016-04-29 16:52:58 +02:00
|
|
|
cpp.setTimeoutS(10);
|
2016-06-10 13:33:40 +03:00
|
|
|
SynchronousProcessResponse response = cpp.runBlocking(gcc.toString(), arguments);
|
2016-04-29 16:52:58 +02:00
|
|
|
if (response.result != SynchronousProcessResponse::Finished ||
|
|
|
|
|
response.exitCode != 0) {
|
|
|
|
|
qWarning() << response.exitMessage(gcc.toString(), 10);
|
2013-09-02 17:23:59 +02:00
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
return response.allOutput().toUtf8();
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
static ProjectExplorer::Macros gccPredefinedMacros(const FileName &gcc,
|
|
|
|
|
const QStringList &args,
|
|
|
|
|
const QStringList &env)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-09-09 15:47:46 +02:00
|
|
|
QStringList arguments = args;
|
2016-11-24 14:57:07 +01:00
|
|
|
arguments << "-";
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
ProjectExplorer::Macros predefinedMacros = Macro::toMacros(runGcc(gcc, arguments, env));
|
2013-07-25 15:18:23 +02:00
|
|
|
// Sanity check in case we get an error message instead of real output:
|
2017-02-07 15:00:38 +01:00
|
|
|
QTC_CHECK(predefinedMacros.isEmpty()
|
|
|
|
|
|| predefinedMacros.front().type == ProjectExplorer::MacroType::Define);
|
2015-02-03 23:59:04 +02:00
|
|
|
if (HostOsInfo::isMacHost()) {
|
2012-08-23 15:53:58 +02:00
|
|
|
// Turn off flag indicating Apple's blocks support
|
2017-02-07 15:00:38 +01:00
|
|
|
const ProjectExplorer::Macro blocksDefine("__BLOCKS__", "1");
|
|
|
|
|
const ProjectExplorer::Macro blocksUndefine("__BLOCKS__", ProjectExplorer::MacroType::Undefine);
|
2012-08-23 15:53:58 +02:00
|
|
|
const int idx = predefinedMacros.indexOf(blocksDefine);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (idx != -1)
|
2017-02-07 15:00:38 +01:00
|
|
|
predefinedMacros[idx] = blocksUndefine;
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
// Define __strong and __weak (used for Apple's GC extension of C) to be empty
|
2017-02-07 15:00:38 +01:00
|
|
|
predefinedMacros.append({"__strong"});
|
|
|
|
|
predefinedMacros.append({"__weak"});
|
2012-08-23 15:53:58 +02:00
|
|
|
}
|
2011-02-01 18:36:00 +01:00
|
|
|
return predefinedMacros;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:19:07 +02:00
|
|
|
HeaderPaths GccToolChain::gccHeaderPaths(const FileName &gcc, const QStringList &arguments,
|
|
|
|
|
const QStringList &env)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2018-09-17 11:29:32 +02:00
|
|
|
HeaderPaths builtInHeaderPaths;
|
2011-02-01 18:36:00 +01:00
|
|
|
QByteArray line;
|
|
|
|
|
QByteArray data = runGcc(gcc, arguments, env);
|
|
|
|
|
QBuffer cpp(&data);
|
2011-03-01 13:23:49 +01:00
|
|
|
cpp.open(QIODevice::ReadOnly);
|
2011-02-01 18:36:00 +01:00
|
|
|
while (cpp.canReadLine()) {
|
|
|
|
|
line = cpp.readLine();
|
|
|
|
|
if (line.startsWith("#include"))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!line.isEmpty() && line.startsWith("#include")) {
|
2018-09-13 11:44:43 +02:00
|
|
|
auto kind = HeaderPathType::User;
|
2011-02-01 18:36:00 +01:00
|
|
|
while (cpp.canReadLine()) {
|
|
|
|
|
line = cpp.readLine();
|
|
|
|
|
if (line.startsWith("#include")) {
|
2018-09-17 11:29:32 +02:00
|
|
|
kind = HeaderPathType::BuiltIn;
|
2016-11-24 14:57:07 +01:00
|
|
|
} else if (! line.isEmpty() && QChar(line.at(0)).isSpace()) {
|
2018-09-13 11:44:43 +02:00
|
|
|
HeaderPathType thisHeaderKind = kind;
|
2011-02-01 18:36:00 +01:00
|
|
|
|
|
|
|
|
line = line.trimmed();
|
|
|
|
|
|
|
|
|
|
const int index = line.indexOf(" (framework directory)");
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
line.truncate(index);
|
2018-09-13 11:44:43 +02:00
|
|
|
thisHeaderKind = HeaderPathType::Framework;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2017-10-24 14:36:11 +02:00
|
|
|
const QString headerPath = QFileInfo(QFile::decodeName(line)).canonicalFilePath();
|
2018-09-17 11:29:32 +02:00
|
|
|
builtInHeaderPaths.append({headerPath, thisHeaderKind});
|
2011-02-01 18:36:00 +01:00
|
|
|
} else if (line.startsWith("End of search list.")) {
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
2012-01-09 16:30:33 +01:00
|
|
|
qWarning("%s: Ignoring line: %s", __FUNCTION__, line.constData());
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-17 11:29:32 +02:00
|
|
|
return builtInHeaderPaths;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2017-10-30 10:12:32 +01:00
|
|
|
void GccToolChain::toolChainUpdated()
|
|
|
|
|
{
|
|
|
|
|
m_predefinedMacrosCache->invalidate();
|
|
|
|
|
m_headerPathsCache->invalidate();
|
|
|
|
|
ToolChain::toolChainUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
static QList<Abi> guessGccAbi(const QString &m, const ProjectExplorer::Macros ¯os)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2012-08-21 13:29:16 +02:00
|
|
|
QList<Abi> abiList;
|
2011-03-10 14:44:49 +01:00
|
|
|
|
2013-08-23 11:45:39 +02:00
|
|
|
Abi guessed = Abi::abiFromTargetTriplet(m);
|
|
|
|
|
if (guessed.isNull())
|
2011-03-10 14:44:49 +01:00
|
|
|
return abiList;
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2013-08-23 11:45:39 +02:00
|
|
|
Abi::Architecture arch = guessed.architecture();
|
|
|
|
|
Abi::OS os = guessed.os();
|
|
|
|
|
Abi::OSFlavor flavor = guessed.osFlavor();
|
|
|
|
|
Abi::BinaryFormat format = guessed.binaryFormat();
|
|
|
|
|
int width = guessed.wordWidth();
|
2017-02-07 15:00:38 +01:00
|
|
|
|
|
|
|
|
const Macro sizeOfMacro = Utils::findOrDefault(macros, [](const Macro &m) { return m.key == "__SIZEOF_SIZE_T__"; });
|
|
|
|
|
if (sizeOfMacro.isValid() && sizeOfMacro.type == MacroType::Define)
|
|
|
|
|
width = sizeOfMacro.value.toInt() * 8;
|
|
|
|
|
const Macro &mscVerMacro = Utils::findOrDefault(macros, [](const Macro &m) { return m.key == "_MSC_VER"; });
|
|
|
|
|
if (mscVerMacro.type == MacroType::Define) {
|
|
|
|
|
const int msvcVersion = mscVerMacro.value.toInt();
|
2017-04-06 16:25:16 +03:00
|
|
|
flavor = Abi::flavorForMsvcVersion(msvcVersion);
|
|
|
|
|
}
|
2013-11-04 13:07:20 +01:00
|
|
|
|
2016-07-25 18:39:16 -07:00
|
|
|
if (os == Abi::DarwinOS) {
|
2011-03-10 14:44:49 +01:00
|
|
|
// Apple does PPC and x86!
|
2012-08-21 13:29:16 +02:00
|
|
|
abiList << Abi(arch, os, flavor, format, width);
|
|
|
|
|
abiList << Abi(arch, os, flavor, format, width == 64 ? 32 : 64);
|
2013-03-15 16:36:48 +01:00
|
|
|
} else if (arch == Abi::X86Architecture && (width == 0 || width == 64)) {
|
2013-11-04 13:07:20 +01:00
|
|
|
abiList << Abi(arch, os, flavor, format, 64);
|
2012-08-21 13:29:16 +02:00
|
|
|
abiList << Abi(arch, os, flavor, format, 32);
|
2011-03-10 14:44:49 +01:00
|
|
|
} else {
|
2012-08-21 13:29:16 +02:00
|
|
|
abiList << Abi(arch, os, flavor, format, width);
|
2011-03-10 14:44:49 +01:00
|
|
|
}
|
|
|
|
|
return abiList;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-04 15:33:16 +01:00
|
|
|
|
|
|
|
|
static GccToolChain::DetectedAbisResult guessGccAbi(const FileName &path, const QStringList &env,
|
2017-02-07 15:00:38 +01:00
|
|
|
const ProjectExplorer::Macros ¯os,
|
2016-03-04 15:33:16 +01:00
|
|
|
const QStringList &extraArgs = QStringList())
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2012-02-09 13:45:08 +01:00
|
|
|
if (path.isEmpty())
|
2016-03-04 15:33:16 +01:00
|
|
|
return GccToolChain::DetectedAbisResult();
|
2012-02-09 13:45:08 +01:00
|
|
|
|
2013-04-22 23:03:45 +02:00
|
|
|
QStringList arguments = extraArgs;
|
2016-11-24 14:57:07 +01:00
|
|
|
arguments << "-dumpmachine";
|
2011-02-01 18:36:00 +01:00
|
|
|
QString machine = QString::fromLocal8Bit(runGcc(path, arguments, env)).trimmed();
|
2013-07-25 14:36:28 +02:00
|
|
|
if (machine.isEmpty())
|
2016-03-04 15:33:16 +01:00
|
|
|
return GccToolChain::DetectedAbisResult(); // no need to continue if running failed once...
|
|
|
|
|
return GccToolChain::DetectedAbisResult(guessGccAbi(machine, macros), machine);
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-21 13:29:16 +02:00
|
|
|
static QString gccVersion(const FileName &path, const QStringList &env)
|
2011-09-06 15:19:05 +00:00
|
|
|
{
|
2016-11-24 14:57:07 +01:00
|
|
|
QStringList arguments("-dumpversion");
|
2011-09-06 15:19:05 +00:00
|
|
|
return QString::fromLocal8Bit(runGcc(path, arguments, env)).trimmed();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// GccToolChain
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-09-03 10:58:59 +02:00
|
|
|
GccToolChain::GccToolChain(Detection d) :
|
2017-10-24 14:36:11 +02:00
|
|
|
GccToolChain(Constants::GCC_TOOLCHAIN_TYPEID, d)
|
2011-02-01 18:36:00 +01:00
|
|
|
{ }
|
|
|
|
|
|
2015-07-09 11:34:37 +02:00
|
|
|
GccToolChain::GccToolChain(Core::Id typeId, Detection d) :
|
2017-10-24 14:36:11 +02:00
|
|
|
ToolChain(typeId, d),
|
2018-09-27 10:18:44 +02:00
|
|
|
m_predefinedMacrosCache(std::make_shared<Cache<MacroInspectionReport, 64>>()),
|
2018-09-13 12:19:07 +02:00
|
|
|
m_headerPathsCache(std::make_shared<Cache<HeaderPaths>>())
|
2011-02-01 18:36:00 +01:00
|
|
|
{ }
|
|
|
|
|
|
2014-07-21 14:23:09 +02:00
|
|
|
void GccToolChain::setCompilerCommand(const FileName &path)
|
|
|
|
|
{
|
|
|
|
|
if (path == m_compilerCommand)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_compilerCommand = path;
|
2016-07-06 14:13:25 +02:00
|
|
|
toolChainUpdated();
|
2014-07-21 14:23:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GccToolChain::setSupportedAbis(const QList<Abi> &m_abis)
|
|
|
|
|
{
|
2016-07-06 14:13:25 +02:00
|
|
|
if (m_supportedAbis == m_abis)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-07-21 14:23:09 +02:00
|
|
|
m_supportedAbis = m_abis;
|
2016-07-06 14:13:25 +02:00
|
|
|
toolChainUpdated();
|
2014-07-21 14:23:09 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-04 15:33:16 +01:00
|
|
|
void GccToolChain::setOriginalTargetTriple(const QString &targetTriple)
|
|
|
|
|
{
|
2016-07-06 14:13:25 +02:00
|
|
|
if (m_originalTargetTriple == targetTriple)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-03-04 15:33:16 +01:00
|
|
|
m_originalTargetTriple = targetTriple;
|
2016-07-06 14:13:25 +02:00
|
|
|
toolChainUpdated();
|
2016-03-04 15:33:16 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
QString GccToolChain::defaultDisplayName() const
|
|
|
|
|
{
|
2017-07-17 22:35:06 +03:00
|
|
|
QString type = typeDisplayName();
|
|
|
|
|
const QRegularExpression regexp(binaryRegexp);
|
|
|
|
|
const QRegularExpressionMatch match = regexp.match(m_compilerCommand.fileName());
|
2017-07-25 23:47:16 +03:00
|
|
|
if (match.lastCapturedIndex() >= 1)
|
2017-07-17 22:35:06 +03:00
|
|
|
type += ' ' + match.captured(1);
|
2017-07-26 22:41:43 +03:00
|
|
|
if (m_targetAbi.architecture() == Abi::UnknownArchitecture || m_targetAbi.wordWidth() == 0)
|
2017-07-17 22:35:06 +03:00
|
|
|
return type;
|
2013-01-08 11:19:27 +01:00
|
|
|
return QCoreApplication::translate("ProjectExplorer::GccToolChain",
|
2017-07-17 22:35:06 +03:00
|
|
|
"%1 (%2, %3 %4 in %5)").arg(type,
|
2016-12-16 00:43:14 +01:00
|
|
|
ToolChainManager::displayNameOfLanguageId(language()),
|
2016-12-16 13:40:00 +01:00
|
|
|
Abi::toString(m_targetAbi.architecture()),
|
|
|
|
|
Abi::toString(m_targetAbi.wordWidth()),
|
|
|
|
|
compilerCommand().parentDir().toUserOutput());
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtensions GccToolChain::defaultLanguageExtensions() const
|
2013-04-28 13:11:48 +04:00
|
|
|
{
|
2018-10-08 09:49:02 +02:00
|
|
|
return LanguageExtension::Gnu;
|
2013-04-28 13:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
2012-01-30 11:55:21 +01:00
|
|
|
QString GccToolChain::typeDisplayName() const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-08-09 17:49:30 +02:00
|
|
|
return GccToolChainFactory::tr("GCC");
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Abi GccToolChain::targetAbi() const
|
|
|
|
|
{
|
|
|
|
|
return m_targetAbi;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 15:33:16 +01:00
|
|
|
QString GccToolChain::originalTargetTriple() const
|
|
|
|
|
{
|
2016-03-31 08:48:59 +02:00
|
|
|
if (m_originalTargetTriple.isEmpty())
|
|
|
|
|
m_originalTargetTriple = detectSupportedAbis().originalTargetTriple;
|
2016-03-04 15:33:16 +01:00
|
|
|
return m_originalTargetTriple;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 15:19:05 +00:00
|
|
|
QString GccToolChain::version() const
|
|
|
|
|
{
|
|
|
|
|
if (m_version.isEmpty())
|
|
|
|
|
m_version = detectVersion();
|
|
|
|
|
return m_version;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-10 14:44:49 +01:00
|
|
|
void GccToolChain::setTargetAbi(const Abi &abi)
|
|
|
|
|
{
|
2011-03-24 13:27:26 +01:00
|
|
|
if (abi == m_targetAbi)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-05-24 14:06:51 +00:00
|
|
|
m_targetAbi = abi;
|
|
|
|
|
toolChainUpdated();
|
2011-03-10 14:44:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Abi> GccToolChain::supportedAbis() const
|
|
|
|
|
{
|
|
|
|
|
return m_supportedAbis;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
bool GccToolChain::isValid() const
|
|
|
|
|
{
|
2013-01-31 16:02:29 +01:00
|
|
|
if (m_compilerCommand.isNull())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
QFileInfo fi = compilerCommand().toFileInfo();
|
|
|
|
|
return fi.isExecutable();
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-13 10:56:38 +01:00
|
|
|
static Utils::FileName findLocalCompiler(const Utils::FileName &compilerPath,
|
|
|
|
|
const Environment &env)
|
|
|
|
|
{
|
2017-09-15 17:33:16 +02:00
|
|
|
// Find the "real" compiler if icecc, distcc or similar are in use. Ignore ccache, since that
|
|
|
|
|
// is local already.
|
|
|
|
|
|
2018-10-22 16:34:31 +02:00
|
|
|
// Get the path to the compiler, ignoring direct calls to icecc and distcc as we cannot
|
2017-09-15 17:33:16 +02:00
|
|
|
// do anything about those.
|
|
|
|
|
const Utils::FileName compilerDir = compilerPath.parentDir();
|
|
|
|
|
const QString compilerDirString = compilerDir.toString();
|
|
|
|
|
if (!compilerDirString.contains("icecc") && !compilerDirString.contains("distcc"))
|
|
|
|
|
return compilerPath;
|
|
|
|
|
|
2017-10-09 12:09:27 +02:00
|
|
|
FileNameList pathComponents = env.path();
|
2017-09-15 17:33:16 +02:00
|
|
|
auto it = std::find_if(pathComponents.begin(), pathComponents.end(),
|
2017-10-09 12:09:27 +02:00
|
|
|
[compilerDir](const FileName &p) {
|
|
|
|
|
return p == compilerDir;
|
2017-02-13 10:56:38 +01:00
|
|
|
});
|
2017-09-15 17:33:16 +02:00
|
|
|
if (it != pathComponents.end()) {
|
|
|
|
|
std::rotate(pathComponents.begin(), it, pathComponents.end());
|
|
|
|
|
pathComponents.removeFirst(); // remove directory of compilerPath
|
|
|
|
|
// No need to put it at the end again, it is in PATH anyway...
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This effectively searches the PATH twice, once via pathComponents and once via PATH itself:
|
|
|
|
|
// searchInPath filters duplicates, so that will not hurt.
|
|
|
|
|
const Utils::FileName path = env.searchInPath(compilerPath.fileName(), pathComponents);
|
2017-02-13 10:56:38 +01:00
|
|
|
|
2017-09-15 17:33:16 +02:00
|
|
|
return path.isEmpty() ? compilerPath : path;
|
2017-02-13 10:56:38 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-27 10:18:44 +02:00
|
|
|
ToolChain::MacroInspectionRunner GccToolChain::createMacroInspectionRunner() const
|
2017-02-06 16:59:53 +01:00
|
|
|
{
|
|
|
|
|
// Using a clean environment breaks ccache/distcc/etc.
|
|
|
|
|
Environment env = Environment::systemEnvironment();
|
|
|
|
|
addToEnvironment(env);
|
|
|
|
|
const Utils::FileName compilerCommand = m_compilerCommand;
|
|
|
|
|
const QStringList platformCodeGenFlags = m_platformCodeGenFlags;
|
|
|
|
|
OptionsReinterpreter reinterpretOptions = m_optionsReinterpreter;
|
|
|
|
|
QTC_CHECK(reinterpretOptions);
|
2018-09-27 10:18:44 +02:00
|
|
|
std::shared_ptr<Cache<MacroInspectionReport, 64>> macroCache = m_predefinedMacrosCache;
|
2017-07-14 15:46:09 +03:00
|
|
|
Core::Id lang = language();
|
2017-02-06 16:59:53 +01:00
|
|
|
|
|
|
|
|
// This runner must be thread-safe!
|
2017-07-14 15:46:09 +03:00
|
|
|
return [env, compilerCommand, platformCodeGenFlags, reinterpretOptions, macroCache, lang]
|
2017-10-24 14:36:11 +02:00
|
|
|
(const QStringList &flags) {
|
|
|
|
|
QStringList allFlags = platformCodeGenFlags + flags; // add only cxxflags is empty?
|
2017-07-14 15:46:09 +03:00
|
|
|
QStringList arguments = gccPredefinedMacrosOptions(lang);
|
2017-10-24 14:36:11 +02:00
|
|
|
for (int iArg = 0; iArg < allFlags.length(); ++iArg) {
|
|
|
|
|
const QString &a = allFlags.at(iArg);
|
2017-02-06 16:59:53 +01:00
|
|
|
if (a.startsWith("--gcc-toolchain=")) {
|
|
|
|
|
arguments << a;
|
|
|
|
|
} else if (a == "-arch") {
|
2017-10-24 14:36:11 +02:00
|
|
|
if (++iArg < allFlags.length() && !arguments.contains(a))
|
|
|
|
|
arguments << a << allFlags.at(iArg);
|
2018-11-21 09:47:55 +01:00
|
|
|
} else if (a == "--sysroot" || a == "-isysroot" || a == "-D" || a == "-U"
|
|
|
|
|
|| a == "-gcc-toolchain" || a == "-target") {
|
2017-10-24 14:36:11 +02:00
|
|
|
if (++iArg < allFlags.length())
|
|
|
|
|
arguments << a << allFlags.at(iArg);
|
2018-11-21 09:47:55 +01:00
|
|
|
} else if (a == "-m128bit-long-double" || a == "-m32" || a == "-m3dnow"
|
|
|
|
|
|| a == "-m3dnowa" || a == "-m64" || a == "-m96bit-long-double"
|
|
|
|
|
|| a == "-mabm" || a == "-maes" || a.startsWith("-march=") || a == "-mavx"
|
|
|
|
|
|| a.startsWith("-masm=") || a.startsWith("-mfloat-abi") || a == "-mcx16"
|
|
|
|
|
|| a == "-mfma" || a == "-mfma4" || a == "-mlwp" || a == "-mpclmul"
|
|
|
|
|
|| a == "-mpopcnt" || a == "-msse" || a == "-msse2" || a == "-msse2avx"
|
|
|
|
|
|| a == "-msse3" || a == "-msse4" || a == "-msse4.1" || a == "-msse4.2"
|
|
|
|
|
|| a == "-msse4a" || a == "-mssse3" || a.startsWith("-mtune=")
|
|
|
|
|
|| a == "-mxop" || a == "-Os" || a == "-O0" || a == "-O1" || a == "-O2"
|
|
|
|
|
|| a == "-O3" || a == "-ffinite-math-only" || a == "-fshort-double"
|
|
|
|
|
|| a == "-fshort-wchar" || a == "-fsignaling-nans" || a == "-fno-inline"
|
|
|
|
|
|| a == "-fno-exceptions" || a == "-fstack-protector"
|
|
|
|
|
|| a == "-fstack-protector-all" || a == "-fsanitize=address"
|
|
|
|
|
|| a == "-fno-rtti" || a.startsWith("-std=") || a.startsWith("-stdlib=")
|
|
|
|
|
|| a.startsWith("-specs=") || a == "-ansi" || a == "-undef"
|
|
|
|
|
|| a.startsWith("-D") || a.startsWith("-U") || a == "-fopenmp"
|
|
|
|
|
|| a == "-Wno-deprecated" || a == "-fPIC" || a == "-fpic" || a == "-fPIE"
|
|
|
|
|
|| a == "-fpie")
|
2017-02-06 16:59:53 +01:00
|
|
|
arguments << a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
arguments = reinterpretOptions(arguments);
|
2018-09-27 10:18:44 +02:00
|
|
|
const Utils::optional<MacroInspectionReport> cachedMacros = macroCache->check(arguments);
|
2017-10-24 14:36:11 +02:00
|
|
|
if (cachedMacros)
|
|
|
|
|
return cachedMacros.value();
|
|
|
|
|
|
2018-09-27 10:18:44 +02:00
|
|
|
const Macros macros = gccPredefinedMacros(findLocalCompiler(compilerCommand, env),
|
|
|
|
|
arguments,
|
|
|
|
|
env.toStringList());
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2018-10-09 14:26:47 +02:00
|
|
|
const auto report = MacroInspectionReport{macros, languageVersion(lang, macros)};
|
2018-09-27 10:18:44 +02:00
|
|
|
macroCache->insert(arguments, report);
|
|
|
|
|
|
|
|
|
|
qCDebug(gccLog) << "MacroInspectionReport for code model:";
|
2018-10-08 09:49:02 +02:00
|
|
|
qCDebug(gccLog) << "Language version:" << static_cast<int>(report.languageVersion);
|
2018-10-09 14:26:47 +02:00
|
|
|
for (const Macro &m : macros) {
|
2017-10-27 16:02:06 +02:00
|
|
|
qCDebug(gccLog) << compilerCommand.toUserOutput()
|
|
|
|
|
<< (lang == Constants::CXX_LANGUAGE_ID ? ": C++ [" : ": C [")
|
|
|
|
|
<< arguments.join(", ") << "]"
|
|
|
|
|
<< QString::fromUtf8(m.toByteArray());
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 10:18:44 +02:00
|
|
|
return report;
|
2017-02-06 16:59:53 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-07 00:31:11 +04:00
|
|
|
/**
|
|
|
|
|
* @brief Asks compiler for set of predefined macros
|
|
|
|
|
* @param cxxflags - compiler flags collected from project settings
|
|
|
|
|
* @return defines list, one per line, e.g. "#define __GXX_WEAK__ 1"
|
|
|
|
|
*
|
|
|
|
|
* @note changing compiler flags sometimes changes macros set, e.g. -fopenmp
|
|
|
|
|
* adds _OPENMP macro, for full list of macro search by word "when" on this page:
|
|
|
|
|
* http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
|
|
|
|
|
*/
|
2017-02-07 15:00:38 +01:00
|
|
|
ProjectExplorer::Macros GccToolChain::predefinedMacros(const QStringList &cxxflags) const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2018-09-27 10:18:44 +02:00
|
|
|
return createMacroInspectionRunner()(cxxflags).macros;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-28 13:11:48 +04:00
|
|
|
/**
|
2018-10-08 09:49:02 +02:00
|
|
|
* @brief Parses gcc flags -std=*, -fopenmp, -fms-extensions.
|
2013-04-28 13:11:48 +04:00
|
|
|
* @see http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
|
|
|
|
|
*/
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtensions GccToolChain::languageExtensions(const QStringList &cxxflags) const
|
2012-02-16 15:09:56 +01:00
|
|
|
{
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtensions extensions = defaultLanguageExtensions();
|
2013-04-28 13:11:48 +04:00
|
|
|
|
|
|
|
|
const QStringList allCxxflags = m_platformCodeGenFlags + cxxflags; // add only cxxflags is empty?
|
|
|
|
|
foreach (const QString &flag, allCxxflags) {
|
2016-11-24 14:57:07 +01:00
|
|
|
if (flag.startsWith("-std=")) {
|
2014-08-28 17:33:47 +02:00
|
|
|
const QByteArray std = flag.mid(5).toLatin1();
|
2018-09-27 10:18:44 +02:00
|
|
|
if (std.startsWith("gnu"))
|
2018-10-08 09:49:02 +02:00
|
|
|
extensions |= LanguageExtension::Gnu;
|
2018-09-27 10:18:44 +02:00
|
|
|
else
|
2018-10-08 09:49:02 +02:00
|
|
|
extensions &= ~LanguageExtensions(LanguageExtension::Gnu);
|
2016-11-24 14:57:07 +01:00
|
|
|
} else if (flag == "-fopenmp") {
|
2018-10-16 09:21:33 +02:00
|
|
|
extensions |= LanguageExtension::OpenMP;
|
2016-11-24 14:57:07 +01:00
|
|
|
} else if (flag == "-fms-extensions") {
|
2018-10-08 09:49:02 +02:00
|
|
|
extensions |= LanguageExtension::Microsoft;
|
2013-04-28 13:11:48 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-08 09:49:02 +02:00
|
|
|
return extensions;
|
2012-02-16 15:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-18 11:56:54 +01:00
|
|
|
WarningFlags GccToolChain::warningFlags(const QStringList &cflags) const
|
2013-03-03 21:53:38 +04:00
|
|
|
{
|
|
|
|
|
// based on 'LC_ALL="en" gcc -Q --help=warnings | grep enabled'
|
2016-01-18 11:56:54 +01:00
|
|
|
WarningFlags flags(WarningFlags::Deprecated | WarningFlags::IgnoredQualfiers
|
|
|
|
|
| WarningFlags::SignedComparison | WarningFlags::UninitializedVars);
|
|
|
|
|
WarningFlags groupWall(WarningFlags::All | WarningFlags::UnknownPragma | WarningFlags::UnusedFunctions
|
|
|
|
|
| WarningFlags::UnusedLocals | WarningFlags::UnusedResult | WarningFlags::UnusedValue
|
|
|
|
|
| WarningFlags::SignedComparison | WarningFlags::UninitializedVars);
|
|
|
|
|
WarningFlags groupWextra(WarningFlags::Extra | WarningFlags::IgnoredQualfiers | WarningFlags::UnusedParams);
|
2013-03-03 21:53:38 +04:00
|
|
|
|
|
|
|
|
foreach (const QString &flag, cflags) {
|
2016-11-24 14:57:07 +01:00
|
|
|
if (flag == "--all-warnings")
|
2013-03-03 21:53:38 +04:00
|
|
|
flags |= groupWall;
|
2016-11-24 14:57:07 +01:00
|
|
|
else if (flag == "--extra-warnings")
|
2013-03-03 21:53:38 +04:00
|
|
|
flags |= groupWextra;
|
|
|
|
|
|
|
|
|
|
WarningFlagAdder add(flag, flags);
|
|
|
|
|
if (add.triggered())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// supported by clang too
|
2016-01-18 11:56:54 +01:00
|
|
|
add("error", WarningFlags::AsErrors);
|
2013-03-03 21:53:38 +04:00
|
|
|
add("all", groupWall);
|
|
|
|
|
add("extra", groupWextra);
|
2016-01-18 11:56:54 +01:00
|
|
|
add("deprecated", WarningFlags::Deprecated);
|
|
|
|
|
add("effc++", WarningFlags::EffectiveCxx);
|
|
|
|
|
add("ignored-qualifiers", WarningFlags::IgnoredQualfiers);
|
|
|
|
|
add("non-virtual-dtor", WarningFlags::NonVirtualDestructor);
|
|
|
|
|
add("overloaded-virtual", WarningFlags::OverloadedVirtual);
|
|
|
|
|
add("shadow", WarningFlags::HiddenLocals);
|
|
|
|
|
add("sign-compare", WarningFlags::SignedComparison);
|
|
|
|
|
add("unknown-pragmas", WarningFlags::UnknownPragma);
|
|
|
|
|
add("unused", WarningFlags::UnusedFunctions | WarningFlags::UnusedLocals | WarningFlags::UnusedParams
|
|
|
|
|
| WarningFlags::UnusedResult | WarningFlags::UnusedValue);
|
|
|
|
|
add("unused-function", WarningFlags::UnusedFunctions);
|
|
|
|
|
add("unused-variable", WarningFlags::UnusedLocals);
|
|
|
|
|
add("unused-parameter", WarningFlags::UnusedParams);
|
|
|
|
|
add("unused-result", WarningFlags::UnusedResult);
|
|
|
|
|
add("unused-value", WarningFlags::UnusedValue);
|
|
|
|
|
add("uninitialized", WarningFlags::UninitializedVars);
|
2013-03-03 21:53:38 +04:00
|
|
|
}
|
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-06 16:00:25 +01:00
|
|
|
QStringList GccToolChain::gccPrepareArguments(const QStringList &flags,
|
|
|
|
|
const QString &sysRoot,
|
|
|
|
|
const QStringList &platformCodeGenFlags,
|
|
|
|
|
Core::Id languageId,
|
|
|
|
|
OptionsReinterpreter reinterpretOptions)
|
|
|
|
|
{
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
const bool hasKitSysroot = !sysRoot.isEmpty();
|
|
|
|
|
if (hasKitSysroot)
|
|
|
|
|
arguments.append(QString::fromLatin1("--sysroot=%1").arg(sysRoot));
|
|
|
|
|
|
|
|
|
|
QStringList allFlags;
|
|
|
|
|
allFlags << platformCodeGenFlags << flags;
|
|
|
|
|
for (int i = 0; i < allFlags.size(); ++i) {
|
|
|
|
|
const QString &flag = allFlags.at(i);
|
2018-11-08 14:33:13 +01:00
|
|
|
if (flag.startsWith("-stdlib=") || flag.startsWith("--gcctoolchain=")
|
2018-11-21 10:25:31 +01:00
|
|
|
|| flag.startsWith("-B") || (flag.startsWith("-isystem") && flag.length() > 8)) {
|
2017-11-06 16:00:25 +01:00
|
|
|
arguments << flag;
|
|
|
|
|
} else if (!hasKitSysroot) {
|
|
|
|
|
// pass build system's sysroot to compiler, if we didn't pass one from kit
|
|
|
|
|
if (flag.startsWith("--sysroot=")) {
|
|
|
|
|
arguments << flag;
|
2018-11-21 09:47:55 +01:00
|
|
|
} else if ((flag.startsWith("-isysroot") || flag.startsWith("--sysroot")
|
2018-11-21 10:25:31 +01:00
|
|
|
|| flag == "-target" || flag == "-gcc-toolchain" || flag == "-isystem")
|
2017-11-06 16:00:25 +01:00
|
|
|
&& i < flags.size() - 1) {
|
|
|
|
|
arguments << flag << allFlags.at(i + 1);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
arguments << languageOption(languageId) << "-E" << "-v" << "-";
|
|
|
|
|
arguments = reinterpretOptions(arguments);
|
|
|
|
|
|
|
|
|
|
return arguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: extraHeaderPathsFunction must NOT capture this or it's members!!!
|
|
|
|
|
void GccToolChain::initExtraHeaderPathsFunction(ExtraHeaderPathsFunction &&extraHeaderPathsFunction) const
|
|
|
|
|
{
|
|
|
|
|
m_extraHeaderPathsFunction = std::move(extraHeaderPathsFunction);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 11:29:32 +02:00
|
|
|
ToolChain::BuiltInHeaderPathsRunner GccToolChain::createBuiltInHeaderPathsRunner() const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2017-02-06 16:59:53 +01:00
|
|
|
// Using a clean environment breaks ccache/distcc/etc.
|
|
|
|
|
Environment env = Environment::systemEnvironment();
|
|
|
|
|
addToEnvironment(env);
|
|
|
|
|
|
|
|
|
|
const Utils::FileName compilerCommand = m_compilerCommand;
|
|
|
|
|
const QStringList platformCodeGenFlags = m_platformCodeGenFlags;
|
|
|
|
|
OptionsReinterpreter reinterpretOptions = m_optionsReinterpreter;
|
|
|
|
|
QTC_CHECK(reinterpretOptions);
|
2018-09-13 12:19:07 +02:00
|
|
|
std::shared_ptr<Cache<HeaderPaths>> headerCache = m_headerPathsCache;
|
2017-10-24 14:36:11 +02:00
|
|
|
Core::Id languageId = language();
|
2017-02-06 16:59:53 +01:00
|
|
|
|
|
|
|
|
// This runner must be thread-safe!
|
2017-11-06 16:00:25 +01:00
|
|
|
return [env, compilerCommand, platformCodeGenFlags, reinterpretOptions, headerCache, languageId,
|
|
|
|
|
extraHeaderPathsFunction = m_extraHeaderPathsFunction]
|
2017-10-24 14:36:11 +02:00
|
|
|
(const QStringList &flags, const QString &sysRoot) {
|
2013-09-09 15:47:46 +02:00
|
|
|
|
2017-11-06 16:00:25 +01:00
|
|
|
QStringList arguments = gccPrepareArguments(flags, sysRoot, platformCodeGenFlags,
|
|
|
|
|
languageId, reinterpretOptions);
|
2013-09-09 15:47:46 +02:00
|
|
|
|
2018-09-13 12:19:07 +02:00
|
|
|
const Utils::optional<HeaderPaths> cachedPaths = headerCache->check(arguments);
|
2017-10-24 14:36:11 +02:00
|
|
|
if (cachedPaths)
|
|
|
|
|
return cachedPaths.value();
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2018-09-13 12:19:07 +02:00
|
|
|
HeaderPaths paths = gccHeaderPaths(findLocalCompiler(compilerCommand, env),
|
|
|
|
|
arguments, env.toStringList());
|
2017-11-06 16:00:25 +01:00
|
|
|
extraHeaderPathsFunction(paths);
|
2017-02-06 16:59:53 +01:00
|
|
|
headerCache->insert(arguments, paths);
|
|
|
|
|
|
2017-10-27 16:02:06 +02:00
|
|
|
qCDebug(gccLog) << "Reporting header paths to code model:";
|
|
|
|
|
for (const HeaderPath &hp : paths) {
|
|
|
|
|
qCDebug(gccLog) << compilerCommand.toUserOutput()
|
|
|
|
|
<< (languageId == Constants::CXX_LANGUAGE_ID ? ": C++ [" : ": C [")
|
|
|
|
|
<< arguments.join(", ") << "]"
|
2018-09-03 16:10:43 +02:00
|
|
|
<< hp.path;
|
2017-10-27 16:02:06 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 16:59:53 +01:00
|
|
|
return paths;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 11:29:32 +02:00
|
|
|
HeaderPaths GccToolChain::builtInHeaderPaths(const QStringList &flags,
|
|
|
|
|
const FileName &sysRoot) const
|
2017-02-06 16:59:53 +01:00
|
|
|
{
|
2018-09-17 11:29:32 +02:00
|
|
|
return createBuiltInHeaderPathsRunner()(flags, sysRoot.toString());
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-02 17:19:57 +02:00
|
|
|
void GccToolChain::addCommandPathToEnvironment(const FileName &command, Environment &env)
|
|
|
|
|
{
|
2017-10-18 16:16:43 +02:00
|
|
|
const Utils::FileName compilerDir = command.parentDir();
|
|
|
|
|
if (!compilerDir.isEmpty())
|
|
|
|
|
env.prependOrSetPath(compilerDir.toString());
|
2013-09-02 17:19:57 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
GccToolChain::GccToolChain(const GccToolChain &) = default;
|
|
|
|
|
|
2012-08-21 13:29:16 +02:00
|
|
|
void GccToolChain::addToEnvironment(Environment &env) const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2017-10-22 11:26:17 +03:00
|
|
|
// On Windows gcc invokes cc1plus which is in libexec directory.
|
|
|
|
|
// cc1plus depends on libwinpthread-1.dll which is in bin, so bin must be in the PATH.
|
|
|
|
|
if (HostOsInfo::isWindowsHost())
|
|
|
|
|
addCommandPathToEnvironment(m_compilerCommand, env);
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-03 14:01:25 +01:00
|
|
|
FileNameList GccToolChain::suggestedMkspecList() const
|
2011-04-07 13:12:55 +02:00
|
|
|
{
|
|
|
|
|
Abi abi = targetAbi();
|
2012-02-02 11:56:09 +01:00
|
|
|
Abi host = Abi::hostAbi();
|
|
|
|
|
|
|
|
|
|
// Cross compile: Leave the mkspec alone!
|
|
|
|
|
if (abi.architecture() != host.architecture()
|
|
|
|
|
|| abi.os() != host.os()
|
|
|
|
|
|| abi.osFlavor() != host.osFlavor()) // Note: This can fail:-(
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList();
|
2012-02-02 11:56:09 +01:00
|
|
|
|
2016-07-25 18:39:16 -07:00
|
|
|
if (abi.os() == Abi::DarwinOS) {
|
2011-09-06 15:19:05 +00:00
|
|
|
QString v = version();
|
2016-07-25 18:39:16 -07:00
|
|
|
// prefer versioned g++ on macOS. This is required to enable building for older macOS versions
|
2016-11-24 14:57:07 +01:00
|
|
|
if (v.startsWith("4.0") && m_compilerCommand.endsWith("-4.0"))
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList() << FileName::fromLatin1("macx-g++40");
|
2016-11-24 14:57:07 +01:00
|
|
|
if (v.startsWith("4.2") && m_compilerCommand.endsWith("-4.2"))
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList() << FileName::fromLatin1("macx-g++42");
|
|
|
|
|
return FileNameList() << FileName::fromLatin1("macx-g++");
|
2011-09-06 15:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (abi.os() == Abi::LinuxOS) {
|
2018-06-14 16:13:46 +02:00
|
|
|
if (abi.osFlavor() != Abi::GenericFlavor)
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList(); // most likely not a desktop, so leave the mkspec alone.
|
2012-08-08 14:19:29 +02:00
|
|
|
if (abi.wordWidth() == host.wordWidth()) {
|
|
|
|
|
// no need to explicitly set the word width, but provide that mkspec anyway to make sure
|
|
|
|
|
// that the correct compiler is picked if a mkspec with a wordwidth is given.
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList() << FileName::fromLatin1("linux-g++")
|
2016-11-24 14:57:07 +01:00
|
|
|
<< FileName::fromString(QString::fromLatin1("linux-g++-") + QString::number(m_targetAbi.wordWidth()));
|
2012-08-08 14:19:29 +02:00
|
|
|
}
|
2016-11-24 14:57:07 +01:00
|
|
|
return FileNameList() << FileName::fromString(QString::fromLatin1("linux-g++-") + QString::number(m_targetAbi.wordWidth()));
|
2011-09-06 15:19:05 +00:00
|
|
|
}
|
2012-02-02 11:56:09 +01:00
|
|
|
|
2011-05-31 10:06:32 +00:00
|
|
|
if (abi.os() == Abi::BsdOS && abi.osFlavor() == Abi::FreeBsdFlavor)
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList() << FileName::fromLatin1("freebsd-g++");
|
2012-02-02 11:56:09 +01:00
|
|
|
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList();
|
2011-04-07 13:12:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
QString GccToolChain::makeCommand(const Environment &environment) const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2016-11-24 14:57:07 +01:00
|
|
|
QString make = "make";
|
2014-07-15 23:32:11 +03:00
|
|
|
FileName tmp = environment.searchInPath(make);
|
|
|
|
|
return tmp.isEmpty() ? make : tmp.toString();
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IOutputParser *GccToolChain::outputParser() const
|
|
|
|
|
{
|
|
|
|
|
return new GccParser;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 14:23:09 +02:00
|
|
|
void GccToolChain::resetToolChain(const FileName &path)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2016-09-12 12:06:50 +02:00
|
|
|
bool resetDisplayName = (displayName() == defaultDisplayName());
|
2011-04-14 14:51:28 +02:00
|
|
|
|
2014-07-21 14:23:09 +02:00
|
|
|
setCompilerCommand(path);
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2011-04-14 14:51:28 +02:00
|
|
|
Abi currentAbi = m_targetAbi;
|
2016-03-04 15:33:16 +01:00
|
|
|
const DetectedAbisResult detectedAbis = detectSupportedAbis();
|
|
|
|
|
m_supportedAbis = detectedAbis.supportedAbis;
|
|
|
|
|
m_originalTargetTriple = detectedAbis.originalTargetTriple;
|
2011-04-14 14:51:28 +02:00
|
|
|
|
2011-03-10 14:44:49 +01:00
|
|
|
m_targetAbi = Abi();
|
2012-01-30 18:07:24 +01:00
|
|
|
if (!m_supportedAbis.isEmpty()) {
|
|
|
|
|
if (m_supportedAbis.contains(currentAbi))
|
|
|
|
|
m_targetAbi = currentAbi;
|
|
|
|
|
else
|
|
|
|
|
m_targetAbi = m_supportedAbis.at(0);
|
2011-03-10 14:44:49 +01:00
|
|
|
}
|
2012-01-30 18:07:24 +01:00
|
|
|
|
|
|
|
|
if (resetDisplayName)
|
|
|
|
|
setDisplayName(defaultDisplayName()); // calls toolChainUpdated()!
|
|
|
|
|
else
|
|
|
|
|
toolChainUpdated();
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-21 13:29:16 +02:00
|
|
|
FileName GccToolChain::compilerCommand() const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2012-02-01 14:39:11 +01:00
|
|
|
return m_compilerCommand;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-22 23:03:45 +02:00
|
|
|
void GccToolChain::setPlatformCodeGenFlags(const QStringList &flags)
|
|
|
|
|
{
|
|
|
|
|
if (flags != m_platformCodeGenFlags) {
|
|
|
|
|
m_platformCodeGenFlags = flags;
|
|
|
|
|
toolChainUpdated();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 15:28:13 +01:00
|
|
|
QStringList GccToolChain::extraCodeModelFlags() const
|
|
|
|
|
{
|
|
|
|
|
return platformCodeGenFlags();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 23:03:45 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Code gen flags that have to be passed to the compiler.
|
2013-04-22 23:03:45 +02:00
|
|
|
*/
|
|
|
|
|
QStringList GccToolChain::platformCodeGenFlags() const
|
|
|
|
|
{
|
|
|
|
|
return m_platformCodeGenFlags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GccToolChain::setPlatformLinkerFlags(const QStringList &flags)
|
|
|
|
|
{
|
|
|
|
|
if (flags != m_platformLinkerFlags) {
|
|
|
|
|
m_platformLinkerFlags = flags;
|
|
|
|
|
toolChainUpdated();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Flags that have to be passed to the linker.
|
2013-04-22 23:03:45 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
For example: \c{-arch armv7}
|
2013-04-22 23:03:45 +02:00
|
|
|
*/
|
|
|
|
|
QStringList GccToolChain::platformLinkerFlags() const
|
|
|
|
|
{
|
|
|
|
|
return m_platformLinkerFlags;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
ToolChain *GccToolChain::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new GccToolChain(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap GccToolChain::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap data = ToolChain::toMap();
|
2016-11-24 14:57:07 +01:00
|
|
|
data.insert(compilerCommandKeyC, m_compilerCommand.toString());
|
|
|
|
|
data.insert(compilerPlatformCodeGenFlagsKeyC, m_platformCodeGenFlags);
|
|
|
|
|
data.insert(compilerPlatformLinkerFlagsKeyC, m_platformLinkerFlags);
|
|
|
|
|
data.insert(targetAbiKeyC, m_targetAbi.toString());
|
|
|
|
|
data.insert(originalTargetTripleKeyC, m_originalTargetTriple);
|
2014-07-07 19:02:26 +02:00
|
|
|
QStringList abiList = Utils::transform(m_supportedAbis, &Abi::toString);
|
2016-11-24 14:57:07 +01:00
|
|
|
data.insert(supportedAbisKeyC, abiList);
|
2011-02-01 18:36:00 +01:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GccToolChain::fromMap(const QVariantMap &data)
|
|
|
|
|
{
|
|
|
|
|
if (!ToolChain::fromMap(data))
|
|
|
|
|
return false;
|
|
|
|
|
|
2016-11-24 14:57:07 +01:00
|
|
|
m_compilerCommand = FileName::fromString(data.value(compilerCommandKeyC).toString());
|
|
|
|
|
m_platformCodeGenFlags = data.value(compilerPlatformCodeGenFlagsKeyC).toStringList();
|
|
|
|
|
m_platformLinkerFlags = data.value(compilerPlatformLinkerFlagsKeyC).toStringList();
|
2018-06-14 15:46:33 +02:00
|
|
|
m_targetAbi = Abi::fromString(data.value(targetAbiKeyC).toString());
|
2016-11-24 14:57:07 +01:00
|
|
|
m_originalTargetTriple = data.value(originalTargetTripleKeyC).toString();
|
|
|
|
|
const QStringList abiList = data.value(supportedAbisKeyC).toStringList();
|
2011-06-21 13:26:22 +02:00
|
|
|
m_supportedAbis.clear();
|
2016-09-12 12:06:50 +02:00
|
|
|
for (const QString &a : abiList) {
|
2018-06-14 15:46:33 +02:00
|
|
|
Abi abi = Abi::fromString(a);
|
2011-06-21 13:26:22 +02:00
|
|
|
if (!abi.isValid())
|
|
|
|
|
continue;
|
|
|
|
|
m_supportedAbis.append(abi);
|
|
|
|
|
}
|
2016-09-12 12:06:50 +02:00
|
|
|
|
|
|
|
|
if (!m_targetAbi.isValid())
|
|
|
|
|
resetToolChain(m_compilerCommand);
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GccToolChain::operator ==(const ToolChain &other) const
|
|
|
|
|
{
|
|
|
|
|
if (!ToolChain::operator ==(other))
|
|
|
|
|
return false;
|
|
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
auto gccTc = static_cast<const GccToolChain *>(&other);
|
2013-04-22 23:03:45 +02:00
|
|
|
return m_compilerCommand == gccTc->m_compilerCommand && m_targetAbi == gccTc->m_targetAbi
|
|
|
|
|
&& m_platformCodeGenFlags == gccTc->m_platformCodeGenFlags
|
|
|
|
|
&& m_platformLinkerFlags == gccTc->m_platformLinkerFlags;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-11 08:25:07 +02:00
|
|
|
std::unique_ptr<ToolChainConfigWidget> GccToolChain::createConfigurationWidget()
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2018-07-11 08:25:07 +02:00
|
|
|
return std::make_unique<GccToolChainConfigWidget>(this);
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-10 14:44:49 +01:00
|
|
|
void GccToolChain::updateSupportedAbis() const
|
|
|
|
|
{
|
2016-03-04 15:33:16 +01:00
|
|
|
if (m_supportedAbis.isEmpty()) {
|
|
|
|
|
const DetectedAbisResult detected = detectSupportedAbis();
|
|
|
|
|
m_supportedAbis = detected.supportedAbis;
|
|
|
|
|
m_originalTargetTriple = detected.originalTargetTriple;
|
|
|
|
|
}
|
2011-05-17 16:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 16:59:53 +01:00
|
|
|
void GccToolChain::setOptionsReinterpreter(const OptionsReinterpreter &optionsReinterpreter)
|
|
|
|
|
{
|
|
|
|
|
m_optionsReinterpreter = optionsReinterpreter;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 15:33:16 +01:00
|
|
|
GccToolChain::DetectedAbisResult GccToolChain::detectSupportedAbis() const
|
2011-05-17 16:02:05 +02:00
|
|
|
{
|
2012-08-21 13:29:16 +02:00
|
|
|
Environment env = Environment::systemEnvironment();
|
2011-05-17 16:02:05 +02:00
|
|
|
addToEnvironment(env);
|
2017-02-07 15:00:38 +01:00
|
|
|
ProjectExplorer::Macros macros = predefinedMacros(QStringList());
|
2017-02-13 10:56:38 +01:00
|
|
|
return guessGccAbi(findLocalCompiler(m_compilerCommand, env),
|
|
|
|
|
env.toStringList(),
|
|
|
|
|
macros,
|
|
|
|
|
platformCodeGenFlags());
|
2011-03-10 14:44:49 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-06 15:19:05 +00:00
|
|
|
QString GccToolChain::detectVersion() const
|
|
|
|
|
{
|
2012-08-21 13:29:16 +02:00
|
|
|
Environment env = Environment::systemEnvironment();
|
2011-09-06 15:19:05 +00:00
|
|
|
addToEnvironment(env);
|
2017-02-13 10:56:38 +01:00
|
|
|
return gccVersion(findLocalCompiler(m_compilerCommand, env), env.toStringList());
|
2011-09-06 15:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// GccToolChainFactory
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
GccToolChainFactory::GccToolChainFactory()
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-08-09 17:49:30 +02:00
|
|
|
setDisplayName(tr("GCC"));
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-12-16 00:43:14 +01:00
|
|
|
QSet<Core::Id> GccToolChainFactory::supportedLanguages() const
|
2016-07-12 11:33:17 +02:00
|
|
|
{
|
2017-02-22 15:09:35 +01:00
|
|
|
return {Constants::C_LANGUAGE_ID, Constants::CXX_LANGUAGE_ID};
|
2016-07-12 11:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
bool GccToolChainFactory::canCreate()
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-16 00:43:14 +01:00
|
|
|
ToolChain *GccToolChainFactory::create(Core::Id language)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2016-07-12 12:20:06 +02:00
|
|
|
ToolChain *tc = createToolChain(false);
|
2016-12-16 00:43:14 +01:00
|
|
|
tc->setLanguage(language);
|
2016-07-12 12:20:06 +02:00
|
|
|
return tc;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-10 23:58:34 +03:00
|
|
|
void GccToolChainFactory::versionProbe(const QString &name, Core::Id language, Core::Id type,
|
|
|
|
|
QList<ToolChain *> &tcs, QList<ToolChain *> &known,
|
|
|
|
|
const QSet<QString> &filteredNames)
|
|
|
|
|
{
|
|
|
|
|
if (!HostOsInfo::isLinuxHost())
|
|
|
|
|
return;
|
|
|
|
|
const QRegularExpression regexp(binaryRegexp);
|
|
|
|
|
for (const QString &dir : QStringList({ "/usr/bin", "/usr/local/bin" })) {
|
|
|
|
|
QDir binDir(dir);
|
|
|
|
|
for (const QString &entry : binDir.entryList(
|
|
|
|
|
{"*-" + name, name + "-*", "*-" + name + "-*"},
|
|
|
|
|
QDir::Files | QDir::Executable)) {
|
|
|
|
|
const QString fileName = FileName::fromString(entry).fileName();
|
|
|
|
|
if (filteredNames.contains(fileName))
|
|
|
|
|
continue;
|
|
|
|
|
const QRegularExpressionMatch match = regexp.match(fileName);
|
|
|
|
|
if (!match.hasMatch())
|
|
|
|
|
continue;
|
|
|
|
|
const bool isNative = fileName.startsWith(name);
|
|
|
|
|
const Abi abi = isNative ? Abi::hostAbi() : Abi();
|
2018-08-06 12:28:08 +02:00
|
|
|
tcs.append(autoDetectToolchains(compilerPathFromEnvironment(entry), abi, language, type,
|
|
|
|
|
known));
|
2018-07-10 23:58:34 +03:00
|
|
|
known.append(tcs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 10:59:06 +03:00
|
|
|
QList<ToolChain *> GccToolChainFactory::autoDetect(const QList<ToolChain *> &alreadyKnown)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QList<ToolChain *> tcs;
|
2017-07-14 15:47:03 +03:00
|
|
|
QList<ToolChain *> known = alreadyKnown;
|
2018-08-06 12:28:08 +02:00
|
|
|
tcs.append(autoDetectToolchains(compilerPathFromEnvironment("g++"), Abi::hostAbi(),
|
|
|
|
|
Constants::CXX_LANGUAGE_ID, Constants::GCC_TOOLCHAIN_TYPEID,
|
|
|
|
|
alreadyKnown));
|
|
|
|
|
tcs.append(autoDetectToolchains(compilerPathFromEnvironment("gcc"), Abi::hostAbi(),
|
|
|
|
|
Constants::C_LANGUAGE_ID, Constants::GCC_TOOLCHAIN_TYPEID,
|
|
|
|
|
alreadyKnown));
|
2017-07-14 15:47:03 +03:00
|
|
|
known.append(tcs);
|
2018-07-10 23:58:34 +03:00
|
|
|
versionProbe("g++", Constants::CXX_LANGUAGE_ID, Constants::GCC_TOOLCHAIN_TYPEID, tcs, known);
|
|
|
|
|
versionProbe("gcc", Constants::C_LANGUAGE_ID, Constants::GCC_TOOLCHAIN_TYPEID, tcs, known,
|
|
|
|
|
{"c89-gcc", "c99-gcc"});
|
2011-10-31 09:52:18 +00:00
|
|
|
|
|
|
|
|
return tcs;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-07 14:18:32 +01:00
|
|
|
QList<ToolChain *> GccToolChainFactory::autoDetect(const FileName &compilerPath, const Core::Id &language)
|
|
|
|
|
{
|
|
|
|
|
const QString fileName = compilerPath.fileName();
|
2017-06-13 11:51:12 +02:00
|
|
|
if ((language == Constants::C_LANGUAGE_ID && (fileName.startsWith("gcc")
|
|
|
|
|
|| fileName.endsWith("gcc")))
|
|
|
|
|
|| (language == Constants::CXX_LANGUAGE_ID && (fileName.startsWith("g++")
|
|
|
|
|
|| fileName.endsWith("g++"))))
|
2017-02-07 14:18:32 +01:00
|
|
|
return autoDetectToolChain(compilerPath, language);
|
|
|
|
|
return QList<ToolChain *>();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-16 17:59:43 +01:00
|
|
|
// Used by the ToolChainManager to restore user-generated tool chains
|
2013-08-09 17:49:30 +02:00
|
|
|
bool GccToolChainFactory::canRestore(const QVariantMap &data)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2015-07-07 15:37:50 +02:00
|
|
|
return typeIdFromMap(data) == Constants::GCC_TOOLCHAIN_TYPEID;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
ToolChain *GccToolChainFactory::restore(const QVariantMap &data)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2015-07-08 12:33:55 +02:00
|
|
|
GccToolChain *tc = createToolChain(false);
|
|
|
|
|
if (tc->fromMap(data))
|
2011-02-01 18:36:00 +01:00
|
|
|
return tc;
|
|
|
|
|
|
|
|
|
|
delete tc;
|
2016-04-13 15:52:14 +02:00
|
|
|
return nullptr;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
GccToolChain *GccToolChainFactory::createToolChain(bool autoDetect)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-09-03 10:58:59 +02:00
|
|
|
return new GccToolChain(autoDetect ? ToolChain::AutoDetection : ToolChain::ManualDetection);
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-06 12:28:08 +02:00
|
|
|
Utils::FileName GccToolChainFactory::compilerPathFromEnvironment(const QString &compilerName)
|
|
|
|
|
{
|
|
|
|
|
Environment systemEnvironment = Environment::systemEnvironment();
|
|
|
|
|
return systemEnvironment.searchInPath(compilerName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ToolChain *> GccToolChainFactory::autoDetectToolchains(const FileName &compilerPath,
|
2015-07-19 10:59:06 +03:00
|
|
|
const Abi &requiredAbi,
|
2016-12-16 00:43:14 +01:00
|
|
|
Core::Id language,
|
2015-10-30 13:30:08 +01:00
|
|
|
const Core::Id requiredTypeId,
|
2015-07-19 10:59:06 +03:00
|
|
|
const QList<ToolChain *> &alreadyKnown)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
|
|
|
|
QList<ToolChain *> result;
|
|
|
|
|
|
2011-02-23 11:36:59 +01:00
|
|
|
if (compilerPath.isEmpty())
|
2011-02-01 18:36:00 +01:00
|
|
|
return result;
|
2011-03-10 14:44:49 +01:00
|
|
|
|
2017-09-08 14:52:48 +02:00
|
|
|
result = Utils::filtered(alreadyKnown, [requiredTypeId, compilerPath](ToolChain *tc) {
|
|
|
|
|
return tc->typeId() == requiredTypeId && tc->compilerCommand() == compilerPath;
|
2017-07-14 15:47:03 +03:00
|
|
|
});
|
2017-05-26 16:53:09 +03:00
|
|
|
if (!result.isEmpty()) {
|
|
|
|
|
for (ToolChain *tc : result) {
|
|
|
|
|
if (tc->isAutoDetected())
|
|
|
|
|
tc->setLanguage(language);
|
|
|
|
|
}
|
2015-07-19 10:59:06 +03:00
|
|
|
return result;
|
2017-05-26 16:53:09 +03:00
|
|
|
}
|
2015-07-19 10:59:06 +03:00
|
|
|
|
2017-02-07 13:05:12 +01:00
|
|
|
result = autoDetectToolChain(compilerPath, language, requiredAbi);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ToolChain *> GccToolChainFactory::autoDetectToolChain(const FileName &compilerPath,
|
|
|
|
|
const Core::Id language,
|
|
|
|
|
const Abi &requiredAbi)
|
|
|
|
|
{
|
|
|
|
|
QList<ToolChain *> result;
|
|
|
|
|
|
|
|
|
|
Environment systemEnvironment = Environment::systemEnvironment();
|
2013-09-02 17:19:57 +02:00
|
|
|
GccToolChain::addCommandPathToEnvironment(compilerPath, systemEnvironment);
|
2017-02-13 10:56:38 +01:00
|
|
|
const FileName localCompilerPath = findLocalCompiler(compilerPath, systemEnvironment);
|
2017-02-07 15:00:38 +01:00
|
|
|
Macros macros
|
2017-07-14 15:46:09 +03:00
|
|
|
= gccPredefinedMacros(localCompilerPath, gccPredefinedMacrosOptions(language),
|
|
|
|
|
systemEnvironment.toStringList());
|
2017-02-13 10:56:38 +01:00
|
|
|
const GccToolChain::DetectedAbisResult detectedAbis = guessGccAbi(localCompilerPath,
|
2016-03-04 15:33:16 +01:00
|
|
|
systemEnvironment.toStringList(),
|
|
|
|
|
macros);
|
2017-02-07 13:05:12 +01:00
|
|
|
|
|
|
|
|
const QList<Abi> abiList = detectedAbis.supportedAbis;
|
|
|
|
|
if (!requiredAbi.isNull() && !abiList.contains(requiredAbi)) {
|
2011-04-19 16:09:23 +02:00
|
|
|
if (requiredAbi.wordWidth() != 64
|
|
|
|
|
|| !abiList.contains(Abi(requiredAbi.architecture(), requiredAbi.os(), requiredAbi.osFlavor(),
|
2018-08-06 12:30:32 +02:00
|
|
|
requiredAbi.binaryFormat(), 32))) {
|
2011-04-19 16:09:23 +02:00
|
|
|
return result;
|
2018-08-06 12:30:32 +02:00
|
|
|
}
|
2011-04-19 16:09:23 +02:00
|
|
|
}
|
2011-03-10 14:44:49 +01:00
|
|
|
|
2017-02-07 13:05:12 +01:00
|
|
|
for (const Abi &abi : abiList) {
|
|
|
|
|
std::unique_ptr<GccToolChain> tc(createToolChain(true));
|
|
|
|
|
if (!tc)
|
2011-03-10 14:44:49 +01:00
|
|
|
return result;
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2017-01-24 14:13:50 +01:00
|
|
|
tc->setLanguage(language);
|
2018-09-27 10:18:44 +02:00
|
|
|
tc->m_predefinedMacrosCache
|
|
|
|
|
->insert(QStringList(),
|
|
|
|
|
ToolChain::MacroInspectionReport{macros,
|
|
|
|
|
ToolChain::languageVersion(language, macros)});
|
2012-01-30 13:07:51 +01:00
|
|
|
tc->setCompilerCommand(compilerPath);
|
2017-02-07 13:05:12 +01:00
|
|
|
tc->setSupportedAbis(detectedAbis.supportedAbis);
|
2011-03-10 14:44:49 +01:00
|
|
|
tc->setTargetAbi(abi);
|
2016-03-04 15:33:16 +01:00
|
|
|
tc->setOriginalTargetTriple(detectedAbis.originalTargetTriple);
|
2011-03-14 11:00:38 +01:00
|
|
|
tc->setDisplayName(tc->defaultDisplayName()); // reset displayname
|
2011-02-23 11:36:59 +01:00
|
|
|
|
2017-02-07 13:05:12 +01:00
|
|
|
result.append(tc.release());
|
2011-03-10 14:44:49 +01:00
|
|
|
}
|
2011-02-01 18:36:00 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// GccToolChainConfigWidget
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
GccToolChainConfigWidget::GccToolChainConfigWidget(GccToolChain *tc) :
|
2011-02-22 12:25:19 +01:00
|
|
|
ToolChainConfigWidget(tc),
|
2012-08-21 13:29:16 +02:00
|
|
|
m_compilerCommand(new PathChooser),
|
2016-04-13 15:52:14 +02:00
|
|
|
m_abiWidget(new AbiWidget)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(tc);
|
|
|
|
|
|
2016-11-24 14:57:07 +01:00
|
|
|
const QStringList gnuVersionArgs = QStringList("--version");
|
2012-08-21 13:29:16 +02:00
|
|
|
m_compilerCommand->setExpectedKind(PathChooser::ExistingCommand);
|
2012-02-01 14:39:11 +01:00
|
|
|
m_compilerCommand->setCommandVersionArguments(gnuVersionArgs);
|
2016-11-24 14:57:07 +01:00
|
|
|
m_compilerCommand->setHistoryCompleter("PE.Gcc.Command.History");
|
2012-08-16 15:59:10 +02:00
|
|
|
m_mainLayout->addRow(tr("&Compiler path:"), m_compilerCommand);
|
2013-04-22 23:03:45 +02:00
|
|
|
m_platformCodeGenFlagsLineEdit = new QLineEdit(this);
|
|
|
|
|
m_platformCodeGenFlagsLineEdit->setText(QtcProcess::joinArgs(tc->platformCodeGenFlags()));
|
|
|
|
|
m_mainLayout->addRow(tr("Platform codegen flags:"), m_platformCodeGenFlagsLineEdit);
|
|
|
|
|
m_platformLinkerFlagsLineEdit = new QLineEdit(this);
|
|
|
|
|
m_platformLinkerFlagsLineEdit->setText(QtcProcess::joinArgs(tc->platformLinkerFlags()));
|
|
|
|
|
m_mainLayout->addRow(tr("Platform linker flags:"), m_platformLinkerFlagsLineEdit);
|
2012-08-16 15:59:10 +02:00
|
|
|
m_mainLayout->addRow(tr("&ABI:"), m_abiWidget);
|
2013-04-22 23:03:45 +02:00
|
|
|
|
2011-06-08 15:39:14 +00:00
|
|
|
m_abiWidget->setEnabled(false);
|
2012-08-16 15:59:10 +02:00
|
|
|
addErrorLabel();
|
2011-04-13 15:50:14 +02:00
|
|
|
|
2011-02-23 11:36:59 +01:00
|
|
|
setFromToolchain();
|
2011-06-21 13:26:22 +02:00
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_compilerCommand, &PathChooser::rawPathChanged,
|
|
|
|
|
this, &GccToolChainConfigWidget::handleCompilerCommandChange);
|
|
|
|
|
connect(m_platformCodeGenFlagsLineEdit, &QLineEdit::editingFinished,
|
|
|
|
|
this, &GccToolChainConfigWidget::handlePlatformCodeGenFlagsChange);
|
|
|
|
|
connect(m_platformLinkerFlagsLineEdit, &QLineEdit::editingFinished,
|
|
|
|
|
this, &GccToolChainConfigWidget::handlePlatformLinkerFlagsChange);
|
|
|
|
|
connect(m_abiWidget, &AbiWidget::abiChanged, this, &ToolChainConfigWidget::dirty);
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
void GccToolChainConfigWidget::applyImpl()
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
|
|
|
|
if (toolChain()->isAutoDetected())
|
|
|
|
|
return;
|
|
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
auto tc = static_cast<GccToolChain *>(toolChain());
|
2011-02-01 18:36:00 +01:00
|
|
|
Q_ASSERT(tc);
|
|
|
|
|
QString displayName = tc->displayName();
|
2012-02-01 14:39:11 +01:00
|
|
|
tc->setCompilerCommand(m_compilerCommand->fileName());
|
2014-07-21 14:23:09 +02:00
|
|
|
tc->setSupportedAbis(m_abiWidget->supportedAbis());
|
2011-05-24 14:06:51 +00:00
|
|
|
tc->setTargetAbi(m_abiWidget->currentAbi());
|
2016-03-04 15:33:16 +01:00
|
|
|
tc->setOriginalTargetTriple(tc->detectSupportedAbis().originalTargetTriple);
|
2011-02-01 18:36:00 +01:00
|
|
|
tc->setDisplayName(displayName); // reset display name
|
2013-04-22 23:03:45 +02:00
|
|
|
tc->setPlatformCodeGenFlags(splitString(m_platformCodeGenFlagsLineEdit->text()));
|
|
|
|
|
tc->setPlatformLinkerFlags(splitString(m_platformLinkerFlagsLineEdit->text()));
|
2018-12-04 10:46:42 +01:00
|
|
|
|
|
|
|
|
if (m_macros.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2018-09-27 10:18:44 +02:00
|
|
|
tc->m_predefinedMacrosCache
|
|
|
|
|
->insert(tc->platformCodeGenFlags(),
|
|
|
|
|
ToolChain::MacroInspectionReport{m_macros,
|
|
|
|
|
ToolChain::languageVersion(tc->language(),
|
|
|
|
|
m_macros)});
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
void GccToolChainConfigWidget::setFromToolchain()
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2011-06-21 13:26:22 +02:00
|
|
|
// subwidgets are not yet connected!
|
2017-09-30 07:12:57 +02:00
|
|
|
QSignalBlocker blocker(this);
|
2016-04-13 15:52:14 +02:00
|
|
|
auto tc = static_cast<GccToolChain *>(toolChain());
|
2012-02-01 14:39:11 +01:00
|
|
|
m_compilerCommand->setFileName(tc->compilerCommand());
|
2013-04-22 23:03:45 +02:00
|
|
|
m_platformCodeGenFlagsLineEdit->setText(QtcProcess::joinArgs(tc->platformCodeGenFlags()));
|
|
|
|
|
m_platformLinkerFlagsLineEdit->setText(QtcProcess::joinArgs(tc->platformLinkerFlags()));
|
2011-06-08 15:39:14 +00:00
|
|
|
m_abiWidget->setAbis(tc->supportedAbis(), tc->targetAbi());
|
2012-02-01 14:39:11 +01:00
|
|
|
if (!m_isReadOnly && !m_compilerCommand->path().isEmpty())
|
2011-06-27 17:24:54 +02:00
|
|
|
m_abiWidget->setEnabled(true);
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
bool GccToolChainConfigWidget::isDirtyImpl() const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2016-04-13 15:52:14 +02:00
|
|
|
auto tc = static_cast<GccToolChain *>(toolChain());
|
2011-02-01 18:36:00 +01:00
|
|
|
Q_ASSERT(tc);
|
2012-02-01 14:39:11 +01:00
|
|
|
return m_compilerCommand->fileName() != tc->compilerCommand()
|
2013-04-22 23:03:45 +02:00
|
|
|
|| m_platformCodeGenFlagsLineEdit->text() != QtcProcess::joinArgs(tc->platformCodeGenFlags())
|
|
|
|
|
|| m_platformLinkerFlagsLineEdit->text() != QtcProcess::joinArgs(tc->platformLinkerFlags())
|
2012-04-24 15:49:09 +02:00
|
|
|
|| m_abiWidget->currentAbi() != tc->targetAbi();
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
void GccToolChainConfigWidget::makeReadOnlyImpl()
|
2011-03-29 17:51:40 +02:00
|
|
|
{
|
2014-07-03 08:39:01 +03:00
|
|
|
m_compilerCommand->setReadOnly(true);
|
2011-05-24 14:06:51 +00:00
|
|
|
m_abiWidget->setEnabled(false);
|
2013-07-15 16:31:27 +02:00
|
|
|
m_platformCodeGenFlagsLineEdit->setEnabled(false);
|
|
|
|
|
m_platformLinkerFlagsLineEdit->setEnabled(false);
|
2011-06-27 17:24:54 +02:00
|
|
|
m_isReadOnly = true;
|
2011-03-29 17:51:40 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
QStringList GccToolChainConfigWidget::splitString(const QString &s)
|
2013-04-22 23:03:45 +02:00
|
|
|
{
|
|
|
|
|
QtcProcess::SplitError splitError;
|
2014-02-05 10:43:21 +01:00
|
|
|
const OsType osType = HostOsInfo::hostOs();
|
|
|
|
|
QStringList res = QtcProcess::splitArgs(s, osType, false, &splitError);
|
2013-04-22 23:03:45 +02:00
|
|
|
if (splitError != QtcProcess::SplitOk){
|
2016-11-24 14:57:07 +01:00
|
|
|
res = QtcProcess::splitArgs(s + '\\', osType, false, &splitError);
|
2013-04-22 23:03:45 +02:00
|
|
|
if (splitError != QtcProcess::SplitOk){
|
2016-11-24 14:57:07 +01:00
|
|
|
res = QtcProcess::splitArgs(s + '"', osType, false, &splitError);
|
2013-04-22 23:03:45 +02:00
|
|
|
if (splitError != QtcProcess::SplitOk)
|
2016-11-24 14:57:07 +01:00
|
|
|
res = QtcProcess::splitArgs(s + '\'', osType, false, &splitError);
|
2013-04-22 23:03:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
void GccToolChainConfigWidget::handleCompilerCommandChange()
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-11-04 14:46:45 +01:00
|
|
|
bool haveCompiler = false;
|
|
|
|
|
Abi currentAbi = m_abiWidget->currentAbi();
|
2018-03-08 10:10:36 +01:00
|
|
|
bool customAbi = m_abiWidget->isCustomAbi() && m_abiWidget->isEnabled();
|
2012-08-21 13:29:16 +02:00
|
|
|
FileName path = m_compilerCommand->fileName();
|
2011-03-10 14:44:49 +01:00
|
|
|
QList<Abi> abiList;
|
2013-11-04 14:46:45 +01:00
|
|
|
|
2011-06-08 15:39:14 +00:00
|
|
|
if (!path.isEmpty()) {
|
2012-01-30 13:07:51 +01:00
|
|
|
QFileInfo fi(path.toFileInfo());
|
2011-06-08 15:39:14 +00:00
|
|
|
haveCompiler = fi.isExecutable() && fi.isFile();
|
|
|
|
|
}
|
2013-09-02 17:19:57 +02:00
|
|
|
if (haveCompiler) {
|
|
|
|
|
Environment env = Environment::systemEnvironment();
|
|
|
|
|
GccToolChain::addCommandPathToEnvironment(path, env);
|
2017-07-14 15:46:09 +03:00
|
|
|
QStringList args = gccPredefinedMacrosOptions(Constants::CXX_LANGUAGE_ID)
|
|
|
|
|
+ splitString(m_platformCodeGenFlagsLineEdit->text());
|
2017-02-13 10:56:38 +01:00
|
|
|
const FileName localCompilerPath = findLocalCompiler(path, env);
|
|
|
|
|
m_macros = gccPredefinedMacros(localCompilerPath, args, env.toStringList());
|
|
|
|
|
abiList = guessGccAbi(localCompilerPath, env.toStringList(), m_macros,
|
2016-03-04 15:33:16 +01:00
|
|
|
splitString(m_platformCodeGenFlagsLineEdit->text())).supportedAbis;
|
2013-09-02 17:19:57 +02:00
|
|
|
}
|
2011-06-08 15:39:14 +00:00
|
|
|
m_abiWidget->setEnabled(haveCompiler);
|
2013-11-04 14:46:45 +01:00
|
|
|
|
|
|
|
|
// Find a good ABI for the new compiler:
|
|
|
|
|
Abi newAbi;
|
|
|
|
|
if (customAbi)
|
|
|
|
|
newAbi = currentAbi;
|
|
|
|
|
else if (abiList.contains(currentAbi))
|
|
|
|
|
newAbi = currentAbi;
|
|
|
|
|
|
|
|
|
|
m_abiWidget->setAbis(abiList, newAbi);
|
2012-02-21 12:00:45 +01:00
|
|
|
emit dirty();
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
void GccToolChainConfigWidget::handlePlatformCodeGenFlagsChange()
|
2013-04-22 23:03:45 +02:00
|
|
|
{
|
|
|
|
|
QString str1 = m_platformCodeGenFlagsLineEdit->text();
|
|
|
|
|
QString str2 = QtcProcess::joinArgs(splitString(str1));
|
|
|
|
|
if (str1 != str2)
|
|
|
|
|
m_platformCodeGenFlagsLineEdit->setText(str2);
|
|
|
|
|
else
|
|
|
|
|
handleCompilerCommandChange();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
void GccToolChainConfigWidget::handlePlatformLinkerFlagsChange()
|
2013-04-22 23:03:45 +02:00
|
|
|
{
|
|
|
|
|
QString str1 = m_platformLinkerFlagsLineEdit->text();
|
|
|
|
|
QString str2 = QtcProcess::joinArgs(splitString(str1));
|
|
|
|
|
if (str1 != str2)
|
|
|
|
|
m_platformLinkerFlagsLineEdit->setText(str2);
|
|
|
|
|
else
|
|
|
|
|
emit dirty();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-13 11:48:34 +02:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// ClangToolChain
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-09-03 10:58:59 +02:00
|
|
|
ClangToolChain::ClangToolChain(Detection d) :
|
2015-07-07 15:37:50 +02:00
|
|
|
GccToolChain(Constants::CLANG_TOOLCHAIN_TYPEID, d)
|
2011-05-13 11:48:34 +02:00
|
|
|
{ }
|
|
|
|
|
|
2018-10-25 18:12:43 +02:00
|
|
|
ClangToolChain::ClangToolChain(Core::Id typeId, ToolChain::Detection d) :
|
|
|
|
|
GccToolChain(typeId, d)
|
|
|
|
|
{ }
|
|
|
|
|
|
2012-01-30 11:55:21 +01:00
|
|
|
QString ClangToolChain::typeDisplayName() const
|
2011-05-13 11:48:34 +02:00
|
|
|
{
|
2013-08-09 17:49:30 +02:00
|
|
|
return ClangToolChainFactory::tr("Clang");
|
2011-05-13 11:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
QString ClangToolChain::makeCommand(const Environment &environment) const
|
2011-05-13 11:48:34 +02:00
|
|
|
{
|
2016-11-24 14:57:07 +01:00
|
|
|
const QStringList makes
|
2017-02-22 15:09:35 +01:00
|
|
|
= HostOsInfo::isWindowsHost() ? QStringList({"mingw32-make.exe", "make.exe"}) : QStringList({"make"});
|
2012-09-11 15:59:17 +02:00
|
|
|
|
2014-07-15 23:32:11 +03:00
|
|
|
FileName tmp;
|
2016-11-24 14:57:07 +01:00
|
|
|
for (const QString &make : makes) {
|
2012-09-11 15:59:17 +02:00
|
|
|
tmp = environment.searchInPath(make);
|
|
|
|
|
if (!tmp.isEmpty())
|
2014-07-15 23:32:11 +03:00
|
|
|
return tmp.toString();
|
2012-09-11 15:59:17 +02:00
|
|
|
}
|
|
|
|
|
return makes.first();
|
2011-05-13 11:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
2013-04-28 13:11:48 +04:00
|
|
|
/**
|
2018-10-08 09:49:02 +02:00
|
|
|
* @brief Similar to \a GccToolchain::languageExtensions, but recognizes
|
2013-04-28 13:11:48 +04:00
|
|
|
* "-fborland-extensions".
|
|
|
|
|
*/
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtensions ClangToolChain::languageExtensions(const QStringList &cxxflags) const
|
2013-04-28 13:11:48 +04:00
|
|
|
{
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtensions extensions = GccToolChain::languageExtensions(cxxflags);
|
2016-11-24 14:57:07 +01:00
|
|
|
if (cxxflags.contains("-fborland-extensions"))
|
2018-10-08 09:49:02 +02:00
|
|
|
extensions |= LanguageExtension::Borland;
|
|
|
|
|
return extensions;
|
2013-04-28 13:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
2016-01-18 11:56:54 +01:00
|
|
|
WarningFlags ClangToolChain::warningFlags(const QStringList &cflags) const
|
2013-03-03 21:53:38 +04:00
|
|
|
{
|
2013-09-03 18:48:02 +02:00
|
|
|
WarningFlags flags = GccToolChain::warningFlags(cflags);
|
2013-03-03 21:53:38 +04:00
|
|
|
foreach (const QString &flag, cflags) {
|
2016-11-24 14:57:07 +01:00
|
|
|
if (flag == "-Wdocumentation")
|
2016-01-18 11:56:54 +01:00
|
|
|
flags |= WarningFlags::Documentation;
|
2016-11-24 14:57:07 +01:00
|
|
|
if (flag == "-Wno-documentation")
|
2016-01-18 11:56:54 +01:00
|
|
|
flags &= ~WarningFlags::Documentation;
|
2013-03-03 21:53:38 +04:00
|
|
|
}
|
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 14:01:25 +01:00
|
|
|
FileNameList ClangToolChain::suggestedMkspecList() const
|
2011-05-13 11:48:34 +02:00
|
|
|
{
|
2011-09-06 15:19:05 +00:00
|
|
|
Abi abi = targetAbi();
|
2016-07-25 18:39:16 -07:00
|
|
|
if (abi.os() == Abi::DarwinOS)
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList()
|
2014-02-07 15:46:36 +01:00
|
|
|
<< FileName::fromLatin1("macx-clang")
|
|
|
|
|
<< FileName::fromLatin1("macx-clang-32")
|
|
|
|
|
<< FileName::fromLatin1("unsupported/macx-clang")
|
|
|
|
|
<< FileName::fromLatin1("macx-ios-clang");
|
2011-09-06 15:19:05 +00:00
|
|
|
else if (abi.os() == Abi::LinuxOS)
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList()
|
2014-02-07 15:46:36 +01:00
|
|
|
<< FileName::fromLatin1("linux-clang")
|
|
|
|
|
<< FileName::fromLatin1("unsupported/linux-clang");
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList(); // Note: Not supported by Qt yet, so default to the mkspec the Qt was build with
|
2011-05-18 18:38:58 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-24 17:09:24 +02:00
|
|
|
void ClangToolChain::addToEnvironment(Environment &env) const
|
|
|
|
|
{
|
|
|
|
|
GccToolChain::addToEnvironment(env);
|
|
|
|
|
// Clang takes PWD as basis for debug info, if set.
|
|
|
|
|
// When running Qt Creator from a shell, PWD is initially set to an "arbitrary" value.
|
|
|
|
|
// Since the tools are not called through a shell, PWD is never changed to the actual cwd,
|
|
|
|
|
// so we better make sure PWD is empty to begin with
|
2016-11-24 14:57:07 +01:00
|
|
|
env.unset("PWD");
|
2013-06-24 17:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtensions ClangToolChain::defaultLanguageExtensions() const
|
2013-04-28 13:11:48 +04:00
|
|
|
{
|
2018-10-08 09:49:02 +02:00
|
|
|
return LanguageExtension::Gnu;
|
2013-04-28 13:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
2011-05-18 18:38:58 +02:00
|
|
|
IOutputParser *ClangToolChain::outputParser() const
|
|
|
|
|
{
|
|
|
|
|
return new ClangParser;
|
2011-05-13 11:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain *ClangToolChain::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new ClangToolChain(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// ClangToolChainFactory
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
ClangToolChainFactory::ClangToolChainFactory()
|
2011-05-13 11:48:34 +02:00
|
|
|
{
|
2013-08-09 17:49:30 +02:00
|
|
|
setDisplayName(tr("Clang"));
|
2011-05-13 11:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-16 00:43:14 +01:00
|
|
|
QSet<Core::Id> ClangToolChainFactory::supportedLanguages() const
|
2016-07-12 11:33:17 +02:00
|
|
|
{
|
2017-02-22 15:09:35 +01:00
|
|
|
return {Constants::CXX_LANGUAGE_ID,
|
|
|
|
|
Constants::C_LANGUAGE_ID};
|
2016-07-12 11:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-19 10:59:06 +03:00
|
|
|
QList<ToolChain *> ClangToolChainFactory::autoDetect(const QList<ToolChain *> &alreadyKnown)
|
2011-05-13 11:48:34 +02:00
|
|
|
{
|
2018-07-11 00:16:44 +03:00
|
|
|
QList<ToolChain *> tcs;
|
|
|
|
|
QList<ToolChain *> known = alreadyKnown;
|
2018-08-06 12:28:08 +02:00
|
|
|
|
2018-08-06 12:30:32 +02:00
|
|
|
const Abi hostAbi = Abi::hostAbi();
|
|
|
|
|
tcs.append(autoDetectToolchains(compilerPathFromEnvironment("clang++"), hostAbi,
|
2018-08-06 12:28:08 +02:00
|
|
|
Constants::CXX_LANGUAGE_ID, Constants::CLANG_TOOLCHAIN_TYPEID,
|
|
|
|
|
alreadyKnown));
|
2018-08-06 12:30:32 +02:00
|
|
|
tcs.append(autoDetectToolchains(compilerPathFromEnvironment("clang"), hostAbi,
|
2018-08-06 12:28:08 +02:00
|
|
|
Constants::C_LANGUAGE_ID, Constants::CLANG_TOOLCHAIN_TYPEID,
|
|
|
|
|
alreadyKnown));
|
2018-07-11 00:16:44 +03:00
|
|
|
known.append(tcs);
|
|
|
|
|
versionProbe("clang++", Constants::CXX_LANGUAGE_ID, Constants::CLANG_TOOLCHAIN_TYPEID, tcs, known);
|
|
|
|
|
versionProbe("clang", Constants::C_LANGUAGE_ID, Constants::CLANG_TOOLCHAIN_TYPEID, tcs, known);
|
2018-08-06 12:30:32 +02:00
|
|
|
|
|
|
|
|
const FileName compilerPath = FileName::fromString(Core::ICore::clangExecutable(CLANG_BINDIR));
|
|
|
|
|
if (!compilerPath.isEmpty()) {
|
2018-10-01 17:02:19 +02:00
|
|
|
const FileName clang = compilerPath.parentDir().appendPath(
|
|
|
|
|
HostOsInfo::withExecutableSuffix("clang"));
|
|
|
|
|
tcs.append(autoDetectToolchains(clang,
|
2018-08-06 12:30:32 +02:00
|
|
|
hostAbi, Constants::CXX_LANGUAGE_ID,
|
|
|
|
|
Constants::CLANG_TOOLCHAIN_TYPEID, alreadyKnown));
|
2018-10-01 17:02:19 +02:00
|
|
|
tcs.append(autoDetectToolchains(clang,
|
2018-08-06 12:30:32 +02:00
|
|
|
hostAbi, Constants::C_LANGUAGE_ID,
|
|
|
|
|
Constants::CLANG_TOOLCHAIN_TYPEID, alreadyKnown));
|
|
|
|
|
}
|
2018-07-11 00:16:44 +03:00
|
|
|
return tcs;
|
2011-05-13 11:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-07 14:18:32 +01:00
|
|
|
QList<ToolChain *> ClangToolChainFactory::autoDetect(const FileName &compilerPath, const Core::Id &language)
|
|
|
|
|
{
|
|
|
|
|
const QString fileName = compilerPath.fileName();
|
|
|
|
|
if ((language == Constants::C_LANGUAGE_ID && fileName.startsWith("clang") && !fileName.startsWith("clang++"))
|
|
|
|
|
|| (language == Constants::CXX_LANGUAGE_ID && fileName.startsWith("clang++")))
|
|
|
|
|
return autoDetectToolChain(compilerPath, language);
|
|
|
|
|
return QList<ToolChain *>();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
bool ClangToolChainFactory::canRestore(const QVariantMap &data)
|
2011-05-13 11:48:34 +02:00
|
|
|
{
|
2015-07-07 15:37:50 +02:00
|
|
|
return typeIdFromMap(data) == Constants::CLANG_TOOLCHAIN_TYPEID;
|
2011-05-13 11:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
GccToolChain *ClangToolChainFactory::createToolChain(bool autoDetect)
|
2011-05-13 11:48:34 +02:00
|
|
|
{
|
2013-09-03 10:58:59 +02:00
|
|
|
return new ClangToolChain(autoDetect ? ToolChain::AutoDetection : ToolChain::ManualDetection);
|
2011-05-13 11:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// MingwToolChain
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-09-03 10:58:59 +02:00
|
|
|
MingwToolChain::MingwToolChain(Detection d) :
|
2015-07-07 15:37:50 +02:00
|
|
|
GccToolChain(Constants::MINGW_TOOLCHAIN_TYPEID, d)
|
2011-02-01 18:36:00 +01:00
|
|
|
{ }
|
|
|
|
|
|
2012-01-30 11:55:21 +01:00
|
|
|
QString MingwToolChain::typeDisplayName() const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-08-09 17:49:30 +02:00
|
|
|
return MingwToolChainFactory::tr("MinGW");
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-03 14:01:25 +01:00
|
|
|
FileNameList MingwToolChain::suggestedMkspecList() const
|
2011-04-07 13:12:55 +02:00
|
|
|
{
|
2015-02-03 23:59:04 +02:00
|
|
|
if (HostOsInfo::isWindowsHost())
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList() << FileName::fromLatin1("win32-g++");
|
2015-02-03 23:59:04 +02:00
|
|
|
if (HostOsInfo::isLinuxHost()) {
|
2016-11-24 14:57:07 +01:00
|
|
|
if (version().startsWith("4.6."))
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList()
|
2014-02-07 15:46:36 +01:00
|
|
|
<< FileName::fromLatin1("win32-g++-4.6-cross")
|
|
|
|
|
<< FileName::fromLatin1("unsupported/win32-g++-4.6-cross");
|
2012-08-23 15:53:58 +02:00
|
|
|
else
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList()
|
2014-02-07 15:46:36 +01:00
|
|
|
<< FileName::fromLatin1("win32-g++-cross")
|
|
|
|
|
<< FileName::fromLatin1("unsupported/win32-g++-cross");
|
2012-08-23 15:53:58 +02:00
|
|
|
}
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList();
|
2011-04-07 13:12:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
QString MingwToolChain::makeCommand(const Environment &environment) const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2016-11-24 14:57:07 +01:00
|
|
|
const QStringList makes
|
2017-02-22 15:09:35 +01:00
|
|
|
= HostOsInfo::isWindowsHost() ? QStringList({"mingw32-make.exe", "make.exe"}) : QStringList({"make"});
|
2012-09-11 15:59:17 +02:00
|
|
|
|
2014-07-15 23:32:11 +03:00
|
|
|
FileName tmp;
|
2012-09-11 15:59:17 +02:00
|
|
|
foreach (const QString &make, makes) {
|
|
|
|
|
tmp = environment.searchInPath(make);
|
|
|
|
|
if (!tmp.isEmpty())
|
2014-07-15 23:32:11 +03:00
|
|
|
return tmp.toString();
|
2012-09-11 15:59:17 +02:00
|
|
|
}
|
|
|
|
|
return makes.first();
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain *MingwToolChain::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new MingwToolChain(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// MingwToolChainFactory
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
MingwToolChainFactory::MingwToolChainFactory()
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-08-09 17:49:30 +02:00
|
|
|
setDisplayName(tr("MinGW"));
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-12-16 00:43:14 +01:00
|
|
|
QSet<Core::Id> MingwToolChainFactory::supportedLanguages() const
|
2016-07-12 11:33:17 +02:00
|
|
|
{
|
2017-02-22 15:09:35 +01:00
|
|
|
return {Constants::CXX_LANGUAGE_ID,
|
|
|
|
|
Constants::C_LANGUAGE_ID};
|
2016-07-12 11:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-19 10:59:06 +03:00
|
|
|
QList<ToolChain *> MingwToolChainFactory::autoDetect(const QList<ToolChain *> &alreadyKnown)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2015-10-14 16:38:23 +03:00
|
|
|
Abi ha = Abi::hostAbi();
|
|
|
|
|
ha = Abi(ha.architecture(), Abi::WindowsOS, Abi::WindowsMSysFlavor, Abi::PEFormat, ha.wordWidth());
|
2018-08-06 12:28:08 +02:00
|
|
|
QList<ToolChain *> result = autoDetectToolchains(
|
|
|
|
|
compilerPathFromEnvironment("g++"), ha, Constants::CXX_LANGUAGE_ID,
|
|
|
|
|
Constants::MINGW_TOOLCHAIN_TYPEID, alreadyKnown);
|
|
|
|
|
result += autoDetectToolchains(
|
|
|
|
|
compilerPathFromEnvironment("gcc"), ha, Constants::C_LANGUAGE_ID,
|
|
|
|
|
Constants::MINGW_TOOLCHAIN_TYPEID, alreadyKnown);
|
2016-07-13 09:47:07 +02:00
|
|
|
return result;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-07 14:18:32 +01:00
|
|
|
QList<ToolChain *> MingwToolChainFactory::autoDetect(const FileName &compilerPath, const Core::Id &language)
|
|
|
|
|
{
|
|
|
|
|
Abi ha = Abi::hostAbi();
|
|
|
|
|
ha = Abi(ha.architecture(), Abi::WindowsOS, Abi::WindowsMSysFlavor, Abi::PEFormat, ha.wordWidth());
|
|
|
|
|
const QString fileName = compilerPath.fileName();
|
2017-06-13 11:51:12 +02:00
|
|
|
if ((language == Constants::C_LANGUAGE_ID && (fileName.startsWith("gcc")
|
|
|
|
|
|| fileName.endsWith("gcc")))
|
|
|
|
|
|| (language == Constants::CXX_LANGUAGE_ID && (fileName.startsWith("g++")
|
|
|
|
|
|| fileName.endsWith("g++"))))
|
2017-02-07 14:18:32 +01:00
|
|
|
return autoDetectToolChain(compilerPath, language, ha);
|
|
|
|
|
return QList<ToolChain *>();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
bool MingwToolChainFactory::canRestore(const QVariantMap &data)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2015-07-07 15:37:50 +02:00
|
|
|
return typeIdFromMap(data) == Constants::MINGW_TOOLCHAIN_TYPEID;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
GccToolChain *MingwToolChainFactory::createToolChain(bool autoDetect)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-09-03 10:58:59 +02:00
|
|
|
return new MingwToolChain(autoDetect ? ToolChain::AutoDetection : ToolChain::ManualDetection);
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// LinuxIccToolChain
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-09-03 10:58:59 +02:00
|
|
|
LinuxIccToolChain::LinuxIccToolChain(Detection d) :
|
2015-07-07 15:37:50 +02:00
|
|
|
GccToolChain(Constants::LINUXICC_TOOLCHAIN_TYPEID, d)
|
2011-02-01 18:36:00 +01:00
|
|
|
{ }
|
|
|
|
|
|
2012-01-30 11:55:21 +01:00
|
|
|
QString LinuxIccToolChain::typeDisplayName() const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-08-09 17:49:30 +02:00
|
|
|
return LinuxIccToolChainFactory::tr("Linux ICC");
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-28 13:11:48 +04:00
|
|
|
/**
|
2018-10-08 09:49:02 +02:00
|
|
|
* Similar to \a GccToolchain::languageExtensions, but uses "-openmp" instead of
|
2013-04-28 13:11:48 +04:00
|
|
|
* "-fopenmp" and "-fms-dialect[=ver]" instead of "-fms-extensions".
|
|
|
|
|
* @see UNIX manual for "icc"
|
|
|
|
|
*/
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtensions LinuxIccToolChain::languageExtensions(const QStringList &cxxflags) const
|
2013-04-28 13:11:48 +04:00
|
|
|
{
|
|
|
|
|
QStringList copy = cxxflags;
|
2016-11-24 14:57:07 +01:00
|
|
|
copy.removeAll("-fopenmp");
|
|
|
|
|
copy.removeAll("-fms-extensions");
|
2013-04-28 13:11:48 +04:00
|
|
|
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtensions extensions = GccToolChain::languageExtensions(cxxflags);
|
2016-11-24 14:57:07 +01:00
|
|
|
if (cxxflags.contains("-openmp"))
|
2018-10-08 09:49:02 +02:00
|
|
|
extensions |= LanguageExtension::OpenMP;
|
2016-11-24 14:57:07 +01:00
|
|
|
if (cxxflags.contains("-fms-dialect")
|
|
|
|
|
|| cxxflags.contains("-fms-dialect=8")
|
|
|
|
|
|| cxxflags.contains("-fms-dialect=9")
|
|
|
|
|
|| cxxflags.contains("-fms-dialect=10"))
|
2018-10-08 09:49:02 +02:00
|
|
|
extensions |= LanguageExtension::Microsoft;
|
|
|
|
|
return extensions;
|
2013-04-28 13:11:48 +04:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
IOutputParser *LinuxIccToolChain::outputParser() const
|
|
|
|
|
{
|
|
|
|
|
return new LinuxIccParser;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 14:01:25 +01:00
|
|
|
FileNameList LinuxIccToolChain::suggestedMkspecList() const
|
2011-04-07 13:12:55 +02:00
|
|
|
{
|
2015-11-03 14:01:25 +01:00
|
|
|
return FileNameList()
|
2016-11-24 14:57:07 +01:00
|
|
|
<< FileName::fromString(QString::fromLatin1("linux-icc-") + QString::number(targetAbi().wordWidth()));
|
2011-04-07 13:12:55 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
ToolChain *LinuxIccToolChain::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new LinuxIccToolChain(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// LinuxIccToolChainFactory
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
LinuxIccToolChainFactory::LinuxIccToolChainFactory()
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-08-09 17:49:30 +02:00
|
|
|
setDisplayName(tr("Linux ICC"));
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-12-16 00:43:14 +01:00
|
|
|
QSet<Core::Id> LinuxIccToolChainFactory::supportedLanguages() const
|
2016-07-12 11:33:17 +02:00
|
|
|
{
|
2018-08-21 13:53:23 +02:00
|
|
|
return {Constants::CXX_LANGUAGE_ID, Constants::C_LANGUAGE_ID};
|
2016-07-12 11:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-19 10:59:06 +03:00
|
|
|
QList<ToolChain *> LinuxIccToolChainFactory::autoDetect(const QList<ToolChain *> &alreadyKnown)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2018-08-21 13:53:23 +02:00
|
|
|
QList<ToolChain *> result
|
|
|
|
|
= autoDetectToolchains(compilerPathFromEnvironment("icpc"),
|
|
|
|
|
Abi::hostAbi(), Constants::CXX_LANGUAGE_ID,
|
|
|
|
|
Constants::LINUXICC_TOOLCHAIN_TYPEID, alreadyKnown);
|
|
|
|
|
result += autoDetectToolchains(compilerPathFromEnvironment("icc"),
|
|
|
|
|
Abi::hostAbi(), Constants::C_LANGUAGE_ID,
|
|
|
|
|
Constants::LINUXICC_TOOLCHAIN_TYPEID, alreadyKnown);
|
|
|
|
|
return result;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-07 14:18:32 +01:00
|
|
|
QList<ToolChain *> LinuxIccToolChainFactory::autoDetect(const FileName &compilerPath, const Core::Id &language)
|
|
|
|
|
{
|
|
|
|
|
const QString fileName = compilerPath.fileName();
|
2018-08-21 13:53:23 +02:00
|
|
|
if ((language == Constants::CXX_LANGUAGE_ID && fileName.startsWith("icpc")) ||
|
|
|
|
|
(language == Constants::C_LANGUAGE_ID && fileName.startsWith("icc")))
|
2017-02-07 14:18:32 +01:00
|
|
|
return autoDetectToolChain(compilerPath, language);
|
2018-08-21 13:53:23 +02:00
|
|
|
return {};
|
2017-02-07 14:18:32 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
bool LinuxIccToolChainFactory::canRestore(const QVariantMap &data)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2015-07-07 15:37:50 +02:00
|
|
|
return typeIdFromMap(data) == Constants::LINUXICC_TOOLCHAIN_TYPEID;
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
GccToolChain *LinuxIccToolChainFactory::createToolChain(bool autoDetect)
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
2013-09-03 10:58:59 +02:00
|
|
|
return new LinuxIccToolChain(autoDetect ? ToolChain::AutoDetection : ToolChain::ManualDetection);
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-18 11:56:54 +01:00
|
|
|
GccToolChain::WarningFlagAdder::WarningFlagAdder(const QString &flag, WarningFlags &flags) :
|
2016-04-13 15:52:14 +02:00
|
|
|
m_flags(flags)
|
2013-03-03 21:53:38 +04:00
|
|
|
{
|
2016-11-24 14:57:07 +01:00
|
|
|
if (!flag.startsWith("-W")) {
|
2013-03-03 21:53:38 +04:00
|
|
|
m_triggered = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 14:57:07 +01:00
|
|
|
m_doesEnable = !flag.startsWith("-Wno-");
|
2013-03-03 21:53:38 +04:00
|
|
|
if (m_doesEnable)
|
|
|
|
|
m_flagUtf8 = flag.mid(2).toUtf8();
|
|
|
|
|
else
|
|
|
|
|
m_flagUtf8 = flag.mid(5).toUtf8();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 11:56:54 +01:00
|
|
|
void GccToolChain::WarningFlagAdder::operator ()(const char name[], WarningFlags flagsSet)
|
2013-03-03 21:53:38 +04:00
|
|
|
{
|
|
|
|
|
if (m_triggered)
|
|
|
|
|
return;
|
|
|
|
|
if (0 == strcmp(m_flagUtf8.data(), name))
|
|
|
|
|
{
|
|
|
|
|
m_triggered = true;
|
|
|
|
|
if (m_doesEnable)
|
|
|
|
|
m_flags |= flagsSet;
|
|
|
|
|
else
|
|
|
|
|
m_flags &= ~flagsSet;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GccToolChain::WarningFlagAdder::triggered() const
|
|
|
|
|
{
|
|
|
|
|
return m_triggered;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
} // namespace ProjectExplorer
|
|
|
|
|
|
|
|
|
|
// Unit tests:
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
# include "projectexplorer.h"
|
|
|
|
|
|
|
|
|
|
# include <QTest>
|
2012-02-15 10:42:41 +01:00
|
|
|
# include <QUrl>
|
2011-02-01 18:36:00 +01:00
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
void ProjectExplorerPlugin::testGccAbiGuessing_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QString>("input");
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::addColumn<QByteArray>("macros");
|
2011-03-10 14:44:49 +01:00
|
|
|
QTest::addColumn<QStringList>("abiList");
|
2011-02-01 18:36:00 +01:00
|
|
|
|
|
|
|
|
QTest::newRow("invalid input")
|
|
|
|
|
<< QString::fromLatin1("Some text")
|
2013-02-20 12:23:45 +01:00
|
|
|
<< QByteArray("")
|
2011-03-10 14:44:49 +01:00
|
|
|
<< (QStringList());
|
2011-02-01 18:36:00 +01:00
|
|
|
QTest::newRow("empty input")
|
|
|
|
|
<< QString::fromLatin1("")
|
2013-02-20 12:23:45 +01:00
|
|
|
<< QByteArray("")
|
|
|
|
|
<< (QStringList());
|
|
|
|
|
QTest::newRow("empty input (with macros)")
|
|
|
|
|
<< QString::fromLatin1("")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n#define __Something\n")
|
2011-03-10 14:44:49 +01:00
|
|
|
<< (QStringList());
|
2013-11-04 13:07:20 +01:00
|
|
|
QTest::newRow("broken input -- 64bit")
|
|
|
|
|
<< QString::fromLatin1("arm-none-foo-gnueabi")
|
|
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n#define __Something\n")
|
2018-03-26 15:13:32 +02:00
|
|
|
<< QStringList({"arm-unknown-unknown-elf-64bit"});
|
2013-11-04 13:07:20 +01:00
|
|
|
QTest::newRow("broken input -- 32bit")
|
2011-02-01 18:36:00 +01:00
|
|
|
<< QString::fromLatin1("arm-none-foo-gnueabi")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n#define __Something\n")
|
2018-03-26 15:13:32 +02:00
|
|
|
<< QStringList({"arm-unknown-unknown-elf-32bit"});
|
2013-11-04 13:07:20 +01:00
|
|
|
QTest::newRow("totally broken input -- 32bit")
|
2011-03-10 14:44:49 +01:00
|
|
|
<< QString::fromLatin1("foo-bar-foo")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n#define __Something\n")
|
2016-11-24 14:57:07 +01:00
|
|
|
<< QStringList();
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Linux 1 (32bit intel)")
|
2011-02-01 18:36:00 +01:00
|
|
|
<< QString::fromLatin1("i686-linux-gnu")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-linux-generic-elf-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Linux 2 (32bit intel)")
|
2011-02-01 18:36:00 +01:00
|
|
|
<< QString::fromLatin1("i486-linux-gnu")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-linux-generic-elf-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Linux 3 (64bit intel)")
|
2011-02-01 18:36:00 +01:00
|
|
|
<< QString::fromLatin1("x86_64-linux-gnu")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-linux-generic-elf-64bit", "x86-linux-generic-elf-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Linux 3 (64bit intel -- non 64bit)")
|
|
|
|
|
<< QString::fromLatin1("x86_64-linux-gnu")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-linux-generic-elf-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Linux 4 (32bit mips)")
|
2011-04-06 10:04:57 +02:00
|
|
|
<< QString::fromLatin1("mipsel-linux-uclibc")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"mips-linux-generic-elf-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Linux 5 (QTCREATORBUG-4690)") // from QTCREATORBUG-4690
|
2011-05-03 14:40:20 +02:00
|
|
|
<< QString::fromLatin1("x86_64-redhat-linux6E")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-linux-generic-elf-64bit", "x86-linux-generic-elf-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Linux 6 (QTCREATORBUG-4690)") // from QTCREATORBUG-4690
|
2011-05-03 14:40:20 +02:00
|
|
|
<< QString::fromLatin1("x86_64-redhat-linux")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-linux-generic-elf-64bit", "x86-linux-generic-elf-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Linux 7 (arm)")
|
2011-07-01 13:39:54 +02:00
|
|
|
<< QString::fromLatin1("armv5tl-montavista-linux-gnueabi")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"arm-linux-generic-elf-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Linux 8 (arm)")
|
2011-08-31 15:24:24 +00:00
|
|
|
<< QString::fromLatin1("arm-angstrom-linux-gnueabi")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"arm-linux-generic-elf-32bit"});
|
2013-03-15 16:36:48 +01:00
|
|
|
QTest::newRow("Linux 9 (ppc)")
|
|
|
|
|
<< QString::fromLatin1("powerpc-nsg-linux")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"ppc-linux-generic-elf-32bit"});
|
2013-03-15 16:36:48 +01:00
|
|
|
QTest::newRow("Linux 10 (ppc 64bit)")
|
|
|
|
|
<< QString::fromLatin1("powerpc64-suse-linux")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"ppc-linux-generic-elf-64bit"});
|
2017-05-24 14:14:39 -07:00
|
|
|
QTest::newRow("Linux 11 (64bit mips)")
|
|
|
|
|
<< QString::fromLatin1("mips64el-linux-uclibc")
|
|
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8")
|
|
|
|
|
<< QStringList({"mips-linux-generic-elf-64bit"});
|
2011-07-01 13:39:54 +02:00
|
|
|
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Mingw 1 (32bit)")
|
|
|
|
|
<< QString::fromLatin1("i686-w64-mingw32")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\r\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-windows-msys-pe-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Mingw 2 (64bit)")
|
2011-02-01 18:36:00 +01:00
|
|
|
<< QString::fromLatin1("i686-w64-mingw32")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\r\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-windows-msys-pe-64bit", "x86-windows-msys-pe-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Mingw 3 (32 bit)")
|
2011-02-01 18:36:00 +01:00
|
|
|
<< QString::fromLatin1("mingw32")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\r\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-windows-msys-pe-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Cross Mingw 1 (64bit)")
|
2012-02-01 17:09:59 +01:00
|
|
|
<< QString::fromLatin1("amd64-mingw32msvc")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\r\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-windows-msys-pe-64bit", "x86-windows-msys-pe-32bit"});
|
2013-02-20 12:23:45 +01:00
|
|
|
QTest::newRow("Cross Mingw 2 (32bit)")
|
2012-02-01 17:09:59 +01:00
|
|
|
<< QString::fromLatin1("i586-mingw32msvc")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\r\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-windows-msys-pe-32bit"});
|
2011-05-13 11:48:34 +02:00
|
|
|
QTest::newRow("Clang 1: windows")
|
|
|
|
|
<< QString::fromLatin1("x86_64-pc-win32")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\r\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-windows-msys-pe-64bit", "x86-windows-msys-pe-32bit"});
|
2011-05-13 11:48:34 +02:00
|
|
|
QTest::newRow("Clang 1: linux")
|
|
|
|
|
<< QString::fromLatin1("x86_64-unknown-linux-gnu")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-linux-generic-elf-64bit", "x86-linux-generic-elf-32bit"});
|
2011-02-01 18:36:00 +01:00
|
|
|
QTest::newRow("Mac 1")
|
|
|
|
|
<< QString::fromLatin1("i686-apple-darwin10")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-darwin-generic-mach_o-64bit", "x86-darwin-generic-mach_o-32bit"});
|
2011-03-11 12:01:39 +01:00
|
|
|
QTest::newRow("Mac 2")
|
|
|
|
|
<< QString::fromLatin1("powerpc-apple-darwin10")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"ppc-darwin-generic-mach_o-64bit", "ppc-darwin-generic-mach_o-32bit"});
|
2011-03-11 12:01:39 +01:00
|
|
|
QTest::newRow("Mac 3")
|
|
|
|
|
<< QString::fromLatin1("i686-apple-darwin9")
|
2013-11-04 15:18:26 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-darwin-generic-mach_o-32bit", "x86-darwin-generic-mach_o-64bit"});
|
2011-04-08 16:33:59 +02:00
|
|
|
QTest::newRow("Mac IOS")
|
|
|
|
|
<< QString::fromLatin1("arm-apple-darwin9")
|
2013-11-04 15:18:26 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"arm-darwin-generic-mach_o-32bit", "arm-darwin-generic-mach_o-64bit"});
|
2011-02-01 18:36:00 +01:00
|
|
|
QTest::newRow("Intel 1")
|
|
|
|
|
<< QString::fromLatin1("86_64 x86_64 GNU/Linux")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 8\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-linux-generic-elf-64bit", "x86-linux-generic-elf-32bit"});
|
2011-05-31 10:06:32 +00:00
|
|
|
QTest::newRow("FreeBSD 1")
|
|
|
|
|
<< QString::fromLatin1("i386-portbld-freebsd9.0")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-bsd-freebsd-elf-32bit"});
|
2011-05-31 10:06:32 +00:00
|
|
|
QTest::newRow("FreeBSD 2")
|
|
|
|
|
<< QString::fromLatin1("i386-undermydesk-freebsd")
|
2013-11-04 13:07:20 +01:00
|
|
|
<< QByteArray("#define __SIZEOF_SIZE_T__ 4\n")
|
2017-02-22 15:09:35 +01:00
|
|
|
<< QStringList({"x86-bsd-freebsd-elf-32bit"});
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectExplorerPlugin::testGccAbiGuessing()
|
|
|
|
|
{
|
|
|
|
|
QFETCH(QString, input);
|
2013-02-20 12:23:45 +01:00
|
|
|
QFETCH(QByteArray, macros);
|
2011-03-10 14:44:49 +01:00
|
|
|
QFETCH(QStringList, abiList);
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
QList<Abi> al = guessGccAbi(input, ProjectExplorer::Macro::toMacros(macros));
|
2011-03-10 14:44:49 +01:00
|
|
|
QCOMPARE(al.count(), abiList.count());
|
2013-03-15 16:36:48 +01:00
|
|
|
for (int i = 0; i < al.count(); ++i)
|
2011-03-10 14:44:49 +01:00
|
|
|
QCOMPARE(al.at(i).toString(), abiList.at(i));
|
2011-02-01 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ProjectExplorer
|
|
|
|
|
|
|
|
|
|
#endif
|