Browse Source

Order cmGeneratorTargetsType elements deterministically.

Define a custom ordering functor to deterministically and strictly
order the cmTarget* key. Otherwise the order would be dependent on
runtime pointer values, which breaks assumptions of some generators.

The functor orders first by target name, and then by directory. Multiple
global targets may have the same name, such as edit_cache, but their
directory differentiates them.
Stephen Kelly 12 years ago
parent
commit
abb13ea565
2 changed files with 18 additions and 1 deletions
  1. 11 0
      Source/cmGeneratorTarget.cxx
  2. 7 1
      Source/cmGeneratorTarget.h

+ 11 - 0
Source/cmGeneratorTarget.cxx

@@ -692,3 +692,14 @@ void cmGeneratorTarget::GenerateTargetManifest(const char* config) const
     gg->AddToManifest(config? config:"", f);
     }
 }
+
+bool cmStrictTargetComparison::operator()(cmTarget *t1, cmTarget *t2) const
+{
+  int nameResult = strcmp(t1->GetName(), t2->GetName());
+  if (nameResult == 0)
+    {
+    return strcmp(t1->GetMakefile()->GetStartDirectory(),
+                  t2->GetMakefile()->GetStartDirectory()) < 0;
+    }
+  return nameResult < 0;
+}

+ 7 - 1
Source/cmGeneratorTarget.h

@@ -100,6 +100,12 @@ private:
   void operator=(cmGeneratorTarget const&);
 };
 
-typedef std::map<cmTarget*, cmGeneratorTarget*> cmGeneratorTargetsType;
+struct cmStrictTargetComparison {
+  bool operator()(cmTarget *t1, cmTarget *t2) const;
+};
+
+typedef std::map<cmTarget*,
+                 cmGeneratorTarget*,
+                 cmStrictTargetComparison> cmGeneratorTargetsType;
 
 #endif