cmXCodeObject.h 4.5 KB

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