Xcode: Sort Xcode objects by Id

this patch series aims to minimize deltas between the CMake Xcode
generator and Xcode itself. It was started by the observation that
if one makes any change to the project within Xcode (e.g. to see
how a variable is called internally) the user cannot diff the CMake
project and the one stored by Xcode afterwards.

Xcode keeps the objects ordered by the object id.
Because cmake stores them into an unordered container
at creation time they must be sorted before writing the
pbxproj file.

I tested this series with Xcode 6.3 and Xcode 3.2. Both show a
reduced diff after this series was applied.
This commit is contained in:
Gregor Jasny 2015-04-07 19:14:52 +02:00
parent 48040c19d5
commit 7b68c8df6b
2 changed files with 17 additions and 0 deletions

View File

@ -591,6 +591,20 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
mf->GetHomeOutputDirectory()) << "\n"; mf->GetHomeOutputDirectory()) << "\n";
} }
//----------------------------------------------------------------------------
static bool objectIdLessThan(cmXCodeObject* l, cmXCodeObject* r)
{
return l->GetId() < r->GetId();
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::SortXCodeObjects()
{
std::sort(this->XCodeObjects.begin(), this->XCodeObjects.end(),
objectIdLessThan);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::ClearXCodeObjects() void cmGlobalXCodeGenerator::ClearXCodeObjects()
{ {
@ -3713,6 +3727,8 @@ cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
cmLocalGenerator* , cmLocalGenerator* ,
std::vector<cmLocalGenerator*>& ) std::vector<cmLocalGenerator*>& )
{ {
SortXCodeObjects();
fout << "// !$*UTF8*$!\n"; fout << "// !$*UTF8*$!\n";
fout << "{\n"; fout << "{\n";
cmXCodeObject::Indent(1, fout); cmXCodeObject::Indent(1, fout);

View File

@ -150,6 +150,7 @@ private:
cmXCodeObject* buildSettings, cmXCodeObject* buildSettings,
const std::string& buildType); const std::string& buildType);
std::string ExtractFlag(const char* flag, std::string& flags); std::string ExtractFlag(const char* flag, std::string& flags);
void SortXCodeObjects();
// delete all objects in the this->XCodeObjects vector. // delete all objects in the this->XCodeObjects vector.
void ClearXCodeObjects(); void ClearXCodeObjects();
bool CreateXCodeObjects(cmLocalGenerator* root, bool CreateXCodeObjects(cmLocalGenerator* root,