summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2018-08-07 15:21:20 +0200
committerIvan Donchevskii <ivan.donchevskii@qt.io>2018-08-08 14:07:13 +0000
commit62e776aa8ed54bf448e355a55cf4f0e6c4579877 (patch)
tree69cda5d86bbc9ef9a68b0284684a55adea6519b7 /src/plugins
parent44b931f7f5bfc1ccdfb456300f13297d88397298 (diff)
downloadqt-creator-62e776aa8ed54bf448e355a55cf4f0e6c4579877.tar.gz
Clang: Provide include directory only for libclang
Only libclang has issues with the include directory search therefore undefining include folders makes sense only for libclang options builder. Change-Id: Ie3f62f5f3a89503e6e0ab59e18889e92425c3abc Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/clangcodemodel/clangutils.cpp27
-rw-r--r--src/plugins/clangpchmanager/projectupdater.cpp2
-rw-r--r--src/plugins/clangrefactoring/clangqueryprojectsfindfilter.cpp2
-rw-r--r--src/plugins/clangrefactoring/refactoringengine.cpp2
-rw-r--r--src/plugins/clangtools/clangtoolruncontrol.cpp16
-rw-r--r--src/plugins/clangtools/clangtoolruncontrol.h2
-rw-r--r--src/plugins/cpptools/compileroptionsbuilder.cpp30
-rw-r--r--src/plugins/cpptools/compileroptionsbuilder.h7
8 files changed, 37 insertions, 51 deletions
diff --git a/src/plugins/clangcodemodel/clangutils.cpp b/src/plugins/clangcodemodel/clangutils.cpp
index 199d4c7e8b..8bd698c2d1 100644
--- a/src/plugins/clangcodemodel/clangutils.cpp
+++ b/src/plugins/clangcodemodel/clangutils.cpp
@@ -86,17 +86,32 @@ static QString creatorResourcePath()
#endif
}
+static QString clangIncludeDirectory(const QString &clangVersion,
+ const QString &clangResourceDirectory)
+{
+#ifndef UNIT_TESTS
+ return Core::ICore::clangIncludeDirectory(clangVersion, clangResourceDirectory);
+#else
+ return QString();
+#endif
+}
+
class LibClangOptionsBuilder final : public CompilerOptionsBuilder
{
public:
LibClangOptionsBuilder(const ProjectPart &projectPart)
- : CompilerOptionsBuilder(projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR)
+ : CompilerOptionsBuilder(projectPart)
+ , m_clangVersion(CLANG_VERSION)
+ , m_clangResourceDirectory(CLANG_RESOURCE_DIR)
{
}
void addPredefinedHeaderPathsOptions() final
{
CompilerOptionsBuilder::addPredefinedHeaderPathsOptions();
+ add("-nostdinc");
+ add("-nostdlibinc");
+ addClangIncludeFolder();
addWrappedQtHeadersIncludePath();
}
@@ -117,6 +132,13 @@ public:
}
private:
+ void addClangIncludeFolder()
+ {
+ QTC_CHECK(!m_clangVersion.isEmpty());
+ add("-I");
+ add(clangIncludeDirectory(m_clangVersion, m_clangResourceDirectory));
+ }
+
void addWrappedQtHeadersIncludePath()
{
static const QString resourcePath = creatorResourcePath();
@@ -140,6 +162,9 @@ private:
add(QDir::toNativeSeparators(path));
}
}
+
+ QString m_clangVersion;
+ QString m_clangResourceDirectory;
};
/**
diff --git a/src/plugins/clangpchmanager/projectupdater.cpp b/src/plugins/clangpchmanager/projectupdater.cpp
index 7a7235b1e2..10fd98771f 100644
--- a/src/plugins/clangpchmanager/projectupdater.cpp
+++ b/src/plugins/clangpchmanager/projectupdater.cpp
@@ -119,7 +119,7 @@ HeaderAndSources ProjectUpdater::headerAndSourcesFromProjectPart(
QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart)
{
using CppTools::CompilerOptionsBuilder;
- CompilerOptionsBuilder builder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
+ CompilerOptionsBuilder builder(*projectPart);
return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None);
}
diff --git a/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.cpp b/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.cpp
index 654253ae9a..336a681ab2 100644
--- a/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.cpp
+++ b/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.cpp
@@ -153,7 +153,7 @@ Utils::SmallStringVector ClangQueryProjectsFindFilter::compilerArguments(CppTool
{
using CppTools::CompilerOptionsBuilder;
- CompilerOptionsBuilder builder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
+ CompilerOptionsBuilder builder(*projectPart);
return Utils::SmallStringVector(builder.build(fileKind,
CompilerOptionsBuilder::PchUsage::None));
diff --git a/src/plugins/clangrefactoring/refactoringengine.cpp b/src/plugins/clangrefactoring/refactoringengine.cpp
index 952ed9bf19..b5127e2b88 100644
--- a/src/plugins/clangrefactoring/refactoringengine.cpp
+++ b/src/plugins/clangrefactoring/refactoringengine.cpp
@@ -74,7 +74,7 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
QString filePath = data.filePath().toString();
QTextCursor textCursor = data.cursor();
- CompilerOptionsBuilder optionsBuilder{*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR};
+ CompilerOptionsBuilder optionsBuilder{*projectPart};
Utils::SmallStringVector commandLine{optionsBuilder.build(
fileKindInProjectPart(projectPart, filePath),
CppTools::getPchUsage())};
diff --git a/src/plugins/clangtools/clangtoolruncontrol.cpp b/src/plugins/clangtools/clangtoolruncontrol.cpp
index 5a587dc381..08cea9383f 100644
--- a/src/plugins/clangtools/clangtoolruncontrol.cpp
+++ b/src/plugins/clangtools/clangtoolruncontrol.cpp
@@ -186,16 +186,12 @@ private:
bool m_success = false;
};
-static AnalyzeUnits toAnalyzeUnits(const FileInfos &fileInfos,
- const QString &clangVersion,
- const QString &clangResourceDirectory)
+static AnalyzeUnits toAnalyzeUnits(const FileInfos &fileInfos)
{
AnalyzeUnits unitsToAnalyze;
const CompilerOptionsBuilder::PchUsage pchUsage = CppTools::getPchUsage();
for (const FileInfo &fileInfo : fileInfos) {
- CompilerOptionsBuilder optionsBuilder(*fileInfo.projectPart,
- clangVersion,
- clangResourceDirectory);
+ CompilerOptionsBuilder optionsBuilder(*fileInfo.projectPart);
QStringList arguments = extraClangToolsPrependOptions();
arguments.append(optionsBuilder.build(fileInfo.kind, pchUsage));
arguments.append(extraClangToolsAppendOptions());
@@ -205,13 +201,11 @@ static AnalyzeUnits toAnalyzeUnits(const FileInfos &fileInfos,
return unitsToAnalyze;
}
-AnalyzeUnits ClangToolRunControl::unitsToAnalyze(const QString &clangVersion)
+AnalyzeUnits ClangToolRunControl::unitsToAnalyze()
{
QTC_ASSERT(m_projectInfo.isValid(), return AnalyzeUnits());
- const QString clangResourceDirectory = Core::ICore::clangIncludeDirectory(m_clangExecutable,
- clangVersion);
- return toAnalyzeUnits(m_fileInfos, clangVersion, clangResourceDirectory);
+ return toAnalyzeUnits(m_fileInfos);
}
static QDebug operator<<(QDebug debug, const Utils::Environment &environment)
@@ -313,7 +307,7 @@ void ClangToolRunControl::start()
}
// Collect files
- const AnalyzeUnits unitsToProcess = unitsToAnalyze(CLANG_VERSION);
+ const AnalyzeUnits unitsToProcess = unitsToAnalyze();
qCDebug(LOG) << "Files to process:" << unitsToProcess;
m_unitsToProcess = unitsToProcess;
m_initialFilesToProcessSize = m_unitsToProcess.count();
diff --git a/src/plugins/clangtools/clangtoolruncontrol.h b/src/plugins/clangtools/clangtoolruncontrol.h
index 65f4bf35d0..dd5a95662e 100644
--- a/src/plugins/clangtools/clangtoolruncontrol.h
+++ b/src/plugins/clangtools/clangtoolruncontrol.h
@@ -77,7 +77,7 @@ private:
void start() final;
void stop() final;
- AnalyzeUnits unitsToAnalyze(const QString &clangVersion);
+ AnalyzeUnits unitsToAnalyze();
void analyzeNextFile();
void handleFinished();
diff --git a/src/plugins/cpptools/compileroptionsbuilder.cpp b/src/plugins/cpptools/compileroptionsbuilder.cpp
index 0eb940dcca..5e5721dc7c 100644
--- a/src/plugins/cpptools/compileroptionsbuilder.cpp
+++ b/src/plugins/cpptools/compileroptionsbuilder.cpp
@@ -39,14 +39,8 @@
namespace CppTools {
-static constexpr char SYSTEM_INCLUDE_PREFIX[] = "-isystem";
-
-CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
- const QString &clangVersion,
- const QString &clangResourceDirectory)
+CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart)
: m_projectPart(projectPart)
- , m_clangVersion(clangVersion)
- , m_clangResourceDirectory(clangResourceDirectory)
{
}
@@ -500,31 +494,9 @@ bool CompilerOptionsBuilder::excludeHeaderPath(const QString &headerPath) const
void CompilerOptionsBuilder::addPredefinedHeaderPathsOptions()
{
- add("-nostdinc");
- add("-nostdlibinc");
-
// In case of MSVC we need builtin clang defines to correctly handle clang includes
if (m_projectPart.toolchainType != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
add("-undef");
-
- addClangIncludeFolder();
-}
-
-static QString clangIncludeDirectory(const QString &clangVersion,
- const QString &clangResourceDirectory)
-{
-#ifndef UNIT_TESTS
- return Core::ICore::clangIncludeDirectory(clangVersion, clangResourceDirectory);
-#else
- return QString();
-#endif
-}
-
-void CompilerOptionsBuilder::addClangIncludeFolder()
-{
- QTC_CHECK(!m_clangVersion.isEmpty());
- add(SYSTEM_INCLUDE_PREFIX);
- add(clangIncludeDirectory(m_clangVersion, m_clangResourceDirectory));
}
void CompilerOptionsBuilder::addProjectConfigFileInclude()
diff --git a/src/plugins/cpptools/compileroptionsbuilder.h b/src/plugins/cpptools/compileroptionsbuilder.h
index 35cd2ce57a..33a72820e4 100644
--- a/src/plugins/cpptools/compileroptionsbuilder.h
+++ b/src/plugins/cpptools/compileroptionsbuilder.h
@@ -39,9 +39,7 @@ public:
Use
};
- CompilerOptionsBuilder(const ProjectPart &projectPart,
- const QString &clangVersion = QString(),
- const QString &clangResourceDirectory = QString());
+ CompilerOptionsBuilder(const ProjectPart &projectPart);
virtual ~CompilerOptionsBuilder() {}
virtual void addTargetTriple();
@@ -90,11 +88,8 @@ private:
QByteArray macroOption(const ProjectExplorer::Macro &macro) const;
QByteArray toDefineOption(const ProjectExplorer::Macro &macro) const;
QString defineDirectiveToDefineOption(const ProjectExplorer::Macro &marco) const;
- void addClangIncludeFolder();
QStringList m_options;
- QString m_clangVersion;
- QString m_clangResourceDirectory;
};
} // namespace CppTools