diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index bb1e792..45618f5 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -2681,6 +2681,131 @@ void cmGlobalXCodeGenerator
     return;
     }
 
+  // Collect libraries to add to "Link Binary With Libraries" build phase
+  std::set<std::string> buildLibs;
+  cmXCodeObject* buildFiles = 0;
+  cmXCodeObject* buildGroup = 0;
+  if(this->XcodeVersion >= 40)
+    {
+    for(std::vector<std::string>::iterator i =
+        this->CurrentConfigurationTypes.begin();
+        i != this->CurrentConfigurationTypes.end(); ++i)
+      {
+      // Get the current configuration name.
+      const char* configName = i->c_str();
+      if(!*configName)
+        {
+        configName = 0;
+        }
+
+      // Compute the link library and directory information.
+      cmComputeLinkInformation* pcli = cmtarget->GetLinkInformation(configName);
+      if(!pcli)
+        {
+        buildLibs.clear();
+        break;
+        }
+      cmComputeLinkInformation& cli = *pcli;
+
+      // get the set of libraries for this configuration
+      std::set<std::string> myLibs;
+      typedef cmComputeLinkInformation::ItemVector ItemVector;
+      ItemVector const& libNames = cli.GetItems();
+      for(ItemVector::const_iterator li = libNames.begin();
+          li != libNames.end(); ++li)
+        {
+        if(li->IsPath)
+          {
+#if defined(_WIN32)
+          std::string::size_type slash_pos = li->Value.find_last_of("/\\");
+#else
+          std::string::size_type slash_pos = li->Value.find_last_of("/");
+#endif
+          std::string file = li->Value.substr(slash_pos + 1);
+          std::set<std::string>::iterator set_pos = myLibs.find(file);
+          if(set_pos == myLibs.end())
+            {
+            myLibs.insert(file);
+            }
+          else
+            {
+            myLibs.erase(set_pos);
+            }
+          }
+        }
+
+      // find libraries that are present in all configurations (intersection)
+      if(buildLibs.empty())
+        {
+        buildLibs = myLibs;
+        }
+      else
+        {
+        std::set<std::string>::iterator li = buildLibs.begin();
+        std::set<std::string>::iterator lj = myLibs.begin();
+        while((li != buildLibs.end()) && (lj != myLibs.end()))
+          {
+          if(*li < *lj)
+            {
+            buildLibs.erase(li++);
+            }
+          else if(*li > *lj)
+            {
+            ++lj;
+            }
+          else
+            {
+            ++li;
+            ++lj;
+            }
+          }
+        buildLibs.erase(li, buildLibs.end());
+        if(buildLibs.empty())
+          {
+          break;
+          }
+        }
+      }
+
+    // Get or create the build phase
+    cmXCodeObject* frameworkBuildPhase = 0;
+    if(!buildLibs.empty())
+      {
+      cmXCodeObject* buildPhases = target->GetObject("buildPhases");
+      frameworkBuildPhase =
+        buildPhases->GetObject(cmXCodeObject::PBXFrameworksBuildPhase);
+      if(frameworkBuildPhase)
+        {
+        buildFiles = frameworkBuildPhase->GetObject("files");
+        }
+      else
+        {
+        frameworkBuildPhase =
+          this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
+        frameworkBuildPhase->SetComment("Frameworks");
+        frameworkBuildPhase->AddAttribute("buildActionMask",
+                                          this->CreateString("2147483647"));
+        buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+        frameworkBuildPhase->AddAttribute("files", buildFiles);
+        frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+                                          this->CreateString("0"));
+        buildPhases->AddObject(frameworkBuildPhase);
+        }
+      }
+
+    // Create the group for libraries
+    if(!buildLibs.empty())
+      {
+      buildGroup = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+      cmXCodeObject* librariesGroup =
+        this->CreateObject(cmXCodeObject::PBXGroup);
+      librariesGroup->AddAttribute("name", this->CreateString("Libraries"));
+      librariesGroup->AddAttribute("children", buildGroup);
+      librariesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
+      this->MainGroupChildren->AddObject(librariesGroup);
+      }
+    }
+
   // Loop over configuration types and set per-configuration info.
   for(std::vector<std::string>::iterator i =
         this->CurrentConfigurationTypes.begin();
@@ -2739,21 +2864,63 @@ void cmGlobalXCodeGenerator
     // now add the link libraries
     {
     std::string linkLibs;
-    const char* sep = "";
+    std::string linkDirs;
+    std::set<std::string> libPaths;
     typedef cmComputeLinkInformation::ItemVector ItemVector;
     ItemVector const& libNames = cli.GetItems();
     for(ItemVector::const_iterator li = libNames.begin();
         li != libNames.end(); ++li)
       {
-      linkLibs += sep;
-      sep = " ";
       if(li->IsPath)
         {
-        linkLibs += this->XCodeEscapePath(li->Value.c_str());
+        if(this->XcodeVersion < 40)
+          {
+          linkLibs += " " + this->XCodeEscapePath(li->Value.c_str());
+          }
+        else
+          {
+#if defined(_WIN32)
+          std::string::size_type slash_pos = li->Value.find_last_of("/\\");
+#else
+          std::string::size_type slash_pos = li->Value.find_last_of("/");
+#endif
+          std::string file = li->Value.substr(slash_pos + 1);
+          std::string path = li->Value.substr(0, slash_pos);
+          if(buildLibs.find(file) != buildLibs.end())
+            {
+            libPaths.insert(path);
+            if(i == this->CurrentConfigurationTypes.begin())
+              {
+                std::string relpath = this->RelativeToSource(li->Value.c_str());
+
+                cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
+
+                fileRef->SetComment(file.c_str());
+
+                fileRef->AddAttribute("lastKnownFileType", this->CreateString("archive.ar"));
+                fileRef->AddAttribute("name", this->CreateString(file.c_str()));
+                fileRef->AddAttribute("path", this->CreateString(relpath.c_str()));
+                fileRef->AddAttribute("sourceTree", this->CreateString("<group>"));
+
+                cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
+
+                std::string comment = file + " in Frameworks";
+                buildFile->SetComment(comment.c_str());
+                buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
+
+                buildFiles->AddObject(buildFile);
+                buildGroup->AddObject(fileRef);
+              }
+            }
+          else
+            {
+            linkLibs += " " + this->XCodeEscapePath(li->Value.c_str());
+            }
+          }
         }
       else
         {
-        linkLibs += li->Value;
+        linkLibs += " " + li->Value;
         }
       if(li->Target && !li->Target->IsImported())
         {
@@ -2762,6 +2929,13 @@ void cmGlobalXCodeGenerator
       }
     this->AppendBuildSettingAttribute(target, "OTHER_LDFLAGS",
                                       linkLibs.c_str(), configName);
+    for(std::set<std::string>::const_iterator li = libPaths.begin();
+        li != libPaths.end(); ++li)
+      {
+      linkDirs += " " + this->XCodeEscapePath(li->c_str());
+      }
+    this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
+                                      linkDirs.c_str(), configName);
     }
     }
 }
