forked from qt-creator/qt-creator
CppTools: Use -isystem only for non-project includes
...and return -I for ones in project. In case -isystem is set for all includes we don't get proper reparse when the included file is in angle brackets and is changed. Change-Id: Iba912edfc488aed2a4484f6a742a7c36099e8a13 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -27,8 +27,10 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
|
|
||||||
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcfallthrough.h>
|
#include <utils/qtcfallthrough.h>
|
||||||
|
|
||||||
@@ -37,6 +39,8 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
|
static constexpr char SYSTEM_INCLUDE_PREFIX[] = "-isystem";
|
||||||
|
|
||||||
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
|
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||||
const QString &clangVersion,
|
const QString &clangVersion,
|
||||||
const QString &clangResourceDirectory)
|
const QString &clangResourceDirectory)
|
||||||
@@ -119,10 +123,23 @@ void CompilerOptionsBuilder::enableExceptions()
|
|||||||
add(QLatin1String("-fexceptions"));
|
add(QLatin1String("-fexceptions"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Utils::FileName absoluteDirectory(const QString &filePath)
|
||||||
|
{
|
||||||
|
return Utils::FileName::fromString(QFileInfo(filePath + '/').absolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
static Utils::FileName projectTopLevelDirectory(const ProjectPart &projectPart)
|
||||||
|
{
|
||||||
|
if (!projectPart.project)
|
||||||
|
return Utils::FileName();
|
||||||
|
return projectPart.project->projectDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addHeaderPathOptions()
|
void CompilerOptionsBuilder::addHeaderPathOptions()
|
||||||
{
|
{
|
||||||
typedef ProjectPartHeaderPath HeaderPath;
|
typedef ProjectPartHeaderPath HeaderPath;
|
||||||
const QString defaultPrefix = includeDirOption();
|
const QString defaultPrefix = includeDirOption();
|
||||||
|
const Utils::FileName projectDirectory = projectTopLevelDirectory(m_projectPart);
|
||||||
|
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
@@ -134,6 +151,7 @@ void CompilerOptionsBuilder::addHeaderPathOptions()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
QString prefix;
|
QString prefix;
|
||||||
|
Utils::FileName path;
|
||||||
switch (headerPath.type) {
|
switch (headerPath.type) {
|
||||||
case HeaderPath::FrameworkPath:
|
case HeaderPath::FrameworkPath:
|
||||||
prefix = QLatin1String("-F");
|
prefix = QLatin1String("-F");
|
||||||
@@ -141,7 +159,11 @@ 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:
|
||||||
|
path = absoluteDirectory(headerPath.path);
|
||||||
|
if (path == projectDirectory || path.isChildOf(projectDirectory))
|
||||||
prefix = defaultPrefix;
|
prefix = defaultPrefix;
|
||||||
|
else
|
||||||
|
prefix = SYSTEM_INCLUDE_PREFIX;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,7 +431,7 @@ void CompilerOptionsBuilder::addDefineFunctionMacrosMsvc()
|
|||||||
|
|
||||||
QString CompilerOptionsBuilder::includeDirOption() const
|
QString CompilerOptionsBuilder::includeDirOption() const
|
||||||
{
|
{
|
||||||
return QLatin1String("-isystem");
|
return QLatin1String("-I");
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray CompilerOptionsBuilder::macroOption(const ProjectExplorer::Macro ¯o) const
|
QByteArray CompilerOptionsBuilder::macroOption(const ProjectExplorer::Macro ¯o) const
|
||||||
@@ -506,7 +528,7 @@ void CompilerOptionsBuilder::addPredefinedHeaderPathsOptions()
|
|||||||
void CompilerOptionsBuilder::addClangIncludeFolder()
|
void CompilerOptionsBuilder::addClangIncludeFolder()
|
||||||
{
|
{
|
||||||
QTC_CHECK(!m_clangVersion.isEmpty());
|
QTC_CHECK(!m_clangVersion.isEmpty());
|
||||||
add(includeDirOption());
|
add(SYSTEM_INCLUDE_PREFIX);
|
||||||
add(clangIncludeDirectory());
|
add(clangIncludeDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user