summaryrefslogtreecommitdiffstats
path: root/Source/cmInstallTargetGenerator.cxx
diff options
context:
space:
mode:
authorClinton Stimpson <clinton@elemtech.com>2013-04-27 04:04:44 (GMT)
committerBrad King <brad.king@kitware.com>2013-06-03 13:42:05 (GMT)
commit94e7fef2268ba9d31bd31834f05f6d0c2ffe5a18 (patch)
tree4676709c61c7f1d8352f5e9729bb875cb2816e34 /Source/cmInstallTargetGenerator.cxx
parentcbe3f2072bdd181660bc4f9174a73febd3ed5230 (diff)
downloadCMake-94e7fef2268ba9d31bd31834f05f6d0c2ffe5a18.zip
CMake-94e7fef2268ba9d31bd31834f05f6d0c2ffe5a18.tar.gz
CMake-94e7fef2268ba9d31bd31834f05f6d0c2ffe5a18.tar.bz2
OS X: Add RPATH support for Mac.
RPATH support is activated on targets that have the MACOSX_RPATH property turned on. For install time, it is also useful to set INSTALL_RPATH to help find dependent libraries with an @rpath in their install name. Also adding detection of rpath conflicts when using frameworks.
Diffstat (limited to 'Source/cmInstallTargetGenerator.cxx')
-rw-r--r--Source/cmInstallTargetGenerator.cxx76
1 files changed, 57 insertions, 19 deletions
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx
index 9aac440..ed01210 100644
--- a/Source/cmInstallTargetGenerator.cxx
+++ b/Source/cmInstallTargetGenerator.cxx
@@ -606,6 +606,12 @@ cmInstallTargetGenerator
return;
}
+ // Skip if on Apple
+ if(this->Target->GetMakefile()->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
+ {
+ return;
+ }
+
// Get the link information for this target.
// It can provide the RPATH.
cmComputeLinkInformation* cli = this->Target->GetLinkInformation(config);
@@ -645,30 +651,62 @@ cmInstallTargetGenerator
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();
-
- // Skip the rule if the paths are identical
- if(oldRpath == newRpath)
+ if(this->Target->GetMakefile()->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
{
- return;
- }
+ // If using install_name_tool, set up the rules to modify the rpaths.
+ std::string installNameTool =
+ this->Target->GetMakefile()->
+ GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
+
+ std::vector<std::string> oldRuntimeDirs, newRuntimeDirs;
+ cli->GetRPath(oldRuntimeDirs, false);
+ cli->GetRPath(newRuntimeDirs, true);
+
+ // Note: These are separate commands to avoid install_name_tool
+ // corruption on 10.6.
+ for(std::vector<std::string>::const_iterator i = oldRuntimeDirs.begin();
+ i != oldRuntimeDirs.end(); ++i)
+ {
+ os << indent << "execute_process(COMMAND " << installNameTool << "\n";
+ os << indent << " -delete_rpath \"" << *i << "\"\n";
+ os << indent << " \"" << toDestDirPath << "\")\n";
+ }
- // Write a rule to run chrpath to set the install-tree RPATH
- if(newRpath.empty())
- {
- os << indent << "FILE(RPATH_REMOVE\n"
- << indent << " FILE \"" << toDestDirPath << "\")\n";
+ for(std::vector<std::string>::const_iterator i = newRuntimeDirs.begin();
+ i != newRuntimeDirs.end(); ++i)
+ {
+ os << indent << "execute_process(COMMAND " << installNameTool << "\n";
+ os << indent << " -add_rpath \"" << *i << "\"\n";
+ os << indent << " \"" << toDestDirPath << "\")\n";
+ }
}
else
{
- os << indent << "FILE(RPATH_CHANGE\n"
- << indent << " FILE \"" << toDestDirPath << "\"\n"
- << indent << " OLD_RPATH \"" << oldRpath << "\"\n"
- << indent << " NEW_RPATH \"" << newRpath << "\")\n";
+ // 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();
+
+ // Skip the rule if the paths are identical
+ if(oldRpath == newRpath)
+ {
+ return;
+ }
+
+ // Write a rule to run chrpath to set the install-tree RPATH
+ if(newRpath.empty())
+ {
+ os << indent << "FILE(RPATH_REMOVE\n"
+ << indent << " FILE \"" << toDestDirPath << "\")\n";
+ }
+ else
+ {
+ os << indent << "FILE(RPATH_CHANGE\n"
+ << indent << " FILE \"" << toDestDirPath << "\"\n"
+ << indent << " OLD_RPATH \"" << oldRpath << "\"\n"
+ << indent << " NEW_RPATH \"" << newRpath << "\")\n";
+ }
}
}