Commit 77c4202e authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmLinkLineComputer: Move RPath computation from cmLocalGenerator

Add state for Relink and populate it at the point of cmLinkLineComputer
initialization.  This allows removal of the parameter in go-between
methods.
parent 09b6cc66
Pipeline #30051 passed with stage
......@@ -12,6 +12,7 @@ cmLinkLineComputer::cmLinkLineComputer(cmOutputConverter* outputConverter,
, OutputConverter(outputConverter)
, ForResponse(false)
, UseWatcomQuote(false)
, Relink(false)
{
}
......@@ -29,6 +30,11 @@ void cmLinkLineComputer::SetForResponse(bool forResponse)
this->ForResponse = forResponse;
}
void cmLinkLineComputer::SetRelink(bool relink)
{
this->Relink = relink;
}
std::string cmLinkLineComputer::ConvertToLinkReference(
std::string const& lib) const
{
......@@ -100,3 +106,33 @@ std::string cmLinkLineComputer::ComputeLinkPath(
}
return linkPath;
}
std::string cmLinkLineComputer::ComputeRPath(cmComputeLinkInformation& cli)
{
std::string rpath;
// 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")
std::vector<std::string> runtimeDirs;
cli.GetRPath(runtimeDirs, this->Relink);
for (std::vector<std::string>::iterator ri = runtimeDirs.begin();
ri != runtimeDirs.end(); ++ri) {
rpath += cli.GetRuntimeFlag();
rpath += this->ConvertToOutputFormat(*ri);
rpath += " ";
}
} else {
// All rpath entries are combined ("-Wl,-rpath,a:b:c").
std::string rpathString = cli.GetRPathString(this->Relink);
// Store the rpath option in the stream.
if (!rpathString.empty()) {
rpath += cli.GetRuntimeFlag();
rpath +=
this->OutputConverter->EscapeForShell(rpathString, !this->ForResponse);
rpath += " ";
}
}
return rpath;
}
......@@ -18,6 +18,7 @@ public:
void SetUseWatcomQuote(bool useWatcomQuote);
void SetForResponse(bool forResponse);
void SetRelink(bool relink);
virtual std::string ConvertToLinkReference(std::string const& input) const;
......@@ -27,6 +28,8 @@ public:
std::string const& libPathFlag,
std::string const& libPathTerminator);
std::string ComputeRPath(cmComputeLinkInformation& cli);
private:
std::string ConvertToOutputFormat(std::string const& input);
std::string ConvertToOutputForExisting(std::string const& input);
......@@ -36,6 +39,7 @@ private:
bool ForResponse;
bool UseWatcomQuote;
bool Relink;
};
#endif
......@@ -1208,7 +1208,7 @@ void cmLocalGenerator::GetTargetFlags(
}
if (pcli) {
this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
frameworkPath, linkPath, false, false,
frameworkPath, linkPath, false,
useWatcomQuote);
}
} break;
......@@ -1231,7 +1231,7 @@ void cmLocalGenerator::GetTargetFlags(
this->AddLanguageFlags(flags, linkLanguage, buildType);
if (pcli) {
this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
frameworkPath, linkPath, false, false,
frameworkPath, linkPath, false,
useWatcomQuote);
}
if (cmSystemTools::IsOn(
......@@ -1400,8 +1400,7 @@ std::string cmLocalGenerator::GetTargetFortranFlags(
void cmLocalGenerator::OutputLinkLibraries(
cmComputeLinkInformation* pcli, cmLinkLineComputer* linkLineComputer,
std::string& linkLibraries, std::string& frameworkPath,
std::string& linkPath, bool relink, bool forResponseFile,
bool useWatcomQuote)
std::string& linkPath, bool forResponseFile, bool useWatcomQuote)
{
OutputFormat shellFormat =
(forResponseFile) ? RESPONSE : ((useWatcomQuote) ? WATCOMQUOTE : SHELL);
......@@ -1446,31 +1445,7 @@ void cmLocalGenerator::OutputLinkLibraries(
std::string linkLibs = linkLineComputer->ComputeLinkLibs(cli);
std::string rpath;
// 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")
std::vector<std::string> runtimeDirs;
cli.GetRPath(runtimeDirs, relink);
for (std::vector<std::string>::iterator ri = runtimeDirs.begin();
ri != runtimeDirs.end(); ++ri) {
rpath += cli.GetRuntimeFlag();
rpath += this->ConvertToOutputFormat(*ri, shellFormat);
rpath += " ";
}
} else {
// All rpath entries are combined ("-Wl,-rpath,a:b:c").
std::string rpathString = cli.GetRPathString(relink);
// Store the rpath option in the stream.
if (!rpathString.empty()) {
rpath += cli.GetRuntimeFlag();
rpath += this->EscapeForShell(rpathString, escapeAllowMakeVars);
rpath += " ";
}
}
std::string rpath = linkLineComputer->ComputeRPath(cli);
std::ostringstream fout;
fout << rpath;
......
......@@ -352,8 +352,7 @@ protected:
cmLinkLineComputer* linkLineComputer,
std::string& linkLibraries,
std::string& frameworkPath, std::string& linkPath,
bool relink, bool forResponseFile,
bool useWatcomQuote);
bool forResponseFile, bool useWatcomQuote);
// Expand rule variables in CMake of the type found in language rules
void ExpandRuleVariables(std::string& string,
......
......@@ -310,10 +310,11 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
linkLineComputer->SetForResponse(useResponseFileForLibs);
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
linkLineComputer->SetRelink(relink);
// Collect up flags to link in needed libraries.
std::string linkLibs;
this->CreateLinkLibs(linkLineComputer.get(), linkLibs, relink,
this->CreateLinkLibs(linkLineComputer.get(), linkLibs,
useResponseFileForLibs, depends, useWatcomQuote);
// Construct object file lists that may be needed to expand the
......
......@@ -511,8 +511,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
linkLineComputer->SetForResponse(useResponseFileForLibs);
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
linkLineComputer->SetRelink(relink);
this->CreateLinkLibs(linkLineComputer.get(), linkLibs, relink,
this->CreateLinkLibs(linkLineComputer.get(), linkLibs,
useResponseFileForLibs, depends, useWatcomQuote);
}
......
......@@ -1601,7 +1601,7 @@ cmLinkLineComputer* cmMakefileTargetGenerator::CreateLinkLineComputer(
}
void cmMakefileTargetGenerator::CreateLinkLibs(
cmLinkLineComputer* linkLineComputer, std::string& linkLibs, bool relink,
cmLinkLineComputer* linkLineComputer, std::string& linkLibs,
bool useResponseFile, std::vector<std::string>& makefile_depends,
bool useWatcomQuote)
{
......@@ -1611,7 +1611,7 @@ void cmMakefileTargetGenerator::CreateLinkLibs(
cmComputeLinkInformation* pcli =
this->GeneratorTarget->GetLinkInformation(config);
this->LocalGenerator->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
frameworkPath, linkPath, relink,
frameworkPath, linkPath,
useResponseFile, useWatcomQuote);
linkLibs = frameworkPath + linkPath + linkLibs;
......
......@@ -154,7 +154,7 @@ protected:
/** Create list of flags for link libraries. */
void CreateLinkLibs(cmLinkLineComputer* linkLineComputer,
std::string& linkLibs, bool relink, bool useResponseFile,
std::string& linkLibs, bool useResponseFile,
std::vector<std::string>& makefile_depends,
bool useWatcomQuote);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment