[cmake-commits] king committed cmComputeLinkInformation.cxx 1.23 1.24 cmFileCommand.cxx 1.101 1.102 cmInstallTargetGenerator.cxx 1.60 1.61 cmLocalGenerator.cxx 1.266 1.267 cmSystemTools.cxx 1.366 1.367 cmSystemTools.h 1.149 1.150 cmTarget.cxx 1.202 1.203

cmake-commits at cmake.org cmake-commits at cmake.org
Sun Mar 2 14:35:25 EST 2008


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

Modified Files:
	cmComputeLinkInformation.cxx cmFileCommand.cxx 
	cmInstallTargetGenerator.cxx cmLocalGenerator.cxx 
	cmSystemTools.cxx cmSystemTools.h cmTarget.cxx 
Log Message:
ENH: Cleanup builtin chrpath support

  - Move computation of extended build-tree rpath
    to cmComputeLinkInformation
  - Only enable the extended build-tree rpath if
    the target will be installed
  - Generalize the interface of file(CHRPATH)
  - When changing the rpath on installation only
    replace the part generated by CMake because
    the native tools (ex SunCC on Linux) might have
    added their own part to the rpath


Index: cmSystemTools.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.h,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -d -r1.149 -r1.150
--- cmSystemTools.h	1 Mar 2008 17:51:07 -0000	1.149
+++ cmSystemTools.h	2 Mar 2008 19:35:23 -0000	1.150
@@ -383,6 +383,7 @@
 
   /** Try to set the RPATH in an ELF binary.  */
   static bool ChangeRPath(std::string const& file,
+                          std::string const& oldRPath,
                           std::string const& newRPath,
                           std::string* emsg = 0);
 

Index: cmLocalGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.cxx,v
retrieving revision 1.266
retrieving revision 1.267
diff -u -d -r1.266 -r1.267
--- cmLocalGenerator.cxx	1 Mar 2008 14:08:34 -0000	1.266
+++ cmLocalGenerator.cxx	2 Mar 2008 19:35:23 -0000	1.267
@@ -1591,17 +1591,6 @@
     // All rpath entries are combined ("-Wl,-rpath,a:b:c").
     std::string rpath = cli.GetRPathString(relink);
 
-    // If not relinking, make sure the rpath string is long enough to
-    // support a subsequent chrpath on installation.
-    if(!relink)
-      {
-      std::string::size_type minLength = cli.GetChrpathString().size();
-      while(rpath.size() < minLength)
-        {
-        rpath += cli.GetRuntimeSep();
-        }
-      }
-
     // Store the rpath option in the stream.
     if(!rpath.empty())
       {

Index: cmComputeLinkInformation.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmComputeLinkInformation.cxx,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- cmComputeLinkInformation.cxx	1 Mar 2008 17:51:07 -0000	1.23
+++ cmComputeLinkInformation.cxx	2 Mar 2008 19:35:23 -0000	1.24
@@ -1463,6 +1463,18 @@
     // Add this path.
     rpath += *ri;
     }
+
+  // If the rpath will be replaced at install time make sure it is
+  // long enough now.
+  if(!for_install && this->RuntimeUseChrpath)
+    {
+    std::string::size_type minLength = this->GetChrpathString().length();
+    while(rpath.length() < minLength)
+      {
+      rpath += this->GetRuntimeSep();
+      }
+    }
+
   return rpath;
 }
 

Index: cmSystemTools.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.cxx,v
retrieving revision 1.366
retrieving revision 1.367
diff -u -d -r1.366 -r1.367
--- cmSystemTools.cxx	1 Mar 2008 20:16:49 -0000	1.366
+++ cmSystemTools.cxx	2 Mar 2008 19:35:23 -0000	1.367
@@ -2198,18 +2198,41 @@
 
 //----------------------------------------------------------------------------
 bool cmSystemTools::ChangeRPath(std::string const& file,
+                                std::string const& oldRPath,
                                 std::string const& newRPath,
                                 std::string* emsg)
 {
 #if defined(CMAKE_USE_ELF_PARSER)
   unsigned long rpathPosition = 0;
   unsigned long rpathSize = 0;
+  std::string rpathSuffix;
   {
   cmELF elf(file.c_str());
   if(cmELF::StringEntry const* se = elf.GetRPath())
     {
+    // Make sure the current rpath begins with the old rpath.
+    if(se->Value.length() < oldRPath.length() ||
+       se->Value.substr(0, oldRPath.length()) != oldRPath)
+      {
+      // If it begins with the new rpath instead then it is okay.
+      if(se->Value.length() >= newRPath.length() &&
+         se->Value.substr(0, newRPath.length()) == newRPath)
+        {
+        return true;
+        }
+      if(emsg)
+        {
+        *emsg = "The current RPATH does not begin with that specified.";
+        }
+      return false;
+      }
+
+    // Store information about the entry.
     rpathPosition = se->Position;
     rpathSize = se->Size;
+
+    // Store the part of the path we must preserve.
+    rpathSuffix = se->Value.substr(oldRPath.length(), oldRPath.npos);
     }
   else if(newRPath.empty())
     {
@@ -2221,14 +2244,19 @@
     {
     if(emsg)
       {
-      *emsg = "No valid ELF RPATH entry exists in the file.";
+      *emsg = "No valid ELF RPATH entry exists in the file; ";
+      *emsg += elf.GetErrorMessage();
       }
     return false;
     }
   }
+  // Compute the full new rpath.
+  std::string rpath = newRPath;
+  rpath += rpathSuffix;
+
   // Make sure there is enough room to store the new rpath and at
   // least one null terminator.
-  if(rpathSize < newRPath.length()+1)
+  if(rpathSize < rpath.length()+1)
     {
     if(emsg)
       {
@@ -2259,8 +2287,8 @@
 
   // Write the new rpath.  Follow it with enough null terminators to
   // fill the string table entry.
-  f << newRPath;
-  for(unsigned long i=newRPath.length(); i < rpathSize; ++i)
+  f << rpath;
+  for(unsigned long i=rpath.length(); i < rpathSize; ++i)
     {
     f << '\0';
     }
@@ -2280,6 +2308,7 @@
     }
 #else
   (void)file;
+  (void)oldRPath;
   (void)newRPath;
   (void)emsg;
   return false;

Index: cmFileCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.cxx,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- cmFileCommand.cxx	1 Mar 2008 17:51:07 -0000	1.101
+++ cmFileCommand.cxx	2 Mar 2008 19:35:23 -0000	1.102
@@ -1333,25 +1333,81 @@
 //----------------------------------------------------------------------------
 bool cmFileCommand::HandleChrpathCommand(std::vector<std::string> const& args)
 {
-  if(args.size() != 3)
+  // Evaluate arguments.
+  const char* file = 0;
+  const char* oldRPath = 0;
+  const char* newRPath = 0;
+  enum Doing { DoingNone, DoingFile, DoingOld, DoingNew };
+  Doing doing = DoingNone;
+  for(unsigned int i=1; i < args.size(); ++i)
     {
-    this->SetError("CHRPATH must be given a file and a new rpath.");
+    if(args[i] == "OLD_RPATH")
+      {
+      doing = DoingOld;
+      }
+    else if(args[i] == "NEW_RPATH")
+      {
+      doing = DoingNew;
+      }
+    else if(args[i] == "FILE")
+      {
+      doing = DoingFile;
+      }
+    else if(doing == DoingFile)
+      {
+      file = args[i].c_str();
+      doing = DoingNone;
+      }
+    else if(doing == DoingOld)
+      {
+      oldRPath = args[i].c_str();
+      doing = DoingNone;
+      }
+    else if(doing == DoingNew)
+      {
+      newRPath = args[i].c_str();
+      doing = DoingNone;
+      }
+    else
+      {
+      cmOStringStream e;
+      e << "CHRPATH given unknown argument " << args[i];
+      this->SetError(e.str().c_str());
+      return false;
+      }
+    }
+  if(!file)
+    {
+    this->SetError("CHRPATH not given FILE option.");
     return false;
     }
-  if(!cmSystemTools::FileExists(args[1].c_str(), true))
+  if(!oldRPath)
     {
-    this->SetError("CHRPATH given file that does not exist.");
+    this->SetError("CHRPATH not given OLD_RPATH option.");
+    return false;
+    }
+  if(!newRPath)
+    {
+    this->SetError("CHRPATH not given NEW_RPATH option.");
+    return false;
+    }
+  if(!cmSystemTools::FileExists(file, true))
+    {
+    cmOStringStream e;
+    e << "CHRPATH given FILE \"" << file << "\" that does not exist.";
+    this->SetError(e.str().c_str());
     return false;
     }
   std::string emsg;
-  if(cmSystemTools::ChangeRPath(args[1], args[2], &emsg))
+  if(cmSystemTools::ChangeRPath(file, oldRPath, newRPath, &emsg))
     {
     return true;
     }
   else
     {
     cmOStringStream e;
-    e << "CHRPATH could not write new RPATH to the file: "
+    e << "CHRPATH could not write new RPATH \""
+      << newRPath << "\" to the file \"" << file << "\": "
       << emsg;
     this->SetError(e.str().c_str());
     return false;

Index: cmInstallTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallTargetGenerator.cxx,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- cmInstallTargetGenerator.cxx	1 Mar 2008 17:51:07 -0000	1.60
+++ cmInstallTargetGenerator.cxx	2 Mar 2008 19:35:23 -0000	1.61
@@ -552,15 +552,8 @@
 ::AddChrpathPatchRule(std::ostream& os, Indent const& indent,
                       const char* config, std::string const& toDestDirPath)
 {
-  if(this->ImportLibrary ||
-     !(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
-       this->Target->GetType() == cmTarget::MODULE_LIBRARY ||
-       this->Target->GetType() == cmTarget::EXECUTABLE))
-    {
-    return;
-    }
-
-  if(!this->Target->IsChrpathUsed())
+  // Skip the chrpath if the target does not need it.
+  if(this->ImportLibrary || !this->Target->IsChrpathUsed())
     {
     return;
     }
@@ -573,12 +566,16 @@
     return;
     }
 
+  // Construct the original rpath string to be replaced.
+  std::string oldRpath = cli->GetRPathString(false);
+
   // Get the install RPATH from the link information.
   std::string newRpath = cli->GetChrpathString();
 
   // Write a rule to run chrpath to set the install-tree RPATH
-  os << indent
-     << "FILE(CHRPATH \"" << toDestDirPath << "\" \"" << newRpath << "\")\n";
+  os << indent << "FILE(CHRPATH FILE \"" << toDestDirPath << "\"\n"
+     << indent << "     OLD_RPATH \"" << oldRpath << "\"\n"
+     << indent << "     NEW_RPATH \"" << newRpath << "\")\n";
 }
 
 //----------------------------------------------------------------------------

Index: cmTarget.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.cxx,v
retrieving revision 1.202
retrieving revision 1.203
diff -u -d -r1.202 -r1.203
--- cmTarget.cxx	1 Mar 2008 18:02:08 -0000	1.202
+++ cmTarget.cxx	2 Mar 2008 19:35:23 -0000	1.203
@@ -3007,6 +3007,21 @@
 bool cmTarget::IsChrpathUsed()
 {
 #if defined(CMAKE_USE_ELF_PARSER)
+  // Only certain target types have an rpath.
+  if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
+       this->GetType() == cmTarget::MODULE_LIBRARY ||
+       this->GetType() == cmTarget::EXECUTABLE))
+    {
+    return false;
+    }
+
+  // If the target will not be installed we do not need to change its
+  // rpath.
+  if(!this->GetHaveInstallRule())
+    {
+    return false;
+    }
+
   // Skip chrpath if skipping rpath altogether.
   if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
     {



More information about the Cmake-commits mailing list