From 9e0176e2b37b93f34718b6333edd73302b5c5350 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 16 Jan 2015 17:37:26 -0500 Subject: Xcode: Sort targets deterministically and with ALL_BUILD first (#15346) The default target in XCode is the first one in the file. In commit v3.1.0-rc1~286^2 (cmTarget: use a hash_map for cmTargets typedef, 2014-06-10) the order of the targets stored in cmMakefile was made non-deterministic instead of lexicographic. Teach the Xcode generator to do its own sorting to restore a predictable order. While at it, place ALL_BUILD first (as is done in VS IDE generators) explicitly in the comparison function so that it is the default target even if other targets sort earlier lexicographically (e.g. "AAA"). --- Source/cmGlobalXCodeGenerator.cxx | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 09d5c79..637e60d 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -966,6 +966,23 @@ struct cmSourceFilePathCompare }; //---------------------------------------------------------------------------- +struct cmCompareTargets +{ + bool operator () (std::string const& a, std::string const& b) const + { + if (a == "ALL_BUILD") + { + return true; + } + if (b == "ALL_BUILD") + { + return false; + } + return strcmp(a.c_str(), b.c_str()) < 0; + } +}; + +//---------------------------------------------------------------------------- bool cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, std::vector& @@ -973,9 +990,16 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, { this->SetCurrentLocalGenerator(gen); cmTargets &tgts = this->CurrentMakefile->GetTargets(); + typedef std::map cmSortedTargets; + cmSortedTargets sortedTargets; for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++) { - cmTarget& cmtarget = l->second; + sortedTargets[l->first] = &l->second; + } + for(cmSortedTargets::iterator l = sortedTargets.begin(); + l != sortedTargets.end(); l++) + { + cmTarget& cmtarget = *l->second; cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget); // make sure ALL_BUILD, INSTALL, etc are only done once -- cgit v0.12