OSX: Warn when attempting to change runtime paths on OS X 10.5

Even though 10.5 supports @rpath, the support is not complete
enough for CMake.  For instance, install_name_tool doesn't support
adding and removing rpaths.

Also modifying BundleUtilities test to remove an undesirable cmake
generated runtime path.  The intent was to build with the install
rpath as is done with the other cases in this test.
This commit is contained in:
Clinton Stimpson 2014-10-06 22:24:10 -06:00 committed by Brad King
parent 9b98fd528d
commit 50e261ddb6
2 changed files with 56 additions and 29 deletions

View File

@ -677,23 +677,47 @@ cmInstallTargetGenerator
return; return;
} }
if(this->Target->GetMakefile()->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) cmMakefile* mf = this->Target->GetMakefile();
if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
{ {
// If using install_name_tool, set up the rules to modify the rpaths. // If using install_name_tool, set up the rules to modify the rpaths.
std::string installNameTool = std::string installNameTool =
this->Target->GetMakefile()-> mf->GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
GetSafeDefinition("CMAKE_INSTALL_NAME_TOOL");
std::vector<std::string> oldRuntimeDirs, newRuntimeDirs; std::vector<std::string> oldRuntimeDirs, newRuntimeDirs;
cli->GetRPath(oldRuntimeDirs, false); cli->GetRPath(oldRuntimeDirs, false);
cli->GetRPath(newRuntimeDirs, true); cli->GetRPath(newRuntimeDirs, true);
// Note: These paths are kept unique to avoid install_name_tool corruption. std::string darwin_major_version_s =
mf->GetSafeDefinition("DARWIN_MAJOR_VERSION");
std::stringstream ss(darwin_major_version_s);
int darwin_major_version;
ss >> darwin_major_version;
if(!ss.fail() && darwin_major_version <= 9 &&
(!oldRuntimeDirs.empty() || !newRuntimeDirs.empty())
)
{
cmOStringStream msg;
msg << "WARNING: Target \"" << this->Target->GetName()
<< "\" has runtime paths which cannot be changed during install. "
<< "To change runtime paths, OS X version 10.6 or newer is required. "
<< "Therefore, runtime paths will not be changed when installing. "
<< "CMAKE_BUILD_WITH_INSTALL_RPATH may be used to work around"
" this limitation.";
mf->IssueMessage(cmake::WARNING, msg.str());
}
else
{
// Note: These paths are kept unique to avoid
// install_name_tool corruption.
std::set<std::string> runpaths; std::set<std::string> runpaths;
for(std::vector<std::string>::const_iterator i = oldRuntimeDirs.begin(); for(std::vector<std::string>::const_iterator i = oldRuntimeDirs.begin();
i != oldRuntimeDirs.end(); ++i) i != oldRuntimeDirs.end(); ++i)
{ {
std::string runpath = this->Target->GetMakefile()->GetLocalGenerator()-> std::string runpath =
mf->GetLocalGenerator()->
GetGlobalGenerator()->ExpandCFGIntDir(*i, config); GetGlobalGenerator()->ExpandCFGIntDir(*i, config);
if(runpaths.find(runpath) == runpaths.end()) if(runpaths.find(runpath) == runpaths.end())
@ -709,7 +733,8 @@ cmInstallTargetGenerator
for(std::vector<std::string>::const_iterator i = newRuntimeDirs.begin(); for(std::vector<std::string>::const_iterator i = newRuntimeDirs.begin();
i != newRuntimeDirs.end(); ++i) i != newRuntimeDirs.end(); ++i)
{ {
std::string runpath = this->Target->GetMakefile()->GetLocalGenerator()-> std::string runpath =
mf->GetLocalGenerator()->
GetGlobalGenerator()->ExpandCFGIntDir(*i, config); GetGlobalGenerator()->ExpandCFGIntDir(*i, config);
if(runpaths.find(runpath) == runpaths.end()) if(runpaths.find(runpath) == runpaths.end())
@ -720,6 +745,7 @@ cmInstallTargetGenerator
} }
} }
} }
}
else else
{ {
// Construct the original rpath string to be replaced. // Construct the original rpath string to be replaced.

View File

@ -109,7 +109,8 @@ if(APPLE AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS 9.0)
target_link_libraries(testbundleutils3 shared-3 framework-3 ${CMAKE_DL_LIBS}) target_link_libraries(testbundleutils3 shared-3 framework-3 ${CMAKE_DL_LIBS})
set_target_properties(testbundleutils3 module3 PROPERTIES set_target_properties(testbundleutils3 module3 PROPERTIES
LINK_FLAGS "-Wl,-rpath,@loader_path/") LINK_FLAGS "-Wl,-rpath,@loader_path/"
BUILD_WITH_INSTALL_RPATH 1)
# add custom target to install and test the app # add custom target to install and test the app
add_custom_target(testbundleutils3_test ALL add_custom_target(testbundleutils3_test ALL