cmXCodeObject.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 std::string& 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. void CopyAttributes(cmXCodeObject* );
  115. void AddDependLibrary(const char* configName,
  116. const std::string& l)
  117. {
  118. if(!configName)
  119. {
  120. configName = "";
  121. }
  122. this->DependLibraries[configName].push_back(l);
  123. }
  124. std::map<cmStdString, StringVec> const& GetDependLibraries()
  125. {
  126. return this->DependLibraries;
  127. }
  128. void AddDependTarget(const char* configName,
  129. const std::string& tName)
  130. {
  131. if(!configName)
  132. {
  133. configName = "";
  134. }
  135. this->DependTargets[configName].push_back(tName);
  136. }
  137. std::map<cmStdString, StringVec> const& GetDependTargets()
  138. {
  139. return this->DependTargets;
  140. }
  141. std::vector<cmXCodeObject*> const& GetObjectList() { return this->List;}
  142. void SetComment(const char* c) { this->Comment = c;}
  143. static void PrintString(std::ostream& os,cmStdString String);
  144. protected:
  145. void PrintString(std::ostream& os) const;
  146. cmTarget* Target;
  147. Type TypeValue;
  148. cmStdString Id;
  149. PBXType IsA;
  150. int Version;
  151. cmStdString Comment;
  152. cmStdString String;
  153. cmXCodeObject* Object;
  154. std::vector<cmXCodeObject*> List;
  155. std::map<cmStdString, StringVec> DependLibraries;
  156. std::map<cmStdString, StringVec> DependTargets;
  157. std::map<cmStdString, cmXCodeObject*> ObjectAttributes;
  158. };
  159. #endif