2005-01-22 00:25:36 +03:00
|
|
|
#include "cmXCodeObject.h"
|
2005-01-28 01:09:09 +03:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2005-01-22 00:25:36 +03:00
|
|
|
const char* cmXCodeObject::PBXTypeNames[] = {
|
|
|
|
"PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
|
|
|
|
"PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
|
2005-02-04 01:42:55 +03:00
|
|
|
"PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
|
|
|
|
"PBXTargetDependency", "PBXShellScriptBuildPhase",
|
|
|
|
"PBXResourcesBuildPhase", "PBXApplicationReference",
|
|
|
|
"PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
|
2006-03-10 21:54:57 +03:00
|
|
|
"PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
|
|
|
|
"XCConfigurationList",
|
2005-01-22 00:25:36 +03:00
|
|
|
"None"
|
|
|
|
};
|
|
|
|
|
2005-02-04 01:42:55 +03:00
|
|
|
cmXCodeObject::~cmXCodeObject()
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Version = 15;
|
2005-02-04 01:42:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-25 01:35:54 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2005-01-22 00:25:36 +03:00
|
|
|
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Version = 15;
|
2006-03-15 19:38:47 +03:00
|
|
|
this->PBXTargetDependencyValue = 0;
|
|
|
|
this->Target = 0;
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Object =0;
|
2005-02-05 01:58:58 +03:00
|
|
|
|
2006-03-15 19:02:08 +03:00
|
|
|
this->IsA = ptype;
|
2005-02-08 01:36:34 +03:00
|
|
|
if(type == OBJECT)
|
|
|
|
{
|
|
|
|
cmOStringStream str;
|
|
|
|
str << (void*)this;
|
|
|
|
str << (void*)this;
|
|
|
|
str << (void*)this;
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Id = str.str();
|
2005-02-08 01:36:34 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Id = "Temporary cmake object, should not be refered to in xcode file";
|
2005-02-08 01:36:34 +03:00
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
cmSystemTools::ReplaceString(this->Id, "0x", "");
|
|
|
|
this->Id = cmSystemTools::UpperCase(this->Id);
|
|
|
|
if(this->Id.size() < 24)
|
2005-02-01 23:48:33 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
int diff = 24 - this->Id.size();
|
2005-02-01 23:48:33 +03:00
|
|
|
for(int i =0; i < diff; ++i)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Id += "0";
|
2005-02-01 23:48:33 +03:00
|
|
|
}
|
|
|
|
}
|
2006-03-15 19:38:47 +03:00
|
|
|
this->TypeValue = type;
|
|
|
|
if(this->TypeValue == OBJECT)
|
2005-01-25 01:35:54 +03:00
|
|
|
{
|
2005-01-25 23:26:57 +03:00
|
|
|
this->AddAttribute("isa", 0);
|
2005-01-25 01:35:54 +03:00
|
|
|
}
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
|
|
|
|
2005-01-25 01:35:54 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2005-01-22 00:25:36 +03:00
|
|
|
void cmXCodeObject::Indent(int level, std::ostream& out)
|
|
|
|
{
|
|
|
|
while(level)
|
|
|
|
{
|
|
|
|
out << " ";
|
|
|
|
level--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-25 01:35:54 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2005-01-22 00:25:36 +03:00
|
|
|
void cmXCodeObject::Print(std::ostream& out)
|
|
|
|
{
|
2005-11-16 21:13:39 +03:00
|
|
|
std::string separator = "\n";
|
|
|
|
int indentFactor = 1;
|
2006-03-15 19:02:08 +03:00
|
|
|
if(this->Version > 15 && (this->IsA == PBXFileReference || this->IsA == PBXBuildFile))
|
2005-11-16 21:13:39 +03:00
|
|
|
{
|
|
|
|
separator = " ";
|
|
|
|
indentFactor = 0;
|
|
|
|
}
|
|
|
|
cmXCodeObject::Indent(2*indentFactor, out);
|
2006-03-15 19:02:08 +03:00
|
|
|
out << this->Id << " ";
|
2006-03-15 19:38:47 +03:00
|
|
|
if(!(this->IsA == PBXGroup && this->Comment.size() == 0))
|
2005-11-16 21:13:39 +03:00
|
|
|
{
|
|
|
|
this->PrintComment(out);
|
|
|
|
}
|
|
|
|
out << " = {";
|
|
|
|
if(separator == "\n")
|
|
|
|
{
|
|
|
|
out << separator;
|
|
|
|
}
|
2005-01-22 00:25:36 +03:00
|
|
|
std::map<cmStdString, cmXCodeObject*>::iterator i;
|
2005-11-16 21:13:39 +03:00
|
|
|
cmXCodeObject::Indent(3*indentFactor, out);
|
2006-03-15 19:02:08 +03:00
|
|
|
out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator;
|
|
|
|
for(i = this->ObjectAttributes.begin(); i != this->ObjectAttributes.end(); ++i)
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
|
|
|
cmXCodeObject* object = i->second;
|
2005-11-16 21:13:39 +03:00
|
|
|
if(i->first != "isa")
|
2005-01-25 23:26:57 +03:00
|
|
|
{
|
2005-11-16 21:13:39 +03:00
|
|
|
cmXCodeObject::Indent(3*indentFactor, out);
|
2005-01-25 23:26:57 +03:00
|
|
|
}
|
2005-11-16 21:13:39 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2006-03-15 19:38:47 +03:00
|
|
|
if(object->TypeValue == OBJECT_LIST)
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2005-11-16 21:13:39 +03:00
|
|
|
out << i->first << " = (" << separator;
|
2006-03-15 19:38:47 +03:00
|
|
|
for(unsigned int k = 0; k < i->second->List.size(); k++)
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2005-11-16 21:13:39 +03:00
|
|
|
cmXCodeObject::Indent(4*indentFactor, out);
|
2006-03-15 19:38:47 +03:00
|
|
|
out << i->second->List[k]->Id << " ";
|
|
|
|
i->second->List[k]->PrintComment(out);
|
2005-11-16 21:13:39 +03:00
|
|
|
out << "," << separator;
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
2005-11-16 21:13:39 +03:00
|
|
|
cmXCodeObject::Indent(3*indentFactor, out);
|
|
|
|
out << ");" << separator;
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
2006-03-15 19:38:47 +03:00
|
|
|
else if(object->TypeValue == ATTRIBUTE_GROUP)
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2005-01-25 23:26:57 +03:00
|
|
|
std::map<cmStdString, cmXCodeObject*>::iterator j;
|
2005-11-16 21:13:39 +03:00
|
|
|
out << i->first << " = {" << separator;
|
2006-03-15 19:02:08 +03:00
|
|
|
for(j = object->ObjectAttributes.begin(); j !=
|
|
|
|
object->ObjectAttributes.end(); ++j)
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2005-11-16 21:13:39 +03:00
|
|
|
cmXCodeObject::Indent(4 *indentFactor, out);
|
2006-03-15 19:38:47 +03:00
|
|
|
out << j->first << " = " << j->second->String << ";";
|
2005-11-16 21:13:39 +03:00
|
|
|
out << separator;
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
2005-11-16 21:13:39 +03:00
|
|
|
cmXCodeObject::Indent(3 *indentFactor, out);
|
|
|
|
out << "};" << separator;
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
2006-03-15 19:38:47 +03:00
|
|
|
else if(object->TypeValue == OBJECT_REF)
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2006-03-15 19:38:47 +03:00
|
|
|
out << i->first << " = " << object->Object->Id;
|
|
|
|
if(object->Object->HasComment() && i->first != "remoteGlobalIDString")
|
2005-11-16 21:13:39 +03:00
|
|
|
{
|
|
|
|
out << " ";
|
2006-03-15 19:38:47 +03:00
|
|
|
object->Object->PrintComment(out);
|
2005-11-16 21:13:39 +03:00
|
|
|
}
|
|
|
|
out << ";" << separator;
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
2006-03-15 19:38:47 +03:00
|
|
|
else if(object->TypeValue == STRING)
|
2005-01-25 23:26:57 +03:00
|
|
|
{
|
2006-03-15 19:38:47 +03:00
|
|
|
out << i->first << " = " << object->String << ";" << separator;
|
2005-01-25 23:26:57 +03:00
|
|
|
}
|
2005-01-28 00:11:44 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
out << "what is this?? " << i->first << "\n";
|
|
|
|
}
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
2005-11-16 21:13:39 +03:00
|
|
|
cmXCodeObject::Indent(2*indentFactor, out);
|
2005-01-22 00:25:36 +03:00
|
|
|
out << "};\n";
|
|
|
|
}
|
|
|
|
|
2005-01-25 01:35:54 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
|
|
|
|
std::ostream& out)
|
|
|
|
{
|
|
|
|
cmXCodeObject::Indent(1, out);
|
2005-01-22 00:25:36 +03:00
|
|
|
out << "objects = {\n";
|
2005-01-25 01:35:54 +03:00
|
|
|
for(unsigned int i = 0; i < objs.size(); ++i)
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2006-03-15 19:38:47 +03:00
|
|
|
if(objs[i]->TypeValue == OBJECT)
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2005-01-25 01:35:54 +03:00
|
|
|
objs[i]->Print(out);
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
|
|
|
}
|
2005-01-25 01:35:54 +03:00
|
|
|
cmXCodeObject::Indent(1, out);
|
2005-01-22 00:25:36 +03:00
|
|
|
out << "};\n";
|
|
|
|
}
|
2005-02-08 01:36:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
|
|
|
|
{
|
2006-03-15 19:38:47 +03:00
|
|
|
this->ObjectAttributes = copy->ObjectAttributes;
|
|
|
|
this->List = copy->List;
|
|
|
|
this->String = copy->String;
|
|
|
|
this->Object = copy->Object;
|
2005-02-08 01:36:34 +03:00
|
|
|
}
|
|
|
|
|
2005-11-16 21:13:39 +03:00
|
|
|
void cmXCodeObject::SetString(const char* s)
|
|
|
|
{
|
|
|
|
std::string ss = s;
|
|
|
|
if(ss.size() == 0)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->String = "\"\"";
|
2005-11-16 21:13:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool needQuote = false;
|
2006-03-15 19:02:08 +03:00
|
|
|
this->String = "";
|
2005-11-19 00:59:53 +03:00
|
|
|
if(ss.find_first_of(" <>.+-=") != ss.npos)
|
2005-11-16 21:13:39 +03:00
|
|
|
{
|
|
|
|
needQuote = true;
|
|
|
|
}
|
|
|
|
if(needQuote)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->String = "\"";
|
2005-11-16 21:13:39 +03:00
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
this->String += s;
|
2005-11-16 21:13:39 +03:00
|
|
|
if(needQuote)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->String += "\"";
|
2005-11-16 21:13:39 +03:00
|
|
|
}
|
|
|
|
}
|