forked from qt-creator/qt-creator
Clang: Clean up CompilerOptionsBuilder
No behavior change. * Remove virtual from methods that are not overridden * Move constant member functions that do no access any members into source file as static functions * Remove QLatin1String where possible * Make variable names a bit more consistent * Other minor stuff Change-Id: I34a582d5a468489e11365507b283e9aee157664f Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -568,14 +568,14 @@ private:
|
|||||||
{
|
{
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
|
|
||||||
if (getPchUsage() == CompilerOptionsBuilder::PchUsage::None)
|
if (getPchUsage() == UsePrecompiledHeaders::No)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_projectPart.precompiledHeaders.contains(m_filePath))
|
if (m_projectPart.precompiledHeaders.contains(m_filePath))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CompilerOptionsBuilder builder(m_projectPart);
|
CompilerOptionsBuilder builder(m_projectPart);
|
||||||
builder.addPrecompiledHeaderOptions(CompilerOptionsBuilder::PchUsage::Use);
|
builder.addPrecompiledHeaderOptions(UsePrecompiledHeaders::Yes);
|
||||||
|
|
||||||
m_options.append(builder.options());
|
m_options.append(builder.options());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ public:
|
|||||||
LibClangOptionsBuilder(const ProjectPart &projectPart)
|
LibClangOptionsBuilder(const ProjectPart &projectPart)
|
||||||
: CompilerOptionsBuilder(projectPart,
|
: CompilerOptionsBuilder(projectPart,
|
||||||
UseSystemHeader::No,
|
UseSystemHeader::No,
|
||||||
CppTools::SkipBuiltIn::No,
|
SkipBuiltIn::No,
|
||||||
CppTools::SkipLanguageDefines::Yes,
|
SkipLanguageDefines::Yes,
|
||||||
QString(CLANG_VERSION),
|
QString(CLANG_VERSION),
|
||||||
QString(CLANG_RESOURCE_DIR))
|
QString(CLANG_RESOURCE_DIR))
|
||||||
{
|
{
|
||||||
@@ -105,8 +105,7 @@ private:
|
|||||||
|
|
||||||
QStringList createClangOptions(const ProjectPart &projectPart, ProjectFile::Kind fileKind)
|
QStringList createClangOptions(const ProjectPart &projectPart, ProjectFile::Kind fileKind)
|
||||||
{
|
{
|
||||||
return LibClangOptionsBuilder(projectPart)
|
return LibClangOptionsBuilder(projectPart).build(fileKind, UsePrecompiledHeaders::No);
|
||||||
.build(fileKind, CompilerOptionsBuilder::PchUsage::None);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectPart::Ptr projectPartForFile(const QString &filePath)
|
ProjectPart::Ptr projectPartForFile(const QString &filePath)
|
||||||
@@ -341,7 +340,7 @@ void generateCompilationDB(::Utils::FileName projectDir, CppTools::ProjectInfo p
|
|||||||
CppTools::UseSystemHeader::No,
|
CppTools::UseSystemHeader::No,
|
||||||
CppTools::SkipBuiltIn::Yes);
|
CppTools::SkipBuiltIn::Yes);
|
||||||
optionsBuilder.build(CppTools::ProjectFile::Unclassified,
|
optionsBuilder.build(CppTools::ProjectFile::Unclassified,
|
||||||
CppTools::CompilerOptionsBuilder::PchUsage::None);
|
CppTools::UsePrecompiledHeaders::No);
|
||||||
|
|
||||||
for (const ProjectFile &projFile : projectPart->files) {
|
for (const ProjectFile &projFile : projectPart->files) {
|
||||||
const QJsonObject json = createFileObject(optionsBuilder, projFile, buildDir);
|
const QJsonObject json = createFileObject(optionsBuilder, projFile, buildDir);
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart
|
|||||||
{
|
{
|
||||||
using CppTools::CompilerOptionsBuilder;
|
using CppTools::CompilerOptionsBuilder;
|
||||||
CompilerOptionsBuilder builder(*projectPart, CppTools::UseSystemHeader::Yes);
|
CompilerOptionsBuilder builder(*projectPart, CppTools::UseSystemHeader::Yes);
|
||||||
return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None);
|
return builder.build(CppTools::ProjectFile::CXXHeader, CppTools::UsePrecompiledHeaders::No);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangBackEnd::CompilerMacros ProjectUpdater::createCompilerMacros(const ProjectExplorer::Macros &projectMacros)
|
ClangBackEnd::CompilerMacros ProjectUpdater::createCompilerMacros(const ProjectExplorer::Macros &projectMacros)
|
||||||
|
|||||||
@@ -155,8 +155,7 @@ Utils::SmallStringVector ClangQueryProjectsFindFilter::compilerArguments(CppTool
|
|||||||
|
|
||||||
CompilerOptionsBuilder builder(*projectPart, CppTools::UseSystemHeader::Yes);
|
CompilerOptionsBuilder builder(*projectPart, CppTools::UseSystemHeader::Yes);
|
||||||
|
|
||||||
return Utils::SmallStringVector(builder.build(fileKind,
|
return Utils::SmallStringVector(builder.build(fileKind, CppTools::UsePrecompiledHeaders::No));
|
||||||
CompilerOptionsBuilder::PchUsage::None));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *ClangQueryProjectsFindFilter::widget() const
|
QWidget *ClangQueryProjectsFindFilter::widget() const
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ private:
|
|||||||
static AnalyzeUnits toAnalyzeUnits(const FileInfos &fileInfos)
|
static AnalyzeUnits toAnalyzeUnits(const FileInfos &fileInfos)
|
||||||
{
|
{
|
||||||
AnalyzeUnits unitsToAnalyze;
|
AnalyzeUnits unitsToAnalyze;
|
||||||
const CompilerOptionsBuilder::PchUsage pchUsage = CppTools::getPchUsage();
|
const UsePrecompiledHeaders usePrecompiledHeaders = CppTools::getPchUsage();
|
||||||
for (const FileInfo &fileInfo : fileInfos) {
|
for (const FileInfo &fileInfo : fileInfos) {
|
||||||
CompilerOptionsBuilder optionsBuilder(*fileInfo.projectPart,
|
CompilerOptionsBuilder optionsBuilder(*fileInfo.projectPart,
|
||||||
CppTools::UseSystemHeader::No,
|
CppTools::UseSystemHeader::No,
|
||||||
@@ -198,7 +198,7 @@ static AnalyzeUnits toAnalyzeUnits(const FileInfos &fileInfos)
|
|||||||
QString(CLANG_VERSION),
|
QString(CLANG_VERSION),
|
||||||
QString(CLANG_RESOURCE_DIR));
|
QString(CLANG_RESOURCE_DIR));
|
||||||
QStringList arguments = extraClangToolsPrependOptions();
|
QStringList arguments = extraClangToolsPrependOptions();
|
||||||
arguments.append(optionsBuilder.build(fileInfo.kind, pchUsage));
|
arguments.append(optionsBuilder.build(fileInfo.kind, usePrecompiledHeaders));
|
||||||
arguments.append(extraClangToolsAppendOptions());
|
arguments.append(extraClangToolsAppendOptions());
|
||||||
unitsToAnalyze << AnalyzeUnit(fileInfo.file.toString(), arguments);
|
unitsToAnalyze << AnalyzeUnit(fileInfo.file.toString(), arguments);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,12 @@
|
|||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/vcsmanager.h>
|
|
||||||
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/headerpath.h>
|
||||||
|
#include <projectexplorer/language.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
|
#include <projectexplorer/projectmacro.h>
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -41,22 +43,51 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
|
static const char defineOption[] = "-D";
|
||||||
|
static const char undefineOption[] = "-U";
|
||||||
|
|
||||||
|
static const char includeUserPathOption[] = "-I";
|
||||||
|
static const char includeSystemPathOption[] = "-isystem";
|
||||||
|
|
||||||
|
static const char includeFileOption[] = "-include";
|
||||||
|
|
||||||
|
static QByteArray macroOption(const ProjectExplorer::Macro ¯o)
|
||||||
|
{
|
||||||
|
switch (macro.type) {
|
||||||
|
case ProjectExplorer::MacroType::Define: return defineOption;
|
||||||
|
case ProjectExplorer::MacroType::Undefine: return undefineOption;
|
||||||
|
default: return QByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static QByteArray toDefineOption(const ProjectExplorer::Macro ¯o)
|
||||||
|
{
|
||||||
|
return macro.toKeyValue(macroOption(macro));
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString defineDirectiveToDefineOption(const ProjectExplorer::Macro ¯o)
|
||||||
|
{
|
||||||
|
const QByteArray option = toDefineOption(macro);
|
||||||
|
return QString::fromUtf8(option);
|
||||||
|
}
|
||||||
|
|
||||||
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
|
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||||
UseSystemHeader useSystemHeader,
|
UseSystemHeader useSystemHeader,
|
||||||
SkipBuiltIn skipBuiltInHeaderPathsAndDefines,
|
SkipBuiltIn skipBuiltInHeaderPathsAndDefines,
|
||||||
SkipLanguageDefines skipLanguageDefines,
|
SkipLanguageDefines skipLanguageDefines,
|
||||||
QString clangVersion,
|
const QString &clangVersion,
|
||||||
QString clangResourceDirectory)
|
const QString &clangResourceDirectory)
|
||||||
: m_projectPart(projectPart)
|
: m_projectPart(projectPart)
|
||||||
, m_clangVersion(clangVersion)
|
|
||||||
, m_clangResourceDirectory(clangResourceDirectory)
|
|
||||||
, m_useSystemHeader(useSystemHeader)
|
, m_useSystemHeader(useSystemHeader)
|
||||||
, m_skipBuiltInHeaderPathsAndDefines(skipBuiltInHeaderPathsAndDefines)
|
, m_skipBuiltInHeaderPathsAndDefines(skipBuiltInHeaderPathsAndDefines)
|
||||||
, m_skipLanguageDefines(skipLanguageDefines)
|
, m_skipLanguageDefines(skipLanguageDefines)
|
||||||
|
, m_clangVersion(clangVersion)
|
||||||
|
, m_clangResourceDirectory(clangResourceDirectory)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList CompilerOptionsBuilder::build(CppTools::ProjectFile::Kind fileKind, PchUsage pchUsage)
|
QStringList CompilerOptionsBuilder::build(ProjectFile::Kind fileKind,
|
||||||
|
UsePrecompiledHeaders usePrecompiledHeaders)
|
||||||
{
|
{
|
||||||
m_options.clear();
|
m_options.clear();
|
||||||
|
|
||||||
@@ -87,7 +118,7 @@ QStringList CompilerOptionsBuilder::build(CppTools::ProjectFile::Kind fileKind,
|
|||||||
addBoostWorkaroundMacros();
|
addBoostWorkaroundMacros();
|
||||||
|
|
||||||
addToolchainFlags();
|
addToolchainFlags();
|
||||||
addPrecompiledHeaderOptions(pchUsage);
|
addPrecompiledHeaderOptions(usePrecompiledHeaders);
|
||||||
addHeaderPathOptions();
|
addHeaderPathOptions();
|
||||||
addProjectConfigFileInclude();
|
addProjectConfigFileInclude();
|
||||||
|
|
||||||
@@ -102,7 +133,7 @@ QStringList CompilerOptionsBuilder::build(CppTools::ProjectFile::Kind fileKind,
|
|||||||
|
|
||||||
static QStringList createLanguageOptionGcc(ProjectFile::Kind fileKind, bool objcExt)
|
static QStringList createLanguageOptionGcc(ProjectFile::Kind fileKind, bool objcExt)
|
||||||
{
|
{
|
||||||
QStringList opts;
|
QStringList options;
|
||||||
|
|
||||||
switch (fileKind) {
|
switch (fileKind) {
|
||||||
case ProjectFile::Unclassified:
|
case ProjectFile::Unclassified:
|
||||||
@@ -110,80 +141,67 @@ static QStringList createLanguageOptionGcc(ProjectFile::Kind fileKind, bool objc
|
|||||||
break;
|
break;
|
||||||
case ProjectFile::CHeader:
|
case ProjectFile::CHeader:
|
||||||
if (objcExt)
|
if (objcExt)
|
||||||
opts += QLatin1String("objective-c-header");
|
options += "objective-c-header";
|
||||||
else
|
else
|
||||||
opts += QLatin1String("c-header");
|
options += "c-header";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ProjectFile::CXXHeader:
|
case ProjectFile::CXXHeader:
|
||||||
default:
|
default:
|
||||||
if (!objcExt) {
|
if (!objcExt) {
|
||||||
opts += QLatin1String("c++-header");
|
options += "c++-header";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Q_FALLTHROUGH();
|
Q_FALLTHROUGH();
|
||||||
case ProjectFile::ObjCHeader:
|
case ProjectFile::ObjCHeader:
|
||||||
case ProjectFile::ObjCXXHeader:
|
case ProjectFile::ObjCXXHeader:
|
||||||
opts += QLatin1String("objective-c++-header");
|
options += "objective-c++-header";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ProjectFile::CSource:
|
case ProjectFile::CSource:
|
||||||
if (!objcExt) {
|
if (!objcExt) {
|
||||||
opts += QLatin1String("c");
|
options += "c";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Q_FALLTHROUGH();
|
Q_FALLTHROUGH();
|
||||||
case ProjectFile::ObjCSource:
|
case ProjectFile::ObjCSource:
|
||||||
opts += QLatin1String("objective-c");
|
options += "objective-c";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ProjectFile::CXXSource:
|
case ProjectFile::CXXSource:
|
||||||
if (!objcExt) {
|
if (!objcExt) {
|
||||||
opts += QLatin1String("c++");
|
options += "c++";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Q_FALLTHROUGH();
|
Q_FALLTHROUGH();
|
||||||
case ProjectFile::ObjCXXSource:
|
case ProjectFile::ObjCXXSource:
|
||||||
opts += QLatin1String("objective-c++");
|
options += "objective-c++";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ProjectFile::OpenCLSource:
|
case ProjectFile::OpenCLSource:
|
||||||
opts += QLatin1String("cl");
|
options += "cl";
|
||||||
break;
|
break;
|
||||||
case ProjectFile::CudaSource:
|
case ProjectFile::CudaSource:
|
||||||
opts += QLatin1String("cuda");
|
options += "cuda";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts.isEmpty())
|
if (!options.isEmpty())
|
||||||
opts.prepend(QLatin1String("-x"));
|
options.prepend("-x");
|
||||||
|
|
||||||
return opts;
|
return options;
|
||||||
}
|
|
||||||
|
|
||||||
QStringList CompilerOptionsBuilder::options() const
|
|
||||||
{
|
|
||||||
return m_options;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CompilerOptionsBuilder::add(const QString &option)
|
|
||||||
{
|
|
||||||
m_options.append(option);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addWordWidth()
|
void CompilerOptionsBuilder::addWordWidth()
|
||||||
{
|
{
|
||||||
const QString argument = m_projectPart.toolChainWordWidth == ProjectPart::WordWidth64Bit
|
const QString argument = m_projectPart.toolChainWordWidth == ProjectPart::WordWidth64Bit
|
||||||
? QLatin1String("-m64")
|
? "-m64"
|
||||||
: QLatin1String("-m32");
|
: "-m32";
|
||||||
add(argument);
|
add(argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addTargetTriple()
|
void CompilerOptionsBuilder::addTargetTriple()
|
||||||
{
|
{
|
||||||
if (!m_projectPart.toolChainTargetTriple.isEmpty()) {
|
if (!m_projectPart.toolChainTargetTriple.isEmpty()) {
|
||||||
m_options.append(QLatin1String("-target"));
|
add("-target");
|
||||||
m_options.append(m_projectPart.toolChainTargetTriple);
|
add(m_projectPart.toolChainTargetTriple);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,8 +216,8 @@ void CompilerOptionsBuilder::addExtraCodeModelFlags()
|
|||||||
void CompilerOptionsBuilder::enableExceptions()
|
void CompilerOptionsBuilder::enableExceptions()
|
||||||
{
|
{
|
||||||
if (m_projectPart.languageVersion > ProjectExplorer::LanguageVersion::LatestC)
|
if (m_projectPart.languageVersion > ProjectExplorer::LanguageVersion::LatestC)
|
||||||
add(QLatin1String("-fcxx-exceptions"));
|
add("-fcxx-exceptions");
|
||||||
add(QLatin1String("-fexceptions"));
|
add("-fexceptions");
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString creatorResourcePath()
|
static QString creatorResourcePath()
|
||||||
@@ -217,6 +235,8 @@ static QString clangIncludeDirectory(const QString &clangVersion,
|
|||||||
#ifndef UNIT_TESTS
|
#ifndef UNIT_TESTS
|
||||||
return Core::ICore::clangIncludeDirectory(clangVersion, clangResourceDirectory);
|
return Core::ICore::clangIncludeDirectory(clangVersion, clangResourceDirectory);
|
||||||
#else
|
#else
|
||||||
|
Q_UNUSED(clangVersion);
|
||||||
|
Q_UNUSED(clangResourceDirectory);
|
||||||
return QDir::toNativeSeparators(QString::fromUtf8(CLANG_RESOURCE_DIR ""));
|
return QDir::toNativeSeparators(QString::fromUtf8(CLANG_RESOURCE_DIR ""));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -225,8 +245,10 @@ static int lastIncludeIndex(const QStringList &options, const QRegularExpression
|
|||||||
{
|
{
|
||||||
int index = options.lastIndexOf(includePathRegEx);
|
int index = options.lastIndexOf(includePathRegEx);
|
||||||
|
|
||||||
while (index > 0 && options[index - 1] != "-I" && options[index - 1] != "-isystem")
|
while (index > 0 && options[index - 1] != includeUserPathOption
|
||||||
|
&& options[index - 1] != includeSystemPathOption) {
|
||||||
index = options.lastIndexOf(includePathRegEx, index - 1);
|
index = options.lastIndexOf(includePathRegEx, index - 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
index = -1;
|
index = -1;
|
||||||
@@ -246,9 +268,8 @@ static int includeIndexForResourceDirectory(const QStringList &options, bool isM
|
|||||||
static const QRegularExpression includeRegExpMac(
|
static const QRegularExpression includeRegExpMac(
|
||||||
"\\A(" + cppIncludes + R"(|([\/\\]usr[\/\\]local[\/\\]include))" + ")\\z");
|
"\\A(" + cppIncludes + R"(|([\/\\]usr[\/\\]local[\/\\]include))" + ")\\z");
|
||||||
|
|
||||||
const int cppIncludeIndex = lastIncludeIndex(options, isMacOs
|
const int cppIncludeIndex = lastIncludeIndex(options,
|
||||||
? includeRegExpMac
|
isMacOs ? includeRegExpMac : includeRegExp);
|
||||||
: includeRegExp);
|
|
||||||
|
|
||||||
if (cppIncludeIndex > 0)
|
if (cppIncludeIndex > 0)
|
||||||
return cppIncludeIndex + 1;
|
return cppIncludeIndex + 1;
|
||||||
@@ -271,6 +292,17 @@ void CompilerOptionsBuilder::insertWrappedQtHeaders()
|
|||||||
m_options = m_options.mid(0, index) + wrappedQtHeaders + m_options.mid(index);
|
m_options = m_options.mid(0, index) + wrappedQtHeaders + m_options.mid(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool excludeHeaderPath(const QString &headerPath)
|
||||||
|
{
|
||||||
|
// Always exclude clang system includes (including intrinsics) which do not come with libclang
|
||||||
|
// that Qt Creator uses for code model.
|
||||||
|
// For example GCC on macOS uses system clang include path which makes clang code model
|
||||||
|
// include incorrect system headers.
|
||||||
|
static const QRegularExpression clangIncludeDir(
|
||||||
|
R"(\A.*[\/\\]lib\d*[\/\\]clang[\/\\]\d+\.\d+(\.\d+)?[\/\\]include\z)");
|
||||||
|
return clangIncludeDir.match(headerPath).hasMatch();
|
||||||
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addHeaderPathOptions()
|
void CompilerOptionsBuilder::addHeaderPathOptions()
|
||||||
{
|
{
|
||||||
using ProjectExplorer::HeaderPathType;
|
using ProjectExplorer::HeaderPathType;
|
||||||
@@ -291,20 +323,18 @@ void CompilerOptionsBuilder::addHeaderPathOptions()
|
|||||||
includes.append("-F");
|
includes.append("-F");
|
||||||
includes.append(QDir::toNativeSeparators(headerPath.path));
|
includes.append(QDir::toNativeSeparators(headerPath.path));
|
||||||
break;
|
break;
|
||||||
default: // This shouldn't happen, but let's be nice..:
|
|
||||||
// intentional fall-through:
|
|
||||||
case HeaderPathType::User:
|
case HeaderPathType::User:
|
||||||
includes.append(includeDirOptionForPath(headerPath.path));
|
includes.append(includeDirOptionForPath(headerPath.path));
|
||||||
includes.append(QDir::toNativeSeparators(headerPath.path));
|
includes.append(QDir::toNativeSeparators(headerPath.path));
|
||||||
break;
|
break;
|
||||||
case HeaderPathType::BuiltIn:
|
case HeaderPathType::BuiltIn:
|
||||||
builtInIncludes.append("-isystem");
|
builtInIncludes.append(includeSystemPathOption);
|
||||||
builtInIncludes.append(QDir::toNativeSeparators(headerPath.path));
|
builtInIncludes.append(QDir::toNativeSeparators(headerPath.path));
|
||||||
break;
|
break;
|
||||||
case HeaderPathType::System:
|
case HeaderPathType::System:
|
||||||
systemIncludes.append(m_useSystemHeader == UseSystemHeader::No
|
systemIncludes.append(m_useSystemHeader == UseSystemHeader::Yes
|
||||||
? QLatin1String("-I")
|
? QLatin1String(includeSystemPathOption)
|
||||||
: QLatin1String("-isystem"));
|
: QLatin1String(includeUserPathOption));
|
||||||
systemIncludes.append(QDir::toNativeSeparators(headerPath.path));
|
systemIncludes.append(QDir::toNativeSeparators(headerPath.path));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -323,39 +353,40 @@ void CompilerOptionsBuilder::addHeaderPathOptions()
|
|||||||
// Exclude all built-in includes and Clang resource directory.
|
// Exclude all built-in includes and Clang resource directory.
|
||||||
m_options.prepend("-nostdinc");
|
m_options.prepend("-nostdinc");
|
||||||
|
|
||||||
const QString clangIncludePath
|
const QString clangIncludePath = clangIncludeDirectory(m_clangVersion,
|
||||||
= clangIncludeDirectory(m_clangVersion, m_clangResourceDirectory);
|
m_clangResourceDirectory);
|
||||||
int includeIndexForResourceDir = includeIndexForResourceDirectory(
|
const int includeIndexForResourceDir
|
||||||
builtInIncludes, m_projectPart.toolChainTargetTriple.contains("darwin"));
|
= includeIndexForResourceDirectory(builtInIncludes,
|
||||||
|
m_projectPart.toolChainTargetTriple.contains(
|
||||||
|
"darwin"));
|
||||||
|
|
||||||
if (includeIndexForResourceDir >= 0) {
|
if (includeIndexForResourceDir >= 0) {
|
||||||
builtInIncludes.insert(includeIndexForResourceDir, clangIncludePath);
|
builtInIncludes.insert(includeIndexForResourceDir, clangIncludePath);
|
||||||
builtInIncludes.insert(includeIndexForResourceDir, "-isystem");
|
builtInIncludes.insert(includeIndexForResourceDir, includeSystemPathOption);
|
||||||
} else {
|
} else {
|
||||||
builtInIncludes.prepend(clangIncludePath);
|
builtInIncludes.prepend(clangIncludePath);
|
||||||
builtInIncludes.prepend("-isystem");
|
builtInIncludes.prepend(includeSystemPathOption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_options.append(builtInIncludes);
|
m_options.append(builtInIncludes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addPrecompiledHeaderOptions(PchUsage pchUsage)
|
void CompilerOptionsBuilder::addPrecompiledHeaderOptions(UsePrecompiledHeaders usePrecompiledHeaders)
|
||||||
{
|
{
|
||||||
if (pchUsage == PchUsage::None)
|
if (usePrecompiledHeaders == UsePrecompiledHeaders::No)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QStringList result;
|
QStringList options;
|
||||||
|
|
||||||
const QString includeOptionString = includeOption();
|
for (const QString &pchFile : m_projectPart.precompiledHeaders) {
|
||||||
foreach (const QString &pchFile, m_projectPart.precompiledHeaders) {
|
|
||||||
if (QFile::exists(pchFile)) {
|
if (QFile::exists(pchFile)) {
|
||||||
result += includeOptionString;
|
options += includeFileOption;
|
||||||
result += QDir::toNativeSeparators(pchFile);
|
options += QDir::toNativeSeparators(pchFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_options.append(result);
|
m_options.append(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addToolchainAndProjectMacros()
|
void CompilerOptionsBuilder::addToolchainAndProjectMacros()
|
||||||
@@ -367,18 +398,18 @@ void CompilerOptionsBuilder::addToolchainAndProjectMacros()
|
|||||||
|
|
||||||
void CompilerOptionsBuilder::addMacros(const ProjectExplorer::Macros ¯os)
|
void CompilerOptionsBuilder::addMacros(const ProjectExplorer::Macros ¯os)
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList options;
|
||||||
|
|
||||||
for (const ProjectExplorer::Macro ¯o : macros) {
|
for (const ProjectExplorer::Macro ¯o : macros) {
|
||||||
if (excludeDefineDirective(macro))
|
if (excludeDefineDirective(macro))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const QString defineOption = defineDirectiveToDefineOption(macro);
|
const QString defineOption = defineDirectiveToDefineOption(macro);
|
||||||
if (!result.contains(defineOption))
|
if (!options.contains(defineOption))
|
||||||
result.append(defineOption);
|
options.append(defineOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_options.append(result);
|
m_options.append(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::updateLanguageOption(ProjectFile::Kind fileKind)
|
void CompilerOptionsBuilder::updateLanguageOption(ProjectFile::Kind fileKind)
|
||||||
@@ -391,11 +422,10 @@ void CompilerOptionsBuilder::updateLanguageOption(ProjectFile::Kind fileKind)
|
|||||||
|
|
||||||
QTC_ASSERT(options.size() == 2, return;);
|
QTC_ASSERT(options.size() == 2, return;);
|
||||||
int langOptIndex = m_options.indexOf("-x");
|
int langOptIndex = m_options.indexOf("-x");
|
||||||
if (langOptIndex == -1) {
|
if (langOptIndex == -1)
|
||||||
m_options.append(options);
|
m_options.append(options);
|
||||||
} else {
|
else
|
||||||
m_options[langOptIndex + 1] = options[1];
|
m_options[langOptIndex + 1] = options[1];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addOptionsForLanguage(bool checkForBorlandExtensions)
|
void CompilerOptionsBuilder::addOptionsForLanguage(bool checkForBorlandExtensions)
|
||||||
@@ -403,54 +433,54 @@ void CompilerOptionsBuilder::addOptionsForLanguage(bool checkForBorlandExtension
|
|||||||
using ProjectExplorer::LanguageExtension;
|
using ProjectExplorer::LanguageExtension;
|
||||||
using ProjectExplorer::LanguageVersion;
|
using ProjectExplorer::LanguageVersion;
|
||||||
|
|
||||||
QStringList opts;
|
QStringList options;
|
||||||
const ProjectExplorer::LanguageExtensions languageExtensions = m_projectPart.languageExtensions;
|
const ProjectExplorer::LanguageExtensions languageExtensions = m_projectPart.languageExtensions;
|
||||||
const bool gnuExtensions = languageExtensions & LanguageExtension::Gnu;
|
const bool gnuExtensions = languageExtensions & LanguageExtension::Gnu;
|
||||||
|
|
||||||
switch (m_projectPart.languageVersion) {
|
switch (m_projectPart.languageVersion) {
|
||||||
case LanguageVersion::C89:
|
case LanguageVersion::C89:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu89") : QLatin1String("-std=c89"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu89") : QLatin1String("-std=c89"));
|
||||||
break;
|
break;
|
||||||
case LanguageVersion::C99:
|
case LanguageVersion::C99:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu99") : QLatin1String("-std=c99"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu99") : QLatin1String("-std=c99"));
|
||||||
break;
|
break;
|
||||||
case LanguageVersion::C11:
|
case LanguageVersion::C11:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu11") : QLatin1String("-std=c11"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu11") : QLatin1String("-std=c11"));
|
||||||
break;
|
break;
|
||||||
case LanguageVersion::C18:
|
case LanguageVersion::C18:
|
||||||
// Clang 6, 7 and current trunk do not accept "gnu18"/"c18", so use the "*17" variants.
|
// Clang 6, 7 and current trunk do not accept "gnu18"/"c18", so use the "*17" variants.
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu17") : QLatin1String("-std=c17"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu17") : QLatin1String("-std=c17"));
|
||||||
break;
|
break;
|
||||||
case LanguageVersion::CXX11:
|
case LanguageVersion::CXX11:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu++11") : QLatin1String("-std=c++11"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu++11") : QLatin1String("-std=c++11"));
|
||||||
break;
|
break;
|
||||||
case LanguageVersion::CXX98:
|
case LanguageVersion::CXX98:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu++98") : QLatin1String("-std=c++98"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu++98") : QLatin1String("-std=c++98"));
|
||||||
break;
|
break;
|
||||||
case LanguageVersion::CXX03:
|
case LanguageVersion::CXX03:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu++03") : QLatin1String("-std=c++03"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu++03") : QLatin1String("-std=c++03"));
|
||||||
break;
|
break;
|
||||||
case LanguageVersion::CXX14:
|
case LanguageVersion::CXX14:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu++14") : QLatin1String("-std=c++14"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu++14") : QLatin1String("-std=c++14"));
|
||||||
break;
|
break;
|
||||||
case LanguageVersion::CXX17:
|
case LanguageVersion::CXX17:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu++17") : QLatin1String("-std=c++17"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu++17") : QLatin1String("-std=c++17"));
|
||||||
break;
|
break;
|
||||||
case LanguageVersion::CXX2a:
|
case LanguageVersion::CXX2a:
|
||||||
opts << (gnuExtensions ? QLatin1String("-std=gnu++2a") : QLatin1String("-std=c++2a"));
|
options << (gnuExtensions ? QLatin1String("-std=gnu++2a") : QLatin1String("-std=c++2a"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (languageExtensions & LanguageExtension::Microsoft)
|
if (languageExtensions & LanguageExtension::Microsoft)
|
||||||
opts << QLatin1String("-fms-extensions");
|
options << "-fms-extensions";
|
||||||
|
|
||||||
if (languageExtensions & LanguageExtension::OpenMP)
|
if (languageExtensions & LanguageExtension::OpenMP)
|
||||||
opts << QLatin1String("-fopenmp");
|
options << "-fopenmp";
|
||||||
|
|
||||||
if (checkForBorlandExtensions && (languageExtensions & LanguageExtension::Borland))
|
if (checkForBorlandExtensions && (languageExtensions & LanguageExtension::Borland))
|
||||||
opts << QLatin1String("-fborland-extensions");
|
options << "-fborland-extensions";
|
||||||
|
|
||||||
m_options.append(opts);
|
m_options.append(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray toMsCompatibilityVersionFormat(const QByteArray &mscFullVer)
|
static QByteArray toMsCompatibilityVersionFormat(const QByteArray &mscFullVer)
|
||||||
@@ -473,14 +503,12 @@ static QByteArray msCompatibilityVersionFromDefines(const ProjectExplorer::Macro
|
|||||||
void CompilerOptionsBuilder::addMsvcCompatibilityVersion()
|
void CompilerOptionsBuilder::addMsvcCompatibilityVersion()
|
||||||
{
|
{
|
||||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
||||||
const ProjectExplorer::Macros macros = m_projectPart.toolChainMacros + m_projectPart.projectMacros;
|
const ProjectExplorer::Macros macros = m_projectPart.toolChainMacros
|
||||||
|
+ m_projectPart.projectMacros;
|
||||||
const QByteArray msvcVersion = msCompatibilityVersionFromDefines(macros);
|
const QByteArray msvcVersion = msCompatibilityVersionFromDefines(macros);
|
||||||
|
|
||||||
if (!msvcVersion.isEmpty()) {
|
if (!msvcVersion.isEmpty())
|
||||||
const QString option = QLatin1String("-fms-compatibility-version=")
|
add(QLatin1String("-fms-compatibility-version=") + msvcVersion);
|
||||||
+ QLatin1String(msvcVersion);
|
|
||||||
m_options.append(option);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,54 +519,54 @@ static QStringList languageFeatureMacros()
|
|||||||
// * Use latest -fms-compatibility-version and -std possible.
|
// * Use latest -fms-compatibility-version and -std possible.
|
||||||
// * Compatibility version 19 vs 1910 did not matter.
|
// * Compatibility version 19 vs 1910 did not matter.
|
||||||
// $ clang++ -fms-compatibility-version=19 -std=c++1z -dM -E D:\empty.cpp | grep __cpp_
|
// $ clang++ -fms-compatibility-version=19 -std=c++1z -dM -E D:\empty.cpp | grep __cpp_
|
||||||
static QStringList macros{
|
static const QStringList macros{
|
||||||
QLatin1String("__cpp_aggregate_bases"),
|
"__cpp_aggregate_bases",
|
||||||
QLatin1String("__cpp_aggregate_nsdmi"),
|
"__cpp_aggregate_nsdmi",
|
||||||
QLatin1String("__cpp_alias_templates"),
|
"__cpp_alias_templates",
|
||||||
QLatin1String("__cpp_aligned_new"),
|
"__cpp_aligned_new",
|
||||||
QLatin1String("__cpp_attributes"),
|
"__cpp_attributes",
|
||||||
QLatin1String("__cpp_binary_literals"),
|
"__cpp_binary_literals",
|
||||||
QLatin1String("__cpp_capture_star_this"),
|
"__cpp_capture_star_this",
|
||||||
QLatin1String("__cpp_constexpr"),
|
"__cpp_constexpr",
|
||||||
QLatin1String("__cpp_decltype"),
|
"__cpp_decltype",
|
||||||
QLatin1String("__cpp_decltype_auto"),
|
"__cpp_decltype_auto",
|
||||||
QLatin1String("__cpp_deduction_guides"),
|
"__cpp_deduction_guides",
|
||||||
QLatin1String("__cpp_delegating_constructors"),
|
"__cpp_delegating_constructors",
|
||||||
QLatin1String("__cpp_digit_separators"),
|
"__cpp_digit_separators",
|
||||||
QLatin1String("__cpp_enumerator_attributes"),
|
"__cpp_enumerator_attributes",
|
||||||
QLatin1String("__cpp_exceptions"),
|
"__cpp_exceptions",
|
||||||
QLatin1String("__cpp_fold_expressions"),
|
"__cpp_fold_expressions",
|
||||||
QLatin1String("__cpp_generic_lambdas"),
|
"__cpp_generic_lambdas",
|
||||||
QLatin1String("__cpp_guaranteed_copy_elision"),
|
"__cpp_guaranteed_copy_elision",
|
||||||
QLatin1String("__cpp_hex_float"),
|
"__cpp_hex_float",
|
||||||
QLatin1String("__cpp_if_constexpr"),
|
"__cpp_if_constexpr",
|
||||||
QLatin1String("__cpp_inheriting_constructors"),
|
"__cpp_inheriting_constructors",
|
||||||
QLatin1String("__cpp_init_captures"),
|
"__cpp_init_captures",
|
||||||
QLatin1String("__cpp_initializer_lists"),
|
"__cpp_initializer_lists",
|
||||||
QLatin1String("__cpp_inline_variables"),
|
"__cpp_inline_variables",
|
||||||
QLatin1String("__cpp_lambdas"),
|
"__cpp_lambdas",
|
||||||
QLatin1String("__cpp_namespace_attributes"),
|
"__cpp_namespace_attributes",
|
||||||
QLatin1String("__cpp_nested_namespace_definitions"),
|
"__cpp_nested_namespace_definitions",
|
||||||
QLatin1String("__cpp_noexcept_function_type"),
|
"__cpp_noexcept_function_type",
|
||||||
QLatin1String("__cpp_nontype_template_args"),
|
"__cpp_nontype_template_args",
|
||||||
QLatin1String("__cpp_nontype_template_parameter_auto"),
|
"__cpp_nontype_template_parameter_auto",
|
||||||
QLatin1String("__cpp_nsdmi"),
|
"__cpp_nsdmi",
|
||||||
QLatin1String("__cpp_range_based_for"),
|
"__cpp_range_based_for",
|
||||||
QLatin1String("__cpp_raw_strings"),
|
"__cpp_raw_strings",
|
||||||
QLatin1String("__cpp_ref_qualifiers"),
|
"__cpp_ref_qualifiers",
|
||||||
QLatin1String("__cpp_return_type_deduction"),
|
"__cpp_return_type_deduction",
|
||||||
QLatin1String("__cpp_rtti"),
|
"__cpp_rtti",
|
||||||
QLatin1String("__cpp_rvalue_references"),
|
"__cpp_rvalue_references",
|
||||||
QLatin1String("__cpp_static_assert"),
|
"__cpp_static_assert",
|
||||||
QLatin1String("__cpp_structured_bindings"),
|
"__cpp_structured_bindings",
|
||||||
QLatin1String("__cpp_template_auto"),
|
"__cpp_template_auto",
|
||||||
QLatin1String("__cpp_threadsafe_static_init"),
|
"__cpp_threadsafe_static_init",
|
||||||
QLatin1String("__cpp_unicode_characters"),
|
"__cpp_unicode_characters",
|
||||||
QLatin1String("__cpp_unicode_literals"),
|
"__cpp_unicode_literals",
|
||||||
QLatin1String("__cpp_user_defined_literals"),
|
"__cpp_user_defined_literals",
|
||||||
QLatin1String("__cpp_variable_templates"),
|
"__cpp_variable_templates",
|
||||||
QLatin1String("__cpp_variadic_templates"),
|
"__cpp_variadic_templates",
|
||||||
QLatin1String("__cpp_variadic_using"),
|
"__cpp_variadic_using",
|
||||||
};
|
};
|
||||||
|
|
||||||
return macros;
|
return macros;
|
||||||
@@ -550,15 +578,19 @@ void CompilerOptionsBuilder::undefineCppLanguageFeatureMacrosForMsvc2015()
|
|||||||
&& m_projectPart.isMsvc2015Toolchain) {
|
&& m_projectPart.isMsvc2015Toolchain) {
|
||||||
// Undefine the language feature macros that are pre-defined in clang-cl,
|
// Undefine the language feature macros that are pre-defined in clang-cl,
|
||||||
// but not in MSVC's cl.exe.
|
// but not in MSVC's cl.exe.
|
||||||
foreach (const QString ¯oName, languageFeatureMacros())
|
const QStringList macroNames = languageFeatureMacros();
|
||||||
m_options.append(undefineOption() + macroName);
|
for (const QString ¯oName : macroNames)
|
||||||
|
add(undefineOption + macroName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addDefineFunctionMacrosMsvc()
|
void CompilerOptionsBuilder::addDefineFunctionMacrosMsvc()
|
||||||
{
|
{
|
||||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
|
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
||||||
addMacros({{"__FUNCSIG__", "\"\""}, {"__FUNCTION__", "\"\""}, {"__FUNCDNAME__", "\"\""}});
|
addMacros({{"__FUNCSIG__", "\"\""},
|
||||||
|
{"__FUNCTION__", "\"\""},
|
||||||
|
{"__FUNCDNAME__", "\"\""}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addBoostWorkaroundMacros()
|
void CompilerOptionsBuilder::addBoostWorkaroundMacros()
|
||||||
@@ -573,46 +605,10 @@ QString CompilerOptionsBuilder::includeDirOptionForPath(const QString &path) con
|
|||||||
{
|
{
|
||||||
if (m_useSystemHeader == UseSystemHeader::No
|
if (m_useSystemHeader == UseSystemHeader::No
|
||||||
|| path.startsWith(m_projectPart.project->rootProjectDirectory().toString())) {
|
|| path.startsWith(m_projectPart.project->rootProjectDirectory().toString())) {
|
||||||
return QString("-I");
|
return includeUserPathOption;
|
||||||
} else {
|
|
||||||
return QString("-isystem");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray CompilerOptionsBuilder::macroOption(const ProjectExplorer::Macro ¯o) const
|
return includeSystemPathOption;
|
||||||
{
|
|
||||||
switch (macro.type) {
|
|
||||||
case ProjectExplorer::MacroType::Define: return defineOption().toUtf8();
|
|
||||||
case ProjectExplorer::MacroType::Undefine: return undefineOption().toUtf8();
|
|
||||||
default: return QByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray CompilerOptionsBuilder::toDefineOption(const ProjectExplorer::Macro ¯o) const
|
|
||||||
{
|
|
||||||
return macro.toKeyValue(macroOption(macro));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CompilerOptionsBuilder::defineDirectiveToDefineOption(const ProjectExplorer::Macro ¯o) const
|
|
||||||
{
|
|
||||||
const QByteArray option = toDefineOption(macro);
|
|
||||||
|
|
||||||
return QString::fromUtf8(option);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CompilerOptionsBuilder::defineOption() const
|
|
||||||
{
|
|
||||||
return QLatin1String("-D");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CompilerOptionsBuilder::undefineOption() const
|
|
||||||
{
|
|
||||||
return QLatin1String("-U");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CompilerOptionsBuilder::includeOption() const
|
|
||||||
{
|
|
||||||
return QLatin1String("-include");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro ¯o) const
|
bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro ¯o) const
|
||||||
@@ -657,24 +653,13 @@ bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompilerOptionsBuilder::excludeHeaderPath(const QString &headerPath) const
|
void CompilerOptionsBuilder::addWrappedQtHeadersIncludePath(QStringList &list) const
|
||||||
{
|
|
||||||
// Always exclude clang system includes (including intrinsics) which do not come with libclang
|
|
||||||
// that Qt Creator uses for code model.
|
|
||||||
// For example GCC on macOS uses system clang include path which makes clang code model
|
|
||||||
// include incorrect system headers.
|
|
||||||
static QRegularExpression clangIncludeDir(
|
|
||||||
QLatin1String("\\A.*[\\/\\\\]lib\\d*[\\/\\\\]clang[\\/\\\\]\\d+\\.\\d+(\\.\\d+)?[\\/\\\\]include\\z"));
|
|
||||||
return clangIncludeDir.match(headerPath).hasMatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addWrappedQtHeadersIncludePath(QStringList &list)
|
|
||||||
{
|
{
|
||||||
static const QString resourcePath = creatorResourcePath();
|
static const QString resourcePath = creatorResourcePath();
|
||||||
static QString wrappedQtHeadersPath = resourcePath + "/cplusplus/wrappedQtHeaders";
|
static QString wrappedQtHeadersPath = resourcePath + "/cplusplus/wrappedQtHeaders";
|
||||||
QTC_ASSERT(QDir(wrappedQtHeadersPath).exists(), return;);
|
QTC_ASSERT(QDir(wrappedQtHeadersPath).exists(), return;);
|
||||||
|
|
||||||
if (m_projectPart.qtVersion != CppTools::ProjectPart::NoQt) {
|
if (m_projectPart.qtVersion != ProjectPart::NoQt) {
|
||||||
const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + "/QtCore";
|
const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + "/QtCore";
|
||||||
list.append(includeDirOptionForPath(wrappedQtHeadersPath));
|
list.append(includeDirOptionForPath(wrappedQtHeadersPath));
|
||||||
list.append(QDir::toNativeSeparators(wrappedQtHeadersPath));
|
list.append(QDir::toNativeSeparators(wrappedQtHeadersPath));
|
||||||
@@ -698,7 +683,7 @@ void CompilerOptionsBuilder::addToolchainFlags()
|
|||||||
void CompilerOptionsBuilder::addProjectConfigFileInclude()
|
void CompilerOptionsBuilder::addProjectConfigFileInclude()
|
||||||
{
|
{
|
||||||
if (!m_projectPart.projectConfigFile.isEmpty()) {
|
if (!m_projectPart.projectConfigFile.isEmpty()) {
|
||||||
add("-include");
|
add(includeFileOption);
|
||||||
add(QDir::toNativeSeparators(m_projectPart.projectConfigFile));
|
add(QDir::toNativeSeparators(m_projectPart.projectConfigFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -706,7 +691,7 @@ void CompilerOptionsBuilder::addProjectConfigFileInclude()
|
|||||||
void CompilerOptionsBuilder::undefineClangVersionMacrosForMsvc()
|
void CompilerOptionsBuilder::undefineClangVersionMacrosForMsvc()
|
||||||
{
|
{
|
||||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
||||||
static QStringList macroNames {
|
static const QStringList macroNames {
|
||||||
"__clang__",
|
"__clang__",
|
||||||
"__clang_major__",
|
"__clang_major__",
|
||||||
"__clang_minor__",
|
"__clang_minor__",
|
||||||
@@ -714,8 +699,8 @@ void CompilerOptionsBuilder::undefineClangVersionMacrosForMsvc()
|
|||||||
"__clang_version__"
|
"__clang_version__"
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (const QString ¯oName, macroNames)
|
for (const QString ¯oName : macroNames)
|
||||||
add(undefineOption() + macroName);
|
add(undefineOption + macroName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,50 +31,30 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
enum class UseSystemHeader : char
|
enum class UsePrecompiledHeaders : char { Yes, No };
|
||||||
{
|
enum class UseSystemHeader : char { Yes, No };
|
||||||
Yes,
|
enum class SkipBuiltIn : char { Yes, No };
|
||||||
No
|
enum class SkipLanguageDefines : char { Yes, No };
|
||||||
};
|
|
||||||
|
|
||||||
enum class SkipBuiltIn : char
|
|
||||||
{
|
|
||||||
Yes,
|
|
||||||
No
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SkipLanguageDefines : char
|
|
||||||
{
|
|
||||||
Yes,
|
|
||||||
No
|
|
||||||
};
|
|
||||||
|
|
||||||
class CPPTOOLS_EXPORT CompilerOptionsBuilder
|
class CPPTOOLS_EXPORT CompilerOptionsBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class PchUsage {
|
|
||||||
None,
|
|
||||||
Use
|
|
||||||
};
|
|
||||||
|
|
||||||
CompilerOptionsBuilder(const ProjectPart &projectPart,
|
CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||||
UseSystemHeader useSystemHeader = UseSystemHeader::No,
|
UseSystemHeader useSystemHeader = UseSystemHeader::No,
|
||||||
SkipBuiltIn skipBuiltInHeaderPathsAndDefines = SkipBuiltIn::No,
|
SkipBuiltIn skipBuiltInHeaderPathsAndDefines = SkipBuiltIn::No,
|
||||||
SkipLanguageDefines skipLanguageDefines = SkipLanguageDefines::Yes,
|
SkipLanguageDefines skipLanguageDefines = SkipLanguageDefines::Yes,
|
||||||
QString clangVersion = QString(),
|
const QString &clangVersion = QString(),
|
||||||
QString clangResourceDirectory = QString());
|
const QString &clangResourceDirectory = QString());
|
||||||
|
|
||||||
QStringList build(ProjectFile::Kind fileKind,
|
QStringList build(ProjectFile::Kind fileKind, UsePrecompiledHeaders usePrecompiledHeaders);
|
||||||
PchUsage pchUsage);
|
QStringList options() const { return m_options; }
|
||||||
QStringList options() const;
|
|
||||||
|
|
||||||
virtual void addExtraOptions() {}
|
|
||||||
// Add options based on project part
|
// Add options based on project part
|
||||||
virtual void addToolchainAndProjectMacros();
|
virtual void addToolchainAndProjectMacros();
|
||||||
void addWordWidth();
|
void addWordWidth();
|
||||||
void addToolchainFlags();
|
void addToolchainFlags();
|
||||||
void addHeaderPathOptions();
|
void addHeaderPathOptions();
|
||||||
void addPrecompiledHeaderOptions(PchUsage pchUsage);
|
void addPrecompiledHeaderOptions(UsePrecompiledHeaders usePrecompiledHeaders);
|
||||||
void addMacros(const ProjectExplorer::Macros ¯os);
|
void addMacros(const ProjectExplorer::Macros ¯os);
|
||||||
|
|
||||||
void addTargetTriple();
|
void addTargetTriple();
|
||||||
@@ -92,36 +72,26 @@ public:
|
|||||||
void addProjectConfigFileInclude();
|
void addProjectConfigFileInclude();
|
||||||
void undefineClangVersionMacrosForMsvc();
|
void undefineClangVersionMacrosForMsvc();
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual bool excludeDefineDirective(const ProjectExplorer::Macro ¯o) const;
|
|
||||||
virtual bool excludeHeaderPath(const QString &headerPath) const;
|
|
||||||
|
|
||||||
virtual QString defineOption() const;
|
|
||||||
virtual QString undefineOption() const;
|
|
||||||
virtual QString includeOption() const;
|
|
||||||
|
|
||||||
// Add custom options
|
// Add custom options
|
||||||
void add(const QString &option);
|
void add(const QString &option) { m_options.append(option); }
|
||||||
|
virtual void addExtraOptions() {}
|
||||||
QString includeDirOptionForPath(const QString &path) const;
|
|
||||||
|
|
||||||
const ProjectPart &m_projectPart;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray macroOption(const ProjectExplorer::Macro ¯o) const;
|
bool excludeDefineDirective(const ProjectExplorer::Macro ¯o) const;
|
||||||
QByteArray toDefineOption(const ProjectExplorer::Macro ¯o) const;
|
QString includeDirOptionForPath(const QString &path) const;
|
||||||
QString defineDirectiveToDefineOption(const ProjectExplorer::Macro &marco) const;
|
void addWrappedQtHeadersIncludePath(QStringList &list) const;
|
||||||
|
|
||||||
void addWrappedQtHeadersIncludePath(QStringList &list);
|
private:
|
||||||
|
const ProjectPart &m_projectPart;
|
||||||
|
|
||||||
|
const UseSystemHeader m_useSystemHeader;
|
||||||
|
const SkipBuiltIn m_skipBuiltInHeaderPathsAndDefines;
|
||||||
|
const SkipLanguageDefines m_skipLanguageDefines;
|
||||||
|
|
||||||
|
const QString m_clangVersion;
|
||||||
|
const QString m_clangResourceDirectory;
|
||||||
|
|
||||||
QStringList m_options;
|
QStringList m_options;
|
||||||
|
|
||||||
QString m_clangVersion;
|
|
||||||
QString m_clangResourceDirectory;
|
|
||||||
|
|
||||||
UseSystemHeader m_useSystemHeader;
|
|
||||||
SkipBuiltIn m_skipBuiltInHeaderPathsAndDefines;
|
|
||||||
SkipLanguageDefines m_skipLanguageDefines;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
|||||||
@@ -279,12 +279,12 @@ bool fileSizeExceedsLimit(const QFileInfo &fileInfo, int sizeLimitInMb)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilerOptionsBuilder::PchUsage getPchUsage()
|
UsePrecompiledHeaders getPchUsage()
|
||||||
{
|
{
|
||||||
const QSharedPointer<CppCodeModelSettings> cms = codeModelSettings();
|
const QSharedPointer<CppCodeModelSettings> cms = codeModelSettings();
|
||||||
if (cms->pchUsage() == CppCodeModelSettings::PchUse_None)
|
if (cms->pchUsage() == CppCodeModelSettings::PchUse_None)
|
||||||
return CompilerOptionsBuilder::PchUsage::None;
|
return UsePrecompiledHeaders::No;
|
||||||
return CompilerOptionsBuilder::PchUsage::Use;
|
return UsePrecompiledHeaders::Yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // CppTools
|
} // CppTools
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ void CPPTOOLS_EXPORT switchHeaderSource();
|
|||||||
class CppCodeModelSettings;
|
class CppCodeModelSettings;
|
||||||
QSharedPointer<CppCodeModelSettings> CPPTOOLS_EXPORT codeModelSettings();
|
QSharedPointer<CppCodeModelSettings> CPPTOOLS_EXPORT codeModelSettings();
|
||||||
|
|
||||||
CompilerOptionsBuilder::PchUsage CPPTOOLS_EXPORT getPchUsage();
|
UsePrecompiledHeaders CPPTOOLS_EXPORT getPchUsage();
|
||||||
|
|
||||||
int indexerFileSizeLimitInMb();
|
int indexerFileSizeLimitInMb();
|
||||||
bool fileSizeExceedsLimit(const QFileInfo &fileInfo, int sizeLimitInMb);
|
bool fileSizeExceedsLimit(const QFileInfo &fileInfo, int sizeLimitInMb);
|
||||||
|
|||||||
@@ -29,6 +29,6 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
inline CompilerOptionsBuilder::PchUsage getPchUsage() { return CompilerOptionsBuilder::PchUsage::None; }
|
inline CppTools::UsePrecompiledHeaders getPchUsage() { return UsePrecompiledHeaders::No; }
|
||||||
|
|
||||||
} // CppTools
|
} // CppTools
|
||||||
|
|||||||
@@ -310,14 +310,14 @@ TEST_F(CompilerOptionsBuilder, ClangHeadersAndCppIncludesPathsOrderAndroidClang)
|
|||||||
|
|
||||||
TEST_F(CompilerOptionsBuilder, NoPrecompiledHeader)
|
TEST_F(CompilerOptionsBuilder, NoPrecompiledHeader)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addPrecompiledHeaderOptions(CppTools::CompilerOptionsBuilder::PchUsage::None);
|
compilerOptionsBuilder.addPrecompiledHeaderOptions(CppTools::UsePrecompiledHeaders::No);
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options().empty(), true);
|
ASSERT_THAT(compilerOptionsBuilder.options().empty(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilder, UsePrecompiledHeader)
|
TEST_F(CompilerOptionsBuilder, UsePrecompiledHeader)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addPrecompiledHeaderOptions(CppTools::CompilerOptionsBuilder::PchUsage::Use);
|
compilerOptionsBuilder.addPrecompiledHeaderOptions(CppTools::UsePrecompiledHeaders::Yes);
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(),
|
ASSERT_THAT(compilerOptionsBuilder.options(),
|
||||||
ElementsAre("-include", QDir::toNativeSeparators(TESTDATA_DIR "/compileroptionsbuilder.pch")));
|
ElementsAre("-include", QDir::toNativeSeparators(TESTDATA_DIR "/compileroptionsbuilder.pch")));
|
||||||
@@ -434,7 +434,7 @@ TEST_F(CompilerOptionsBuilder, UndefineClangVersionMacrosForMsvc)
|
|||||||
|
|
||||||
TEST_F(CompilerOptionsBuilder, BuildAllOptions)
|
TEST_F(CompilerOptionsBuilder, BuildAllOptions)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.build(ProjectFile::CXXSource, CppTools::CompilerOptionsBuilder::PchUsage::None);
|
compilerOptionsBuilder.build(ProjectFile::CXXSource, CppTools::UsePrecompiledHeaders::No);
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(),
|
ASSERT_THAT(compilerOptionsBuilder.options(),
|
||||||
ElementsAre(
|
ElementsAre(
|
||||||
|
|||||||
@@ -150,9 +150,8 @@ void RefactoringEngine::SetUp()
|
|||||||
projectPart->files.push_back(projectFile);
|
projectPart->files.push_back(projectFile);
|
||||||
|
|
||||||
CompilerOptionsBuilder optionsBuilder(*projectPart);
|
CompilerOptionsBuilder optionsBuilder(*projectPart);
|
||||||
commandLine = Utils::SmallStringVector(optionsBuilder.build(
|
commandLine = Utils::SmallStringVector(
|
||||||
projectFile.kind,
|
optionsBuilder.build(projectFile.kind, CppTools::UsePrecompiledHeaders::No));
|
||||||
CompilerOptionsBuilder::PchUsage::None));
|
|
||||||
commandLine.push_back(qStringFilePath);
|
commandLine.push_back(qStringFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user