mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 14:08:35 +08:00
cmGlobalXCodeGenerator: Adopt pbxproj object id generation
This commit is contained in:
@@ -799,7 +799,8 @@ void cmGlobalXCodeGenerator::addObject(std::unique_ptr<cmXCodeObject> obj)
|
|||||||
cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(
|
cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(
|
||||||
cmXCodeObject::PBXType ptype)
|
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();
|
auto ptr = obj.get();
|
||||||
this->addObject(std::move(obj));
|
this->addObject(std::move(obj));
|
||||||
return ptr;
|
return ptr;
|
||||||
@@ -807,7 +808,9 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(
|
|||||||
|
|
||||||
cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
|
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();
|
auto ptr = obj.get();
|
||||||
this->addObject(std::move(obj));
|
this->addObject(std::move(obj));
|
||||||
return ptr;
|
return ptr;
|
||||||
@@ -3138,6 +3141,23 @@ cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(
|
|||||||
return i->second;
|
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,
|
std::string cmGlobalXCodeGenerator::GetOrCreateId(const std::string& name,
|
||||||
const std::string& id)
|
const std::string& id)
|
||||||
{
|
{
|
||||||
|
@@ -162,6 +162,7 @@ private:
|
|||||||
const std::string& configName);
|
const std::string& configName);
|
||||||
|
|
||||||
cmXCodeObject* FindXCodeTarget(const cmGeneratorTarget*);
|
cmXCodeObject* FindXCodeTarget(const cmGeneratorTarget*);
|
||||||
|
std::string GetObjectId();
|
||||||
std::string GetOrCreateId(const std::string& name, const std::string& id);
|
std::string GetOrCreateId(const std::string& name, const std::string& id);
|
||||||
|
|
||||||
// create cmXCodeObject from these functions so that memory can be managed
|
// create cmXCodeObject from these functions so that memory can be managed
|
||||||
|
@@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
|
|
||||||
cmXCode21Object::cmXCode21Object(PBXType ptype, Type type)
|
cmXCode21Object::cmXCode21Object(PBXType ptype, Type type, std::string id)
|
||||||
: cmXCodeObject(ptype, type)
|
: cmXCodeObject(ptype, type, std::move(id))
|
||||||
{
|
{
|
||||||
this->Version = 21;
|
this->Version = 21;
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
class cmXCode21Object : public cmXCodeObject
|
class cmXCode21Object : public cmXCodeObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cmXCode21Object(PBXType ptype, Type type);
|
cmXCode21Object(PBXType ptype, Type type, std::string id);
|
||||||
void PrintComment(std::ostream&) override;
|
void PrintComment(std::ostream&) override;
|
||||||
static void PrintList(std::vector<std::unique_ptr<cmXCodeObject>> const&,
|
static void PrintList(std::vector<std::unique_ptr<cmXCodeObject>> const&,
|
||||||
std::ostream& out, PBXType t);
|
std::ostream& out, PBXType t);
|
||||||
|
@@ -40,7 +40,7 @@ cmXCodeObject::~cmXCodeObject()
|
|||||||
this->Version = 15;
|
this->Version = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
|
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type, std::string id)
|
||||||
{
|
{
|
||||||
this->Version = 15;
|
this->Version = 15;
|
||||||
this->Target = nullptr;
|
this->Target = nullptr;
|
||||||
@@ -48,27 +48,7 @@ cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
|
|||||||
|
|
||||||
this->IsA = ptype;
|
this->IsA = ptype;
|
||||||
|
|
||||||
if (type == OBJECT) {
|
this->Id = std::move(id);
|
||||||
// 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->TypeValue = type;
|
this->TypeValue = type;
|
||||||
if (this->TypeValue == OBJECT) {
|
if (this->TypeValue == OBJECT) {
|
||||||
|
@@ -57,7 +57,7 @@ public:
|
|||||||
};
|
};
|
||||||
static const char* PBXTypeNames[];
|
static const char* PBXTypeNames[];
|
||||||
virtual ~cmXCodeObject();
|
virtual ~cmXCodeObject();
|
||||||
cmXCodeObject(PBXType ptype, Type type);
|
cmXCodeObject(PBXType ptype, Type type, std::string id);
|
||||||
Type GetType() const { return this->TypeValue; }
|
Type GetType() const { return this->TypeValue; }
|
||||||
PBXType GetIsA() const { return this->IsA; }
|
PBXType GetIsA() const { return this->IsA; }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user