2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-07-27 18:55:24 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2007-07-27 18:55:24 +04:00
|
|
|
|
2009-09-28 19:43:28 +04: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-22 00:25:36 +03:00
|
|
|
#include "cmXCodeObject.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2005-01-28 01:09:09 +03:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2011-08-24 02:22:33 +04:00
|
|
|
#include <CoreFoundation/CoreFoundation.h> // CFUUIDCreate
|
|
|
|
|
2005-01-22 00:25:36 +03:00
|
|
|
const char* cmXCodeObject::PBXTypeNames[] = {
|
2016-05-06 22:21:30 +03:00
|
|
|
/* clang-format needs this comment to break after the opening brace */
|
2012-08-13 21:42:58 +04:00
|
|
|
"PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
|
2005-01-22 00:25:36 +03:00
|
|
|
"PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
|
2012-08-13 21:42:58 +04:00
|
|
|
"PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
|
|
|
|
"PBXTargetDependency", "PBXShellScriptBuildPhase",
|
2005-02-04 01:42:55 +03:00
|
|
|
"PBXResourcesBuildPhase", "PBXApplicationReference",
|
|
|
|
"PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
|
2012-08-13 21:42:58 +04:00
|
|
|
"PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
|
2006-03-10 21:54:57 +03:00
|
|
|
"XCConfigurationList",
|
2006-03-30 00:02:35 +04:00
|
|
|
"PBXCopyFilesBuildPhase",
|
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-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->Target = 0;
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Object =0;
|
2011-08-24 02:22:33 +04:00
|
|
|
|
2006-03-15 19:02:08 +03:00
|
|
|
this->IsA = ptype;
|
2011-08-24 02:22:33 +04:00
|
|
|
|
2005-02-08 01:36:34 +03:00
|
|
|
if(type == OBJECT)
|
|
|
|
{
|
2011-08-24 02:22:33 +04: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-08 01:36:34 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-24 02:22:33 +04:00
|
|
|
this->Id =
|
|
|
|
"Temporary cmake object, should not be referred to in Xcode file";
|
2005-02-01 23:48:33 +03:00
|
|
|
}
|
2011-08-24 02:22:33 +04:00
|
|
|
|
|
|
|
cmSystemTools::ReplaceString(this->Id, "-", "");
|
2008-05-09 05:14:16 +04:00
|
|
|
if(this->Id.size() > 24)
|
|
|
|
{
|
2011-08-24 02:22:33 +04:00
|
|
|
this->Id = this->Id.substr(0, 24);
|
2008-05-09 05:14:16 +04:00
|
|
|
}
|
2011-08-24 02:22:33 +04: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
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeObject::Indent(int level, std::ostream& out)
|
|
|
|
{
|
|
|
|
while(level)
|
|
|
|
{
|
2015-04-07 20:13:57 +03:00
|
|
|
out << "\t";
|
2005-01-22 00:25:36 +03:00
|
|
|
level--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeObject::Print(std::ostream& out)
|
|
|
|
{
|
2005-11-16 21:13:39 +03:00
|
|
|
std::string separator = "\n";
|
|
|
|
int indentFactor = 1;
|
2015-04-07 21:47:10 +03:00
|
|
|
cmXCodeObject::Indent(2*indentFactor, out);
|
2012-08-13 21:42:58 +04:00
|
|
|
if(this->Version > 15
|
2006-05-12 22:36:39 +04:00
|
|
|
&& (this->IsA == PBXFileReference || this->IsA == PBXBuildFile))
|
2005-11-16 21:13:39 +03:00
|
|
|
{
|
|
|
|
separator = " ";
|
|
|
|
indentFactor = 0;
|
|
|
|
}
|
2015-04-09 11:14:47 +03:00
|
|
|
out << this->Id;
|
2015-04-09 11:48:33 +03:00
|
|
|
this->PrintComment(out);
|
2005-11-16 21:13:39 +03:00
|
|
|
out << " = {";
|
|
|
|
if(separator == "\n")
|
|
|
|
{
|
|
|
|
out << separator;
|
|
|
|
}
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, 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;
|
2012-08-13 21:42:58 +04:00
|
|
|
for(i = this->ObjectAttributes.begin();
|
2006-05-12 22:36:39 +04:00
|
|
|
i != this->ObjectAttributes.end(); ++i)
|
2012-08-13 21:42:58 +04:00
|
|
|
{
|
2016-02-19 22:00:19 +03:00
|
|
|
if(i->first == "isa")
|
2005-11-16 21:13:39 +03:00
|
|
|
continue;
|
2016-02-19 22:00:19 +03:00
|
|
|
|
|
|
|
PrintAttribute(out, 3, separator, indentFactor, i->first, i->second, this);
|
|
|
|
}
|
|
|
|
cmXCodeObject::Indent(2*indentFactor, out);
|
|
|
|
out << "};\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeObject::PrintAttribute(std::ostream& out, const int level,
|
|
|
|
const std::string separator,
|
|
|
|
const int factor, const std::string& name,
|
|
|
|
const cmXCodeObject* object,
|
|
|
|
const cmXCodeObject* parent)
|
|
|
|
{
|
|
|
|
cmXCodeObject::Indent(level * factor, out);
|
|
|
|
switch(object->TypeValue)
|
|
|
|
{
|
|
|
|
case OBJECT_LIST:
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2016-02-19 22:00:19 +03:00
|
|
|
out << name << " = (";
|
|
|
|
if(parent->TypeValue != ATTRIBUTE_GROUP)
|
2015-04-07 23:00:29 +03:00
|
|
|
{
|
|
|
|
out << separator;
|
|
|
|
}
|
2016-02-19 22:00:19 +03:00
|
|
|
for(unsigned int i = 0; i < object->List.size(); ++i)
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2016-02-19 22:00:19 +03:00
|
|
|
if(object->List[i]->TypeValue == STRING)
|
2007-08-14 19:45:15 +04:00
|
|
|
{
|
2016-02-19 22:00:19 +03:00
|
|
|
object->List[i]->PrintString(out);
|
|
|
|
if(i+1 < object->List.size())
|
2007-08-14 19:45:15 +04:00
|
|
|
{
|
2016-02-19 22:00:19 +03:00
|
|
|
out << ",";
|
2007-08-14 19:45:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-19 22:00:19 +03:00
|
|
|
cmXCodeObject::Indent((level + 1) * factor, out);
|
|
|
|
out << object->List[i]->Id;
|
|
|
|
object->List[i]->PrintComment(out);
|
|
|
|
out << "," << separator;
|
2007-08-14 19:45:15 +04:00
|
|
|
}
|
2016-02-19 22:00:19 +03:00
|
|
|
}
|
|
|
|
if(parent->TypeValue != ATTRIBUTE_GROUP)
|
|
|
|
{
|
|
|
|
cmXCodeObject::Indent(level * factor, out);
|
|
|
|
}
|
|
|
|
out << ");" << separator;
|
|
|
|
}
|
|
|
|
break;
|
2007-08-14 19:45:15 +04:00
|
|
|
|
2016-02-19 22:00:19 +03:00
|
|
|
case ATTRIBUTE_GROUP:
|
|
|
|
{
|
|
|
|
out << name << " = {";
|
|
|
|
if(separator == "\n")
|
|
|
|
{
|
2005-11-16 21:13:39 +03:00
|
|
|
out << separator;
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
2016-02-19 22:00:19 +03:00
|
|
|
std::map<std::string, cmXCodeObject*>::const_iterator i;
|
|
|
|
for(i = object->ObjectAttributes.begin();
|
|
|
|
i != object->ObjectAttributes.end(); ++i)
|
|
|
|
{
|
|
|
|
PrintAttribute(out, (level + 1) * factor, separator, factor,
|
|
|
|
i->first, i->second, object);
|
|
|
|
}
|
|
|
|
cmXCodeObject::Indent(level * factor, out);
|
2005-11-16 21:13:39 +03:00
|
|
|
out << "};" << separator;
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
2016-02-19 22:00:19 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OBJECT_REF:
|
2005-01-22 00:25:36 +03:00
|
|
|
{
|
2016-02-19 22:00:19 +03:00
|
|
|
cmXCodeObject::PrintString(out, name);
|
2011-04-05 17:25:58 +04:00
|
|
|
out << " = " << object->Object->Id;
|
2016-02-19 22:00:19 +03:00
|
|
|
if(object->Object->HasComment() && name != "remoteGlobalIDString")
|
2005-11-16 21:13:39 +03:00
|
|
|
{
|
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
|
|
|
}
|
2016-02-19 22:00:19 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STRING:
|
2005-01-25 23:26:57 +03:00
|
|
|
{
|
2016-02-19 22:00:19 +03:00
|
|
|
cmXCodeObject::PrintString(out, name);
|
2011-04-05 17:25:58 +04:00
|
|
|
out << " = ";
|
2008-09-02 18:27:15 +04:00
|
|
|
object->PrintString(out);
|
|
|
|
out << ";" << separator;
|
2005-01-25 23:26:57 +03:00
|
|
|
}
|
2016-02-19 22:00:19 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-01-28 00:11:44 +03:00
|
|
|
{
|
2016-02-19 22:00:19 +03:00
|
|
|
break;
|
2005-01-28 00:11:44 +03:00
|
|
|
}
|
2005-01-22 00:25:36 +03:00
|
|
|
}
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2005-01-25 01:35:54 +03:00
|
|
|
void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
|
|
|
|
std::ostream& out)
|
2012-08-13 21:42:58 +04:00
|
|
|
{
|
2005-01-25 01:35:54 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
void cmXCodeObject::PrintString(std::ostream& os,std::string String)
|
2005-11-16 21:13:39 +03:00
|
|
|
{
|
2008-09-02 18:27:15 +04: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 17:25:58 +04:00
|
|
|
(String.empty() ||
|
2015-04-04 23:13:45 +03:00
|
|
|
String.find("//") != String.npos ||
|
2015-08-02 01:06:49 +03:00
|
|
|
String.find_first_not_of(
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"abcdefghijklmnopqrstuvwxyz"
|
|
|
|
"0123456789"
|
|
|
|
"$_./") != String.npos);
|
2008-09-02 18:27:15 +04:00
|
|
|
const char* quote = needQuote? "\"" : "";
|
|
|
|
|
|
|
|
// Print the string, quoted and escaped as necessary.
|
|
|
|
os << quote;
|
2011-04-05 17:25:58 +04:00
|
|
|
for(std::string::const_iterator i = String.begin();
|
|
|
|
i != String.end(); ++i)
|
2005-11-16 21:13:39 +03:00
|
|
|
{
|
2015-12-27 18:33:46 +03:00
|
|
|
if(*i == '"' || *i == '\\')
|
2008-09-02 18:27:15 +04:00
|
|
|
{
|
2015-12-27 18:33:46 +03:00
|
|
|
// Escape double-quotes and backslashes.
|
2008-09-02 18:27:15 +04:00
|
|
|
os << '\\';
|
|
|
|
}
|
|
|
|
os << *i;
|
2005-11-16 21:13:39 +03:00
|
|
|
}
|
2008-09-02 18:27:15 +04:00
|
|
|
os << quote;
|
|
|
|
}
|
|
|
|
|
2011-04-05 17:25:58 +04:00
|
|
|
void cmXCodeObject::PrintString(std::ostream& os) const
|
|
|
|
{
|
|
|
|
cmXCodeObject::PrintString(os,this->String);
|
|
|
|
}
|
|
|
|
|
2014-02-04 06:16:12 +04:00
|
|
|
void cmXCodeObject::SetString(const std::string& s)
|
2008-09-02 18:27:15 +04:00
|
|
|
{
|
|
|
|
this->String = s;
|
2005-11-16 21:13:39 +03:00
|
|
|
}
|