cmXCodeObject.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. 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);
  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. bool HasObject(cmXCodeObject* o) const
  75. {
  76. return !(std::find(this->List.begin(), this->List.end(), o) ==
  77. this->List.end());
  78. }
  79. void AddUniqueObject(cmXCodeObject* value)
  80. {
  81. if (std::find(this->List.begin(), this->List.end(), value) ==
  82. this->List.end()) {
  83. this->List.push_back(value);
  84. }
  85. }
  86. static void Indent(int level, std::ostream& out);
  87. void Print(std::ostream& out);
  88. void PrintAttribute(std::ostream& out, int level,
  89. const std::string& separator, int factor,
  90. const std::string& name, const cmXCodeObject* object,
  91. const cmXCodeObject* parent);
  92. virtual void PrintComment(std::ostream&) {}
  93. static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out);
  94. const std::string& GetId() const { return this->Id; }
  95. void SetId(const std::string& id) { this->Id = id; }
  96. cmGeneratorTarget* GetTarget() const { return this->Target; }
  97. void SetTarget(cmGeneratorTarget* t) { this->Target = t; }
  98. const std::string& GetComment() const { return this->Comment; }
  99. bool HasComment() const { return (!this->Comment.empty()); }
  100. cmXCodeObject* GetObject(const char* name) const
  101. {
  102. std::map<std::string, cmXCodeObject*>::const_iterator i =
  103. this->ObjectAttributes.find(name);
  104. if (i != this->ObjectAttributes.end()) {
  105. return i->second;
  106. }
  107. return nullptr;
  108. }
  109. // search the attribute list for an object of the specified type
  110. cmXCodeObject* GetObject(cmXCodeObject::PBXType t) const
  111. {
  112. for (auto o : this->List) {
  113. if (o->IsA == t) {
  114. return o;
  115. }
  116. }
  117. return nullptr;
  118. }
  119. void CopyAttributes(cmXCodeObject*);
  120. void AddDependLibrary(const std::string& configName, const std::string& l)
  121. {
  122. this->DependLibraries[configName].push_back(l);
  123. }
  124. std::map<std::string, StringVec> const& GetDependLibraries() const
  125. {
  126. return this->DependLibraries;
  127. }
  128. void AddDependTarget(const std::string& configName, const std::string& tName)
  129. {
  130. this->DependTargets[configName].push_back(tName);
  131. }
  132. std::map<std::string, StringVec> const& GetDependTargets() const
  133. {
  134. return this->DependTargets;
  135. }
  136. std::vector<cmXCodeObject*> const& GetObjectList() const
  137. {
  138. return this->List;
  139. }
  140. void SetComment(const std::string& c) { this->Comment = c; }
  141. static void PrintString(std::ostream& os, const std::string& String);
  142. protected:
  143. void PrintString(std::ostream& os) const;
  144. cmGeneratorTarget* Target;
  145. Type TypeValue;
  146. std::string Id;
  147. PBXType IsA;
  148. int Version;
  149. std::string Comment;
  150. std::string String;
  151. cmXCodeObject* Object;
  152. std::vector<cmXCodeObject*> List;
  153. std::map<std::string, StringVec> DependLibraries;
  154. std::map<std::string, StringVec> DependTargets;
  155. std::map<std::string, cmXCodeObject*> ObjectAttributes;
  156. };
  157. #endif