1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmXCodeObject.cxx,v $
6 Date: $Date: 2008-09-02 14:27:15 $
7 Version: $Revision: 1.26 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmXCodeObject.h"
18 #include "cmSystemTools.h"
20 //----------------------------------------------------------------------------
21 const char* cmXCodeObject::PBXTypeNames
[] = {
22 "PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
23 "PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
24 "PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
25 "PBXTargetDependency", "PBXShellScriptBuildPhase",
26 "PBXResourcesBuildPhase", "PBXApplicationReference",
27 "PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
28 "PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
29 "XCConfigurationList",
30 "PBXCopyFilesBuildPhase",
34 //----------------------------------------------------------------------------
35 cmXCodeObject::~cmXCodeObject()
40 //----------------------------------------------------------------------------
41 cmXCodeObject::cmXCodeObject(PBXType ptype
, Type type
)
44 this->PBXTargetDependencyValue
= 0;
60 "Temporary cmake object, should not be refered to in xcode file";
62 cmSystemTools::ReplaceString(this->Id
, "0x", "");
63 this->Id
= cmSystemTools::UpperCase(this->Id
);
64 if(this->Id
.size() < 24)
66 int diff
= 24 - this->Id
.size();
67 for(int i
=0; i
< diff
; ++i
)
72 if(this->Id
.size() > 24)
74 this->Id
= this->Id
.substr(0,24);
76 this->TypeValue
= type
;
77 if(this->TypeValue
== OBJECT
)
79 this->AddAttribute("isa", 0);
83 //----------------------------------------------------------------------------
84 void cmXCodeObject::Indent(int level
, std::ostream
& out
)
93 //----------------------------------------------------------------------------
94 void cmXCodeObject::Print(std::ostream
& out
)
96 std::string separator
= "\n";
99 && (this->IsA
== PBXFileReference
|| this->IsA
== PBXBuildFile
))
104 cmXCodeObject::Indent(2*indentFactor
, out
);
105 out
<< this->Id
<< " ";
106 if(!(this->IsA
== PBXGroup
&& this->Comment
.size() == 0))
108 this->PrintComment(out
);
111 if(separator
== "\n")
115 std::map
<cmStdString
, cmXCodeObject
*>::iterator i
;
116 cmXCodeObject::Indent(3*indentFactor
, out
);
117 out
<< "isa = " << PBXTypeNames
[this->IsA
] << ";" << separator
;
118 for(i
= this->ObjectAttributes
.begin();
119 i
!= this->ObjectAttributes
.end(); ++i
)
121 cmXCodeObject
* object
= i
->second
;
122 if(i
->first
!= "isa")
124 cmXCodeObject::Indent(3*indentFactor
, out
);
130 if(object
->TypeValue
== OBJECT_LIST
)
132 out
<< i
->first
<< " = (" << separator
;
133 for(unsigned int k
= 0; k
< i
->second
->List
.size(); k
++)
135 cmXCodeObject::Indent(4*indentFactor
, out
);
136 out
<< i
->second
->List
[k
]->Id
<< " ";
137 i
->second
->List
[k
]->PrintComment(out
);
138 out
<< "," << separator
;
140 cmXCodeObject::Indent(3*indentFactor
, out
);
141 out
<< ");" << separator
;
143 else if(object
->TypeValue
== ATTRIBUTE_GROUP
)
145 std::map
<cmStdString
, cmXCodeObject
*>::iterator j
;
146 out
<< i
->first
<< " = {" << separator
;
147 for(j
= object
->ObjectAttributes
.begin(); j
!=
148 object
->ObjectAttributes
.end(); ++j
)
150 cmXCodeObject::Indent(4 *indentFactor
, out
);
152 if(j
->second
->TypeValue
== STRING
)
154 out
<< j
->first
<< " = ";
155 j
->second
->PrintString(out
);
158 else if(j
->second
->TypeValue
== OBJECT_LIST
)
160 out
<< j
->first
<< " = (";
161 for(unsigned int k
= 0; k
< j
->second
->List
.size(); k
++)
163 if(j
->second
->List
[k
]->TypeValue
== STRING
)
165 j
->second
->List
[k
]->PrintString(out
);
170 out
<< "List_" << k
<< "_TypeValue_IS_NOT_STRING, ";
177 out
<< j
->first
<< " = error_unexpected_TypeValue_" <<
178 j
->second
->TypeValue
<< ";";
183 cmXCodeObject::Indent(3 *indentFactor
, out
);
184 out
<< "};" << separator
;
186 else if(object
->TypeValue
== OBJECT_REF
)
188 out
<< i
->first
<< " = " << 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 out
<< i
->first
<< " = ";
199 object
->PrintString(out
);
200 out
<< ";" << separator
;
204 out
<< "what is this?? " << i
->first
<< "\n";
207 cmXCodeObject::Indent(2*indentFactor
, out
);
211 //----------------------------------------------------------------------------
212 void cmXCodeObject::PrintList(std::vector
<cmXCodeObject
*> const& objs
,
215 cmXCodeObject::Indent(1, out
);
216 out
<< "objects = {\n";
217 for(unsigned int i
= 0; i
< objs
.size(); ++i
)
219 if(objs
[i
]->TypeValue
== OBJECT
)
224 cmXCodeObject::Indent(1, out
);
228 //----------------------------------------------------------------------------
229 void cmXCodeObject::CopyAttributes(cmXCodeObject
* copy
)
231 this->ObjectAttributes
= copy
->ObjectAttributes
;
232 this->List
= copy
->List
;
233 this->String
= copy
->String
;
234 this->Object
= copy
->Object
;
237 //----------------------------------------------------------------------------
238 void cmXCodeObject::PrintString(std::ostream
& os
) const
240 // The string needs to be quoted if it contains any characters
241 // considered special by the Xcode project file parser.
243 (this->String
.empty() ||
244 this->String
.find_first_of(" <>.+-=@") != this->String
.npos
);
245 const char* quote
= needQuote
? "\"" : "";
247 // Print the string, quoted and escaped as necessary.
249 for(std::string::const_iterator i
= this->String
.begin();
250 i
!= this->String
.end(); ++i
)
254 // Escape double-quotes.
262 //----------------------------------------------------------------------------
263 void cmXCodeObject::SetString(const char* s
)