cmXCodeObject.cxx 5.3 KB

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