aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/cpptools/cpprawprojectpart.cpp42
-rw-r--r--src/plugins/cpptools/cpprawprojectpart.h1
2 files changed, 26 insertions, 17 deletions
diff --git a/src/plugins/cpptools/cpprawprojectpart.cpp b/src/plugins/cpptools/cpprawprojectpart.cpp
index ee18166c05..6c29c2bb34 100644
--- a/src/plugins/cpptools/cpprawprojectpart.cpp
+++ b/src/plugins/cpptools/cpprawprojectpart.cpp
@@ -29,6 +29,8 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/kitinformation.h>
+#include <utils/algorithm.h>
+
namespace CppTools {
RawProjectPartFlags::RawProjectPartFlags(const ProjectExplorer::ToolChain *toolChain,
@@ -54,6 +56,25 @@ void RawProjectPart::setFiles(const QStringList &files, const FileClassifier &fi
this->fileClassifier = fileClassifier;
}
+static QString trimTrailingSlashes(const QString &path) {
+ QString p = path;
+ while (p.endsWith('/') && p.count() > 1) {
+ p.chop(1);
+ }
+ return p;
+}
+
+ProjectExplorer::HeaderPath RawProjectPart::frameworkDetectionHeuristic(const ProjectExplorer::HeaderPath &header)
+{
+ QString path = trimTrailingSlashes(header.path);
+
+ if (path.endsWith(".framework")) {
+ path = path.left(path.lastIndexOf(QLatin1Char('/')));
+ return {path, ProjectExplorer::HeaderPathType::Framework};
+ }
+ return header;
+}
+
void RawProjectPart::setProjectFileLocation(const QString &projectFile, int line, int column)
{
this->projectFile = projectFile;
@@ -93,23 +114,10 @@ void RawProjectPart::setHeaderPaths(const ProjectExplorer::HeaderPaths &headerPa
void RawProjectPart::setIncludePaths(const QStringList &includePaths)
{
- headerPaths.clear();
-
- foreach (const QString &includeFile, includePaths) {
- ProjectExplorer::HeaderPath hp(includeFile, ProjectExplorer::HeaderPathType::User);
-
- // The simple project managers are utterly ignorant of frameworks on macOS, and won't report
- // framework paths. The work-around is to check if the include path ends in ".framework",
- // and if so, add the parent directory as framework path.
- if (includeFile.endsWith(QLatin1String(".framework"))) {
- const int slashIdx = includeFile.lastIndexOf(QLatin1Char('/'));
- if (slashIdx != -1) {
- hp = {includeFile.left(slashIdx), ProjectExplorer::HeaderPathType::Framework};
- }
- }
-
- headerPaths.push_back(std::move(hp));
- }
+ this->headerPaths = Utils::transform<QVector>(includePaths, [](const QString &path) {
+ ProjectExplorer::HeaderPath hp(path, ProjectExplorer::HeaderPathType::User);
+ return RawProjectPart::frameworkDetectionHeuristic(hp);
+ });
}
void RawProjectPart::setPreCompiledHeaders(const QStringList &preCompiledHeaders)
diff --git a/src/plugins/cpptools/cpprawprojectpart.h b/src/plugins/cpptools/cpprawprojectpart.h
index 43e3067753..2cddd71bf9 100644
--- a/src/plugins/cpptools/cpprawprojectpart.h
+++ b/src/plugins/cpptools/cpprawprojectpart.h
@@ -61,6 +61,7 @@ public:
// FileClassifier must be thread-safe.
using FileClassifier = std::function<ProjectFile(const QString &filePath)>;
void setFiles(const QStringList &files, const FileClassifier &fileClassifier = FileClassifier());
+ static ProjectExplorer::HeaderPath frameworkDetectionHeuristic(const ProjectExplorer::HeaderPath &header);
void setHeaderPaths(const ProjectExplorer::HeaderPaths &headerPaths);
void setIncludePaths(const QStringList &includePaths);
void setPreCompiledHeaders(const QStringList &preCompiledHeaders);