From 98621ecfaa4794cf934011205ca1d9832600f14d Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Wed, 13 Feb 2008 15:29:55 -0500
Subject: BUG: Update cmComputeLinkDepends to support leading/trailing
 whitespace stripping off link items for compatibility.

---
 Source/cmComputeLinkDepends.cxx | 37 +++++++++++++++++++++++++++++++++++--
 Source/cmComputeLinkDepends.h   |  1 +
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index 29164a2..391b991 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -510,13 +510,14 @@ cmComputeLinkDepends::AddLinkEntries(int depender_index,
     {
     // Skip entries that will resolve to the target getting linked or
     // are empty.
-    if(*li == this->Target->GetName() || li->empty())
+    std::string item = this->CleanItemName(*li);
+    if(item == this->Target->GetName() || item.empty())
       {
       continue;
       }
 
     // Add a link entry for this item.
-    int dependee_index = this->AddLinkEntry(*li);
+    int dependee_index = this->AddLinkEntry(item);
 
     // The depender must come before the dependee.
     if(depender_index >= 0)
@@ -551,6 +552,38 @@ cmComputeLinkDepends::AddLinkEntries(int depender_index,
 }
 
 //----------------------------------------------------------------------------
+std::string cmComputeLinkDepends::CleanItemName(std::string const& item)
+{
+  // Strip whitespace off the library names because we used to do this
+  // in case variables were expanded at generate time.  We no longer
+  // do the expansion but users link to libraries like " ${VAR} ".
+  std::string lib = item;
+  std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
+  if(pos != lib.npos)
+    {
+    lib = lib.substr(pos, lib.npos);
+    }
+  pos = lib.find_last_not_of(" \t\r\n");
+  if(pos != lib.npos)
+    {
+    lib = lib.substr(0, pos+1);
+    }
+  if(lib != item && !this->Makefile->NeedBackwardsCompatibility(2,4))
+    {
+    cmOStringStream e;
+    e << "Target \"" << this->Target->GetName() << "\" links to item \""
+      << item << "\" which has leading or trailing whitespace.  "
+      << "CMake is stripping off the whitespace but this may not be "
+      << "supported in the future.  "
+      << "Update the CMakeLists.txt files to avoid adding the whitespace.  "
+      << "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.4 or lower to disable this "
+      << "warning.";
+    cmSystemTools::Message(e.str().c_str());
+    }
+  return lib;
+}
+
+//----------------------------------------------------------------------------
 void cmComputeLinkDepends::InferDependencies()
 {
   // The inferred dependency sets for each item list the possible
diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h
index b81f8bc..c208909 100644
--- a/Source/cmComputeLinkDepends.h
+++ b/Source/cmComputeLinkDepends.h
@@ -78,6 +78,7 @@ private:
                             LinkLibraryVectorType const& libs);
   void AddLinkEntries(int depender_index,
                       std::vector<std::string> const& libs);
+  std::string CleanItemName(std::string const& item);
 
   // One entry for each unique item.
   std::vector<LinkEntry> EntryList;
-- 
cgit v0.12