diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index d1b6130637aee7f2d4af674b6865c725c7ae0c4c..b023d5cf622b6f3bb3715addc4b6a5fc4b26fa6c 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -3344,7 +3344,8 @@ void cmGlobalXCodeGenerator::OutputXCodeProject(
   if (this->GetCMakeInstance()->GetState()->GetGlobalPropertyAsBool(
         "XCODE_GENERATE_SCHEME") &&
       this->XcodeVersion >= 70) {
-    this->OutputXCodeSharedSchemes(xcodeDir, root);
+    this->OutputXCodeSharedSchemes(xcodeDir);
+    this->OutputXCodeWorkspaceSettings(xcodeDir);
   }
 
   this->ClearXCodeObjects();
@@ -3356,7 +3357,7 @@ void cmGlobalXCodeGenerator::OutputXCodeProject(
 }
 
 void cmGlobalXCodeGenerator::OutputXCodeSharedSchemes(
-  const std::string& xcProjDir, cmLocalGenerator* root)
+  const std::string& xcProjDir)
 {
   for (std::vector<cmXCodeObject*>::const_iterator i =
          this->XCodeObjects.begin();
@@ -3368,11 +3369,41 @@ void cmGlobalXCodeGenerator::OutputXCodeSharedSchemes(
       cmXCodeScheme schm(obj, this->CurrentConfigurationTypes,
                          this->XcodeVersion);
       schm.WriteXCodeSharedScheme(xcProjDir,
-                                  root->GetCurrentSourceDirectory());
+                                  this->RelativeToSource(xcProjDir.c_str()));
     }
   }
 }
 
+void cmGlobalXCodeGenerator::OutputXCodeWorkspaceSettings(
+  const std::string& xcProjDir)
+{
+  std::string xcodeSharedDataDir = xcProjDir;
+  xcodeSharedDataDir += "/project.xcworkspace/xcshareddata";
+  cmSystemTools::MakeDirectory(xcodeSharedDataDir);
+
+  std::string workspaceSettingsFile = xcodeSharedDataDir;
+  workspaceSettingsFile += "/WorkspaceSettings.xcsettings";
+
+  cmGeneratedFileStream fout(workspaceSettingsFile.c_str());
+  fout.SetCopyIfDifferent(true);
+  if (!fout) {
+    return;
+  }
+
+  cmXMLWriter xout(fout);
+  xout.StartDocument();
+  xout.Doctype("plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\""
+               "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
+  xout.StartElement("plist");
+  xout.Attribute("version", "1.0");
+  xout.StartElement("dict");
+  xout.Element("key", "IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
+  xout.Element("false");
+  xout.EndElement(); // dict
+  xout.EndElement(); // plist
+  xout.EndDocument();
+}
+
 void cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
                                                cmLocalGenerator*,
                                                std::vector<cmLocalGenerator*>&)
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index c9157b06ecb504e3ae67faa90046ebaeeae50a37..9eacdef4a98dbe8d1aebe38f8b7e2e378413410b 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -166,8 +166,8 @@ private:
   void OutputXCodeProject(cmLocalGenerator* root,
                           std::vector<cmLocalGenerator*>& generators);
   // Write shared scheme files for all the native targets
-  void OutputXCodeSharedSchemes(const std::string& xcProjDir,
-                                cmLocalGenerator* root);
+  void OutputXCodeSharedSchemes(const std::string& xcProjDir);
+  void OutputXCodeWorkspaceSettings(const std::string& xcProjDir);
   void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root,
                          std::vector<cmLocalGenerator*>& generators);
   cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string& fullpath,
diff --git a/Source/cmXCodeScheme.cxx b/Source/cmXCodeScheme.cxx
index 3c8c0b77792f21d03de11f48c59d909f758dfaab..5c22531d425715981e137e3c25d8c3ce39eaf6cd 100644
--- a/Source/cmXCodeScheme.cxx
+++ b/Source/cmXCodeScheme.cxx
@@ -3,6 +3,7 @@
 #include "cmXCodeScheme.h"
 
 #include <iomanip>
+#include <iostream>
 #include <sstream>
 
 #include "cmGeneratedFileStream.h"
@@ -12,7 +13,9 @@
 cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj,
                              const std::vector<std::string>& configList,
                              unsigned int xcVersion)
-  : TargetName(xcObj->GetTarget()->GetName())
+  : Target(xcObj)
+  , TargetName(xcObj->GetTarget()->GetName())
+  , BuildableName(xcObj->GetTarget()->GetFullName())
   , TargetId(xcObj->GetId())
   , ConfigList(configList)
   , XcodeVersion(xcVersion)
@@ -20,7 +23,7 @@ cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj,
 }
 
 void cmXCodeScheme::WriteXCodeSharedScheme(const std::string& xcProjDir,
-                                           const std::string sourceRoot)
+                                           const std::string& container)
 {
   // Create shared scheme sub-directory tree
   //
@@ -39,14 +42,14 @@ void cmXCodeScheme::WriteXCodeSharedScheme(const std::string& xcProjDir,
     return;
   }
 
-  std::string xcProjRelDir = xcProjDir.substr(sourceRoot.size() + 1);
-  WriteXCodeXCScheme(fout, xcProjRelDir);
+  WriteXCodeXCScheme(fout, container);
 }
 
 void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout,
-                                       const std::string& xcProjDir)
+                                       const std::string& container)
 {
   cmXMLWriter xout(fout);
+  xout.SetIndentationElement(std::string(3, ' '));
   xout.StartDocument();
 
   xout.StartElement("Scheme");
@@ -54,9 +57,9 @@ void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout,
   xout.Attribute("LastUpgradeVersion", WriteVersionString());
   xout.Attribute("version", "1.3");
 
-  WriteBuildAction(xout, xcProjDir);
+  WriteBuildAction(xout, container);
   WriteTestAction(xout, FindConfiguration("Debug"));
-  WriteLaunchAction(xout, FindConfiguration("Debug"), xcProjDir);
+  WriteLaunchAction(xout, FindConfiguration("Debug"), container);
   WriteProfileAction(xout, FindConfiguration("Release"));
   WriteAnalyzeAction(xout, FindConfiguration("Debug"));
   WriteArchiveAction(xout, FindConfiguration("Release"));
@@ -65,7 +68,7 @@ void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout,
 }
 
 void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
-                                     const std::string& xcProjDir)
+                                     const std::string& container)
 {
   xout.StartElement("BuildAction");
   xout.BreakAttributes();
@@ -85,9 +88,9 @@ void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
   xout.BreakAttributes();
   xout.Attribute("BuildableIdentifier", "primary");
   xout.Attribute("BlueprintIdentifier", this->TargetId);
-  xout.Attribute("BuildableName", this->TargetName);
+  xout.Attribute("BuildableName", this->BuildableName);
   xout.Attribute("BlueprintName", this->TargetName);
-  xout.Attribute("ReferencedContainer", "container:" + xcProjDir);
+  xout.Attribute("ReferencedContainer", "container:" + container);
   xout.EndElement();
 
   xout.EndElement(); // BuildActionEntry
@@ -118,7 +121,7 @@ void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
 
 void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
                                       std::string configuration,
-                                      const std::string& xcProjDir)
+                                      const std::string& container)
 {
   xout.StartElement("LaunchAction");
   xout.BreakAttributes();
@@ -134,15 +137,22 @@ void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
   xout.Attribute("debugServiceExtension", "internal");
   xout.Attribute("allowLocationSimulation", "YES");
 
-  xout.StartElement("MacroExpansion");
+  if (IsExecutable(this->Target)) {
+    xout.StartElement("BuildableProductRunnable");
+    xout.BreakAttributes();
+    xout.Attribute("runnableDebuggingMode", "0");
+
+  } else {
+    xout.StartElement("MacroExpansion");
+  }
 
   xout.StartElement("BuildableReference");
   xout.BreakAttributes();
   xout.Attribute("BuildableIdentifier", "primary");
   xout.Attribute("BlueprintIdentifier", this->TargetId);
-  xout.Attribute("BuildableName", this->TargetName);
+  xout.Attribute("BuildableName", this->BuildableName);
   xout.Attribute("BlueprintName", this->TargetName);
-  xout.Attribute("ReferencedContainer", "container:" + xcProjDir);
+  xout.Attribute("ReferencedContainer", "container:" + container);
   xout.EndElement();
 
   xout.EndElement(); // MacroExpansion
@@ -204,3 +214,14 @@ std::string cmXCodeScheme::FindConfiguration(const std::string& name)
 
   return name;
 }
+
+bool cmXCodeScheme::IsExecutable(const cmXCodeObject* target)
+{
+  cmGeneratorTarget* gt = target->GetTarget();
+  if (!gt) {
+    cmSystemTools::Error("Error no target on xobject\n");
+    return false;
+  }
+
+  return gt->GetType() == cmStateEnums::EXECUTABLE;
+}
diff --git a/Source/cmXCodeScheme.h b/Source/cmXCodeScheme.h
index b174c51b572dde3910a47621809bda95df158810..0a8e7376b3f09eb6d3a5df035dd54b11f7cd30fc 100644
--- a/Source/cmXCodeScheme.h
+++ b/Source/cmXCodeScheme.h
@@ -21,26 +21,30 @@ public:
                 unsigned int xcVersion);
 
   void WriteXCodeSharedScheme(const std::string& xcProjDir,
-                              const std::string sourceRoot);
+                              const std::string& container);
 
 private:
+  const cmXCodeObject* const Target;
   const std::string& TargetName;
+  const std::string BuildableName;
   const std::string& TargetId;
   const std::vector<std::string>& ConfigList;
   const unsigned int XcodeVersion;
 
-  void WriteXCodeXCScheme(std::ostream& fout, const std::string& xcProjDir);
+  void WriteXCodeXCScheme(std::ostream& fout, const std::string& container);
 
-  void WriteBuildAction(cmXMLWriter& xout, const std::string& xcProjDir);
+  void WriteBuildAction(cmXMLWriter& xout, const std::string& container);
   void WriteTestAction(cmXMLWriter& xout, std::string configuration);
   void WriteLaunchAction(cmXMLWriter& xout, std::string configuration,
-                         const std::string& xcProjDir);
+                         const std::string& container);
   void WriteProfileAction(cmXMLWriter& xout, std::string configuration);
   void WriteAnalyzeAction(cmXMLWriter& xout, std::string configuration);
   void WriteArchiveAction(cmXMLWriter& xout, std::string configuration);
 
   std::string WriteVersionString();
   std::string FindConfiguration(const std::string& name);
+
+  static bool IsExecutable(const cmXCodeObject* target);
 };
 
 #endif
diff --git a/Source/cmXMLWriter.cxx b/Source/cmXMLWriter.cxx
index 2f50fe929ce42d9ee7c1d2e2b91a9bfb4a70cb5b..541cb3d2c724500f03ad8e78ea5d01c9cb0b3387 100644
--- a/Source/cmXMLWriter.cxx
+++ b/Source/cmXMLWriter.cxx
@@ -7,6 +7,7 @@
 
 cmXMLWriter::cmXMLWriter(std::ostream& output, std::size_t level)
   : Output(output)
+  , IndentationElement(1, '\t')
   , Level(level)
   , ElementOpen(false)
   , BreakAttrib(false)
@@ -100,10 +101,18 @@ void cmXMLWriter::FragmentFile(const char* fname)
   this->Output << fin.rdbuf();
 }
 
+void cmXMLWriter::SetIndentationElement(std::string const& element)
+{
+  this->IndentationElement = element;
+}
+
 void cmXMLWriter::ConditionalLineBreak(bool condition, std::size_t indent)
 {
   if (condition) {
-    this->Output << '\n' << std::string(indent + this->Level, '\t');
+    this->Output << '\n';
+    for (std::size_t i = 0; i < indent + this->Level; ++i) {
+      this->Output << this->IndentationElement;
+    }
   }
 }
 
diff --git a/Source/cmXMLWriter.h b/Source/cmXMLWriter.h
index 904f73b45d2cf8b1c37ef58030e7bee542928521..6d1e6b4226fd738c2e42d249bca202a3f2421b36 100644
--- a/Source/cmXMLWriter.h
+++ b/Source/cmXMLWriter.h
@@ -60,6 +60,8 @@ public:
 
   void FragmentFile(const char* fname);
 
+  void SetIndentationElement(std::string const& element);
+
 private:
   cmXMLWriter(const cmXMLWriter&);
   cmXMLWriter& operator=(const cmXMLWriter&);
@@ -107,6 +109,7 @@ private:
 private:
   std::ostream& Output;
   std::stack<std::string, std::vector<std::string> > Elements;
+  std::string IndentationElement;
   std::size_t Level;
   bool ElementOpen;
   bool BreakAttrib;