From 7b68c8df6b78951e6d04eea62c3d5cc056796993 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Tue, 7 Apr 2015 19:14:52 +0200 Subject: [PATCH] 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. --- Source/cmGlobalXCodeGenerator.cxx | 16 ++++++++++++++++ Source/cmGlobalXCodeGenerator.h | 1 + 2 files changed, 17 insertions(+) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 0561a0542..be40c66df 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -591,6 +591,20 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile( 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() { @@ -3713,6 +3727,8 @@ cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* , std::vector& ) { + SortXCodeObjects(); + fout << "// !$*UTF8*$!\n"; fout << "{\n"; cmXCodeObject::Indent(1, fout); diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index b272f6a94..1a69fce82 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -150,6 +150,7 @@ private: cmXCodeObject* buildSettings, const std::string& buildType); std::string ExtractFlag(const char* flag, std::string& flags); + void SortXCodeObjects(); // delete all objects in the this->XCodeObjects vector. void ClearXCodeObjects(); bool CreateXCodeObjects(cmLocalGenerator* root,