[cmake-commits] king committed cmComputeLinkInformation.cxx 1.5 1.6 cmComputeLinkInformation.h 1.3 1.4 cmDocumentVariables.cxx 1.11 1.12

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Jan 23 15:22:40 EST 2008


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

Modified Files:
	cmComputeLinkInformation.cxx cmComputeLinkInformation.h 
	cmDocumentVariables.cxx 
Log Message:
ENH: Added CMAKE_LINK_OLD_PATHS compatibility mode for linker search paths.


Index: cmDocumentVariables.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmDocumentVariables.cxx,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- cmDocumentVariables.cxx	23 Jan 2008 18:30:55 -0000	1.11
+++ cmDocumentVariables.cxx	23 Jan 2008 20:22:38 -0000	1.12
@@ -784,6 +784,24 @@
      "This is needed only on very few platforms.", false,
      "Variables that Control the Build");
   cm->DefineProperty
+    ("CMAKE_LINK_OLD_PATHS", cmProperty::VARIABLE,
+     "Enable linker search path compatibility mode.",
+     "This option enables linking compatibility mode for broken projects.  "
+     "There exists code that effectively does\n"
+     "  target_link_libraries(myexe /path/to/libA.so -lB)\n"
+     "where -lB is meant to link to /path/to/libB.so.  This is broken "
+     "because it specifies -lB without adding \"/path/to\" to the linker "
+     "search path with the link_directories command.  With CMake 2.4 and "
+     "below the code worked accidentally because \"/path/to\" would be "
+     "added to the linker search path by its implementation of linking to "
+     "/path/to/libA.so (which passed -L/path/to -lA to the linker).  "
+     "This option tells CMake to add the directories containing libraries "
+     "specified with a full path to the linker search path if the link "
+     "line contains any items like -lB.  "
+     "The behavior is also enabled if CMAKE_BACKWARDS_COMPATIBILITY is "
+     "set to 2.4 or lower.", false,
+     "Variables that Control the Build");
+  cm->DefineProperty
     ("CMAKE_USE_RELATIVE_PATHS", cmProperty::VARIABLE,
      "Use relative paths (May not work!).",
      "If this is set to TRUE, then the CMake will use "

Index: cmComputeLinkInformation.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmComputeLinkInformation.cxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cmComputeLinkInformation.cxx	23 Jan 2008 18:37:28 -0000	1.5
+++ cmComputeLinkInformation.cxx	23 Jan 2008 20:22:38 -0000	1.6
@@ -203,6 +203,26 @@
 
   // Initial state.
   this->RuntimeSearchPathComputed = false;
+  this->HaveUserFlagItem = false;
+
+  // Decide whether to enable compatible library search path mode.
+  // There exists code that effectively does
+  //
+  //    /path/to/libA.so -lB
+  //
+  // where -lB is meant to link to /path/to/libB.so.  This is broken
+  // because it specified -lB without specifying a link directory (-L)
+  // in which to search for B.  This worked in CMake 2.4 and below
+  // because -L/path/to would be added by the -L/-l split for A.  In
+  // order to support such projects we need to add the directories
+  // containing libraries linked with a full path to the -L path.
+  this->OldLinkDirMode = false;
+  if(this->Makefile->IsOn("CMAKE_LINK_OLD_PATHS") ||
+     this->Makefile->GetLocalGenerator()
+     ->NeedBackwardsCompatibility(2, 4))
+    {
+    this->OldLinkDirMode = true;
+    }
 }
 
 //----------------------------------------------------------------------------
@@ -658,6 +678,13 @@
       }
     }
 
+  // Record the directory in which the library appears because CMake
+  // 2.4 in below added these as -L paths.
+  if(this->OldLinkDirMode)
+    {
+    this->OldLinkDirs.push_back(cmSystemTools::GetFilenamePath(item));
+    }
+
   // If this platform wants a flag before the full path, add it.
   if(!this->LibLinkFileFlag.empty())
     {
@@ -738,8 +765,11 @@
     }
   else if(item[0] == '-' || item[0] == '$' || item[0] == '`')
     {
-    // This is a linker option provided by the user.  Restore the
-    // target link type since this item does not specify one.
+    // This is a linker option provided by the user.
+    this->HaveUserFlagItem = true;
+
+    // Restore the target link type since this item does not specify
+    // one.
     this->SetCurrentLinkType(this->StartLinkType);
 
     // Use the item verbatim.
@@ -748,9 +778,12 @@
     }
   else
     {
-    // This is a name specified by the user.  We must ask the linker
-    // to search for a library with this name.  Restore the target
-    // link type since this item does not specify one.
+    // This is a name specified by the user.
+    this->HaveUserFlagItem = true;
+
+    // We must ask the linker to search for a library with this name.
+    // Restore the target link type since this item does not specify
+    // one.
     this->SetCurrentLinkType(this->StartLinkType);
     lib = item;
     }
@@ -872,6 +905,12 @@
 
   // Get the search path entries requested by the user.
   this->AddLinkerSearchDirectories(this->Target->GetLinkDirectories());
+
+  // Support broken projects if necessary.
+  if(this->HaveUserFlagItem && this->OldLinkDirMode)
+    {
+    this->AddLinkerSearchDirectories(this->OldLinkDirs);
+    }
 }
 
 //----------------------------------------------------------------------------

Index: cmComputeLinkInformation.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmComputeLinkInformation.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cmComputeLinkInformation.h	23 Jan 2008 18:30:55 -0000	1.3
+++ cmComputeLinkInformation.h	23 Jan 2008 20:22:38 -0000	1.4
@@ -121,6 +121,11 @@
   void AddLinkerSearchDirectories(std::vector<std::string> const& dirs);
   std::set<cmStdString> DirectoriesEmmitted;
 
+  // Linker search path compatibility mode.
+  std::vector<std::string> OldLinkDirs;
+  bool OldLinkDirMode;
+  bool HaveUserFlagItem;
+
   // Runtime path computation.
   struct LibraryRuntimeEntry
   {



More information about the Cmake-commits mailing list