1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmXCodeObject.h"
13 #include "cmSystemTools.h"
15 #include <CoreFoundation/CoreFoundation.h> // CFUUIDCreate
17 //----------------------------------------------------------------------------
18 const char* cmXCodeObject::PBXTypeNames[] = {
19 "PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
20 "PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
21 "PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
22 "PBXTargetDependency", "PBXShellScriptBuildPhase",
23 "PBXResourcesBuildPhase", "PBXApplicationReference",
24 "PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
25 "PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
26 "XCConfigurationList",
27 "PBXCopyFilesBuildPhase",
31 //----------------------------------------------------------------------------
32 cmXCodeObject::~cmXCodeObject()
37 //----------------------------------------------------------------------------
38 cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
48 // Set the Id of an Xcode object to a unique string for each instance.
49 // However the Xcode user file references certain Ids: for those cases,
50 // override the generated Id using SetId().
53 CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
54 CFStringRef s = CFUUIDCreateString(kCFAllocatorDefault, uuid);
55 CFStringGetCString(s, cUuid, sizeof(cUuid), kCFStringEncodingUTF8);
63 "Temporary cmake object, should not be referred to in Xcode file";
66 cmSystemTools::ReplaceString(this->Id, "-", "");
67 if(this->Id.size() > 24)
69 this->Id = this->Id.substr(0, 24);
72 this->TypeValue = type;
73 if(this->TypeValue == OBJECT)
75 this->AddAttribute("isa", 0);
79 //----------------------------------------------------------------------------
80 void cmXCodeObject::Indent(int level, std::ostream& out)
89 //----------------------------------------------------------------------------
90 void cmXCodeObject::Print(std::ostream& out)
92 std::string separator = "\n";
95 && (this->IsA == PBXFileReference || this->IsA == PBXBuildFile))
100 cmXCodeObject::Indent(2*indentFactor, out);
101 out << this->Id << " ";
102 if(!(this->IsA == PBXGroup && this->Comment.size() == 0))
104 this->PrintComment(out);
107 if(separator == "\n")
111 std::map<cmStdString, cmXCodeObject*>::iterator i;
112 cmXCodeObject::Indent(3*indentFactor, out);
113 out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator;
114 for(i = this->ObjectAttributes.begin();
115 i != this->ObjectAttributes.end(); ++i)
117 cmXCodeObject* object = i->second;
118 if(i->first != "isa")
120 cmXCodeObject::Indent(3*indentFactor, out);
126 if(object->TypeValue == OBJECT_LIST)
128 out << i->first << " = (" << separator;
129 for(unsigned int k = 0; k < i->second->List.size(); k++)
131 cmXCodeObject::Indent(4*indentFactor, out);
132 out << i->second->List[k]->Id << " ";
133 i->second->List[k]->PrintComment(out);
134 out << "," << separator;
136 cmXCodeObject::Indent(3*indentFactor, out);
137 out << ");" << separator;
139 else if(object->TypeValue == ATTRIBUTE_GROUP)
141 std::map<cmStdString, cmXCodeObject*>::iterator j;
142 out << i->first << " = {" << separator;
143 for(j = object->ObjectAttributes.begin(); j !=
144 object->ObjectAttributes.end(); ++j)
146 cmXCodeObject::Indent(4 *indentFactor, out);
148 if(j->second->TypeValue == STRING)
150 cmXCodeObject::PrintString(out,j->first);
152 j->second->PrintString(out);
155 else if(j->second->TypeValue == OBJECT_LIST)
157 cmXCodeObject::PrintString(out,j->first);
159 for(unsigned int k = 0; k < j->second->List.size(); k++)
161 if(j->second->List[k]->TypeValue == STRING)
163 j->second->List[k]->PrintString(out);
168 out << "List_" << k << "_TypeValue_IS_NOT_STRING, ";
175 cmXCodeObject::PrintString(out,j->first);
176 out << " = error_unexpected_TypeValue_" <<
177 j->second->TypeValue << ";";
182 cmXCodeObject::Indent(3 *indentFactor, out);
183 out << "};" << separator;
185 else if(object->TypeValue == OBJECT_REF)
187 cmXCodeObject::PrintString(out,i->first);
188 out << " = " << object->Object->Id;
189 if(object->Object->HasComment() && i->first != "remoteGlobalIDString")
192 object->Object->PrintComment(out);
194 out << ";" << separator;
196 else if(object->TypeValue == STRING)
198 cmXCodeObject::PrintString(out,i->first);
200 object->PrintString(out);
201 out << ";" << separator;
205 out << "what is this?? " << i->first << "\n";
208 cmXCodeObject::Indent(2*indentFactor, out);
212 //----------------------------------------------------------------------------
213 void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
216 cmXCodeObject::Indent(1, out);
217 out << "objects = {\n";
218 for(unsigned int i = 0; i < objs.size(); ++i)
220 if(objs[i]->TypeValue == OBJECT)
225 cmXCodeObject::Indent(1, out);
229 //----------------------------------------------------------------------------
230 void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
232 this->ObjectAttributes = copy->ObjectAttributes;
233 this->List = copy->List;
234 this->String = copy->String;
235 this->Object = copy->Object;
238 //----------------------------------------------------------------------------
239 void cmXCodeObject::PrintString(std::ostream& os,cmStdString String)
241 // The string needs to be quoted if it contains any characters
242 // considered special by the Xcode project file parser.
245 String.find_first_of(" <>.+-=@$[],") != String.npos);
246 const char* quote = needQuote? "\"" : "";
248 // Print the string, quoted and escaped as necessary.
250 for(std::string::const_iterator i = String.begin();
251 i != String.end(); ++i)
255 // Escape double-quotes.
263 void cmXCodeObject::PrintString(std::ostream& os) const
265 cmXCodeObject::PrintString(os,this->String);
268 //----------------------------------------------------------------------------
269 void cmXCodeObject::SetString(const char* s)