cmXCodeObject.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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, const int level,
  89. const std::string separator, const 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 0;
  108. }
  109. // search the attribute list for an object of the specified type
  110. cmXCodeObject* GetObject(cmXCodeObject::PBXType t) const
  111. {
  112. for (std::vector<cmXCodeObject*>::const_iterator i = this->List.begin();
  113. i != this->List.end(); ++i) {
  114. cmXCodeObject* o = *i;
  115. if (o->IsA == t) {
  116. return o;
  117. }
  118. }
  119. return 0;
  120. }
  121. void CopyAttributes(cmXCodeObject*);
  122. void AddDependLibrary(const std::string& configName, const std::string& l)
  123. {
  124. this->DependLibraries[configName].push_back(l);
  125. }
  126. std::map<std::string, StringVec> const& GetDependLibraries() const
  127. {
  128. return this->DependLibraries;
  129. }
  130. void AddDependTarget(const std::string& configName, const std::string& tName)
  131. {
  132. this->DependTargets[configName].push_back(tName);
  133. }
  134. std::map<std::string, StringVec> const& GetDependTargets() const
  135. {
  136. return this->DependTargets;
  137. }
  138. std::vector<cmXCodeObject*> const& GetObjectList() const
  139. {
  140. return this->List;
  141. }
  142. void SetComment(const std::string& c) { this->Comment = c; }
  143. static void PrintString(std::ostream& os, std::string String);
  144. protected:
  145. void PrintString(std::ostream& os) const;
  146. cmGeneratorTarget* Target;
  147. Type TypeValue;
  148. std::string Id;
  149. PBXType IsA;
  150. int Version;
  151. std::string Comment;
  152. std::string String;
  153. cmXCodeObject* Object;
  154. std::vector<cmXCodeObject*> List;
  155. std::map<std::string, StringVec> DependLibraries;
  156. std::map<std::string, StringVec> DependTargets;
  157. std::map<std::string, cmXCodeObject*> ObjectAttributes;
  158. };
  159. #endif