cmXCodeObject.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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", "XCConfigurationList",
  11. "None"
  12. };
  13. cmXCodeObject::~cmXCodeObject()
  14. {
  15. }
  16. //----------------------------------------------------------------------------
  17. cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
  18. {
  19. m_PBXTargetDependency = 0;
  20. m_cmTarget = 0;
  21. m_Object =0;
  22. m_IsA = ptype;
  23. if(type == OBJECT)
  24. {
  25. cmOStringStream str;
  26. str << (void*)this;
  27. str << (void*)this;
  28. str << (void*)this;
  29. m_Id = str.str();
  30. }
  31. else
  32. {
  33. m_Id = "Temporary cmake object, should not be refered to in xcode file";
  34. }
  35. cmSystemTools::ReplaceString(m_Id, "0x", "");
  36. m_Id = cmSystemTools::UpperCase(m_Id);
  37. if(m_Id.size() < 24)
  38. {
  39. int diff = 24 - m_Id.size();
  40. for(int i =0; i < diff; ++i)
  41. {
  42. m_Id += "0";
  43. }
  44. }
  45. m_Type = type;
  46. if(m_Type == OBJECT)
  47. {
  48. this->AddAttribute("isa", 0);
  49. }
  50. }
  51. //----------------------------------------------------------------------------
  52. void cmXCodeObject::Indent(int level, std::ostream& out)
  53. {
  54. while(level)
  55. {
  56. out << " ";
  57. level--;
  58. }
  59. }
  60. //----------------------------------------------------------------------------
  61. void cmXCodeObject::Print(std::ostream& out)
  62. {
  63. cmXCodeObject::Indent(2, out);
  64. out << m_Id << " ";
  65. this->PrintComment(out);
  66. out << " = {\n";
  67. std::map<cmStdString, cmXCodeObject*>::iterator i;
  68. for(i = m_ObjectAttributes.begin(); i != m_ObjectAttributes.end(); ++i)
  69. {
  70. cmXCodeObject* object = i->second;
  71. cmXCodeObject::Indent(3, out);
  72. if(i->first == "isa")
  73. {
  74. out << i->first << " = " << PBXTypeNames[m_IsA] << ";\n";
  75. }
  76. else if(object->m_Type == OBJECT_LIST)
  77. {
  78. out << i->first << " = (\n";
  79. for(unsigned int k = 0; k < i->second->m_List.size(); k++)
  80. {
  81. cmXCodeObject::Indent(4, out);
  82. out << i->second->m_List[k]->m_Id << ",\n";
  83. }
  84. cmXCodeObject::Indent(3, out);
  85. out << ");\n";
  86. }
  87. else if(object->m_Type == ATTRIBUTE_GROUP)
  88. {
  89. std::map<cmStdString, cmXCodeObject*>::iterator j;
  90. out << i->first << " = {\n";
  91. for(j = object->m_ObjectAttributes.begin(); j != object->m_ObjectAttributes.end(); ++j)
  92. {
  93. cmXCodeObject::Indent(4, out);
  94. out << j->first << " = " << j->second->m_String << ";\n";
  95. }
  96. cmXCodeObject::Indent(3, out);
  97. out << "};\n";
  98. }
  99. else if(object->m_Type == OBJECT_REF)
  100. {
  101. out << i->first << " = " << object->m_Object->m_Id << ";\n";
  102. }
  103. else if(object->m_Type == STRING)
  104. {
  105. out << i->first << " = " << object->m_String << ";\n";
  106. }
  107. else
  108. {
  109. out << "what is this?? " << i->first << "\n";
  110. }
  111. }
  112. cmXCodeObject::Indent(2, out);
  113. out << "};\n";
  114. }
  115. //----------------------------------------------------------------------------
  116. void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
  117. std::ostream& out)
  118. {
  119. cmXCodeObject::Indent(1, out);
  120. out << "objects = {\n";
  121. for(unsigned int i = 0; i < objs.size(); ++i)
  122. {
  123. if(objs[i]->m_Type == OBJECT)
  124. {
  125. objs[i]->Print(out);
  126. }
  127. }
  128. cmXCodeObject::Indent(1, out);
  129. out << "};\n";
  130. }
  131. void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
  132. {
  133. this->m_ObjectAttributes = copy->m_ObjectAttributes;
  134. this->m_List = copy->m_List;
  135. this->m_String = copy->m_String;
  136. this->m_Object = copy->m_Object;
  137. }