forked from qt-creator/qt-creator
Add optional system include to compiler option builder
System includes suppress warnings and prevent indexing of unwanted symbols. Using system includes for all includes outside of the project can be quite advantageous. The rootProjectDirectory() can be extended to be set in the project settings. An automatic generation could be possible but could create an unwanted path which includes files outside of the perceived project. Change-Id: Ib9d3158f14f41efe1f6657f962d5c4437bb324b2 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -153,9 +153,9 @@ private:
|
|||||||
|
|
||||||
if (m_projectPart.qtVersion != CppTools::ProjectPart::NoQt) {
|
if (m_projectPart.qtVersion != CppTools::ProjectPart::NoQt) {
|
||||||
const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + "/QtCore";
|
const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + "/QtCore";
|
||||||
add(includeDirOption());
|
add(includeDirOptionForPath(wrappedQtHeadersPath));
|
||||||
add(QDir::toNativeSeparators(wrappedQtHeadersPath));
|
add(QDir::toNativeSeparators(wrappedQtHeadersPath));
|
||||||
add(includeDirOption());
|
add(includeDirOptionForPath(wrappedQtHeadersPath));
|
||||||
add(QDir::toNativeSeparators(wrappedQtCoreHeaderPath));
|
add(QDir::toNativeSeparators(wrappedQtCoreHeaderPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ private:
|
|||||||
{
|
{
|
||||||
const QString path = ModelManagerSupportClang::instance()->dummyUiHeaderOnDiskDirPath();
|
const QString path = ModelManagerSupportClang::instance()->dummyUiHeaderOnDiskDirPath();
|
||||||
if (!path.isEmpty()) {
|
if (!path.isEmpty()) {
|
||||||
add(includeDirOption());
|
add("-I");
|
||||||
add(QDir::toNativeSeparators(path));
|
add(QDir::toNativeSeparators(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -149,7 +149,7 @@ HeaderAndSources ProjectUpdater::headerAndSourcesFromProjectPart(
|
|||||||
QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart)
|
QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart)
|
||||||
{
|
{
|
||||||
using CppTools::CompilerOptionsBuilder;
|
using CppTools::CompilerOptionsBuilder;
|
||||||
CompilerOptionsBuilder builder(*projectPart);
|
CompilerOptionsBuilder builder(*projectPart, CppTools::UseSystemHeader::Yes);
|
||||||
return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None);
|
return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -153,7 +153,7 @@ Utils::SmallStringVector ClangQueryProjectsFindFilter::compilerArguments(CppTool
|
|||||||
{
|
{
|
||||||
using CppTools::CompilerOptionsBuilder;
|
using CppTools::CompilerOptionsBuilder;
|
||||||
|
|
||||||
CompilerOptionsBuilder builder(*projectPart);
|
CompilerOptionsBuilder builder(*projectPart, CppTools::UseSystemHeader::Yes);
|
||||||
|
|
||||||
return Utils::SmallStringVector(builder.build(fileKind,
|
return Utils::SmallStringVector(builder.build(fileKind,
|
||||||
CompilerOptionsBuilder::PchUsage::None));
|
CompilerOptionsBuilder::PchUsage::None));
|
||||||
|
@@ -74,7 +74,7 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
|
|||||||
|
|
||||||
QString filePath = data.filePath().toString();
|
QString filePath = data.filePath().toString();
|
||||||
QTextCursor textCursor = data.cursor();
|
QTextCursor textCursor = data.cursor();
|
||||||
CompilerOptionsBuilder optionsBuilder{*projectPart};
|
CompilerOptionsBuilder optionsBuilder{*projectPart, CppTools::UseSystemHeader::Yes};
|
||||||
Utils::SmallStringVector commandLine{optionsBuilder.build(
|
Utils::SmallStringVector commandLine{optionsBuilder.build(
|
||||||
fileKindInProjectPart(projectPart, filePath),
|
fileKindInProjectPart(projectPart, filePath),
|
||||||
CppTools::getPchUsage())};
|
CppTools::getPchUsage())};
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include <coreplugin/vcsmanager.h>
|
#include <coreplugin/vcsmanager.h>
|
||||||
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -38,8 +39,10 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart)
|
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||||
: m_projectPart(projectPart)
|
UseSystemHeader useSystemHeader)
|
||||||
|
: m_projectPart(projectPart),
|
||||||
|
m_useSystemHeader(useSystemHeader)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +191,6 @@ void CompilerOptionsBuilder::enableExceptions()
|
|||||||
void CompilerOptionsBuilder::addHeaderPathOptions()
|
void CompilerOptionsBuilder::addHeaderPathOptions()
|
||||||
{
|
{
|
||||||
typedef ProjectPartHeaderPath HeaderPath;
|
typedef ProjectPartHeaderPath HeaderPath;
|
||||||
const QString defaultPrefix = includeDirOption();
|
|
||||||
|
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
@@ -208,7 +210,7 @@ void CompilerOptionsBuilder::addHeaderPathOptions()
|
|||||||
default: // This shouldn't happen, but let's be nice..:
|
default: // This shouldn't happen, but let's be nice..:
|
||||||
// intentional fall-through:
|
// intentional fall-through:
|
||||||
case HeaderPath::IncludePath:
|
case HeaderPath::IncludePath:
|
||||||
prefix = defaultPrefix;
|
prefix = includeDirOptionForPath(headerPath.path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,9 +425,14 @@ void CompilerOptionsBuilder::addDefineFunctionMacrosMsvc()
|
|||||||
addMacros({{"__FUNCSIG__", "\"\""}, {"__FUNCTION__", "\"\""}, {"__FUNCDNAME__", "\"\""}});
|
addMacros({{"__FUNCSIG__", "\"\""}, {"__FUNCTION__", "\"\""}, {"__FUNCDNAME__", "\"\""}});
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CompilerOptionsBuilder::includeDirOption() const
|
QString CompilerOptionsBuilder::includeDirOptionForPath(const QString &path) const
|
||||||
{
|
{
|
||||||
return QLatin1String("-I");
|
if (m_useSystemHeader == UseSystemHeader::No
|
||||||
|
|| path.startsWith(m_projectPart.project->rootProjectDirectory().toString())) {
|
||||||
|
return QString("-I");
|
||||||
|
} else {
|
||||||
|
return QString("-isystem");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray CompilerOptionsBuilder::macroOption(const ProjectExplorer::Macro ¯o) const
|
QByteArray CompilerOptionsBuilder::macroOption(const ProjectExplorer::Macro ¯o) const
|
||||||
|
@@ -31,6 +31,12 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
|
enum class UseSystemHeader
|
||||||
|
{
|
||||||
|
Yes,
|
||||||
|
No
|
||||||
|
};
|
||||||
|
|
||||||
class CPPTOOLS_EXPORT CompilerOptionsBuilder
|
class CPPTOOLS_EXPORT CompilerOptionsBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -39,7 +45,8 @@ public:
|
|||||||
Use
|
Use
|
||||||
};
|
};
|
||||||
|
|
||||||
CompilerOptionsBuilder(const ProjectPart &projectPart);
|
CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||||
|
UseSystemHeader useSystemHeader = UseSystemHeader::No);
|
||||||
virtual ~CompilerOptionsBuilder() {}
|
virtual ~CompilerOptionsBuilder() {}
|
||||||
|
|
||||||
virtual void addTargetTriple();
|
virtual void addTargetTriple();
|
||||||
@@ -80,8 +87,7 @@ protected:
|
|||||||
virtual QString defineOption() const;
|
virtual QString defineOption() const;
|
||||||
virtual QString undefineOption() const;
|
virtual QString undefineOption() const;
|
||||||
virtual QString includeOption() const;
|
virtual QString includeOption() const;
|
||||||
virtual QString includeDirOption() const;
|
QString includeDirOptionForPath(const QString &path) const;
|
||||||
|
|
||||||
const ProjectPart m_projectPart;
|
const ProjectPart m_projectPart;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -90,6 +96,7 @@ private:
|
|||||||
QString defineDirectiveToDefineOption(const ProjectExplorer::Macro &marco) const;
|
QString defineDirectiveToDefineOption(const ProjectExplorer::Macro &marco) const;
|
||||||
|
|
||||||
QStringList m_options;
|
QStringList m_options;
|
||||||
|
UseSystemHeader m_useSystemHeader;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
@@ -642,6 +642,15 @@ Utils::FileName Project::projectDirectory(const Utils::FileName &top)
|
|||||||
return Utils::FileName::fromString(top.toFileInfo().absoluteDir().path());
|
return Utils::FileName::fromString(top.toFileInfo().absoluteDir().path());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the common root directory that contains all files which belongs to a project.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Utils::FileName Project::rootProjectDirectory() const
|
||||||
|
{
|
||||||
|
return projectDirectory(); // TODO parse all files and find the common path
|
||||||
|
}
|
||||||
|
|
||||||
ProjectNode *Project::rootProjectNode() const
|
ProjectNode *Project::rootProjectNode() const
|
||||||
{
|
{
|
||||||
return d->m_rootProjectNode.get();
|
return d->m_rootProjectNode.get();
|
||||||
|
@@ -36,6 +36,10 @@ public:
|
|||||||
Utils::FileName projectDirectory() const {
|
Utils::FileName projectDirectory() const {
|
||||||
return Utils::FileName();
|
return Utils::FileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::FileName rootProjectDirectory() const {
|
||||||
|
return Utils::FileName();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user