diff options
author | Alexander Neundorf <neundorf@kde.org> | 2007-12-18 22:50:27 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2007-12-18 22:50:27 (GMT) |
commit | 3ae731fab7a3b992c321226262076a2622f64c11 (patch) | |
tree | 223da7b100533710445dde2a52243baff0883452 /Source/cmInstallTargetGenerator.cxx | |
parent | f5f397debde141a15225ea52bc2768d723a27375 (diff) | |
download | CMake-3ae731fab7a3b992c321226262076a2622f64c11.zip CMake-3ae731fab7a3b992c321226262076a2622f64c11.tar.gz CMake-3ae731fab7a3b992c321226262076a2622f64c11.tar.bz2 |
ENH: add support for chrpath, so the RPATH in ELF files can be changed when
installing without having to link the target again -> can save a lot of time
chrpath is handled very similar to install_name_tool on the mac. If the
RPATH in the build tree file is to short, it is padded using the separator
character.
This is currently disabled by default, it can be enabled using the option
CMAKE_USE_CHRPATH. There are additional checks whether it is safe to enable
it. I will rework them and use FILE(READ) instead to detect whether the
binaries are actually ELF files.
chrpath is available here
http://www.tux.org/pub/X-Windows/ftp.hungry.com/chrpath/
or kde svn (since a few days): http://websvn.kde.org/trunk/kdesupport/chrpath/
Alex
Diffstat (limited to 'Source/cmInstallTargetGenerator.cxx')
-rw-r--r-- | Source/cmInstallTargetGenerator.cxx | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index abe9348..9998d0d 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -305,6 +305,7 @@ cmInstallTargetGenerator os << indent << "IF(EXISTS \"" << toDestDirPath << "\")\n"; this->AddInstallNamePatchRule(os, indent.Next(), config, toDestDirPath); + this->AddChrpathPatchRule(os, indent.Next(), config, toDestDirPath); this->AddRanlibRule(os, indent.Next(), type, toDestDirPath); this->AddStripRule(os, indent.Next(), type, toDestDirPath); os << indent << "ENDIF(EXISTS \"" << toDestDirPath << "\")\n"; @@ -506,6 +507,60 @@ cmInstallTargetGenerator //---------------------------------------------------------------------------- void +cmInstallTargetGenerator +::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->GetMakefile()->IsOn("CMAKE_USE_CHRPATH")==false) + || (this->Target->IsChrpathAvailable()==false)) + { + return; + } + + // Fix the RPATH in installed ELF binaries using chrpath. + std::string chrpathTool = + this->Target->GetMakefile()->GetSafeDefinition("CMAKE_CHRPATH"); + + std::string installRpath; + std::string dummy; + this->Target->GetMakefile()->GetLocalGenerator()->GetLinkerArgs( + installRpath, dummy, *this->Target, true, 0); + + const char* linkLanguage = this->Target->GetLinkerLanguage(this->Target-> + GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()); + if (linkLanguage==0) + { + return; + } + + std::string runTimeFlagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_"; + runTimeFlagVar += linkLanguage; + runTimeFlagVar += "_FLAG"; + + std::string runtimeFlag = + this->Target->GetMakefile()->GetSafeDefinition(runTimeFlagVar.c_str()); + + const char* newRpath=installRpath.c_str(); + if (strstr(installRpath.c_str(), runtimeFlag.c_str())==installRpath.c_str()) + { + newRpath = installRpath.c_str()+strlen(runtimeFlag.c_str()); + } + + // Write a rule to run chrpath to set the install-tree RPATH + os << indent << "EXECUTE_PROCESS(COMMAND \"" << chrpathTool; + os << "\" -r \"" << newRpath << "\" \"" << toDestDirPath << "\")\n"; +} + +//---------------------------------------------------------------------------- +void cmInstallTargetGenerator::AddStripRule(std::ostream& os, Indent const& indent, cmTarget::TargetType type, |