From f2bb0af819d5ac2860984c440f1a1f01e7c11007 Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Mon, 26 Nov 2007 17:57:39 -0500 Subject: [PATCH] STYLE: restructure OutputLinkLibraries() a bit, so that new there is a function which returns the RPATH, so e.g. the install rpath can be queried when the command for the build rpath is created. This is a first step for supporting chrpath. Alex --- Source/cmLocalGenerator.cxx | 67 ++++++++++++++++++++++++++----------- Source/cmLocalGenerator.h | 4 +++ 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 5586ff51c..6c081b9cb 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1476,15 +1476,15 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, } } -/** - * Output the linking rules on a command line. For executables, - * targetLibrary should be a NULL pointer. For libraries, it should point - * to the name of the library. This will not link a library against itself. - */ -void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, - cmTarget& tgt, - bool relink) +bool cmLocalGenerator::GetLinkerArgs(std::string& rpath, + std::string& linkLibs, + cmTarget& tgt, + bool relink) { + rpath = ""; + // collect all the flags needed for linking libraries + linkLibs = ""; + // Try to emit each search path once std::set emitted; // Embed runtime search paths if possible and if required. @@ -1494,13 +1494,13 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"); const char* linkLanguage = - tgt.GetLinkerLanguage(this->GetGlobalGenerator()); + tgt.GetLinkerLanguage(this->GetGlobalGenerator()); if(!linkLanguage) { cmSystemTools:: Error("CMake can not determine linker language for target:", tgt.GetName()); - return; + return false; } std::string runTimeFlagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_"; runTimeFlagVar += linkLanguage; @@ -1535,8 +1535,6 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR"); std::string libLinkFlag = this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG"); - // collect all the flags needed for linking libraries - std::string linkLibs; // Flags to link an executable to shared libraries. std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_"; @@ -1635,29 +1633,60 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, linkLibs += " "; } - fout << linkLibs; - if(!runtimeDirs.empty()) { // For the runtime search directories, do a "-Wl,-rpath,a:b:c" or // a "-R a -R b -R c" type link line - fout << runtimeFlag; + rpath += runtimeFlag; std::vector::iterator itr = runtimeDirs.begin(); - fout << *itr; + rpath += *itr; ++itr; for( ; itr != runtimeDirs.end(); ++itr ) { if(runtimeConcatenate) { - fout << runtimeSep << *itr; + rpath += runtimeSep; + rpath += *itr; } else { - fout << " " << runtimeFlag << *itr; + rpath += " "; + rpath += runtimeFlag; + rpath += *itr; } } - fout << " "; } + return true; +} + +/** + * Output the linking rules on a command line. For executables, + * targetLibrary should be a NULL pointer. For libraries, it should point + * to the name of the library. This will not link a library against itself. + */ +void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, + cmTarget& tgt, + bool relink) +{ + std::string rpath; + std::string linkLibs; + if (!this->GetLinkerArgs(rpath, linkLibs, tgt, relink)) + { + return; + } + + const char* linkLanguage = + tgt.GetLinkerLanguage(this->GetGlobalGenerator()); + if(!linkLanguage) + { + cmSystemTools:: + Error("CMake can not determine linker language for target:", + tgt.GetName()); + return; + } + + fout << linkLibs; + fout << rpath << " "; // Add standard libraries for this language. std::string standardLibsVar = "CMAKE_"; diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 1c2128ae7..9f24f3f01 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -257,6 +257,10 @@ protected: ///! put all the libraries for a target on into the given stream virtual void OutputLinkLibraries(std::ostream&, cmTarget&, bool relink); + + ///! Determine the arguments for the linker call + bool GetLinkerArgs(std::string& rpath, std::string& linkLibs, + cmTarget& tgt, bool relink); // Expand rule variables in CMake of the type found in language rules void ExpandRuleVariables(std::string& string,