cmXCodeScheme.cxx 7.1 KB

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