From b4542762a77c7fa7848a3ac8e85cf42c05bc73a9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 15 Jun 2006 10:12:19 -0400 Subject: [PATCH] ENH: Added target property INSTALL_RPATH_USE_LINK_PATH to append the linker search path directories not inside the project to the INSTALL_RPATH automatically. The property is initialized by the variable CMAKE_INSTALL_RPATH_USE_LINK_PATH when the target is created. --- Source/cmLocalGenerator.cxx | 25 ++++++++++++++++++++++--- Source/cmSetTargetPropertiesCommand.h | 6 +++++- Source/cmTarget.cxx | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 52f48aca4..a73fbce89 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1418,6 +1418,9 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, outputRuntime && tgt.HaveInstallTreeRPATH() && linking_for_install; bool use_build_rpath = outputRuntime && tgt.HaveBuildTreeRPATH() && !linking_for_install; + bool use_link_rpath = + outputRuntime && linking_for_install && + tgt.GetPropertyAsBool("INSTALL_RPATH_USE_LINK_PATH"); // Construct the RPATH. std::vector runtimeDirs; @@ -1454,13 +1457,29 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, && libDir->find("${") == std::string::npos) { linkLibs += libPathFlag; + linkLibs += fullLibPath; + linkLibs += " "; + + // Put this directory in the rpath if using build-tree rpath + // support or if using the link path as an rpath. if(use_build_rpath) { - runtimeDirs.push_back( fullLibPath ); + runtimeDirs.push_back(fullLibPath); + } + else if(use_link_rpath) + { + // Do not add any path inside the source or build tree. + const char* topSourceDir = this->Makefile->GetHomeDirectory(); + const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory(); + if(!cmSystemTools::ComparePath(libDir->c_str(), topSourceDir) && + !cmSystemTools::ComparePath(libDir->c_str(), topBinaryDir) && + !cmSystemTools::IsSubDirectory(libDir->c_str(), topSourceDir) && + !cmSystemTools::IsSubDirectory(libDir->c_str(), topBinaryDir)) + { + runtimeDirs.push_back(fullLibPath); + } } } - linkLibs += fullLibPath; - linkLibs += " "; } } diff --git a/Source/cmSetTargetPropertiesCommand.h b/Source/cmSetTargetPropertiesCommand.h index 9bd348368..7de65c153 100644 --- a/Source/cmSetTargetPropertiesCommand.h +++ b/Source/cmSetTargetPropertiesCommand.h @@ -112,6 +112,9 @@ public: "There are a few properties used to specify RPATH rules. " "INSTALL_RPATH is a semicolon-separated list specifying the rpath " "to use in installed targets (for platforms that support it). " + "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will " + "append directories in the linker search path and outside the project " + "to the INSTALL_RPATH. " "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic " "generation of an rpath allowing the target to run from the " "build tree. " @@ -122,7 +125,8 @@ public: "directory portion of the \"install_name\" field of shared libraries " "on Mac OSX to use in the installed targets. " "When the target is created the values of " - "the variables CMAKE_INSTALL_RPATH, CMAKE_SKIP_BUILD_RPATH, " + "the variables CMAKE_INSTALL_RPATH, " + "CMAKE_INSTALL_RPATH_USE_LINK_PATH, CMAKE_SKIP_BUILD_RPATH, " "CMAKE_BUILD_WITH_INSTALL_RPATH, and CMAKE_INSTALL_NAME_DIR " "are used to initialize these properties.\n" "PROJECT_LABEL can be used to change the name of " diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 5f0998ab0..26bc47d9d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -63,6 +63,7 @@ void cmTarget::SetMakefile(cmMakefile* mf) // Setup default property values. this->SetPropertyDefault("INSTALL_NAME_DIR", ""); this->SetPropertyDefault("INSTALL_RPATH", ""); + this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF"); this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF"); this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");