Commit 68a49c79 authored by Ivan Donchevskii's avatar Ivan Donchevskii

Clang: Unify compiler options builders

Make build command the same for all builders.
Minimize differences.

Change-Id: I1cfe5071b3afb4944ed178fff1e57d3aee45d8a9
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 736e568d
......@@ -223,8 +223,6 @@ def deploy_libclang(install_dir, llvm_install_dir, chrpath_bin):
os.path.join(install_dir, 'bin')))
deployinfo.append((os.path.join(llvm_install_dir, 'bin', 'clang.exe'),
clangbindirtarget))
deployinfo.append((os.path.join(llvm_install_dir, 'bin', 'clang-cl.exe'),
clangbindirtarget))
resourcetarget = os.path.join(clanglibdirtarget, 'clang')
else:
libsources = glob(os.path.join(llvm_install_dir, 'lib', 'libclang.so*'))
......
......@@ -70,46 +70,21 @@ QStringList createClangOptions(const ProjectPart::Ptr &pPart, const QString &fil
return createClangOptions(pPart, fileKind);
}
class LibClangOptionsBuilder : public ClangCompilerOptionsBuilder
class LibClangOptionsBuilder final : public ClangCompilerOptionsBuilder
{
public:
static QStringList build(const ProjectPart::Ptr &projectPart, ProjectFile::Kind fileKind)
LibClangOptionsBuilder(const ProjectPart &projectPart)
: ClangCompilerOptionsBuilder(projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR)
{
if (projectPart.isNull())
return QStringList();
LibClangOptionsBuilder optionsBuilder(*projectPart.data());
optionsBuilder.addWordWidth();
optionsBuilder.addTargetTriple();
optionsBuilder.addLanguageOption(fileKind);
optionsBuilder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
optionsBuilder.enableExceptions();
optionsBuilder.addDefineToAvoidIncludingGccOrMinGwIntrinsics();
optionsBuilder.addDefineFloat128ForMingw();
optionsBuilder.addToolchainAndProjectDefines();
optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
optionsBuilder.addPredefinedMacrosAndHeaderPathsOptions();
optionsBuilder.addWrappedQtHeadersIncludePath();
optionsBuilder.addHeaderPathOptions();
optionsBuilder.addDummyUiHeaderOnDiskIncludePath();
optionsBuilder.addProjectConfigFileInclude();
optionsBuilder.addMsvcCompatibilityVersion();
optionsBuilder.addExtraOptions();
return optionsBuilder.options();
}
private:
LibClangOptionsBuilder(const CppTools::ProjectPart &projectPart)
: ClangCompilerOptionsBuilder(projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR)
void addExtraOptions() final
{
addDummyUiHeaderOnDiskIncludePath();
ClangCompilerOptionsBuilder::addExtraOptions();
}
private:
void addDummyUiHeaderOnDiskIncludePath()
{
const QString path = ModelManagerSupportClang::instance()->dummyUiHeaderOnDiskDirPath();
......@@ -125,7 +100,9 @@ private:
*/
QStringList createClangOptions(const ProjectPart::Ptr &pPart, ProjectFile::Kind fileKind)
{
return LibClangOptionsBuilder::build(pPart, fileKind);
if (!pPart)
return QStringList();
return LibClangOptionsBuilder(*pPart).build(fileKind, CompilerOptionsBuilder::PchUsage::None);
}
ProjectPart::Ptr projectPartForFile(const QString &filePath)
......
......@@ -108,35 +108,9 @@ HeaderAndSources ProjectUpdater::headerAndSourcesFromProjectPart(
QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart)
{
using CppTools::ClangCompilerOptionsBuilder;
ClangCompilerOptionsBuilder builder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
builder.addWordWidth();
builder.addTargetTriple();
builder.addLanguageOption(CppTools::ProjectFile::CXXHeader);
builder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
builder.enableExceptions();
builder.addDefineToAvoidIncludingGccOrMinGwIntrinsics();
builder.addDefineFloat128ForMingw();
builder.addToolchainAndProjectDefines();
builder.undefineCppLanguageFeatureMacrosForMsvc2015();
builder.addPredefinedMacrosAndHeaderPathsOptions();
builder.addWrappedQtHeadersIncludePath();
builder.addPrecompiledHeaderOptions(ClangCompilerOptionsBuilder::PchUsage::None);
builder.addHeaderPathOptions();
builder.addProjectConfigFileInclude();
builder.addMsvcCompatibilityVersion();
builder.add("-fmessage-length=0");
builder.add("-fmacro-backtrace-limit=0");
builder.add("-w");
builder.add("-ferror-limit=100000");
return builder.options();
using ClangCOBuilder = CppTools::ClangCompilerOptionsBuilder;
ClangCOBuilder builder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
return builder.build(CppTools::ProjectFile::CXXHeader, ClangCOBuilder::PchUsage::None);
}
ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(
......
......@@ -155,31 +155,8 @@ Utils::SmallStringVector ClangQueryProjectsFindFilter::compilerArguments(CppTool
ClangCompilerOptionsBuilder builder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
builder.addWordWidth();
builder.addTargetTriple();
builder.addLanguageOption(fileKind);
builder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
builder.enableExceptions();
builder.addDefineToAvoidIncludingGccOrMinGwIntrinsics();
builder.addDefineFloat128ForMingw();
builder.addToolchainAndProjectDefines();
builder.undefineCppLanguageFeatureMacrosForMsvc2015();
builder.addPredefinedMacrosAndHeaderPathsOptions();
builder.addWrappedQtHeadersIncludePath();
builder.addPrecompiledHeaderOptions(ClangCompilerOptionsBuilder::PchUsage::None);
builder.addHeaderPathOptions();
builder.addProjectConfigFileInclude();
builder.addMsvcCompatibilityVersion();
builder.add("-fmessage-length=0");
builder.add("-fmacro-backtrace-limit=0");
builder.add("-w");
builder.add("-ferror-limit=1000000");
return Utils::SmallStringVector(builder.options());
return Utils::SmallStringVector(builder.build(fileKind,
ClangCompilerOptionsBuilder::PchUsage::None));
}
QWidget *ClangQueryProjectsFindFilter::widget() const
......
......@@ -64,12 +64,10 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
QString filePath = data.filePath().toString();
QTextCursor textCursor = data.cursor();
Utils::SmallStringVector commandLine{ClangCompilerOptionsBuilder::build(
projectPart,
ClangCompilerOptionsBuilder clangCOBuilder{*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR};
Utils::SmallStringVector commandLine{clangCOBuilder.build(
fileKindInProjectPart(projectPart, filePath),
CppTools::getPchUsage(),
CLANG_VERSION,
CLANG_RESOURCE_DIR)};
CppTools::getPchUsage())};
commandLine.push_back(filePath);
......
......@@ -167,7 +167,7 @@ static QList<Target *> validTargets(Project *project)
const ToolChain * const toolchain = ToolChainKitInformation::toolChain(kit, ProjectExplorer::Constants::CXX_LANGUAGE_ID);
QTC_ASSERT(toolchain, return false);
bool hasClangExecutable;
clangExecutableFromSettings(toolchain->typeId(), &hasClangExecutable);
clangExecutableFromSettings(&hasClangExecutable);
if (!hasClangExecutable) {
qWarning("Project \"%s\": Skipping target \"%s\" since no suitable clang was found for the toolchain.",
qPrintable(projectFileName),
......
......@@ -38,7 +38,7 @@
#include <coreplugin/progressmanager/futureprogress.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <cpptools/compileroptionsbuilder.h>
#include <cpptools/clangcompileroptionsbuilder.h>
#include <cpptools/cppmodelmanager.h>
#include <cpptools/cppprojectfile.h>
#include <cpptools/cpptoolsreuse.h>
......@@ -161,8 +161,7 @@ static void prependTargetTripleIfNotIncludedAndNotEmpty(QStringList *arguments,
}
// Removes (1) inputFile (2) -o <somePath>.
QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStringList &arguments,
bool isMsvc)
QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStringList &arguments)
{
QStringList newArguments;
......@@ -174,9 +173,6 @@ QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStri
} else if (argument == QLatin1String("-o")) {
skip = true;
continue;
} else if (isMsvc && argument == QLatin1String("-target")) {
skip = true;
continue;
} else if (QDir::fromNativeSeparators(argument) == inputFile) {
continue; // TODO: Let it in?
}
......@@ -188,55 +184,11 @@ QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStri
return newArguments;
}
static QString createLanguageOptionMsvc(ProjectFile::Kind fileKind)
{
switch (fileKind) {
case ProjectFile::CHeader:
case ProjectFile::CSource:
return QLatin1String("/TC");
break;
case ProjectFile::CXXHeader:
case ProjectFile::CXXSource:
return QLatin1String("/TP");
break;
default:
break;
}
return QString();
}
class ClangStaticAnalyzerOptionsBuilder : public CompilerOptionsBuilder
class ClangStaticAnalyzerOptionsBuilder final : public ClangCompilerOptionsBuilder
{
public:
static QStringList build(const CppTools::ProjectPart &projectPart,
CppTools::ProjectFile::Kind fileKind,
PchUsage pchUsage)
{
ClangStaticAnalyzerOptionsBuilder optionsBuilder(projectPart);
optionsBuilder.addWordWidth();
optionsBuilder.addTargetTriple();
optionsBuilder.addLanguageOption(fileKind);
optionsBuilder.addOptionsForLanguage(false);
optionsBuilder.enableExceptions();
optionsBuilder.addDefineFloat128ForMingw();
optionsBuilder.addDefineToAvoidIncludingGccOrMinGwIntrinsics();
const Core::Id type = projectPart.toolchainType;
if (type != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
optionsBuilder.addMacros(projectPart.toolChainMacros);
optionsBuilder.addMacros(projectPart.projectMacros);
optionsBuilder.undefineClangVersionMacrosForMsvc();
optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
optionsBuilder.addHeaderPathOptions();
optionsBuilder.addPrecompiledHeaderOptions(pchUsage);
optionsBuilder.addMsvcCompatibilityVersion();
return optionsBuilder.options();
}
ClangStaticAnalyzerOptionsBuilder(const CppTools::ProjectPart &projectPart)
: CompilerOptionsBuilder(projectPart)
: ClangCompilerOptionsBuilder(projectPart)
, m_isMsvcToolchain(m_projectPart.toolchainType
== ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
, m_isMinGWToolchain(m_projectPart.toolchainType
......@@ -244,91 +196,28 @@ public:
{
}
public:
bool excludeHeaderPath(const QString &headerPath) const override
bool excludeHeaderPath(const QString &headerPath) const final
{
if (CompilerOptionsBuilder::excludeHeaderPath(headerPath))
return true;
if (m_isMinGWToolchain && headerPath.contains(m_projectPart.toolChainTargetTriple))
return true;
return false;
return ClangCompilerOptionsBuilder::excludeHeaderPath(headerPath);
}
void undefineClangVersionMacrosForMsvc()
void addPredefinedHeaderPathsOptions() final
{
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
static QStringList macroNames {
"__clang__",
"__clang_major__",
"__clang_minor__",
"__clang_patchlevel__",
"__clang_version__"
};
foreach (const QString &macroName, macroNames)
add(QLatin1String("/U") + macroName);
add("-undef");
if (m_isMsvcToolchain) {
// exclude default clang path to use msvc includes
add("-nostdinc");
add("-nostdlibinc");
}
}
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_isMsvcToolchain)
CompilerOptionsBuilder::addTargetTriple();
}
void addLanguageOption(ProjectFile::Kind fileKind) override
{
if (m_isMsvcToolchain)
add(createLanguageOptionMsvc(fileKind));
else
CompilerOptionsBuilder::addLanguageOption(fileKind);
}
void addOptionsForLanguage(bool checkForBorlandExtensions) override
{
if (m_isMsvcToolchain)
return;
CompilerOptionsBuilder::addOptionsForLanguage(checkForBorlandExtensions);
}
QString includeOption() const override
{
if (m_isMsvcToolchain)
return QLatin1String("/FI");
return CompilerOptionsBuilder::includeOption();
}
void addExtraOptions() final {}
QString includeDirOption() const override
void addWrappedQtHeadersIncludePath() final
{
if (m_isMsvcToolchain)
return QLatin1String("/I");
return CompilerOptionsBuilder::includeDirOption();
}
QString defineOption() const override
{
if (m_isMsvcToolchain)
return QLatin1String("/D");
return CompilerOptionsBuilder::defineOption();
}
QString undefineOption() const override
{
if (m_isMsvcToolchain)
return QLatin1String("/U");
return CompilerOptionsBuilder::undefineOption();
}
void enableExceptions() override
{
if (m_isMsvcToolchain)
add(QLatin1String("/EHsc"));
else
CompilerOptionsBuilder::enableExceptions();
// Empty, analyzer doesn't need them
}
private:
......@@ -383,7 +272,7 @@ static QStringList tweakedArguments(const ProjectPart &projectPart,
{
const bool isMsvc = projectPart.toolchainType
== ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
QStringList newArguments = inputAndOutputArgumentsRemoved(filePath, arguments, isMsvc);
QStringList newArguments = inputAndOutputArgumentsRemoved(filePath, arguments);
prependWordWidthArgumentIfNotIncluded(&newArguments, projectPart.toolChainWordWidth);
if (!isMsvc)
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, targetTriple);
......@@ -434,7 +323,7 @@ static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QVector<ProjectPart::Pt
AnalyzeUnits unitsToAnalyze;
foreach (const ProjectPart::Ptr &projectPart, projectParts) {
if (!projectPart->selectedForBuilding)
if (!projectPart->selectedForBuilding || !projectPart.data())
continue;
foreach (const ProjectFile &file, projectPart->files) {
......@@ -445,7 +334,7 @@ static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QVector<ProjectPart::Pt
if (ProjectFile::isSource(file.kind)) {
const CompilerOptionsBuilder::PchUsage pchUsage = CppTools::getPchUsage();
const QStringList arguments
= ClangStaticAnalyzerOptionsBuilder::build(*projectPart.data(), file.kind, pchUsage);
= ClangStaticAnalyzerOptionsBuilder(*projectPart).build(file.kind, pchUsage);
unitsToAnalyze << AnalyzeUnit(file.path, arguments);
}
}
......@@ -501,21 +390,6 @@ static QDebug operator<<(QDebug debug, const AnalyzeUnits &analyzeUnits)
return debug;
}
static QString executableForVersionCheck(Core::Id toolchainType, const QString &executable)
{
if (toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
const QString suffix = QLatin1String("-cl.exe");
if (executable.endsWith(suffix, Utils::HostOsInfo::fileNameCaseSensitivity())) {
QString modified = executable;
modified.chop(suffix.length());
modified.append(QLatin1String(".exe"));
return modified;
}
}
return executable;
}
void ClangStaticAnalyzerToolRunner::start()
{
m_success = false;
......@@ -532,8 +406,7 @@ void ClangStaticAnalyzerToolRunner::start()
// Check clang executable
bool isValidClangExecutable;
const QString executable = clangExecutableFromSettings(m_toolChainType,
&isValidClangExecutable);
const QString executable = clangExecutableFromSettings(&isValidClangExecutable);
if (!isValidClangExecutable) {
const QString errorMessage = tr("Clang Static Analyzer: Invalid executable \"%1\", stop.")
.arg(executable);
......@@ -545,13 +418,12 @@ void ClangStaticAnalyzerToolRunner::start()
}
// Check clang version
const QString versionCheckExecutable = executableForVersionCheck(m_toolChainType, executable);
const ClangExecutableVersion version = clangExecutableVersion(versionCheckExecutable);
const ClangExecutableVersion version = clangExecutableVersion(executable);
if (!version.isValid()) {
const QString warningMessage
= tr("Clang Static Analyzer: Running with possibly unsupported version, "
"could not determine version from executable \"%1\".")
.arg(versionCheckExecutable);
.arg(executable);
appendMessage(warningMessage, Utils::StdErrFormat);
TaskHub::addTask(Task::Warning, warningMessage, Debugger::Constants::ANALYZERTASK_ID);
TaskHub::requestPopup();
......
......@@ -58,7 +58,7 @@ void ClangStaticAnalyzerUnitTests::initTestCase()
if (!toolchain)
QSKIP("This test requires that there is a kit with a toolchain.");
bool hasClangExecutable;
clangExecutableFromSettings(toolchain->typeId(), &hasClangExecutable);
clangExecutableFromSettings(&hasClangExecutable);
if (!hasClangExecutable)
QSKIP("No clang suitable for analyzing found");
......
......@@ -50,7 +50,7 @@ static bool isFileExecutable(const QString &executablePath)
namespace ClangStaticAnalyzer {
namespace Internal {
QString clangExecutableFromSettings(Core::Id toolchainType, bool *isValid)
QString clangExecutableFromSettings(bool *isValid)
{
QString executable = ClangStaticAnalyzerSettings::instance()->clangExecutable();
if (executable.isEmpty()) {
......@@ -62,14 +62,6 @@ QString clangExecutableFromSettings(Core::Id toolchainType, bool *isValid)
const Qt::CaseSensitivity caseSensitivity = Utils::HostOsInfo::fileNameCaseSensitivity();
const bool hasSuffix = executable.endsWith(hostExeSuffix, caseSensitivity);
if (toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
if (hasSuffix)
executable.chop(hostExeSuffix.length());
executable.append(QLatin1String("-cl"));
if (hasSuffix)
executable.append(hostExeSuffix);
}
const QFileInfo fileInfo = QFileInfo(executable);
if (fileInfo.isAbsolute()) {
if (!hasSuffix)
......
......@@ -41,7 +41,7 @@ namespace Internal {
bool isClangExecutableUsable(const QString &filePath, QString *errorMessage = 0);
QString clangExecutableFromSettings(Core::Id toolchainType, bool *isValid);
QString clangExecutableFromSettings(bool *isValid);
QString createFullLocationString(const Debugger::DiagnosticLocation &location);
......
......@@ -26,7 +26,6 @@
#include "clangcompileroptionsbuilder.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/qtcassert.h>
......@@ -38,46 +37,46 @@ namespace CppTools {
static QString creatorResourcePath()
{
#ifndef UNIT_TESTS
return Core::ICore::instance()->libexecPath();
return Core::ICore::instance()->resourcePath();
#else
return QString();
#endif
}
QStringList ClangCompilerOptionsBuilder::build(const CppTools::ProjectPart *projectPart,
CppTools::ProjectFile::Kind fileKind,
PchUsage pchUsage,
const QString &clangVersion,
const QString &clangResourceDirectory)
static QString creatorLibexecPath()
{
if (projectPart) {
ClangCompilerOptionsBuilder builder(*projectPart, clangVersion, clangResourceDirectory);
builder.addWordWidth();
builder.addTargetTriple();
builder.addLanguageOption(fileKind);
builder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
builder.enableExceptions();
#ifndef UNIT_TESTS
return Core::ICore::instance()->libexecPath();
#else
return QString();
#endif
}
builder.addDefineToAvoidIncludingGccOrMinGwIntrinsics();
builder.addDefineFloat128ForMingw();
builder.addToolchainAndProjectDefines();
builder.undefineCppLanguageFeatureMacrosForMsvc2015();
QStringList ClangCompilerOptionsBuilder::build(CppTools::ProjectFile::Kind fileKind,
PchUsage pchUsage)
{
addWordWidth();
addTargetTriple();
addLanguageOption(fileKind);
addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
enableExceptions();
builder.addPredefinedMacrosAndHeaderPathsOptions();
builder.addWrappedQtHeadersIncludePath();
builder.addPrecompiledHeaderOptions(pchUsage);
builder.addHeaderPathOptions();
builder.addProjectConfigFileInclude();
addDefineFloat128ForMingw();
addToolchainAndProjectMacros();
undefineClangVersionMacrosForMsvc();
undefineCppLanguageFeatureMacrosForMsvc2015();
builder.addMsvcCompatibilityVersion();
addPredefinedHeaderPathsOptions();
addWrappedQtHeadersIncludePath();
addPrecompiledHeaderOptions(pchUsage);
addHeaderPathOptions();
addProjectConfigFileInclude();
builder.addExtraOptions();
addMsvcCompatibilityVersion();
return builder.options();
}
addExtraOptions();
return QStringList();
return options();
}
ClangCompilerOptionsBuilder::ClangCompilerOptionsBuilder(const CppTools::ProjectPart &projectPart,
......@@ -91,47 +90,35 @@ ClangCompilerOptionsBuilder::ClangCompilerOptionsBuilder(const CppTools::Project
bool ClangCompilerOptionsBuilder::excludeHeaderPath(const QString &path) const
{
if (m_projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID) {
if (path.contains("lib/gcc/i686-apple-darwin"))
return true;
if (m_projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID
&& path.contains("lib/gcc/i686-apple-darwin")) {
return true;
}
return CompilerOptionsBuilder::excludeHeaderPath(path);
}
void ClangCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptions()
void ClangCompilerOptionsBuilder::addPredefinedHeaderPathsOptions()
{
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
addPredefinedMacrosAndHeaderPathsOptionsForMsvc();
else
addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc();
}
void ClangCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptionsForMsvc()
{
add("-nostdinc");
add("-undef");
}
add("-nostdinc");
add("-nostdlibinc");
void ClangCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc()
{
static const QString resourceDir = clangIncludeDirectory();
if (QTC_GUARD(!resourceDir.isEmpty())) {
add("-nostdlibinc");
add("-I" + QDir::toNativeSeparators(resourceDir));
add("-undef");
}
if (m_projectPart.toolchainType != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
add(includeDirOption() + clangIncludeDirectory());
}
void ClangCompilerOptionsBuilder::addWrappedQtHeadersIncludePath()
{
static const QString wrappedQtHeadersPath = creatorResourcePath()
+ "/cplusplus/wrappedQtHeaders";
static const QString resourcePath = creatorResourcePath();
static QString wrappedQtHeadersPath = resourcePath + "/cplusplus/wrappedQtHeaders";
QDir dir(wrappedQtHeadersPath);
QTC_ASSERT(QDir(wrappedQtHeadersPath).exists(), return;);
if (m_projectPart.qtVersion != CppTools::ProjectPart::NoQt) {
const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + "/QtCore";
add("-I" + QDir::toNativeSeparators(wrappedQtHeadersPath));
add("-I" + QDir::toNativeSeparators(wrappedQtCoreHeaderPath));
add(includeDirOption() + QDir::toNativeSeparators(wrappedQtHeadersPath));
add(includeDirOption() + QDir::toNativeSeparators(wrappedQtCoreHeaderPath));
}
}
......@@ -154,12 +141,26 @@ void ClangCompilerOptionsBuilder::addExtraOptions()
QString ClangCompilerOptionsBuilder::clangIncludeDirectory() const
{
QDir dir(creatorResourcePath() + "/clang/lib/clang/" + m_clangVersion + "/include");
QDir dir(creatorLibexecPath() + "/clang/lib/clang/" + m_clangVersion + "/include");
if (!dir.exists() || !QFileInfo(dir, "stdint.h").exists())
dir = QDir(m_clangResourceDirectory);
return QDir::toNativeSeparators(dir.canonicalPath());
}
return dir.canonicalPath();
void ClangCompilerOptionsBuilder::undefineClangVersionMacrosForMsvc()
{
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
static QStringList macroNames {
"__clang__",
"__clang_major__",
"__clang_minor__",
"__clang_patchlevel__",
"__clang_version__"
};
foreach (const QString &macroName, macroNames)
add(undefineOption() + macroName);
}
}
} // namespace CppTools
......@@ -34,33 +34,24 @@ namespace CppTools {
class CPPTOOLS_EXPORT ClangCompilerOptionsBuilder : public CompilerOptionsBuilder
{
public:
static QStringList build(const ProjectPart *projectPart,
ProjectFile::Kind fileKind,
PchUsage pchUsage,
const QString &clangVersion,
const QString &clangResourceDirectory);
QStringList build(ProjectFile::Kind fileKind,
PchUsage pchUsage);
ClangCompilerOptionsBuilder(const ProjectPart &projectPart,
const QString &clangVersion,
const QString &clangResourceDirectory);
const QString &clangVersion = QString(),
const QString &clangResourceDirectory = QString());
bool excludeHeaderPath(const QString &path) const override;
void addPredefinedMacrosAndHeaderPathsOptions();
void addPredefinedMacrosAndHeaderPathsOptionsForMsvc();
void addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc();