[cmake-commits] king committed cmGlobalUnixMakefileGenerator3.cxx 1.121 1.122 cmGlobalUnixMakefileGenerator3.h 1.51 1.52

cmake-commits at cmake.org cmake-commits at cmake.org
Sat Dec 22 13:08:28 EST 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv28714/Source

Modified Files:
	cmGlobalUnixMakefileGenerator3.cxx 
	cmGlobalUnixMakefileGenerator3.h 
Log Message:
BUG: Support cyclic dependencies among STATIC libraries by removing one from the generated Makefile rules.


Index: cmGlobalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalUnixMakefileGenerator3.cxx,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- cmGlobalUnixMakefileGenerator3.cxx	21 Dec 2007 23:32:22 -0000	1.121
+++ cmGlobalUnixMakefileGenerator3.cxx	22 Dec 2007 18:08:26 -0000	1.122
@@ -905,7 +905,8 @@
   emitted.insert(target.GetName());
 
   // Loop over all library dependencies.
-  const cmTarget::LinkLibraryVectorType& tlibs = target.GetLinkLibraries();
+  const cmTarget::LinkLibraryVectorType&
+    tlibs = target.GetOriginalLinkLibraries();
   for(cmTarget::LinkLibraryVectorType::const_iterator lib = tlibs.begin();
       lib != tlibs.end(); ++lib)
     {
@@ -960,6 +961,13 @@
   // if a match was found then ...
   if (result)
     {
+    // Avoid creating cyclic dependencies.
+    if(!this->AllowTargetDepends(&target, result))
+      {
+      return;
+      }
+
+    // Create the target-level dependency.
     std::string tgtName = lg3->GetRelativeTargetDirectory(*result);
     tgtName += "/all";
     depends.push_back(tgtName);
@@ -1049,3 +1057,76 @@
     }
   return false;
 }
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalUnixMakefileGenerator3
+::AllowTargetDepends(cmTarget const* depender, cmTarget const* dependee)
+{
+  // Check whether the depender is among the dependee's dependencies.
+  std::vector<cmTarget const*> steps;
+  if(this->FindDependency(depender, dependee, steps))
+    {
+    // This creates a cyclic dependency.
+    bool isStatic = depender->GetType() == cmTarget::STATIC_LIBRARY;
+    cmOStringStream e;
+    e << "Cyclic dependency among targets:\n"
+      << "  " << depender->GetName() << "\n";
+    for(unsigned int i = static_cast<unsigned int>(steps.size());
+        i > 0; --i)
+      {
+      cmTarget const* step = steps[i-1];
+      e << "    -> " << step->GetName() << "\n";
+      isStatic = isStatic && step->GetType() == cmTarget::STATIC_LIBRARY;
+      }
+    if(isStatic)
+      {
+      e << "  All targets are STATIC libraries.\n";
+      e << "  Dropping "
+        << depender->GetName() << " -> " << dependee->GetName()
+        << " to resolve.\n";
+      cmSystemTools::Message(e.str().c_str());
+      }
+    else
+      {
+      e << "  At least one target is not a STATIC library.\n";
+      cmSystemTools::Error(e.str().c_str());
+      }
+    return false;
+    }
+  else
+    {
+    // This does not create a cyclic dependency.
+    this->TargetDependencies[depender].insert(dependee);
+    return true;
+    }
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalUnixMakefileGenerator3
+::FindDependency(cmTarget const* goal, cmTarget const* current,
+                 std::vector<cmTarget const*>& steps)
+{
+  if(current == goal)
+    {
+    steps.push_back(current);
+    return true;
+    }
+  TargetDependMap::const_iterator i = this->TargetDependencies.find(current);
+  if(i == this->TargetDependencies.end())
+    {
+    return false;
+    }
+  TargetDependSet const& depends = i->second;
+  for(TargetDependSet::const_iterator j = depends.begin();
+      j != depends.end(); ++j)
+    {
+    if(this->FindDependency(goal, *j, steps))
+      {
+      steps.push_back(current);
+      return true;
+      }
+    }
+  return false;
+}

Index: cmGlobalUnixMakefileGenerator3.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalUnixMakefileGenerator3.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- cmGlobalUnixMakefileGenerator3.h	21 Dec 2007 23:32:22 -0000	1.51
+++ cmGlobalUnixMakefileGenerator3.h	22 Dec 2007 18:08:26 -0000	1.52
@@ -179,6 +179,14 @@
 
   std::map<cmStdString, int > TargetSourceFileCount;
   bool ForceVerboseMakefiles;
+
+  bool AllowTargetDepends(cmTarget const* depender,
+                          cmTarget const* dependee);
+  bool FindDependency(cmTarget const* goal, cmTarget const* current,
+                      std::vector<cmTarget const*>& steps);
+  class TargetDependSet: public std::set<cmTarget const*> {};
+  typedef std::map<cmTarget const*, TargetDependSet> TargetDependMap;
+  TargetDependMap TargetDependencies;
 };
 
 #endif



More information about the Cmake-commits mailing list