CMake/Source/cmXCodeObject.cxx

255 lines
7.0 KiB
C++
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 22:01:08 +03:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2005-01-22 00:25:36 +03:00
#include "cmXCodeObject.h"
#include "cmSystemTools.h"
#include <CoreFoundation/CoreFoundation.h> // CFUUIDCreate
2005-01-22 00:25:36 +03:00
const char* cmXCodeObject::PBXTypeNames[] = {
/* clang-format needs this comment to break after the opening brace */
"PBXGroup",
"PBXBuildStyle",
"PBXProject",
"PBXHeadersBuildPhase",
"PBXSourcesBuildPhase",
"PBXFrameworksBuildPhase",
"PBXNativeTarget",
"PBXFileReference",
"PBXBuildFile",
"PBXContainerItemProxy",
"PBXTargetDependency",
"PBXShellScriptBuildPhase",
"PBXResourcesBuildPhase",
"PBXApplicationReference",
"PBXExecutableFileReference",
"PBXLibraryReference",
"PBXToolTarget",
"PBXLibraryTarget",
"PBXAggregateTarget",
"XCBuildConfiguration",
"XCConfigurationList",
"PBXCopyFilesBuildPhase",
"None"
};
2005-01-22 00:25:36 +03:00
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;
this->Object = 0;
2006-03-15 19:02:08 +03:00
this->IsA = ptype;
if (type == OBJECT) {
// 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);
} else {
this->Id =
"Temporary cmake object, should not be referred to in Xcode file";
}
cmSystemTools::ReplaceString(this->Id, "-", "");
if (this->Id.size() > 24) {
this->Id = this->Id.substr(0, 24);
}
2006-03-15 19:38:47 +03:00
this->TypeValue = type;
if (this->TypeValue == OBJECT) {
this->AddAttribute("isa", 0);
}
2005-01-22 00:25:36 +03:00
}
bool cmXCodeObject::IsEmpty() const
{
switch (this->TypeValue) {
case OBJECT_LIST:
return this->List.empty();
case STRING:
return this->String.empty();
case ATTRIBUTE_GROUP:
return this->ObjectAttributes.empty();
case OBJECT_REF:
case OBJECT:
return this->Object == 0;
}
return true; // unreachable, but quiets warnings
}
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--;
}
2005-01-22 00:25:36 +03:00
}
void cmXCodeObject::Print(std::ostream& out)
{
std::string separator = "\n";
int indentFactor = 1;
cmXCodeObject::Indent(2 * indentFactor, out);
if (this->Version > 15 &&
(this->IsA == PBXFileReference || this->IsA == PBXBuildFile)) {
separator = " ";
indentFactor = 0;
}
out << this->Id;
this->PrintComment(out);
out << " = {";
if (separator == "\n") {
out << separator;
}
std::map<std::string, cmXCodeObject*>::iterator i;
cmXCodeObject::Indent(3 * indentFactor, out);
out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator;
for (i = this->ObjectAttributes.begin(); i != this->ObjectAttributes.end();
++i) {
if (i->first == "isa")
continue;
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: {
out << name << " = (";
if (parent->TypeValue != ATTRIBUTE_GROUP) {
out << separator;
}
for (unsigned int i = 0; i < object->List.size(); ++i) {
if (object->List[i]->TypeValue == STRING) {
object->List[i]->PrintString(out);
if (i + 1 < object->List.size()) {
out << ",";
}
} else {
cmXCodeObject::Indent((level + 1) * factor, out);
out << object->List[i]->Id;
object->List[i]->PrintComment(out);
out << "," << separator;
}
}
if (parent->TypeValue != ATTRIBUTE_GROUP) {
cmXCodeObject::Indent(level * factor, out);
}
out << ");" << separator;
} break;
case ATTRIBUTE_GROUP: {
out << name << " = {";
if (separator == "\n") {
out << separator;
}
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);
out << "};" << separator;
} break;
case OBJECT_REF: {
cmXCodeObject::PrintString(out, name);
out << " = " << object->Object->Id;
if (object->Object->HasComment() && name != "remoteGlobalIDString") {
2006-03-15 19:38:47 +03:00
object->Object->PrintComment(out);
2005-01-22 00:25:36 +03:00
}
out << ";" << separator;
} break;
case STRING: {
cmXCodeObject::PrintString(out, name);
out << " = ";
object->PrintString(out);
out << ";" << separator;
} break;
default: {
break;
2005-01-22 00:25:36 +03:00
}
}
2005-01-22 00:25:36 +03:00
}
2005-01-25 01:35:54 +03:00
void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
std::ostream& out)
{
2005-01-25 01:35:54 +03:00
cmXCodeObject::Indent(1, out);
2005-01-22 00:25:36 +03:00
out << "objects = {\n";
for (unsigned int i = 0; i < objs.size(); ++i) {
if (objs[i]->TypeValue == OBJECT) {
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
}
void cmXCodeObject::PrintString(std::ostream& os, std::string String)
{
// The string needs to be quoted if it contains any characters
// considered special by the Xcode project file parser.
bool needQuote = (String.empty() || String.find("//") != String.npos ||
String.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789"
"$_./") != String.npos);
const char* quote = needQuote ? "\"" : "";
// Print the string, quoted and escaped as necessary.
os << quote;
for (std::string::const_iterator i = String.begin(); i != String.end();
++i) {
if (*i == '"' || *i == '\\') {
// Escape double-quotes and backslashes.
os << '\\';
}
os << *i;
}
os << quote;
}
void cmXCodeObject::PrintString(std::ostream& os) const
{
cmXCodeObject::PrintString(os, this->String);
}
void cmXCodeObject::SetString(const std::string& s)
{
this->String = s;
}