From 528ec741c1bff3a7682be7a4bc7bfa157b86b5d3 Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@nokia.com>
Date: Tue, 13 Apr 2010 11:14:34 +0200
Subject: [PATCH] Add private frameworks when a framework is added.

Task-number: QTCREATORBUG-1102
Reviewed-by: Roberto Raggi
---
 src/plugins/cpptools/cppmodelmanager.cpp | 36 +++++++++++++++++++++++-
 src/plugins/cpptools/cppmodelmanager.h   |  1 +
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index 4b2622de4aa..20a70be1e71 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -219,7 +219,41 @@ void CppPreprocessor::setIncludePaths(const QStringList &includePaths)
 }
 
 void CppPreprocessor::setFrameworkPaths(const QStringList &frameworkPaths)
-{ m_frameworkPaths = frameworkPaths; }
+{
+    m_frameworkPaths.clear();
+
+    foreach (const QString &frameworkPath, frameworkPaths) {
+        addFrameworkPath(frameworkPath);
+    }
+}
+
+// Add the given framework path, and expand private frameworks.
+//
+// Example:
+//  <framework-path>/ApplicationServices.framework
+// has private frameworks in:
+//  <framework-path>/ApplicationServices.framework/Frameworks
+// if the "Frameworks" folder exists inside the top level framework.
+void CppPreprocessor::addFrameworkPath(const QString &frameworkPath)
+{
+    // The algorithm below is a bit too eager, but that's because we're not getting
+    // in the frameworks we're linking against. If we would have that, then we could
+    // add only those private frameworks.
+    if (!m_frameworkPaths.contains(frameworkPath)) {
+        m_frameworkPaths.append(frameworkPath);
+    }
+
+    const QDir frameworkDir(frameworkPath);
+    const QStringList filter = QStringList() << QLatin1String("*.framework");
+    foreach (const QFileInfo &framework, frameworkDir.entryInfoList(filter)) {
+        if (!framework.isDir())
+            continue;
+        const QFileInfo privateFrameworks(framework.absoluteFilePath(), QLatin1String("Frameworks"));
+        if (privateFrameworks.exists() && privateFrameworks.isDir()) {
+            addFrameworkPath(privateFrameworks.absoluteFilePath());
+        }
+    }
+}
 
 void CppPreprocessor::setProjectFiles(const QStringList &files)
 { m_projectFiles = files; }
diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h
index d8eee0da277..ac35ef0e5bc 100644
--- a/src/plugins/cpptools/cppmodelmanager.h
+++ b/src/plugins/cpptools/cppmodelmanager.h
@@ -252,6 +252,7 @@ public:
     void setWorkingCopy(const CppModelManagerInterface::WorkingCopy &workingCopy);
     void setIncludePaths(const QStringList &includePaths);
     void setFrameworkPaths(const QStringList &frameworkPaths);
+    void addFrameworkPath(const QString &frameworkPath);
     void setProjectFiles(const QStringList &files);
     void setTodo(const QStringList &files);
 
-- 
GitLab