cmXCodeObject.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <algorithm>
  6. #include <iosfwd>
  7. #include <map>
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11. #include <cmext/algorithm>
  12. class cmGeneratorTarget;
  13. class cmXCodeObject
  14. {
  15. public:
  16. enum Type
  17. {
  18. OBJECT_LIST,
  19. STRING,
  20. ATTRIBUTE_GROUP,
  21. OBJECT_REF,
  22. OBJECT
  23. };
  24. enum PBXType
  25. {
  26. PBXGroup,
  27. PBXBuildStyle,
  28. PBXProject,
  29. PBXHeadersBuildPhase,
  30. PBXSourcesBuildPhase,
  31. PBXFrameworksBuildPhase,
  32. PBXNativeTarget,
  33. PBXFileReference,
  34. PBXBuildFile,
  35. PBXContainerItemProxy,
  36. PBXTargetDependency,
  37. PBXShellScriptBuildPhase,
  38. PBXResourcesBuildPhase,
  39. PBXApplicationReference,
  40. PBXExecutableFileReference,
  41. PBXLibraryReference,
  42. PBXToolTarget,
  43. PBXLibraryTarget,
  44. PBXAggregateTarget,
  45. XCBuildConfiguration,
  46. XCConfigurationList,
  47. PBXCopyFilesBuildPhase,
  48. None
  49. };
  50. class StringVec : public std::vector<std::string>
  51. {
  52. };
  53. static const char* PBXTypeNames[];
  54. virtual ~cmXCodeObject();
  55. cmXCodeObject(PBXType ptype, Type type, std::string id);
  56. Type GetType() const { return this->TypeValue; }
  57. PBXType GetIsA() const { return this->IsA; }
  58. bool IsEmpty() const;
  59. void SetString(const std::string& s);
  60. const std::string& GetString() const { return this->String; }
  61. void AddAttribute(const std::string& name, cmXCodeObject* value)
  62. {
  63. this->ObjectAttributes[name] = value;
  64. }
  65. void AddAttributeIfNotEmpty(const std::string& name, cmXCodeObject* value)
  66. {
  67. if (value && !value->IsEmpty()) {
  68. AddAttribute(name, value);
  69. }
  70. }
  71. void SetObject(cmXCodeObject* value) { this->Object = value; }
  72. cmXCodeObject* GetObject() { return this->Object; }
  73. void AddObject(cmXCodeObject* value) { this->List.push_back(value); }
  74. void PrependObject(cmXCodeObject* value)
  75. {
  76. this->List.insert(this->List.begin(), value);
  77. }
  78. bool HasObject(cmXCodeObject* o) const
  79. {
  80. return cm::contains(this->List, o);
  81. }
  82. void AddUniqueObject(cmXCodeObject* value)
  83. {
  84. if (!cm::contains(this->List, value)) {
  85. this->List.push_back(value);
  86. }
  87. }
  88. static void Indent(int level, std::ostream& out);
  89. void Print(std::ostream& out);
  90. void PrintAttribute(std::ostream& out, int level,
  91. const std::string& separator, int factor,
  92. const std::string& name, const cmXCodeObject* object,
  93. const cmXCodeObject* parent);
  94. virtual void PrintComment(std::ostream&) {}
  95. static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out);
  96. const std::string& GetId() const { return this->Id; }
  97. void SetId(const std::string& id) { this->Id = id; }
  98. cmGeneratorTarget* GetTarget() const { return this->Target; }
  99. void SetTarget(cmGeneratorTarget* t) { this->Target = t; }
  100. const std::string& GetComment() const { return this->Comment; }
  101. bool HasComment() const { return (!this->Comment.empty()); }
  102. cmXCodeObject* GetAttribute(const char* name) const
  103. {
  104. auto const i = this->ObjectAttributes.find(name);
  105. if (i != this->ObjectAttributes.end()) {
  106. return i->second;
  107. }
  108. return nullptr;
  109. }
  110. // search the attribute list for an object of the specified type
  111. cmXCodeObject* GetObject(cmXCodeObject::PBXType t) const
  112. {
  113. for (auto o : this->List) {
  114. if (o->IsA == t) {
  115. return o;
  116. }
  117. }
  118. return nullptr;
  119. }
  120. void CopyAttributes(cmXCodeObject*);
  121. void AddDependLibrary(const std::string& configName, const std::string& l)
  122. {
  123. this->DependLibraries[configName].push_back(l);
  124. }
  125. std::map<std::string, StringVec> const& GetDependLibraries() const
  126. {
  127. return this->DependLibraries;
  128. }
  129. void AddDependTarget(const std::string& configName, const std::string& tName)
  130. {
  131. this->DependTargets[configName].push_back(tName);
  132. }
  133. std::map<std::string, StringVec> const& GetDependTargets() const
  134. {
  135. return this->DependTargets;
  136. }
  137. std::vector<cmXCodeObject*> const& GetObjectList() const
  138. {
  139. return this->List;
  140. }
  141. void SetComment(const std::string& c) { this->Comment = c; }
  142. static void PrintString(std::ostream& os, const std::string& String);
  143. protected:
  144. void PrintString(std::ostream& os) const;
  145. cmGeneratorTarget* Target;
  146. Type TypeValue;
  147. std::string Id;
  148. PBXType IsA;
  149. int Version;
  150. std::string Comment;
  151. std::string String;
  152. cmXCodeObject* Object;
  153. std::vector<cmXCodeObject*> List;
  154. std::map<std::string, StringVec> DependLibraries;
  155. std::map<std::string, StringVec> DependTargets;
  156. std::map<std::string, cmXCodeObject*> ObjectAttributes;
  157. };