Re-order link line to place RPATH entries before libraries

Since we support adding arbitrary flags to the link line via
`target_link_libraries` the project/user may add their own RPATH flags
(typically for system library locations).  Re-order the link line to
place our generated RPATH entries before the libraries so that they also
come before flag-specified entries.  Otherwise our in-build-tree RPATH
entries may not be preferred by the dynamic loader and we could collide
with libraries in the system directories.

Closes: #16293
This commit is contained in:
Dan Kegel 2016-09-09 13:45:41 -07:00 committed by Brad King
parent d5e4cdc0f8
commit 9370b697e9
1 changed files with 3 additions and 3 deletions

View File

@ -1531,9 +1531,6 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
linkLibs += " ";
}
// Write the library flags to the build rule.
fout << linkLibs;
// Check what kind of rpath flags to use.
if (cli.GetRuntimeSep().empty()) {
// Each rpath entry gets its own option ("-R a -R b -R c")
@ -1560,6 +1557,9 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
}
}
// Write the library flags to the build rule.
fout << linkLibs;
// Add the linker runtime search path if any.
std::string rpath_link = cli.GetRPathLinkString();
if (!cli.GetRPathLinkFlag().empty() && !rpath_link.empty()) {