cmXCodeObject.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 cmTarget;
  14. class cmXCodeObject
  15. {
  16. public:
  17. enum Type { OBJECT_LIST, STRING, ATTRIBUTE_GROUP, OBJECT_REF, OBJECT };
  18. enum PBXType { PBXGroup, PBXBuildStyle, PBXProject, PBXHeadersBuildPhase,
  19. PBXSourcesBuildPhase, PBXFrameworksBuildPhase,
  20. PBXNativeTarget, PBXFileReference, PBXBuildFile,
  21. PBXContainerItemProxy, PBXTargetDependency,
  22. PBXShellScriptBuildPhase, PBXResourcesBuildPhase,
  23. PBXApplicationReference, PBXExecutableFileReference,
  24. PBXLibraryReference, PBXToolTarget, PBXLibraryTarget,
  25. PBXAggregateTarget,XCBuildConfiguration,XCConfigurationList,
  26. PBXCopyFilesBuildPhase,
  27. None
  28. };
  29. class StringVec: public std::vector<cmStdString> {};
  30. static const char* PBXTypeNames[];
  31. virtual ~cmXCodeObject();
  32. cmXCodeObject(PBXType ptype, Type type);
  33. Type GetType() { return this->TypeValue;}
  34. PBXType GetIsA() { return this->IsA;}
  35. void SetString(const char* s);
  36. const char* GetString()
  37. {
  38. return this->String.c_str();
  39. }
  40. void AddAttribute(const char* name, cmXCodeObject* value)
  41. {
  42. this->ObjectAttributes[name] = value;
  43. }
  44. void SetObject(cmXCodeObject* value)
  45. {
  46. this->Object = value;
  47. }
  48. cmXCodeObject* GetObject()
  49. {
  50. return this->Object;
  51. }
  52. void AddObject(cmXCodeObject* value)
  53. {
  54. this->List.push_back(value);
  55. }
  56. bool HasObject(cmXCodeObject* o)
  57. {
  58. return !(std::find(this->List.begin(), this->List.end(), o)
  59. == this->List.end());
  60. }
  61. void AddUniqueObject(cmXCodeObject* value)
  62. {
  63. if(std::find(this->List.begin(), this->List.end(), value)
  64. == this->List.end())
  65. {
  66. this->List.push_back(value);
  67. }
  68. }
  69. static void Indent(int level, std::ostream& out);
  70. void Print(std::ostream& out);
  71. virtual void PrintComment(std::ostream&) {};
  72. static void PrintList(std::vector<cmXCodeObject*> const&,
  73. std::ostream& out);
  74. const char* GetId()
  75. {
  76. return this->Id.c_str();
  77. }
  78. void SetId(const char* id)
  79. {
  80. this->Id = id;
  81. }
  82. cmTarget* GetTarget()
  83. {
  84. return this->Target;
  85. }
  86. void SetTarget(cmTarget* t)
  87. {
  88. this->Target = t;
  89. }
  90. const char* GetComment() {return this->Comment.c_str();}
  91. bool HasComment() { return (this->Comment.size() != 0);}
  92. cmXCodeObject* GetObject(const char* name)
  93. {
  94. if(this->ObjectAttributes.count(name))
  95. {
  96. return this->ObjectAttributes[name];
  97. }
  98. return 0;
  99. }
  100. // serach the attribute list for an object of the specified type
  101. cmXCodeObject* GetObject(cmXCodeObject::PBXType t)
  102. {
  103. for(std::vector<cmXCodeObject*>::iterator i = this->List.begin();
  104. i != this->List.end(); ++i)
  105. {
  106. cmXCodeObject* o = *i;
  107. if(o->IsA == t)
  108. {
  109. return o;
  110. }
  111. }
  112. return 0;
  113. }
  114. cmXCodeObject* GetPBXTargetDependency()
  115. {
  116. return this->PBXTargetDependencyValue;
  117. }
  118. void SetPBXTargetDependency(cmXCodeObject* d)
  119. {
  120. this->PBXTargetDependencyValue = d;
  121. }
  122. void CopyAttributes(cmXCodeObject* );
  123. void AddDependLibrary(const char* configName,
  124. const char* l)
  125. {
  126. if(!configName)
  127. {
  128. configName = "";
  129. }
  130. this->DependLibraries[configName].push_back(l);
  131. }
  132. std::map<cmStdString, StringVec> const& GetDependLibraries()
  133. {
  134. return this->DependLibraries;
  135. }
  136. void AddDependTarget(const char* configName,
  137. const char* tName)
  138. {
  139. if(!configName)
  140. {
  141. configName = "";
  142. }
  143. this->DependTargets[configName].push_back(tName);
  144. }
  145. std::map<cmStdString, StringVec> const& GetDependTargets()
  146. {
  147. return this->DependTargets;
  148. }
  149. std::vector<cmXCodeObject*> const& GetObjectList() { return this->List;}
  150. void SetComment(const char* c) { this->Comment = c;}
  151. static void PrintString(std::ostream& os,cmStdString String);
  152. protected:
  153. void PrintString(std::ostream& os) const;
  154. cmTarget* Target;
  155. Type TypeValue;
  156. cmStdString Id;
  157. PBXType IsA;
  158. int Version;
  159. cmStdString Comment;
  160. cmStdString String;
  161. cmXCodeObject* Object;
  162. cmXCodeObject* PBXTargetDependencyValue;
  163. std::vector<cmXCodeObject*> List;
  164. std::map<cmStdString, StringVec> DependLibraries;
  165. std::map<cmStdString, StringVec> DependTargets;
  166. std::map<cmStdString, cmXCodeObject*> ObjectAttributes;
  167. };
  168. #endif