cmXCodeScheme.cxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmXCodeScheme.h"
  4. #include <iomanip>
  5. #include <sstream>
  6. #include "cmGeneratedFileStream.h"
  7. #include "cmGeneratorTarget.h"
  8. #include "cmXMLSafe.h"
  9. cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj,
  10. const std::vector<std::string>& configList,
  11. unsigned int xcVersion)
  12. : TargetName(xcObj->GetTarget()->GetName())
  13. , TargetId(xcObj->GetId())
  14. , ConfigList(configList)
  15. , XcodeVersion(xcVersion)
  16. {
  17. }
  18. void cmXCodeScheme::WriteXCodeSharedScheme(const std::string& xcProjDir,
  19. const std::string sourceRoot)
  20. {
  21. // Create shared scheme sub-directory tree
  22. //
  23. std::string xcodeSchemeDir = xcProjDir;
  24. xcodeSchemeDir += "/xcshareddata/xcschemes";
  25. cmSystemTools::MakeDirectory(xcodeSchemeDir.c_str());
  26. std::string xcodeSchemeFile = xcodeSchemeDir;
  27. xcodeSchemeFile += "/";
  28. xcodeSchemeFile += this->TargetName;
  29. xcodeSchemeFile += ".xcscheme";
  30. cmGeneratedFileStream fout(xcodeSchemeFile.c_str());
  31. fout.SetCopyIfDifferent(true);
  32. if (!fout) {
  33. return;
  34. }
  35. std::string xcProjRelDir = xcProjDir.substr(sourceRoot.size() + 1);
  36. WriteXCodeXCScheme(fout, xcProjRelDir);
  37. }
  38. void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout,
  39. const std::string& xcProjDir)
  40. {
  41. cmXMLWriter xout(fout);
  42. xout.StartDocument();
  43. xout.StartElement("Scheme");
  44. xout.BreakAttributes();
  45. xout.Attribute("LastUpgradeVersion", WriteVersionString());
  46. xout.Attribute("version", "1.3");
  47. WriteBuildAction(xout, xcProjDir);
  48. WriteTestAction(xout, FindConfiguration("Debug"));
  49. WriteLaunchAction(xout, FindConfiguration("Debug"), xcProjDir);
  50. WriteProfileAction(xout, FindConfiguration("Release"));
  51. WriteAnalyzeAction(xout, FindConfiguration("Debug"));
  52. WriteArchiveAction(xout, FindConfiguration("Release"));
  53. xout.EndElement();
  54. }
  55. void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
  56. const std::string& xcProjDir)
  57. {
  58. xout.StartElement("BuildAction");
  59. xout.BreakAttributes();
  60. xout.Attribute("parallelizeBuildables", "YES");
  61. xout.Attribute("buildImplicitDependencies", "YES");
  62. xout.StartElement("BuildActionEntries");
  63. xout.StartElement("BuildActionEntry");
  64. xout.BreakAttributes();
  65. xout.Attribute("buildForTesting", "YES");
  66. xout.Attribute("buildForRunning", "YES");
  67. xout.Attribute("buildForProfiling", "YES");
  68. xout.Attribute("buildForArchiving", "YES");
  69. xout.Attribute("buildForAnalyzing", "YES");
  70. xout.StartElement("BuildableReference");
  71. xout.BreakAttributes();
  72. xout.Attribute("BuildableIdentifier", "primary");
  73. xout.Attribute("BlueprintIdentifier", this->TargetId);
  74. xout.Attribute("BuildableName", this->TargetName);
  75. xout.Attribute("BlueprintName", this->TargetName);
  76. xout.Attribute("ReferencedContainer", "container:" + xcProjDir);
  77. xout.EndElement();
  78. xout.EndElement(); // BuildActionEntry
  79. xout.EndElement(); // BuildActionEntries
  80. xout.EndElement(); // BuildAction
  81. }
  82. void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
  83. std::string configuration)
  84. {
  85. xout.StartElement("TestAction");
  86. xout.BreakAttributes();
  87. xout.Attribute("buildConfiguration", configuration);
  88. xout.Attribute("selectedDebuggerIdentifier",
  89. "Xcode.DebuggerFoundation.Debugger.LLDB");
  90. xout.Attribute("selectedLauncherIdentifier",
  91. "Xcode.DebuggerFoundation.Launcher.LLDB");
  92. xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES");
  93. xout.StartElement("Testables");
  94. xout.EndElement();
  95. xout.StartElement("AdditionalOptions");
  96. xout.EndElement();
  97. xout.EndElement(); // TestAction
  98. }
  99. void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
  100. std::string configuration,
  101. const std::string& xcProjDir)
  102. {
  103. xout.StartElement("LaunchAction");
  104. xout.BreakAttributes();
  105. xout.Attribute("buildConfiguration", configuration);
  106. xout.Attribute("selectedDebuggerIdentifier",
  107. "Xcode.DebuggerFoundation.Debugger.LLDB");
  108. xout.Attribute("selectedLauncherIdentifier",
  109. "Xcode.DebuggerFoundation.Launcher.LLDB");
  110. xout.Attribute("launchStyle", "0");
  111. xout.Attribute("useCustomWorkingDirectory", "NO");
  112. xout.Attribute("ignoresPersistentStateOnLaunch", "NO");
  113. xout.Attribute("debugDocumentVersioning", "YES");
  114. xout.Attribute("debugServiceExtension", "internal");
  115. xout.Attribute("allowLocationSimulation", "YES");
  116. xout.StartElement("MacroExpansion");
  117. xout.StartElement("BuildableReference");
  118. xout.BreakAttributes();
  119. xout.Attribute("BuildableIdentifier", "primary");
  120. xout.Attribute("BlueprintIdentifier", this->TargetId);
  121. xout.Attribute("BuildableName", this->TargetName);
  122. xout.Attribute("BlueprintName", this->TargetName);
  123. xout.Attribute("ReferencedContainer", "container:" + xcProjDir);
  124. xout.EndElement();
  125. xout.EndElement(); // MacroExpansion
  126. xout.StartElement("AdditionalOptions");
  127. xout.EndElement();
  128. xout.EndElement(); // LaunchAction
  129. }
  130. void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout,
  131. std::string configuration)
  132. {
  133. xout.StartElement("ProfileAction");
  134. xout.BreakAttributes();
  135. xout.Attribute("buildConfiguration", configuration);
  136. xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES");
  137. xout.Attribute("savedToolIdentifier", "");
  138. xout.Attribute("useCustomWorkingDirectory", "NO");
  139. xout.Attribute("debugDocumentVersioning", "YES");
  140. xout.EndElement();
  141. }
  142. void cmXCodeScheme::WriteAnalyzeAction(cmXMLWriter& xout,
  143. std::string configuration)
  144. {
  145. xout.StartElement("AnalyzeAction");
  146. xout.BreakAttributes();
  147. xout.Attribute("buildConfiguration", configuration);
  148. xout.EndElement();
  149. }
  150. void cmXCodeScheme::WriteArchiveAction(cmXMLWriter& xout,
  151. std::string configuration)
  152. {
  153. xout.StartElement("ArchiveAction");
  154. xout.BreakAttributes();
  155. xout.Attribute("buildConfiguration", configuration);
  156. xout.Attribute("revealArchiveInOrganizer", "YES");
  157. xout.EndElement();
  158. }
  159. std::string cmXCodeScheme::WriteVersionString()
  160. {
  161. std::ostringstream v;
  162. v << std::setfill('0') << std::setw(4) << this->XcodeVersion * 10;
  163. return v.str();
  164. }
  165. std::string cmXCodeScheme::FindConfiguration(const std::string& name)
  166. {
  167. // Try to find the desired configuration by name,
  168. // and if it's not found return first from the list
  169. //
  170. if (std::find(this->ConfigList.begin(), this->ConfigList.end(), name) ==
  171. this->ConfigList.end() &&
  172. this->ConfigList.size() > 0)
  173. return this->ConfigList[0];
  174. return name;
  175. }