Commit 276f4c48 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Explicitly set the target triple

As for the analyzer, this makes us independent of the default triple and will
most likely reduce the maintenance - e.g. the target implies certain internal
command line arguments, we will profit from added ones.

This fixes parsing of mingw headers with the clang code model.

Change-Id: I722b981125a80fac5f62a7af40a83ecdd7bbf811
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent 0235412b
......@@ -88,6 +88,7 @@ public:
LibClangOptionsBuilder optionsBuilder(*projectPart.data());
optionsBuilder.addTargetTriple();
optionsBuilder.addLanguageOption(fileKind);
optionsBuilder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
......
......@@ -236,6 +236,8 @@ public:
const ExtraToolChainInfo &extraParams)
{
ClangStaticAnalyzerOptionsBuilder optionsBuilder(projectPart);
optionsBuilder.addTargetTriple();
optionsBuilder.addLanguageOption(fileKind);
optionsBuilder.addOptionsForLanguage(false);
......@@ -258,7 +260,6 @@ public:
QStringList options = optionsBuilder.options();
prependWordWidthArgumentIfNotIncluded(&options, extraParams.wordWidth);
prependTargetTripleIfNotIncludedAndNotEmpty(&options, extraParams.targetTriple);
appendMsCompatibility2015OptionForMsvc2015(&options, extraParams.isMsvc2015);
undefineCppLanguageFeatureMacrosForMsvc2015(&options, extraParams.isMsvc2015);
......@@ -272,6 +273,15 @@ private:
{
}
void addTargetTriple() override
{
// For MSVC toolchains we use clang-cl.exe, so there is nothing to do here since
// 1) clang-cl.exe does not understand the "-triple" option
// 2) clang-cl.exe already hardcodes the right triple value (even if built with mingw)
if (m_projectPart.toolchainType != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
CompilerOptionsBuilder::addTargetTriple();
}
void addLanguageOption(ProjectFile::Kind fileKind) override
{
if (m_isMsvcToolchain)
......
......@@ -61,6 +61,14 @@ void CompilerOptionsBuilder::addDefine(const QByteArray &defineLine)
m_options.append(defineLineToDefineOption(defineLine));
}
void CompilerOptionsBuilder::addTargetTriple()
{
if (!m_projectPart.targetTriple.isEmpty()) {
m_options.append(QLatin1String("-target"));
m_options.append(m_projectPart.targetTriple);
}
}
void CompilerOptionsBuilder::addHeaderPathOptions()
{
typedef ProjectPartHeaderPath HeaderPath;
......
......@@ -45,6 +45,7 @@ public:
void addDefine(const QByteArray &defineLine);
// Add options based on project part
virtual void addTargetTriple();
void addHeaderPathOptions();
void addToolchainAndProjectDefines();
virtual void addLanguageOption(ProjectFile::Kind fileKind);
......
......@@ -104,6 +104,7 @@ public: // fields
QByteArray projectDefines;
QByteArray toolchainDefines;
Core::Id toolchainType;
QString targetTriple;
ProjectPartHeaderPaths headerPaths;
QStringList precompiledHeaders;
LanguageVersion languageVersion;
......
......@@ -262,6 +262,23 @@ ProjectPartHeaderPath toProjectPartHeaderPath(const ProjectExplorer::HeaderPath
return ProjectPartHeaderPath(headerPath.path(), headerPathType);
}
QString targetTriple(ProjectExplorer::Project *project, const Core::Id &toolchainId)
{
using namespace ProjectExplorer;
if (toolchainId == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
return QLatin1String("i686-pc-windows-msvc");
if (project) {
if (Target *target = project->activeTarget()) {
if (ToolChain *toolChain = ToolChainKitInformation::toolChain(target->kit()))
return toolChain->originalTargetTriple();
}
}
return QString();
}
}
/*!
......@@ -324,6 +341,7 @@ void ProjectPartBuilder::evaluateProjectPartToolchain(
projectPart->toolchainDefines = toolChain->predefinedMacros(commandLineFlags);
projectPart->toolchainType = toolChain->typeId();
projectPart->targetTriple = targetTriple(projectPart->project, toolChain->typeId());
projectPart->updateLanguageFeatures();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment