2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-07-27 14:55:24 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2007-07-27 14:55:24 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2005-01-21 21:25:36 +00:00
|
|
|
#include "cmXCodeObject.h"
|
2005-01-27 22:09:09 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2011-08-23 22:22:33 +00:00
|
|
|
#include <CoreFoundation/CoreFoundation.h> // CFUUIDCreate
|
|
|
|
|
2007-08-14 15:45:15 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2005-01-21 21:25:36 +00:00
|
|
|
const char* cmXCodeObject::PBXTypeNames[] = {
|
2012-08-13 17:42:58 +00:00
|
|
|
"PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
|
2005-01-21 21:25:36 +00:00
|
|
|
"PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
|
2012-08-13 17:42:58 +00:00
|
|
|
"PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
|
|
|
|
"PBXTargetDependency", "PBXShellScriptBuildPhase",
|
2005-02-03 22:42:55 +00:00
|
|
|
"PBXResourcesBuildPhase", "PBXApplicationReference",
|
|
|
|
"PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
|
2012-08-13 17:42:58 +00:00
|
|
|
"PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
|
2006-03-10 18:54:57 +00:00
|
|
|
"XCConfigurationList",
|
2006-03-29 20:02:35 +00:00
|
|
|
"PBXCopyFilesBuildPhase",
|
2005-01-21 21:25:36 +00:00
|
|
|
"None"
|
|
|
|
};
|
|
|
|
|
2007-08-14 15:45:15 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2005-02-03 22:42:55 +00:00
|
|
|
cmXCodeObject::~cmXCodeObject()
|
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Version = 15;
|
2005-02-03 22:42:55 +00:00
|
|
|
}
|
|
|
|
|
2005-01-24 22:35:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2005-01-21 21:25:36 +00:00
|
|
|
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
|
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Version = 15;
|
2006-03-15 16:38:47 +00:00
|
|
|
this->Target = 0;
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Object =0;
|
2011-08-23 22:22:33 +00:00
|
|
|
|
2006-03-15 16:02:08 +00:00
|
|
|
this->IsA = ptype;
|
2011-08-23 22:22:33 +00:00
|
|
|
|
2005-02-07 22:36:34 +00:00
|
|
|
if(type == OBJECT)
|
|
|
|
{
|
2011-08-23 22:22:33 +00:00
|
|
|
// Set the Id of an Xcode object to a unique string for each instance.
|
|
|
|
// However the Xcode user file references certain Ids: for those cases,
|
|
|
|
// override the generated Id using SetId().
|
|
|
|
//
|
|
|
|
char cUuid[40] = {0};
|
|
|
|
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
|
|
|
|
CFStringRef s = CFUUIDCreateString(kCFAllocatorDefault, uuid);
|
|
|
|
CFStringGetCString(s, cUuid, sizeof(cUuid), kCFStringEncodingUTF8);
|
|
|
|
this->Id = cUuid;
|
|
|
|
CFRelease(s);
|
|
|
|
CFRelease(uuid);
|
2005-02-07 22:36:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-23 22:22:33 +00:00
|
|
|
this->Id =
|
|
|
|
"Temporary cmake object, should not be referred to in Xcode file";
|
2005-02-01 20:48:33 +00:00
|
|
|
}
|
2011-08-23 22:22:33 +00:00
|
|
|
|
|
|
|
cmSystemTools::ReplaceString(this->Id, "-", "");
|
2008-05-09 01:14:16 +00:00
|
|
|
if(this->Id.size() > 24)
|
|
|
|
{
|
2011-08-23 22:22:33 +00:00
|
|
|
this->Id = this->Id.substr(0, 24);
|
2008-05-09 01:14:16 +00:00
|
|
|
}
|
2011-08-23 22:22:33 +00:00
|
|
|
|
2006-03-15 16:38:47 +00:00
|
|
|
this->TypeValue = type;
|
|
|
|
if(this->TypeValue == OBJECT)
|
2005-01-24 22:35:54 +00:00
|
|
|
{
|
2005-01-25 20:26:57 +00:00
|
|
|
this->AddAttribute("isa", 0);
|
2005-01-24 22:35:54 +00:00
|
|
|
}
|
2005-01-21 21:25:36 +00:00
|
|
|
}
|
|
|
|
|
2005-01-24 22:35:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2005-01-21 21:25:36 +00:00
|
|
|
void cmXCodeObject::Indent(int level, std::ostream& out)
|
|
|
|
{
|
|
|
|
while(level)
|
|
|
|
{
|
|
|
|
out << " ";
|
|
|
|
level--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-24 22:35:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2005-01-21 21:25:36 +00:00
|
|
|
void cmXCodeObject::Print(std::ostream& out)
|
|
|
|
{
|
2005-11-16 18:13:39 +00:00
|
|
|
std::string separator = "\n";
|
|
|
|
int indentFactor = 1;
|
2012-08-13 17:42:58 +00:00
|
|
|
if(this->Version > 15
|
2006-05-12 18:36:39 +00:00
|
|
|
&& (this->IsA == PBXFileReference || this->IsA == PBXBuildFile))
|
2005-11-16 18:13:39 +00:00
|
|
|
{
|
|
|
|
separator = " ";
|
|
|
|
indentFactor = 0;
|
|
|
|
}
|
|
|
|
cmXCodeObject::Indent(2*indentFactor, out);
|
2006-03-15 16:02:08 +00:00
|
|
|
out << this->Id << " ";
|
2006-03-15 16:38:47 +00:00
|
|
|
if(!(this->IsA == PBXGroup && this->Comment.size() == 0))
|
2005-11-16 18:13:39 +00:00
|
|
|
{
|
|
|
|
this->PrintComment(out);
|
|
|
|
}
|
|
|
|
out << " = {";
|
|
|
|
if(separator == "\n")
|
|
|
|
{
|
|
|
|
out << separator;
|
|
|
|
}
|
2005-01-21 21:25:36 +00:00
|
|
|
std::map<cmStdString, cmXCodeObject*>::iterator i;
|
2005-11-16 18:13:39 +00:00
|
|
|
cmXCodeObject::Indent(3*indentFactor, out);
|
2006-03-15 16:02:08 +00:00
|
|
|
out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator;
|
2012-08-13 17:42:58 +00:00
|
|
|
for(i = this->ObjectAttributes.begin();
|
2006-05-12 18:36:39 +00:00
|
|
|
i != this->ObjectAttributes.end(); ++i)
|
2012-08-13 17:42:58 +00:00
|
|
|
{
|
2005-01-21 21:25:36 +00:00
|
|
|
cmXCodeObject* object = i->second;
|
2005-11-16 18:13:39 +00:00
|
|
|
if(i->first != "isa")
|
2012-08-13 17:42:58 +00:00
|
|
|
{
|
2005-11-16 18:13:39 +00:00
|
|
|
cmXCodeObject::Indent(3*indentFactor, out);
|
2005-01-25 20:26:57 +00:00
|
|
|
}
|
2005-11-16 18:13:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2006-03-15 16:38:47 +00:00
|
|
|
if(object->TypeValue == OBJECT_LIST)
|
2005-01-21 21:25:36 +00:00
|
|
|
{
|
2005-11-16 18:13:39 +00:00
|
|
|
out << i->first << " = (" << separator;
|
2006-03-15 16:38:47 +00:00
|
|
|
for(unsigned int k = 0; k < i->second->List.size(); k++)
|
2005-01-21 21:25:36 +00:00
|
|
|
{
|
2005-11-16 18:13:39 +00:00
|
|
|
cmXCodeObject::Indent(4*indentFactor, out);
|
2006-03-15 16:38:47 +00:00
|
|
|
out << i->second->List[k]->Id << " ";
|
|
|
|
i->second->List[k]->PrintComment(out);
|
2005-11-16 18:13:39 +00:00
|
|
|
out << "," << separator;
|
2012-08-13 17:42:58 +00:00
|
|
|
}
|
2005-11-16 18:13:39 +00:00
|
|
|
cmXCodeObject::Indent(3*indentFactor, out);
|
|
|
|
out << ");" << separator;
|
2005-01-21 21:25:36 +00:00
|
|
|
}
|
2006-03-15 16:38:47 +00:00
|
|
|
else if(object->TypeValue == ATTRIBUTE_GROUP)
|
2005-01-21 21:25:36 +00:00
|
|
|
{
|
2005-01-25 20:26:57 +00:00
|
|
|
std::map<cmStdString, cmXCodeObject*>::iterator j;
|
2005-11-16 18:13:39 +00:00
|
|
|
out << i->first << " = {" << separator;
|
2012-08-13 17:42:58 +00:00
|
|
|
for(j = object->ObjectAttributes.begin(); j !=
|
2006-03-15 16:02:08 +00:00
|
|
|
object->ObjectAttributes.end(); ++j)
|
2005-01-21 21:25:36 +00:00
|
|
|
{
|
2005-11-16 18:13:39 +00:00
|
|
|
cmXCodeObject::Indent(4 *indentFactor, out);
|
2007-08-14 15:45:15 +00:00
|
|
|
|
|
|
|
if(j->second->TypeValue == STRING)
|
|
|
|
{
|
2011-04-05 13:25:58 +00:00
|
|
|
cmXCodeObject::PrintString(out,j->first);
|
|
|
|
out << " = ";
|
2008-09-02 14:27:15 +00:00
|
|
|
j->second->PrintString(out);
|
|
|
|
out << ";";
|
2007-08-14 15:45:15 +00:00
|
|
|
}
|
|
|
|
else if(j->second->TypeValue == OBJECT_LIST)
|
|
|
|
{
|
2011-04-05 13:25:58 +00:00
|
|
|
cmXCodeObject::PrintString(out,j->first);
|
|
|
|
out << " = (";
|
2007-08-14 15:45:15 +00:00
|
|
|
for(unsigned int k = 0; k < j->second->List.size(); k++)
|
|
|
|
{
|
|
|
|
if(j->second->List[k]->TypeValue == STRING)
|
|
|
|
{
|
2008-09-02 14:27:15 +00:00
|
|
|
j->second->List[k]->PrintString(out);
|
|
|
|
out << ", ";
|
2007-08-14 15:45:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out << "List_" << k << "_TypeValue_IS_NOT_STRING, ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out << ");";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-05 13:25:58 +00:00
|
|
|
cmXCodeObject::PrintString(out,j->first);
|
|
|
|
out << " = error_unexpected_TypeValue_" <<
|
2007-08-14 15:45:15 +00:00
|
|
|
j->second->TypeValue << ";";
|
|
|
|
}
|
|
|
|
|
2005-11-16 18:13:39 +00:00
|
|
|
out << separator;
|
2005-01-21 21:25:36 +00:00
|
|
|
}
|
2005-11-16 18:13:39 +00:00
|
|
|
cmXCodeObject::Indent(3 *indentFactor, out);
|
|
|
|
out << "};" << separator;
|
2005-01-21 21:25:36 +00:00
|
|
|
}
|
2006-03-15 16:38:47 +00:00
|
|
|
else if(object->TypeValue == OBJECT_REF)
|
2005-01-21 21:25:36 +00:00
|
|
|
{
|
2011-04-05 13:25:58 +00:00
|
|
|
cmXCodeObject::PrintString(out,i->first);
|
|
|
|
out << " = " << object->Object->Id;
|
2006-03-15 16:38:47 +00:00
|
|
|
if(object->Object->HasComment() && i->first != "remoteGlobalIDString")
|
2005-11-16 18:13:39 +00:00
|
|
|
{
|
|
|
|
out << " ";
|
2006-03-15 16:38:47 +00:00
|
|
|
object->Object->PrintComment(out);
|
2005-11-16 18:13:39 +00:00
|
|
|
}
|
|
|
|
out << ";" << separator;
|
2005-01-21 21:25:36 +00:00
|
|
|
}
|
2006-03-15 16:38:47 +00:00
|
|
|
else if(object->TypeValue == STRING)
|
2005-01-25 20:26:57 +00:00
|
|
|
{
|
2011-04-05 13:25:58 +00:00
|
|
|
cmXCodeObject::PrintString(out,i->first);
|
|
|
|
out << " = ";
|
2008-09-02 14:27:15 +00:00
|
|
|
object->PrintString(out);
|
|
|
|
out << ";" << separator;
|
2005-01-25 20:26:57 +00:00
|
|
|
}
|
2005-01-27 21:11:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
out << "what is this?? " << i->first << "\n";
|
|
|
|
}
|
2005-01-21 21:25:36 +00:00
|
|
|
}
|
2005-11-16 18:13:39 +00:00
|
|
|
cmXCodeObject::Indent(2*indentFactor, out);
|
2005-01-21 21:25:36 +00:00
|
|
|
out << "};\n";
|
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2005-01-24 22:35:54 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
|
|
|
|
std::ostream& out)
|
2012-08-13 17:42:58 +00:00
|
|
|
{
|
2005-01-24 22:35:54 +00:00
|
|
|
cmXCodeObject::Indent(1, out);
|
2005-01-21 21:25:36 +00:00
|
|
|
out << "objects = {\n";
|
2005-01-24 22:35:54 +00:00
|
|
|
for(unsigned int i = 0; i < objs.size(); ++i)
|
2005-01-21 21:25:36 +00:00
|
|
|
{
|
2006-03-15 16:38:47 +00:00
|
|
|
if(objs[i]->TypeValue == OBJECT)
|
2005-01-21 21:25:36 +00:00
|
|
|
{
|
2005-01-24 22:35:54 +00:00
|
|
|
objs[i]->Print(out);
|
2005-01-21 21:25:36 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-24 22:35:54 +00:00
|
|
|
cmXCodeObject::Indent(1, out);
|
2005-01-21 21:25:36 +00:00
|
|
|
out << "};\n";
|
|
|
|
}
|
2005-02-07 22:36:34 +00:00
|
|
|
|
2007-08-14 15:45:15 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2005-02-07 22:36:34 +00:00
|
|
|
void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
|
|
|
|
{
|
2006-03-15 16:38:47 +00:00
|
|
|
this->ObjectAttributes = copy->ObjectAttributes;
|
|
|
|
this->List = copy->List;
|
|
|
|
this->String = copy->String;
|
|
|
|
this->Object = copy->Object;
|
2005-02-07 22:36:34 +00:00
|
|
|
}
|
|
|
|
|
2007-08-14 15:45:15 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2011-04-05 13:25:58 +00:00
|
|
|
void cmXCodeObject::PrintString(std::ostream& os,cmStdString String)
|
2005-11-16 18:13:39 +00:00
|
|
|
{
|
2008-09-02 14:27:15 +00:00
|
|
|
// The string needs to be quoted if it contains any characters
|
|
|
|
// considered special by the Xcode project file parser.
|
|
|
|
bool needQuote =
|
2011-04-05 13:25:58 +00:00
|
|
|
(String.empty() ||
|
2011-06-09 08:36:53 +00:00
|
|
|
String.find_first_of(" <>.+-=@$[],") != String.npos);
|
2008-09-02 14:27:15 +00:00
|
|
|
const char* quote = needQuote? "\"" : "";
|
|
|
|
|
|
|
|
// Print the string, quoted and escaped as necessary.
|
|
|
|
os << quote;
|
2011-04-05 13:25:58 +00:00
|
|
|
for(std::string::const_iterator i = String.begin();
|
|
|
|
i != String.end(); ++i)
|
2005-11-16 18:13:39 +00:00
|
|
|
{
|
2008-09-02 14:27:15 +00:00
|
|
|
if(*i == '"')
|
|
|
|
{
|
|
|
|
// Escape double-quotes.
|
|
|
|
os << '\\';
|
|
|
|
}
|
|
|
|
os << *i;
|
2005-11-16 18:13:39 +00:00
|
|
|
}
|
2008-09-02 14:27:15 +00:00
|
|
|
os << quote;
|
|
|
|
}
|
|
|
|
|
2011-04-05 13:25:58 +00:00
|
|
|
void cmXCodeObject::PrintString(std::ostream& os) const
|
|
|
|
{
|
|
|
|
cmXCodeObject::PrintString(os,this->String);
|
|
|
|
}
|
|
|
|
|
2008-09-02 14:27:15 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmXCodeObject::SetString(const char* s)
|
|
|
|
{
|
|
|
|
this->String = s;
|
2005-11-16 18:13:39 +00:00
|
|
|
}
|