summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2015-01-16 17:37:26 -0500
committerBrad King <brad.king@kitware.com>2015-01-19 08:36:45 -0500
commit9e0176e2b37b93f34718b6333edd73302b5c5350 (patch)
tree27540950bdf171cc98ab30d44e486068a4019999
parentc0ff542c58e48ac91714d9dc44058c9cb42fb828 (diff)
downloadcmake-9e0176e2b37b93f34718b6333edd73302b5c5350.tar.gz
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").
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx26
1 files changed, 25 insertions, 1 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 09d5c79bcd..637e60d19a 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<cmXCodeObject*>&
@@ -973,9 +990,16 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
{
this->SetCurrentLocalGenerator(gen);
cmTargets &tgts = this->CurrentMakefile->GetTargets();
+ typedef std::map<std::string, cmTarget*, cmCompareTargets> 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