Attached Files | 0001-Xcode-Remember-generated-ObjectIDs-in-the-cache-to-a.patch [^] (4,611 bytes) 2011-01-30 16:47 [Show Content] [Hide Content]From dd1d1630b4149a19a0d8990352baff798c8d2fc8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Johan=20Bj=C3=B6rk?= <phb@spotify.com>
Date: Sun, 30 Jan 2011 22:45:00 +0100
Subject: [PATCH] Xcode: Remember generated ObjectIDs in the cache to allow functional <user>.pbxuser files to work.
---
Source/cmGlobalXCodeGenerator.cxx | 23 ++++++++++++++++++++++-
Source/cmGlobalXCodeGenerator.h | 2 ++
Source/cmXCodeObject.cxx | 3 +++
Source/cmXCodeObject.h | 5 +++++
4 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 358721f..0096e81 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -1984,7 +1984,7 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
}
}
}
-
+ target->SetId(this->GetOrCreateId(cmtarget.GetName(),target->GetId()).c_str());
return target;
}
@@ -2126,6 +2126,7 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
target->AddAttribute("productType", this->CreateString(productType));
}
target->SetTarget(&cmtarget);
+ target->SetId(this->GetOrCreateId(cmtarget.GetName(),target->GetId()).c_str());
return target;
}
@@ -2148,6 +2149,22 @@ cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
return 0;
}
+std::string cmGlobalXCodeGenerator::GetOrCreateId(const char* name, const char* id)
+{
+ std::string guidStoreName = name;
+ guidStoreName += "_GUID_CMAKE";
+ const char* storedGUID = this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
+ if(storedGUID)
+ {
+ return storedGUID;
+ }
+
+ this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
+ id, "Stored XCode object GUID",
+ cmCacheManager::INTERNAL);
+ return id;
+}
+
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
cmXCodeObject* dependTarget)
@@ -2615,6 +2632,9 @@ void cmGlobalXCodeGenerator
this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
this->RootObject->SetComment("Project object");
+
+ this->RootObject->SetId(this->GetOrCreateId(root->GetMakefile()->GetProjectName(),this->RootObject->GetId()).c_str());
+
group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
this->RootObject->AddAttribute("mainGroup",
this->CreateObjectReference(mainGroup));
@@ -3018,6 +3038,7 @@ cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
}
this->WriteXCodePBXProj(fout, root, generators);
this->ClearXCodeObjects();
+ root->GetMakefile()->GetCacheManager()->SaveCache(root->GetMakefile()->GetHomeOutputDirectory());
}
//----------------------------------------------------------------------------
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index 290532a..00f38ff 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -121,6 +121,8 @@ private:
);
cmXCodeObject* FindXCodeTarget(cmTarget*);
+ std::string GetOrCreateId(const char* name, const char* id);
+
// create cmXCodeObject from these functions so that memory can be managed
// correctly. All objects created are stored in this->XCodeObjects.
cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx
index 5920470..79407f1 100644
--- a/Source/cmXCodeObject.cxx
+++ b/Source/cmXCodeObject.cxx
@@ -33,6 +33,9 @@ cmXCodeObject::~cmXCodeObject()
}
//----------------------------------------------------------------------------
+//We set the Id of an xcode object to a unique number for every new generation.
+//However the XCode user file references certain Ids, for those cases, we override
+//the generated Id using SetId().
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
{
this->Version = 15;
diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h
index 2bea63b..c0729d1 100644
--- a/Source/cmXCodeObject.h
+++ b/Source/cmXCodeObject.h
@@ -79,10 +79,15 @@ public:
static void PrintList(std::vector<cmXCodeObject*> const&,
std::ostream& out);
+
const char* GetId()
{
return this->Id.c_str();
}
+ void SetId(const char* id)
+ {
+ this->Id = id;
+ }
cmTarget* GetTarget()
{
return this->Target;
--
1.7.2.1
0001-xcode-Remember-generated-objectIDs-in-the-CMakeCache.patch [^] (4,708 bytes) 2011-01-31 14:34 [Show Content] [Hide Content]From 41e4f27a969cdfd6e3591d858cdd05fbd9d23e8f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Johan=20Bj=C3=B6rk?= <phb@spotify.com>
Date: Mon, 31 Jan 2011 19:43:05 +0100
Subject: [PATCH] xcode: Remember generated objectIDs in the CMakeCache to allow <user>.pbxuser to work after source regeneration.
---
Source/cmGlobalXCodeGenerator.cxx | 26 +++++++++++++++++++++++++-
Source/cmGlobalXCodeGenerator.h | 2 ++
Source/cmXCodeObject.cxx | 3 +++
Source/cmXCodeObject.h | 5 +++++
4 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 358721f..c25eef6 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -1984,7 +1984,7 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
}
}
}
-
+ target->SetId(this->GetOrCreateId(cmtarget.GetName(),target->GetId()).c_str());
return target;
}
@@ -2126,6 +2126,7 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
target->AddAttribute("productType", this->CreateString(productType));
}
target->SetTarget(&cmtarget);
+ target->SetId(this->GetOrCreateId(cmtarget.GetName(),target->GetId()).c_str());
return target;
}
@@ -2148,6 +2149,23 @@ cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
return 0;
}
+std::string cmGlobalXCodeGenerator::GetOrCreateId(const char* name, const char* id)
+{
+ std::string guidStoreName = name;
+ guidStoreName += "_GUID_CMAKE";
+ const char* storedGUID = this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
+
+ if(storedGUID)
+ {
+ return storedGUID;
+ }
+
+ this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
+ id, "Stored XCode object GUID",
+ cmCacheManager::INTERNAL);
+ return id;
+}
+
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
cmXCodeObject* dependTarget)
@@ -2615,6 +2633,11 @@ void cmGlobalXCodeGenerator
this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
this->RootObject->SetComment("Project object");
+
+ std::string project_id = "PROJECT_";
+ project_id += root->GetMakefile()->GetProjectName();
+ this->RootObject->SetId(this->GetOrCreateId(project_id.c_str(),this->RootObject->GetId()).c_str());
+
group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
this->RootObject->AddAttribute("mainGroup",
this->CreateObjectReference(mainGroup));
@@ -3018,6 +3041,7 @@ cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
}
this->WriteXCodePBXProj(fout, root, generators);
this->ClearXCodeObjects();
+ root->GetMakefile()->GetCacheManager()->SaveCache(root->GetMakefile()->GetHomeOutputDirectory());
}
//----------------------------------------------------------------------------
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index 290532a..00f38ff 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -121,6 +121,8 @@ private:
);
cmXCodeObject* FindXCodeTarget(cmTarget*);
+ std::string GetOrCreateId(const char* name, const char* id);
+
// create cmXCodeObject from these functions so that memory can be managed
// correctly. All objects created are stored in this->XCodeObjects.
cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx
index 5920470..79407f1 100644
--- a/Source/cmXCodeObject.cxx
+++ b/Source/cmXCodeObject.cxx
@@ -33,6 +33,9 @@ cmXCodeObject::~cmXCodeObject()
}
//----------------------------------------------------------------------------
+//We set the Id of an xcode object to a unique number for every new generation.
+//However the XCode user file references certain Ids, for those cases, we override
+//the generated Id using SetId().
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
{
this->Version = 15;
diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h
index 2bea63b..c0729d1 100644
--- a/Source/cmXCodeObject.h
+++ b/Source/cmXCodeObject.h
@@ -79,10 +79,15 @@ public:
static void PrintList(std::vector<cmXCodeObject*> const&,
std::ostream& out);
+
const char* GetId()
{
return this->Id.c_str();
}
+ void SetId(const char* id)
+ {
+ this->Id = id;
+ }
cmTarget* GetTarget()
{
return this->Target;
--
1.7.2.1
0002-XCode-Reuse-ObjectIDs.-This-version-uses-CoreFoundat.patch [^] (8,173 bytes) 2011-02-15 09:35 [Show Content] [Hide Content]From b7b16efa92ac5f41bc514442ddd7b9d00518e55f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Johan=20Bj=C3=B6rk?= <phb@spotify.com>
Date: Tue, 15 Feb 2011 15:15:39 +0100
Subject: [PATCH 2/2] XCode: Reuse ObjectIDs. This version uses CoreFoundation to get a UUID, then as an extra check we verify that we don't create duplicates, as it creates hard to track down issues with XCode.
---
Source/cmGlobalXCodeGenerator.cxx | 45 +++++++++++++++++++++++++++++++++---
Source/cmGlobalXCodeGenerator.h | 4 +++
Source/cmXCodeObject.cxx | 26 +++++++++------------
Source/cmXCodeObject.h | 5 ++++
4 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 9b97dbf..ac1d38c 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -21,7 +21,7 @@
#include "cmCustomCommandGenerator.h"
#include <cmsys/auto_ptr.hxx>
-
+#include <assert.h>
//----------------------------------------------------------------------------
#if defined(CMAKE_BUILD_WITH_CMAKE)
#include "cmXMLParser.h"
@@ -456,12 +456,25 @@ void cmGlobalXCodeGenerator::ClearXCodeObjects()
delete this->XCodeObjects[i];
}
this->XCodeObjects.clear();
+ this->XCodeObjectIDs.clear();
this->GroupMap.clear();
this->GroupNameMap.clear();
this->TargetGroup.clear();
this->FileRefs.clear();
}
+/* XCode will freak out if we happen to generate two identical object IDs, so let's verify we don't */
+void cmGlobalXCodeGenerator::addObject(cmXCodeObject *obj)
+{
+ if(obj->GetType() == cmXCodeObject::OBJECT)
+ {
+ cmStdString id = obj->GetId();
+ assert(!this->XCodeObjectIDs.count(id));
+ this->XCodeObjectIDs.insert(id);
+ }
+ this->XCodeObjects.push_back(obj);
+}
+
//----------------------------------------------------------------------------
cmXCodeObject*
cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
@@ -475,7 +488,7 @@ cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
{
obj = new cmXCode21Object(ptype, cmXCodeObject::OBJECT);
}
- this->XCodeObjects.push_back(obj);
+ addObject(obj);
return obj;
}
@@ -484,7 +497,7 @@ cmXCodeObject*
cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
{
cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
- this->XCodeObjects.push_back(obj);
+ addObject(obj);
return obj;
}
@@ -2021,7 +2034,7 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
}
}
}
-
+ target->SetId(this->GetOrCreateId(cmtarget.GetName(),target->GetId()).c_str());
return target;
}
@@ -2170,6 +2183,7 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
target->AddAttribute("productType", this->CreateString(productType));
}
target->SetTarget(&cmtarget);
+ target->SetId(this->GetOrCreateId(cmtarget.GetName(),target->GetId()).c_str());
return target;
}
@@ -2192,6 +2206,23 @@ cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
return 0;
}
+std::string cmGlobalXCodeGenerator::GetOrCreateId(const char* name, const char* id)
+{
+ std::string guidStoreName = name;
+ guidStoreName += "_GUID_CMAKE";
+ const char* storedGUID = this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
+
+ if(storedGUID)
+ {
+ return storedGUID;
+ }
+
+ this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
+ id, "Stored XCode object GUID",
+ cmCacheManager::INTERNAL);
+ return id;
+}
+
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
cmXCodeObject* dependTarget)
@@ -2689,6 +2720,11 @@ void cmGlobalXCodeGenerator
this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
this->RootObject->SetComment("Project object");
+
+ std::string project_id = "PROJECT_";
+ project_id += root->GetMakefile()->GetProjectName();
+ this->RootObject->SetId(this->GetOrCreateId(project_id.c_str(),this->RootObject->GetId()).c_str());
+
group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
this->RootObject->AddAttribute("mainGroup",
this->CreateObjectReference(mainGroup));
@@ -3092,6 +3128,7 @@ cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
}
this->WriteXCodePBXProj(fout, root, generators);
this->ClearXCodeObjects();
+ root->GetMakefile()->GetCacheManager()->SaveCache(root->GetMakefile()->GetHomeOutputDirectory());
}
//----------------------------------------------------------------------------
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index 22a78f2..10aa828 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -123,6 +123,8 @@ private:
);
cmXCodeObject* FindXCodeTarget(cmTarget*);
+ std::string GetOrCreateId(const char* name, const char* id);
+
// create cmXCodeObject from these functions so that memory can be managed
// correctly. All objects created are stored in this->XCodeObjects.
cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
@@ -197,9 +199,11 @@ protected:
unsigned int XcodeVersion;
std::string VersionString;
+ std::set<cmStdString> XCodeObjectIDs;
std::vector<cmXCodeObject*> XCodeObjects;
cmXCodeObject* RootObject;
private:
+ void addObject(cmXCodeObject *obj);
cmXCodeObject* MainGroupChildren;
cmXCodeObject* SourcesGroupChildren;
cmXCodeObject* ResourcesGroupChildren;
diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx
index 5920470..7a380be 100644
--- a/Source/cmXCodeObject.cxx
+++ b/Source/cmXCodeObject.cxx
@@ -12,6 +12,7 @@
#include "cmXCodeObject.h"
#include "cmSystemTools.h"
+#include <CoreFoundation/CoreFoundation.h> //For UUID generation
//----------------------------------------------------------------------------
const char* cmXCodeObject::PBXTypeNames[] = {
"PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
@@ -33,6 +34,9 @@ cmXCodeObject::~cmXCodeObject()
}
//----------------------------------------------------------------------------
+//We set the Id of an xcode object to a unique number for every new generation.
+//However the XCode user file references certain Ids, for those cases, we override
+//the generated Id using SetId().
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
{
this->Version = 15;
@@ -43,27 +47,19 @@ cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
this->IsA = ptype;
if(type == OBJECT)
{
- cmOStringStream str;
- str << (void*)this;
- str << (void*)this;
- str << (void*)this;
- this->Id = str.str();
+ char cUuid[40];
+ CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
+ CFStringRef s = CFUUIDCreateString(kCFAllocatorDefault,uuid);
+ assert(CFStringGetCString(s,cUuid,sizeof(cUuid),kCFStringEncodingUTF8));
+ this->Id = cUuid;
+ CFRelease(uuid);
}
else
{
this->Id =
"Temporary cmake object, should not be refered to in xcode file";
}
- cmSystemTools::ReplaceString(this->Id, "0x", "");
- this->Id = cmSystemTools::UpperCase(this->Id);
- if(this->Id.size() < 24)
- {
- int diff = 24 - this->Id.size();
- for(int i =0; i < diff; ++i)
- {
- this->Id += "0";
- }
- }
+ cmSystemTools::ReplaceString(this->Id, "-", "");
if(this->Id.size() > 24)
{
this->Id = this->Id.substr(0,24);
diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h
index 2bea63b..c0729d1 100644
--- a/Source/cmXCodeObject.h
+++ b/Source/cmXCodeObject.h
@@ -79,10 +79,15 @@ public:
static void PrintList(std::vector<cmXCodeObject*> const&,
std::ostream& out);
+
const char* GetId()
{
return this->Id.c_str();
}
+ void SetId(const char* id)
+ {
+ this->Id = id;
+ }
cmTarget* GetTarget()
{
return this->Target;
--
1.7.2.1
0001-Save-objectIDS.patch [^] (8,015 bytes) 2011-02-15 14:23 [Show Content] [Hide Content]From 561e4781a225f6d6b0c3a9ccb6a8d13072df603c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Johan=20Bj=C3=B6rk?= <phb@spotify.com>
Date: Tue, 15 Feb 2011 19:31:57 +0100
Subject: [PATCH] Save objectIDS.
---
Source/cmGlobalXCodeGenerator.cxx | 45 +++++++++++++++++++++++++++++++++---
Source/cmGlobalXCodeGenerator.h | 4 +++
Source/cmXCodeObject.cxx | 27 ++++++++++------------
Source/cmXCodeObject.h | 5 ++++
4 files changed, 62 insertions(+), 19 deletions(-)
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index c336e08..c85882f 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -21,7 +21,7 @@
#include "cmCustomCommandGenerator.h"
#include <cmsys/auto_ptr.hxx>
-
+#include <assert.h>
//----------------------------------------------------------------------------
#if defined(CMAKE_BUILD_WITH_CMAKE)
#include "cmXMLParser.h"
@@ -456,12 +456,25 @@ void cmGlobalXCodeGenerator::ClearXCodeObjects()
delete this->XCodeObjects[i];
}
this->XCodeObjects.clear();
+ this->XCodeObjectIDs.clear();
this->GroupMap.clear();
this->GroupNameMap.clear();
this->TargetGroup.clear();
this->FileRefs.clear();
}
+/* XCode will freak out if we happen to generate two identical object IDs, so let's verify we don't */
+void cmGlobalXCodeGenerator::addObject(cmXCodeObject *obj)
+{
+ if(obj->GetType() == cmXCodeObject::OBJECT)
+ {
+ cmStdString id = obj->GetId();
+ assert(!this->XCodeObjectIDs.count(id));
+ this->XCodeObjectIDs.insert(id);
+ }
+ this->XCodeObjects.push_back(obj);
+}
+
//----------------------------------------------------------------------------
cmXCodeObject*
cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
@@ -475,7 +488,7 @@ cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
{
obj = new cmXCode21Object(ptype, cmXCodeObject::OBJECT);
}
- this->XCodeObjects.push_back(obj);
+ addObject(obj);
return obj;
}
@@ -484,7 +497,7 @@ cmXCodeObject*
cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
{
cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
- this->XCodeObjects.push_back(obj);
+ addObject(obj);
return obj;
}
@@ -2021,7 +2034,7 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
}
}
}
-
+ target->SetId(this->GetOrCreateId(cmtarget.GetName(),target->GetId()).c_str());
return target;
}
@@ -2170,6 +2183,7 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
target->AddAttribute("productType", this->CreateString(productType));
}
target->SetTarget(&cmtarget);
+ target->SetId(this->GetOrCreateId(cmtarget.GetName(),target->GetId()).c_str());
return target;
}
@@ -2192,6 +2206,23 @@ cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
return 0;
}
+std::string cmGlobalXCodeGenerator::GetOrCreateId(const char* name, const char* id)
+{
+ std::string guidStoreName = name;
+ guidStoreName += "_GUID_CMAKE";
+ const char* storedGUID = this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
+
+ if(storedGUID)
+ {
+ return storedGUID;
+ }
+
+ this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
+ id, "Stored XCode object GUID",
+ cmCacheManager::INTERNAL);
+ return id;
+}
+
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
cmXCodeObject* dependTarget)
@@ -2683,6 +2714,11 @@ void cmGlobalXCodeGenerator
this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
this->RootObject->SetComment("Project object");
+
+ std::string project_id = "PROJECT_";
+ project_id += root->GetMakefile()->GetProjectName();
+ this->RootObject->SetId(this->GetOrCreateId(project_id.c_str(),this->RootObject->GetId()).c_str());
+
group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
this->RootObject->AddAttribute("mainGroup",
this->CreateObjectReference(mainGroup));
@@ -3086,6 +3122,7 @@ cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
}
this->WriteXCodePBXProj(fout, root, generators);
this->ClearXCodeObjects();
+ root->GetMakefile()->GetCacheManager()->SaveCache(root->GetMakefile()->GetHomeOutputDirectory());
}
//----------------------------------------------------------------------------
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index 22a78f2..10aa828 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -123,6 +123,8 @@ private:
);
cmXCodeObject* FindXCodeTarget(cmTarget*);
+ std::string GetOrCreateId(const char* name, const char* id);
+
// create cmXCodeObject from these functions so that memory can be managed
// correctly. All objects created are stored in this->XCodeObjects.
cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
@@ -197,9 +199,11 @@ protected:
unsigned int XcodeVersion;
std::string VersionString;
+ std::set<cmStdString> XCodeObjectIDs;
std::vector<cmXCodeObject*> XCodeObjects;
cmXCodeObject* RootObject;
private:
+ void addObject(cmXCodeObject *obj);
cmXCodeObject* MainGroupChildren;
cmXCodeObject* SourcesGroupChildren;
cmXCodeObject* ResourcesGroupChildren;
diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx
index 5920470..6ce3b60 100644
--- a/Source/cmXCodeObject.cxx
+++ b/Source/cmXCodeObject.cxx
@@ -12,6 +12,7 @@
#include "cmXCodeObject.h"
#include "cmSystemTools.h"
+#include <CoreFoundation/CoreFoundation.h> //For UUID generation
//----------------------------------------------------------------------------
const char* cmXCodeObject::PBXTypeNames[] = {
"PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
@@ -33,6 +34,9 @@ cmXCodeObject::~cmXCodeObject()
}
//----------------------------------------------------------------------------
+//We set the Id of an xcode object to a unique number for every new generation.
+//However the XCode user file references certain Ids, for those cases, we override
+//the generated Id using SetId().
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
{
this->Version = 15;
@@ -43,27 +47,20 @@ cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
this->IsA = ptype;
if(type == OBJECT)
{
- cmOStringStream str;
- str << (void*)this;
- str << (void*)this;
- str << (void*)this;
- this->Id = str.str();
+ 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 refered to in xcode file";
}
- cmSystemTools::ReplaceString(this->Id, "0x", "");
- this->Id = cmSystemTools::UpperCase(this->Id);
- if(this->Id.size() < 24)
- {
- int diff = 24 - this->Id.size();
- for(int i =0; i < diff; ++i)
- {
- this->Id += "0";
- }
- }
+ cmSystemTools::ReplaceString(this->Id, "-", "");
if(this->Id.size() > 24)
{
this->Id = this->Id.substr(0,24);
diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h
index 2bea63b..c0729d1 100644
--- a/Source/cmXCodeObject.h
+++ b/Source/cmXCodeObject.h
@@ -79,10 +79,15 @@ public:
static void PrintList(std::vector<cmXCodeObject*> const&,
std::ostream& out);
+
const char* GetId()
{
return this->Id.c_str();
}
+ void SetId(const char* id)
+ {
+ this->Id = id;
+ }
cmTarget* GetTarget()
{
return this->Target;
--
1.7.2.1
|