cmXCodeScheme.cxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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.SetIndentationElement(std::string(3, ' '));
  43. xout.StartDocument();
  44. xout.StartElement("Scheme");
  45. xout.BreakAttributes();
  46. xout.Attribute("LastUpgradeVersion", WriteVersionString());
  47. xout.Attribute("version", "1.3");
  48. WriteBuildAction(xout, xcProjDir);
  49. WriteTestAction(xout, FindConfiguration("Debug"));
  50. WriteLaunchAction(xout, FindConfiguration("Debug"), xcProjDir);
  51. WriteProfileAction(xout, FindConfiguration("Release"));
  52. WriteAnalyzeAction(xout, FindConfiguration("Debug"));
  53. WriteArchiveAction(xout, FindConfiguration("Release"));
  54. xout.EndElement();
  55. }
  56. void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
  57. const std::string& xcProjDir)
  58. {
  59. xout.StartElement("BuildAction");
  60. xout.BreakAttributes();
  61. xout.Attribute("parallelizeBuildables", "YES");
  62. xout.Attribute("buildImplicitDependencies", "YES");
  63. xout.StartElement("BuildActionEntries");
  64. xout.StartElement("BuildActionEntry");
  65. xout.BreakAttributes();
  66. xout.Attribute("buildForTesting", "YES");
  67. xout.Attribute("buildForRunning", "YES");
  68. xout.Attribute("buildForProfiling", "YES");
  69. xout.Attribute("buildForArchiving", "YES");
  70. xout.Attribute("buildForAnalyzing", "YES");
  71. xout.StartElement("BuildableReference");
  72. xout.BreakAttributes();
  73. xout.Attribute("BuildableIdentifier", "primary");
  74. xout.Attribute("BlueprintIdentifier", this->TargetId);
  75. xout.Attribute("BuildableName", this->TargetName);
  76. xout.Attribute("BlueprintName", this->TargetName);
  77. xout.Attribute("ReferencedContainer", "container:" + xcProjDir);
  78. xout.EndElement();
  79. xout.EndElement(); // BuildActionEntry
  80. xout.EndElement(); // BuildActionEntries
  81. xout.EndElement(); // BuildAction
  82. }
  83. void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
  84. std::string configuration)
  85. {
  86. xout.StartElement("TestAction");
  87. xout.BreakAttributes();
  88. xout.Attribute("buildConfiguration", configuration);
  89. xout.Attribute("selectedDebuggerIdentifier",
  90. "Xcode.DebuggerFoundation.Debugger.LLDB");
  91. xout.Attribute("selectedLauncherIdentifier",
  92. "Xcode.DebuggerFoundation.Launcher.LLDB");
  93. xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES");
  94. xout.StartElement("Testables");
  95. xout.EndElement();
  96. xout.StartElement("AdditionalOptions");
  97. xout.EndElement();
  98. xout.EndElement(); // TestAction
  99. }
  100. void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
  101. std::string configuration,
  102. const std::string& xcProjDir)
  103. {
  104. xout.StartElement("LaunchAction");
  105. xout.BreakAttributes();
  106. xout.Attribute("buildConfiguration", configuration);
  107. xout.Attribute("selectedDebuggerIdentifier",
  108. "Xcode.DebuggerFoundation.Debugger.LLDB");
  109. xout.Attribute("selectedLauncherIdentifier",
  110. "Xcode.DebuggerFoundation.Launcher.LLDB");
  111. xout.Attribute("launchStyle", "0");
  112. xout.Attribute("useCustomWorkingDirectory", "NO");
  113. xout.Attribute("ignoresPersistentStateOnLaunch", "NO");
  114. xout.Attribute("debugDocumentVersioning", "YES");
  115. xout.Attribute("debugServiceExtension", "internal");
  116. xout.Attribute("allowLocationSimulation", "YES");
  117. xout.StartElement("MacroExpansion");
  118. xout.StartElement("BuildableReference");
  119. xout.BreakAttributes();
  120. xout.Attribute("BuildableIdentifier", "primary");
  121. xout.Attribute("BlueprintIdentifier", this->TargetId);
  122. xout.Attribute("BuildableName", this->TargetName);
  123. xout.Attribute("BlueprintName", this->TargetName);
  124. xout.Attribute("ReferencedContainer", "container:" + xcProjDir);
  125. xout.EndElement();
  126. xout.EndElement(); // MacroExpansion
  127. xout.StartElement("AdditionalOptions");
  128. xout.EndElement();
  129. xout.EndElement(); // LaunchAction
  130. }
  131. void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout,
  132. std::string configuration)
  133. {
  134. xout.StartElement("ProfileAction");
  135. xout.BreakAttributes();
  136. xout.Attribute("buildConfiguration", configuration);
  137. xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES");
  138. xout.Attribute("savedToolIdentifier", "");
  139. xout.Attribute("useCustomWorkingDirectory", "NO");
  140. xout.Attribute("debugDocumentVersioning", "YES");
  141. xout.EndElement();
  142. }
  143. void cmXCodeScheme::WriteAnalyzeAction(cmXMLWriter& xout,
  144. std::string configuration)
  145. {
  146. xout.StartElement("AnalyzeAction");
  147. xout.BreakAttributes();
  148. xout.Attribute("buildConfiguration", configuration);
  149. xout.EndElement();
  150. }
  151. void cmXCodeScheme::WriteArchiveAction(cmXMLWriter& xout,
  152. std::string configuration)
  153. {
  154. xout.StartElement("ArchiveAction");
  155. xout.BreakAttributes();
  156. xout.Attribute("buildConfiguration", configuration);
  157. xout.Attribute("revealArchiveInOrganizer", "YES");
  158. xout.EndElement();
  159. }
  160. std::string cmXCodeScheme::WriteVersionString()
  161. {
  162. std::ostringstream v;
  163. v << std::setfill('0') << std::setw(4) << this->XcodeVersion * 10;
  164. return v.str();
  165. }
  166. std::string cmXCodeScheme::FindConfiguration(const std::string& name)
  167. {
  168. // Try to find the desired configuration by name,
  169. // and if it's not found return first from the list
  170. //
  171. if (std::find(this->ConfigList.begin(), this->ConfigList.end(), name) ==
  172. this->ConfigList.end() &&
  173. this->ConfigList.size() > 0)
  174. return this->ConfigList[0];
  175. return name;
  176. }