CMake/Source/cmXCodeObject.cxx

203 lines
5.1 KiB
C++
Raw Normal View History

2005-01-22 00:25:36 +03:00
#include "cmXCodeObject.h"
#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",
2005-09-03 00:29:32 +04:00
"PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration", "XCConfigurationList",
2005-01-22 00:25:36 +03:00
"None"
};
2005-02-04 01:42:55 +03:00
cmXCodeObject::~cmXCodeObject()
{
m_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)
{
m_Version = 15;
2005-02-05 01:58:58 +03:00
m_PBXTargetDependency = 0;
m_cmTarget = 0;
m_Object =0;
2005-01-22 00:25:36 +03:00
m_IsA = ptype;
2005-02-08 01:36:34 +03:00
if(type == OBJECT)
{
cmOStringStream str;
str << (void*)this;
str << (void*)this;
str << (void*)this;
m_Id = str.str();
}
else
{
m_Id = "Temporary cmake object, should not be refered to in xcode file";
}
cmSystemTools::ReplaceString(m_Id, "0x", "");
2005-02-08 01:36:34 +03:00
m_Id = cmSystemTools::UpperCase(m_Id);
2005-02-01 23:48:33 +03:00
if(m_Id.size() < 24)
{
int diff = 24 - m_Id.size();
for(int i =0; i < diff; ++i)
{
m_Id += "0";
}
}
2005-01-22 00:25:36 +03:00
m_Type = type;
2005-01-25 01:35:54 +03:00
if(m_Type == OBJECT)
{
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)
{
std::string separator = "\n";
int indentFactor = 1;
if(m_Version > 15 && (m_IsA == PBXFileReference || m_IsA == PBXBuildFile))
{
separator = " ";
indentFactor = 0;
}
cmXCodeObject::Indent(2*indentFactor, out);
2005-09-03 00:29:32 +04:00
out << m_Id << " ";
if(!(this->m_IsA == PBXGroup && this->m_Comment.size() == 0))
{
this->PrintComment(out);
}
out << " = {";
if(separator == "\n")
{
out << separator;
}
2005-01-22 00:25:36 +03:00
std::map<cmStdString, cmXCodeObject*>::iterator i;
cmXCodeObject::Indent(3*indentFactor, out);
out << "isa = " << PBXTypeNames[m_IsA] << ";" << separator;
2005-01-22 00:25:36 +03:00
for(i = m_ObjectAttributes.begin(); i != m_ObjectAttributes.end(); ++i)
{
cmXCodeObject* object = i->second;
if(i->first != "isa")
{
cmXCodeObject::Indent(3*indentFactor, out);
}
else
{
continue;
}
if(object->m_Type == OBJECT_LIST)
2005-01-22 00:25:36 +03:00
{
out << i->first << " = (" << separator;
2005-01-22 00:25:36 +03:00
for(unsigned int k = 0; k < i->second->m_List.size(); k++)
{
cmXCodeObject::Indent(4*indentFactor, out);
out << i->second->m_List[k]->m_Id << " ";
i->second->m_List[k]->PrintComment(out);
out << "," << separator;
2005-01-22 00:25:36 +03:00
}
cmXCodeObject::Indent(3*indentFactor, out);
out << ");" << separator;
2005-01-22 00:25:36 +03:00
}
else if(object->m_Type == ATTRIBUTE_GROUP)
{
std::map<cmStdString, cmXCodeObject*>::iterator j;
out << i->first << " = {" << separator;
for(j = object->m_ObjectAttributes.begin(); j != object->m_ObjectAttributes.end(); ++j)
2005-01-22 00:25:36 +03:00
{
cmXCodeObject::Indent(4 *indentFactor, out);
out << j->first << " = " << j->second->m_String << ";";
out << separator;
2005-01-22 00:25:36 +03:00
}
cmXCodeObject::Indent(3 *indentFactor, out);
out << "};" << separator;
2005-01-22 00:25:36 +03:00
}
else if(object->m_Type == OBJECT_REF)
{
out << i->first << " = " << object->m_Object->m_Id;
if(object->m_Object->HasComment() && i->first != "remoteGlobalIDString")
{
out << " ";
object->m_Object->PrintComment(out);
}
out << ";" << separator;
2005-01-22 00:25:36 +03:00
}
else if(object->m_Type == STRING)
{
out << i->first << " = " << object->m_String << ";" << separator;
}
2005-01-28 00:11:44 +03:00
else
{
out << "what is this?? " << i->first << "\n";
}
2005-01-22 00:25:36 +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
{
2005-01-25 01:35:54 +03:00
if(objs[i]->m_Type == 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)
{
this->m_ObjectAttributes = copy->m_ObjectAttributes;
this->m_List = copy->m_List;
this->m_String = copy->m_String;
this->m_Object = copy->m_Object;
}
void cmXCodeObject::SetString(const char* s)
{
std::string ss = s;
if(ss.size() == 0)
{
m_String = "\"\"";
return;
}
bool needQuote = false;
m_String = "";
2005-11-19 00:59:53 +03:00
if(ss.find_first_of(" <>.+-=") != ss.npos)
{
needQuote = true;
}
if(needQuote)
{
m_String = "\"";
}
m_String += s;
if(needQuote)
{
m_String += "\"";
}
}