cmGlobalXCodeGenerator: Adopt pbxproj object id generation

This commit is contained in:
Brad King 2021-01-06 15:29:24 -05:00
parent 95e3ff2e88
commit d250b67722
6 changed files with 30 additions and 28 deletions

View File

@ -799,7 +799,8 @@ void cmGlobalXCodeGenerator::addObject(std::unique_ptr<cmXCodeObject> obj)
cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(
cmXCodeObject::PBXType ptype)
{
auto obj = cm::make_unique<cmXCode21Object>(ptype, cmXCodeObject::OBJECT);
auto obj = cm::make_unique<cmXCode21Object>(ptype, cmXCodeObject::OBJECT,
this->GetObjectId());
auto ptr = obj.get();
this->addObject(std::move(obj));
return ptr;
@ -807,7 +808,9 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(
cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
{
auto obj = cm::make_unique<cmXCodeObject>(cmXCodeObject::None, type);
auto obj = cm::make_unique<cmXCodeObject>(
cmXCodeObject::None, type,
"Temporary cmake object, should not be referred to in Xcode file");
auto ptr = obj.get();
this->addObject(std::move(obj));
return ptr;
@ -3138,6 +3141,23 @@ cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(
return i->second;
}
std::string cmGlobalXCodeGenerator::GetObjectId()
{
std::string objectId;
char cUuid[40] = { 0 };
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef s = CFUUIDCreateString(kCFAllocatorDefault, uuid);
CFStringGetCString(s, cUuid, sizeof(cUuid), kCFStringEncodingUTF8);
objectId = cUuid;
CFRelease(s);
CFRelease(uuid);
cmSystemTools::ReplaceString(objectId, "-", "");
if (objectId.size() > 24) {
objectId = objectId.substr(0, 24);
}
return objectId;
}
std::string cmGlobalXCodeGenerator::GetOrCreateId(const std::string& name,
const std::string& id)
{

View File

@ -162,6 +162,7 @@ private:
const std::string& configName);
cmXCodeObject* FindXCodeTarget(const cmGeneratorTarget*);
std::string GetObjectId();
std::string GetOrCreateId(const std::string& name, const std::string& id);
// create cmXCodeObject from these functions so that memory can be managed

View File

@ -4,11 +4,12 @@
#include <ostream>
#include <string>
#include <utility>
#include "cmSystemTools.h"
cmXCode21Object::cmXCode21Object(PBXType ptype, Type type)
: cmXCodeObject(ptype, type)
cmXCode21Object::cmXCode21Object(PBXType ptype, Type type, std::string id)
: cmXCodeObject(ptype, type, std::move(id))
{
this->Version = 21;
}

View File

@ -13,7 +13,7 @@
class cmXCode21Object : public cmXCodeObject
{
public:
cmXCode21Object(PBXType ptype, Type type);
cmXCode21Object(PBXType ptype, Type type, std::string id);
void PrintComment(std::ostream&) override;
static void PrintList(std::vector<std::unique_ptr<cmXCodeObject>> const&,
std::ostream& out, PBXType t);

View File

@ -40,7 +40,7 @@ cmXCodeObject::~cmXCodeObject()
this->Version = 15;
}
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type, std::string id)
{
this->Version = 15;
this->Target = nullptr;
@ -48,27 +48,7 @@ cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
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);
}
this->Id = std::move(id);
this->TypeValue = type;
if (this->TypeValue == OBJECT) {

View File

@ -57,7 +57,7 @@ public:
};
static const char* PBXTypeNames[];
virtual ~cmXCodeObject();
cmXCodeObject(PBXType ptype, Type type);
cmXCodeObject(PBXType ptype, Type type, std::string id);
Type GetType() const { return this->TypeValue; }
PBXType GetIsA() const { return this->IsA; }