You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
7.0 KiB

  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmXCodeObject.h"
  14. #include "cmSystemTools.h"
  15. //----------------------------------------------------------------------------
  16. const char* cmXCodeObject::PBXTypeNames[] = {
  17. "PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
  18. "PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
  19. "PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
  20. "PBXTargetDependency", "PBXShellScriptBuildPhase",
  21. "PBXResourcesBuildPhase", "PBXApplicationReference",
  22. "PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
  23. "PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
  24. "XCConfigurationList",
  25. "PBXCopyFilesBuildPhase",
  26. "None"
  27. };
  28. //----------------------------------------------------------------------------
  29. cmXCodeObject::~cmXCodeObject()
  30. {
  31. this->Version = 15;
  32. }
  33. //----------------------------------------------------------------------------
  34. cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
  35. {
  36. this->Version = 15;
  37. this->PBXTargetDependencyValue = 0;
  38. this->Target = 0;
  39. this->Object =0;
  40. this->IsA = ptype;
  41. if(type == OBJECT)
  42. {
  43. cmOStringStream str;
  44. str << (void*)this;
  45. str << (void*)this;
  46. str << (void*)this;
  47. this->Id = str.str();
  48. }
  49. else
  50. {
  51. this->Id =
  52. "Temporary cmake object, should not be refered to in xcode file";
  53. }
  54. cmSystemTools::ReplaceString(this->Id, "0x", "");
  55. this->Id = cmSystemTools::UpperCase(this->Id);
  56. if(this->Id.size() < 24)
  57. {
  58. int diff = 24 - this->Id.size();
  59. for(int i =0; i < diff; ++i)
  60. {
  61. this->Id += "0";
  62. }
  63. }
  64. this->TypeValue = type;
  65. if(this->TypeValue == OBJECT)
  66. {
  67. this->AddAttribute("isa", 0);
  68. }
  69. }
  70. //----------------------------------------------------------------------------
  71. void cmXCodeObject::Indent(int level, std::ostream& out)
  72. {
  73. while(level)
  74. {
  75. out << " ";
  76. level--;
  77. }
  78. }
  79. //----------------------------------------------------------------------------
  80. void cmXCodeObject::Print(std::ostream& out)
  81. {
  82. std::string separator = "\n";
  83. int indentFactor = 1;
  84. if(this->Version > 15
  85. && (this->IsA == PBXFileReference || this->IsA == PBXBuildFile))
  86. {
  87. separator = " ";
  88. indentFactor = 0;
  89. }
  90. cmXCodeObject::Indent(2*indentFactor, out);
  91. out << this->Id << " ";
  92. if(!(this->IsA == PBXGroup && this->Comment.size() == 0))
  93. {
  94. this->PrintComment(out);
  95. }
  96. out << " = {";
  97. if(separator == "\n")
  98. {
  99. out << separator;
  100. }
  101. std::map<cmStdString, cmXCodeObject*>::iterator i;
  102. cmXCodeObject::Indent(3*indentFactor, out);
  103. out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator;
  104. for(i = this->ObjectAttributes.begin();
  105. i != this->ObjectAttributes.end(); ++i)
  106. {
  107. cmXCodeObject* object = i->second;
  108. if(i->first != "isa")
  109. {
  110. cmXCodeObject::Indent(3*indentFactor, out);
  111. }
  112. else
  113. {
  114. continue;
  115. }
  116. if(object->TypeValue == OBJECT_LIST)
  117. {
  118. out << i->first << " = (" << separator;
  119. for(unsigned int k = 0; k < i->second->List.size(); k++)
  120. {
  121. cmXCodeObject::Indent(4*indentFactor, out);
  122. out << i->second->List[k]->Id << " ";
  123. i->second->List[k]->PrintComment(out);
  124. out << "," << separator;
  125. }
  126. cmXCodeObject::Indent(3*indentFactor, out);
  127. out << ");" << separator;
  128. }
  129. else if(object->TypeValue == ATTRIBUTE_GROUP)
  130. {
  131. std::map<cmStdString, cmXCodeObject*>::iterator j;
  132. out << i->first << " = {" << separator;
  133. for(j = object->ObjectAttributes.begin(); j !=
  134. object->ObjectAttributes.end(); ++j)
  135. {
  136. cmXCodeObject::Indent(4 *indentFactor, out);
  137. if(j->second->TypeValue == STRING)
  138. {
  139. out << j->first << " = " << j->second->String << ";";
  140. }
  141. else if(j->second->TypeValue == OBJECT_LIST)
  142. {
  143. out << j->first << " = (";
  144. for(unsigned int k = 0; k < j->second->List.size(); k++)
  145. {
  146. if(j->second->List[k]->TypeValue == STRING)
  147. {
  148. out << j->second->List[k]->String << ", ";
  149. }
  150. else
  151. {
  152. out << "List_" << k << "_TypeValue_IS_NOT_STRING, ";
  153. }
  154. }
  155. out << ");";
  156. }
  157. else
  158. {
  159. out << j->first << " = error_unexpected_TypeValue_" <<
  160. j->second->TypeValue << ";";
  161. }
  162. out << separator;
  163. }
  164. cmXCodeObject::Indent(3 *indentFactor, out);
  165. out << "};" << separator;
  166. }
  167. else if(object->TypeValue == OBJECT_REF)
  168. {
  169. out << i->first << " = " << object->Object->Id;
  170. if(object->Object->HasComment() && i->first != "remoteGlobalIDString")
  171. {
  172. out << " ";
  173. object->Object->PrintComment(out);
  174. }
  175. out << ";" << separator;
  176. }
  177. else if(object->TypeValue == STRING)
  178. {
  179. out << i->first << " = " << object->String << ";" << separator;
  180. }
  181. else
  182. {
  183. out << "what is this?? " << i->first << "\n";
  184. }
  185. }
  186. cmXCodeObject::Indent(2*indentFactor, out);
  187. out << "};\n";
  188. }
  189. //----------------------------------------------------------------------------
  190. void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
  191. std::ostream& out)
  192. {
  193. cmXCodeObject::Indent(1, out);
  194. out << "objects = {\n";
  195. for(unsigned int i = 0; i < objs.size(); ++i)
  196. {
  197. if(objs[i]->TypeValue == OBJECT)
  198. {
  199. objs[i]->Print(out);
  200. }
  201. }
  202. cmXCodeObject::Indent(1, out);
  203. out << "};\n";
  204. }
  205. //----------------------------------------------------------------------------
  206. void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
  207. {
  208. this->ObjectAttributes = copy->ObjectAttributes;
  209. this->List = copy->List;
  210. this->String = copy->String;
  211. this->Object = copy->Object;
  212. }
  213. //----------------------------------------------------------------------------
  214. void cmXCodeObject::SetString(const char* s)
  215. {
  216. std::string ss = s;
  217. if(ss.size() == 0)
  218. {
  219. this->String = "\"\"";
  220. return;
  221. }
  222. // escape quotes
  223. cmSystemTools::ReplaceString(ss, "\"", "\\\"");
  224. bool needQuote = false;
  225. this->String = "";
  226. if(ss.find_first_of(" <>.+-=@") != ss.npos)
  227. {
  228. needQuote = true;
  229. }
  230. if(needQuote)
  231. {
  232. this->String = "\"";
  233. }
  234. this->String += ss;
  235. if(needQuote)
  236. {
  237. this->String += "\"";
  238. }
  239. }