cmXCodeObject.cxx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #include "cmXCodeObject.h"
  2. #include "cmSystemTools.h"
  3. const char* cmXCodeObject::PBXTypeNames[] = {
  4. "PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
  5. "PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
  6. "PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
  7. "PBXTargetDependency", "PBXShellScriptBuildPhase",
  8. "PBXResourcesBuildPhase", "PBXApplicationReference",
  9. "PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
  10. "PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
  11. "XCConfigurationList",
  12. "None"
  13. };
  14. cmXCodeObject::~cmXCodeObject()
  15. {
  16. this->Version = 15;
  17. }
  18. //----------------------------------------------------------------------------
  19. cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
  20. {
  21. this->Version = 15;
  22. this->PBXTargetDependencyValue = 0;
  23. this->Target = 0;
  24. this->Object =0;
  25. this->IsA = ptype;
  26. if(type == OBJECT)
  27. {
  28. cmOStringStream str;
  29. str << (void*)this;
  30. str << (void*)this;
  31. str << (void*)this;
  32. this->Id = str.str();
  33. }
  34. else
  35. {
  36. this->Id = "Temporary cmake object, should not be refered to in xcode file";
  37. }
  38. cmSystemTools::ReplaceString(this->Id, "0x", "");
  39. this->Id = cmSystemTools::UpperCase(this->Id);
  40. if(this->Id.size() < 24)
  41. {
  42. int diff = 24 - this->Id.size();
  43. for(int i =0; i < diff; ++i)
  44. {
  45. this->Id += "0";
  46. }
  47. }
  48. this->TypeValue = type;
  49. if(this->TypeValue == OBJECT)
  50. {
  51. this->AddAttribute("isa", 0);
  52. }
  53. }
  54. //----------------------------------------------------------------------------
  55. void cmXCodeObject::Indent(int level, std::ostream& out)
  56. {
  57. while(level)
  58. {
  59. out << " ";
  60. level--;
  61. }
  62. }
  63. //----------------------------------------------------------------------------
  64. void cmXCodeObject::Print(std::ostream& out)
  65. {
  66. std::string separator = "\n";
  67. int indentFactor = 1;
  68. if(this->Version > 15 && (this->IsA == PBXFileReference || this->IsA == PBXBuildFile))
  69. {
  70. separator = " ";
  71. indentFactor = 0;
  72. }
  73. cmXCodeObject::Indent(2*indentFactor, out);
  74. out << this->Id << " ";
  75. if(!(this->IsA == PBXGroup && this->Comment.size() == 0))
  76. {
  77. this->PrintComment(out);
  78. }
  79. out << " = {";
  80. if(separator == "\n")
  81. {
  82. out << separator;
  83. }
  84. std::map<cmStdString, cmXCodeObject*>::iterator i;
  85. cmXCodeObject::Indent(3*indentFactor, out);
  86. out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator;
  87. for(i = this->ObjectAttributes.begin(); i != this->ObjectAttributes.end(); ++i)
  88. {
  89. cmXCodeObject* object = i->second;
  90. if(i->first != "isa")
  91. {
  92. cmXCodeObject::Indent(3*indentFactor, out);
  93. }
  94. else
  95. {
  96. continue;
  97. }
  98. if(object->TypeValue == OBJECT_LIST)
  99. {
  100. out << i->first << " = (" << separator;
  101. for(unsigned int k = 0; k < i->second->List.size(); k++)
  102. {
  103. cmXCodeObject::Indent(4*indentFactor, out);
  104. out << i->second->List[k]->Id << " ";
  105. i->second->List[k]->PrintComment(out);
  106. out << "," << separator;
  107. }
  108. cmXCodeObject::Indent(3*indentFactor, out);
  109. out << ");" << separator;
  110. }
  111. else if(object->TypeValue == ATTRIBUTE_GROUP)
  112. {
  113. std::map<cmStdString, cmXCodeObject*>::iterator j;
  114. out << i->first << " = {" << separator;
  115. for(j = object->ObjectAttributes.begin(); j !=
  116. object->ObjectAttributes.end(); ++j)
  117. {
  118. cmXCodeObject::Indent(4 *indentFactor, out);
  119. out << j->first << " = " << j->second->String << ";";
  120. out << separator;
  121. }
  122. cmXCodeObject::Indent(3 *indentFactor, out);
  123. out << "};" << separator;
  124. }
  125. else if(object->TypeValue == OBJECT_REF)
  126. {
  127. out << i->first << " = " << object->Object->Id;
  128. if(object->Object->HasComment() && i->first != "remoteGlobalIDString")
  129. {
  130. out << " ";
  131. object->Object->PrintComment(out);
  132. }
  133. out << ";" << separator;
  134. }
  135. else if(object->TypeValue == STRING)
  136. {
  137. out << i->first << " = " << object->String << ";" << separator;
  138. }
  139. else
  140. {
  141. out << "what is this?? " << i->first << "\n";
  142. }
  143. }
  144. cmXCodeObject::Indent(2*indentFactor, out);
  145. out << "};\n";
  146. }
  147. //----------------------------------------------------------------------------
  148. void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
  149. std::ostream& out)
  150. {
  151. cmXCodeObject::Indent(1, out);
  152. out << "objects = {\n";
  153. for(unsigned int i = 0; i < objs.size(); ++i)
  154. {
  155. if(objs[i]->TypeValue == OBJECT)
  156. {
  157. objs[i]->Print(out);
  158. }
  159. }
  160. cmXCodeObject::Indent(1, out);
  161. out << "};\n";
  162. }
  163. void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
  164. {
  165. this->ObjectAttributes = copy->ObjectAttributes;
  166. this->List = copy->List;
  167. this->String = copy->String;
  168. this->Object = copy->Object;
  169. }
  170. void cmXCodeObject::SetString(const char* s)
  171. {
  172. std::string ss = s;
  173. if(ss.size() == 0)
  174. {
  175. this->String = "\"\"";
  176. return;
  177. }
  178. bool needQuote = false;
  179. this->String = "";
  180. if(ss.find_first_of(" <>.+-=") != ss.npos)
  181. {
  182. needQuote = true;
  183. }
  184. if(needQuote)
  185. {
  186. this->String = "\"";
  187. }
  188. this->String += s;
  189. if(needQuote)
  190. {
  191. this->String += "\"";
  192. }
  193. }