cmXCodeObject.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmXCodeObject_h
  11. #define cmXCodeObject_h
  12. #include "cmStandardIncludes.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. 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 SetObject(cmXCodeObject* value) { this->Object = value; }
  66. cmXCodeObject* GetObject() { return this->Object; }
  67. void AddObject(cmXCodeObject* value) { this->List.push_back(value); }
  68. bool HasObject(cmXCodeObject* o) const
  69. {
  70. return !(std::find(this->List.begin(), this->List.end(), o) ==
  71. this->List.end());
  72. }
  73. void AddUniqueObject(cmXCodeObject* value)
  74. {
  75. if (std::find(this->List.begin(), this->List.end(), value) ==
  76. this->List.end()) {
  77. this->List.push_back(value);
  78. }
  79. }
  80. static void Indent(int level, std::ostream& out);
  81. void Print(std::ostream& out);
  82. void PrintAttribute(std::ostream& out, const int level,
  83. const std::string separator, const int factor,
  84. const std::string& name, const cmXCodeObject* object,
  85. const cmXCodeObject* parent);
  86. virtual void PrintComment(std::ostream&) {}
  87. static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out);
  88. const std::string& GetId() const { return this->Id; }
  89. void SetId(const std::string& id) { this->Id = id; }
  90. cmGeneratorTarget* GetTarget() const { return this->Target; }
  91. void SetTarget(cmGeneratorTarget* t) { this->Target = t; }
  92. const std::string& GetComment() const { return this->Comment; }
  93. bool HasComment() const { return (!this->Comment.empty()); }
  94. cmXCodeObject* GetObject(const char* name) const
  95. {
  96. std::map<std::string, cmXCodeObject*>::const_iterator i =
  97. this->ObjectAttributes.find(name);
  98. if (i != this->ObjectAttributes.end()) {
  99. return i->second;
  100. }
  101. return 0;
  102. }
  103. // search the attribute list for an object of the specified type
  104. cmXCodeObject* GetObject(cmXCodeObject::PBXType t) const
  105. {
  106. for (std::vector<cmXCodeObject*>::const_iterator i = this->List.begin();
  107. i != this->List.end(); ++i) {
  108. cmXCodeObject* o = *i;
  109. if (o->IsA == t) {
  110. return o;
  111. }
  112. }
  113. return 0;
  114. }
  115. void CopyAttributes(cmXCodeObject*);
  116. void AddDependLibrary(const std::string& configName, const std::string& l)
  117. {
  118. this->DependLibraries[configName].push_back(l);
  119. }
  120. std::map<std::string, StringVec> const& GetDependLibraries() const
  121. {
  122. return this->DependLibraries;
  123. }
  124. void AddDependTarget(const std::string& configName, const std::string& tName)
  125. {
  126. this->DependTargets[configName].push_back(tName);
  127. }
  128. std::map<std::string, StringVec> const& GetDependTargets() const
  129. {
  130. return this->DependTargets;
  131. }
  132. std::vector<cmXCodeObject*> const& GetObjectList() const
  133. {
  134. return this->List;
  135. }
  136. void SetComment(const std::string& c) { this->Comment = c; }
  137. static void PrintString(std::ostream& os, std::string String);
  138. protected:
  139. void PrintString(std::ostream& os) const;
  140. cmGeneratorTarget* Target;
  141. Type TypeValue;
  142. std::string Id;
  143. PBXType IsA;
  144. int Version;
  145. std::string Comment;
  146. std::string String;
  147. cmXCodeObject* Object;
  148. std::vector<cmXCodeObject*> List;
  149. std::map<std::string, StringVec> DependLibraries;
  150. std::map<std::string, StringVec> DependTargets;
  151. std::map<std::string, cmXCodeObject*> ObjectAttributes;
  152. };
  153. #endif