[cmake-commits] king committed cmGlobalVisualStudio6Generator.cxx 1.65 1.66 cmGlobalVisualStudio71Generator.cxx 1.37 1.38 cmGlobalVisualStudio7Generator.cxx 1.82 1.83 cmGlobalVisualStudio8Generator.h 1.9 1.10 cmGlobalVisualStudioGenerator.cxx 1.1 1.2 cmGlobalVisualStudioGenerator.h 1.1 1.2

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Apr 4 14:49:37 EDT 2007


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

Modified Files:
	cmGlobalVisualStudio6Generator.cxx 
	cmGlobalVisualStudio71Generator.cxx 
	cmGlobalVisualStudio7Generator.cxx 
	cmGlobalVisualStudio8Generator.h 
	cmGlobalVisualStudioGenerator.cxx 
	cmGlobalVisualStudioGenerator.h 
Log Message:
BUG: Fix utility dependencies for static libraries in VS generators.  This addresses bug#4789.


Index: cmGlobalVisualStudio8Generator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio8Generator.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- cmGlobalVisualStudio8Generator.h	12 Mar 2007 16:35:11 -0000	1.9
+++ cmGlobalVisualStudio8Generator.h	4 Apr 2007 18:49:35 -0000	1.10
@@ -50,6 +50,10 @@
   virtual void Configure();
   virtual void Generate();
 protected:
+
+  // Utility target fix is not needed for VS8.
+  virtual void FixUtilityDepends() {}
+
   static cmVS7FlagTable const* GetExtraFlagTableVS8();
   virtual void AddPlatformDefinitions(cmMakefile* mf);
   virtual void WriteSLNFile(std::ostream& fout, cmLocalGenerator* root,

Index: cmGlobalVisualStudio71Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio71Generator.cxx,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- cmGlobalVisualStudio71Generator.cxx	12 Mar 2007 16:35:11 -0000	1.37
+++ cmGlobalVisualStudio71Generator.cxx	4 Apr 2007 18:49:35 -0000	1.38
@@ -349,17 +349,7 @@
     {
     if(*i != dspname)
       {
-      std::string name = i->c_str();
-      if(strncmp(name.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
-        {
-        // kind of weird removing the first 27 letters.  my
-        // recommendatsions: use cmCustomCommand::GetCommand() to get the
-        // project name or get rid of the target name starting with
-        // "INCLUDE_EXTERNAL_MSPROJECT_" and use another indicator/flag
-        // somewhere.  These external project names shouldn't conflict
-        // with cmake target names anyways.
-        name.erase(name.begin(), name.begin() + 27);
-        }
+      std::string name = this->GetUtilityForTarget(target, i->c_str());
       std::string guid = this->GetGUID(name.c_str());
       if(guid.size() == 0)
         {

Index: cmGlobalVisualStudioGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudioGenerator.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cmGlobalVisualStudioGenerator.h	4 Apr 2007 15:22:14 -0000	1.1
+++ cmGlobalVisualStudioGenerator.h	4 Apr 2007 18:49:35 -0000	1.2
@@ -30,6 +30,15 @@
 public:
   cmGlobalVisualStudioGenerator();
   virtual ~cmGlobalVisualStudioGenerator();
+
+protected:
+  virtual void CreateGUID(const char*) {}
+  virtual void FixUtilityDepends();
+  const char* GetUtilityForTarget(cmTarget& target, const char*);
+private:
+  void FixUtilityDependsForTarget(cmTarget& target);
+  void CreateUtilityDependTarget(cmTarget& target);
+  bool CheckTargetLinks(cmTarget& target, const char* name);
 };
 
 #endif

Index: cmGlobalVisualStudioGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudioGenerator.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cmGlobalVisualStudioGenerator.cxx	4 Apr 2007 15:22:14 -0000	1.1
+++ cmGlobalVisualStudioGenerator.cxx	4 Apr 2007 18:49:35 -0000	1.2
@@ -16,6 +16,10 @@
 =========================================================================*/
 #include "cmGlobalVisualStudioGenerator.h"
 
+#include "cmLocalGenerator.h"
+#include "cmMakefile.h"
+#include "cmTarget.h"
+
 //----------------------------------------------------------------------------
 cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator()
 {
@@ -25,3 +29,167 @@
 cmGlobalVisualStudioGenerator::~cmGlobalVisualStudioGenerator()
 {
 }
+
+//----------------------------------------------------------------------------
+void cmGlobalVisualStudioGenerator::FixUtilityDepends()
+{
+  // For VS versions before 8:
+  //
+  // When a target that links contains a project-level dependency on a
+  // library target that library is automatically linked.  In order to
+  // allow utility-style project-level dependencies that do not
+  // actually link we need to automatically insert an intermediate
+  // custom target.
+  //
+  // Here we edit the utility dependencies of a target to add the
+  // intermediate custom target when necessary.
+  for(unsigned i = 0; i < this->LocalGenerators.size(); ++i)
+    {
+    cmTargets* targets =
+      &(this->LocalGenerators[i]->GetMakefile()->GetTargets());
+    for(cmTargets::iterator tarIt = targets->begin();
+        tarIt != targets->end(); ++tarIt)
+      {
+      this->FixUtilityDependsForTarget(tarIt->second);
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalVisualStudioGenerator::FixUtilityDependsForTarget(cmTarget& target)
+{
+  // Only targets that link need to be fixed.
+  if(target.GetType() != cmTarget::STATIC_LIBRARY &&
+     target.GetType() != cmTarget::SHARED_LIBRARY &&
+     target.GetType() != cmTarget::MODULE_LIBRARY &&
+     target.GetType() != cmTarget::EXECUTABLE)
+    {
+    return;
+    }
+
+  // Look at each utility dependency.
+  for(std::set<cmStdString>::const_iterator ui =
+        target.GetUtilities().begin();
+      ui != target.GetUtilities().end(); ++ui)
+    {
+    if(cmTarget* depTarget = this->FindTarget(0, ui->c_str()))
+      {
+      if(depTarget->GetType() == cmTarget::STATIC_LIBRARY ||
+         depTarget->GetType() == cmTarget::SHARED_LIBRARY ||
+         depTarget->GetType() == cmTarget::MODULE_LIBRARY)
+        {
+        // This utility dependency will cause an attempt to link.  If
+        // the depender does not already link the dependee we need an
+        // intermediate target.
+        if(!this->CheckTargetLinks(target, ui->c_str()))
+          {
+          this->CreateUtilityDependTarget(*depTarget);
+          }
+        }
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
+void
+cmGlobalVisualStudioGenerator::CreateUtilityDependTarget(cmTarget& target)
+{
+  // This target is a library on which a utility dependency exists.
+  // We need to create an intermediate custom target to hook up the
+  // dependency without causing a link.
+  const char* altName = target.GetProperty("ALTERNATIVE_DEPENDENCY_NAME");
+  if(!altName)
+    {
+    // Create the intermediate utility target.
+    std::string altNameStr = target.GetName();
+    altNameStr += "_UTILITY";
+    const std::vector<std::string> no_depends;
+    cmCustomCommandLines no_commands;
+    const char* no_working_dir = 0;
+    const char* no_comment = 0;
+    target.GetMakefile()->AddUtilityCommand(altNameStr.c_str(), true,
+                                            no_working_dir, no_depends,
+                                            no_commands, false, no_comment);
+    target.SetProperty("ALTERNATIVE_DEPENDENCY_NAME", altNameStr.c_str());
+
+    // Most targets have a GUID created in ConfigureFinalPass.  Since
+    // that has already been called, create one for this target now.
+    this->CreateGUID(altNameStr.c_str());
+
+    // The intermediate target should depend on the original target.
+    if(cmTarget* alt = this->FindTarget(0, altNameStr.c_str()))
+      {
+      alt->AddUtility(target.GetName());
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudioGenerator::CheckTargetLinks(cmTarget& target,
+                                                     const char* name)
+{
+  // Return whether the given target links to a target with the given name.
+  if(target.GetType() == cmTarget::STATIC_LIBRARY)
+    {
+    // Static libraries never link to anything.
+    return false;
+    }
+  cmTarget::LinkLibraryVectorType const& libs = target.GetLinkLibraries();
+  for(cmTarget::LinkLibraryVectorType::const_iterator i = libs.begin();
+      i != libs.end(); ++i)
+    {
+    if(i->first == name)
+      {
+      return true;
+      }
+    }
+  return false;
+}
+
+//----------------------------------------------------------------------------
+const char*
+cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target,
+                                                   const char* name)
+{
+  // Handle the external MS project special case.
+  if(strncmp(name, "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
+    {
+    // Note from Ken:
+    // kind of weird removing the first 27 letters.  my
+    // recommendatsions: use cmCustomCommand::GetCommand() to get the
+    // project name or get rid of the target name starting with
+    // "INCLUDE_EXTERNAL_MSPROJECT_" and use another indicator/flag
+    // somewhere.  These external project names shouldn't conflict
+    // with cmake target names anyways.
+    return name+27;
+    }
+
+  // Possibly depend on an intermediate utility target to avoid
+  // linking.
+  if(target.GetType() == cmTarget::STATIC_LIBRARY ||
+     target.GetType() == cmTarget::SHARED_LIBRARY ||
+     target.GetType() == cmTarget::MODULE_LIBRARY ||
+     target.GetType() == cmTarget::EXECUTABLE)
+    {
+    // The depender is a target that links.  Lookup the dependee to
+    // see if it provides an alternative dependency name.
+    if(cmTarget* depTarget = this->FindTarget(0, name))
+      {
+      // Check for an alternative name created by FixUtilityDepends.
+      if(const char* altName =
+         depTarget->GetProperty("ALTERNATIVE_DEPENDENCY_NAME"))
+        {
+        // The alternative name is needed only if the depender does
+        // not really link to the dependee.
+        if(!this->CheckTargetLinks(target, name))
+          {
+          return altName;
+          }
+        }
+      }
+    }
+
+  // No special case.  Just use the original dependency name.
+  return name;
+}

Index: cmGlobalVisualStudio6Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio6Generator.cxx,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- cmGlobalVisualStudio6Generator.cxx	13 Mar 2007 19:18:27 -0000	1.65
+++ cmGlobalVisualStudio6Generator.cxx	4 Apr 2007 18:49:35 -0000	1.66
@@ -177,7 +177,10 @@
                                                "echo", "Build all projects");
       }
     }
-  
+
+  // Fix utility dependencies to avoid linking to libraries.
+  this->FixUtilityDepends();
+
   // first do the superclass method
   this->cmGlobalGenerator::Generate();
   
@@ -438,12 +441,7 @@
     {
     if(*i != dspname)
       {
-      std::string depName = *i;
-      if(strncmp(depName.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
-        {
-        depName.erase(depName.begin(), depName.begin() + 27);
-        }
-          
+      std::string depName = this->GetUtilityForTarget(target, i->c_str());
       fout << "Begin Project Dependency\n";
       fout << "Project_Dep_Name " << depName << "\n";
       fout << "End Project Dependency\n";

Index: cmGlobalVisualStudio7Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio7Generator.cxx,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- cmGlobalVisualStudio7Generator.cxx	13 Mar 2007 19:18:27 -0000	1.82
+++ cmGlobalVisualStudio7Generator.cxx	4 Apr 2007 18:49:35 -0000	1.83
@@ -235,6 +235,9 @@
       }
     }
 
+  // Fix utility dependencies to avoid linking to libraries.
+  this->FixUtilityDepends();
+
   // first do the superclass method
   this->cmGlobalGenerator::Generate();
   
@@ -634,17 +637,7 @@
     {
     if(*i != dspname)
       {
-      std::string name = *i;
-      if(strncmp(name.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
-        {
-        // kind of weird removing the first 27 letters.  my
-        // recommendatsions: use cmCustomCommand::GetCommand() to get the
-        // project name or get rid of the target name starting with
-        // "INCLUDE_EXTERNAL_MSPROJECT_" and use another indicator/flag
-        // somewhere.  These external project names shouldn't conflict
-        // with cmake target names anyways.
-        name.erase(name.begin(), name.begin() + 27);
-        }
+      std::string name = this->GetUtilityForTarget(target, i->c_str());
       std::string guid = this->GetGUID(name.c_str());
       if(guid.size() == 0)
         {



More information about the Cmake-commits mailing list