Commit 0c978063 authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmLinkLineComputer: Move ComputeLinkLibs from cmLocalGenerator

Add a cmOutputConverter to the cmLinkLineComputer and factory methods to
facilitate shell escapes.

Add state to the cmLinkLineComputer to record whether outputting for
response files or for watcom, to satisfy the cmOutputConverter API.
These are constant for the lifetime of the cmLinkLineComputer, even when
its functionality is extended in the future.  This also keeps the
signatures of cmLinkLineComputer relatively simple.

Pass the cmComputeLinkInformation as a method parameter so that
cmLinkLineComputer is free from target-specific state.  An instance
should be usable for all targets in a directory.
parent 0152a01f
Pipeline #30053 passed with stage
......@@ -365,6 +365,7 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries(
this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE");
CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
this->GetGlobalGenerator()->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
this->LocalGenerator->GetTargetFlags(
......
......@@ -1415,15 +1415,15 @@ cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
}
cmLinkLineComputer* cmGlobalGenerator::CreateLinkLineComputer(
cmState::Directory stateDir) const
cmOutputConverter* outputConverter, cmState::Directory stateDir) const
{
return new cmLinkLineComputer(stateDir);
return new cmLinkLineComputer(outputConverter, stateDir);
}
cmLinkLineComputer* cmGlobalGenerator::CreateMSVC60LinkLineComputer(
cmState::Directory stateDir) const
cmOutputConverter* outputConverter, cmState::Directory stateDir) const
{
return new cmMSVC60LinkLineComputer(stateDir);
return new cmMSVC60LinkLineComputer(outputConverter, stateDir);
}
void cmGlobalGenerator::FinalizeTargetCompileInfo()
......
......@@ -36,6 +36,7 @@ class cmGeneratorTarget;
class cmLocalGenerator;
class cmLinkLineComputer;
class cmMakefile;
class cmOutputConverter;
class cmake;
/** \class cmGlobalGenerator
......@@ -107,10 +108,10 @@ public:
virtual void Generate();
virtual cmLinkLineComputer* CreateLinkLineComputer(
cmState::Directory stateDir) const;
cmOutputConverter* outputConverter, cmState::Directory stateDir) const;
cmLinkLineComputer* CreateMSVC60LinkLineComputer(
cmState::Directory stateDir) const;
cmOutputConverter* outputConverter, cmState::Directory stateDir) const;
/**
* Set/Get and Clear the enabled languages.
......
......@@ -66,9 +66,10 @@ void cmGlobalNinjaGenerator::WriteComment(std::ostream& os,
}
cmLinkLineComputer* cmGlobalNinjaGenerator::CreateLinkLineComputer(
cmState::Directory /* stateDir */) const
cmOutputConverter* outputConverter, cmState::Directory /* stateDir */) const
{
return new cmNinjaLinkLineComputer(
outputConverter,
this->LocalGenerators[0]->GetStateSnapshot().GetDirectory(), this);
}
......
......@@ -70,8 +70,9 @@ public:
std::string EncodePath(const std::string& path);
static std::string EncodeDepfileSpace(const std::string& path);
cmLinkLineComputer* CreateLinkLineComputer(cmState::Directory stateDir) const
CM_OVERRIDE;
cmLinkLineComputer* CreateLinkLineComputer(
cmOutputConverter* outputConverter,
cmState::Directory stateDir) const CM_OVERRIDE;
/**
* Write the given @a comment to the output stream @a os. It
......
......@@ -2,10 +2,16 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmLinkLineComputer.h"
#include "cmComputeLinkInformation.h"
#include "cmGeneratorTarget.h"
#include "cmOutputConverter.h"
cmLinkLineComputer::cmLinkLineComputer(cmState::Directory stateDir)
cmLinkLineComputer::cmLinkLineComputer(cmOutputConverter* outputConverter,
cmState::Directory stateDir)
: StateDir(stateDir)
, OutputConverter(outputConverter)
, ForResponse(false)
, UseWatcomQuote(false)
{
}
......@@ -13,6 +19,16 @@ cmLinkLineComputer::~cmLinkLineComputer()
{
}
void cmLinkLineComputer::SetUseWatcomQuote(bool useWatcomQuote)
{
this->UseWatcomQuote = useWatcomQuote;
}
void cmLinkLineComputer::SetForResponse(bool forResponse)
{
this->ForResponse = forResponse;
}
std::string cmLinkLineComputer::ConvertToLinkReference(
std::string const& lib) const
{
......@@ -25,3 +41,34 @@ std::string cmLinkLineComputer::ConvertToLinkReference(
}
return relLib;
}
std::string cmLinkLineComputer::ComputeLinkLibs(cmComputeLinkInformation& cli)
{
std::string linkLibs;
typedef cmComputeLinkInformation::ItemVector ItemVector;
ItemVector const& items = cli.GetItems();
for (ItemVector::const_iterator li = items.begin(); li != items.end();
++li) {
if (li->Target && li->Target->GetType() == cmState::INTERFACE_LIBRARY) {
continue;
}
if (li->IsPath) {
linkLibs +=
this->ConvertToOutputFormat(this->ConvertToLinkReference(li->Value));
} else {
linkLibs += li->Value;
}
linkLibs += " ";
}
return linkLibs;
}
std::string cmLinkLineComputer::ConvertToOutputFormat(std::string const& input)
{
cmOutputConverter::OutputFormat shellFormat = (this->ForResponse)
? cmOutputConverter::RESPONSE
: ((this->UseWatcomQuote) ? cmOutputConverter::WATCOMQUOTE
: cmOutputConverter::SHELL);
return this->OutputConverter->ConvertToOutputFormat(input, shellFormat);
}
......@@ -6,16 +6,31 @@
#include "cmState.h"
class cmComputeLinkInformation;
class cmOutputConverter;
class cmLinkLineComputer
{
public:
cmLinkLineComputer(cmState::Directory stateDir);
cmLinkLineComputer(cmOutputConverter* outputConverter,
cmState::Directory stateDir);
virtual ~cmLinkLineComputer();
void SetUseWatcomQuote(bool useWatcomQuote);
void SetForResponse(bool forResponse);
virtual std::string ConvertToLinkReference(std::string const& input) const;
std::string ComputeLinkLibs(cmComputeLinkInformation& cli);
private:
std::string ConvertToOutputFormat(std::string const& input);
cmState::Directory StateDir;
cmOutputConverter* OutputConverter;
bool ForResponse;
bool UseWatcomQuote;
};
#endif
......@@ -1453,24 +1453,7 @@ void cmLocalGenerator::OutputLinkLibraries(
linkPath += " ";
}
std::string linkLibs;
// Append the link items.
typedef cmComputeLinkInformation::ItemVector ItemVector;
ItemVector const& items = cli.GetItems();
for (ItemVector::const_iterator li = items.begin(); li != items.end();
++li) {
if (li->Target && li->Target->GetType() == cmState::INTERFACE_LIBRARY) {
continue;
}
if (li->IsPath) {
linkLibs += this->ConvertToOutputFormat(
linkLineComputer->ConvertToLinkReference(li->Value), shellFormat);
} else {
linkLibs += li->Value;
}
linkLibs += " ";
}
std::string linkLibs = linkLineComputer->ComputeLinkLibs(cli);
std::string rpath;
......
......@@ -5,8 +5,9 @@
#include "cmSystemTools.h"
cmMSVC60LinkLineComputer::cmMSVC60LinkLineComputer(cmState::Directory stateDir)
: cmLinkLineComputer(stateDir)
cmMSVC60LinkLineComputer::cmMSVC60LinkLineComputer(
cmOutputConverter* outputConverter, cmState::Directory stateDir)
: cmLinkLineComputer(outputConverter, stateDir)
{
}
......
......@@ -9,7 +9,8 @@
class cmMSVC60LinkLineComputer : public cmLinkLineComputer
{
public:
cmMSVC60LinkLineComputer(cmState::Directory stateDir);
cmMSVC60LinkLineComputer(cmOutputConverter* outputConverter,
cmState::Directory stateDir);
std::string ConvertToLinkReference(std::string const& input) const
CM_OVERRIDE;
......
......@@ -219,6 +219,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
{
CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
this->AddModuleDefinitionFlag(linkLineComputer.get(), linkFlags);
......@@ -305,7 +306,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
linkLineComputer->SetForResponse(useResponseFileForLibs);
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
// Collect up flags to link in needed libraries.
std::string linkLibs;
......
......@@ -163,6 +163,7 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
......@@ -193,6 +194,7 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
......@@ -505,7 +507,10 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
linkLineComputer->SetForResponse(useResponseFileForLibs);
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
this->CreateLinkLibs(linkLineComputer.get(), linkLibs, relink,
useResponseFileForLibs, depends, useWatcomQuote);
......
......@@ -1590,12 +1590,14 @@ std::string cmMakefileTargetGenerator::CreateResponseFile(
}
cmLinkLineComputer* cmMakefileTargetGenerator::CreateLinkLineComputer(
cmState::Directory stateDir)
cmOutputConverter* outputConverter, cmState::Directory stateDir)
{
if (this->Makefile->IsOn("MSVC60")) {
return this->GlobalGenerator->CreateMSVC60LinkLineComputer(stateDir);
return this->GlobalGenerator->CreateMSVC60LinkLineComputer(outputConverter,
stateDir);
}
return this->GlobalGenerator->CreateLinkLineComputer(stateDir);
return this->GlobalGenerator->CreateLinkLineComputer(outputConverter,
stateDir);
}
void cmMakefileTargetGenerator::CreateLinkLibs(
......
......@@ -140,7 +140,8 @@ protected:
std::vector<std::string>& makefile_commands,
std::vector<std::string>& makefile_depends);
cmLinkLineComputer* CreateLinkLineComputer(cmState::Directory stateDir);
cmLinkLineComputer* CreateLinkLineComputer(
cmOutputConverter* outputConverter, cmState::Directory stateDir);
/** Create a response file with the given set of options. Returns
the relative path from the target build working directory to the
......
......@@ -5,8 +5,9 @@
#include "cmGlobalNinjaGenerator.h"
cmNinjaLinkLineComputer::cmNinjaLinkLineComputer(
cmState::Directory stateDir, cmGlobalNinjaGenerator const* gg)
: cmLinkLineComputer(stateDir)
cmOutputConverter* outputConverter, cmState::Directory stateDir,
cmGlobalNinjaGenerator const* gg)
: cmLinkLineComputer(outputConverter, stateDir)
, GG(gg)
{
}
......
......@@ -12,7 +12,8 @@ class cmGlobalNinjaGenerator;
class cmNinjaLinkLineComputer : public cmLinkLineComputer
{
public:
cmNinjaLinkLineComputer(cmState::Directory stateDir,
cmNinjaLinkLineComputer(cmOutputConverter* outputConverter,
cmState::Directory stateDir,
cmGlobalNinjaGenerator const* gg);
std::string ConvertToLinkReference(std::string const& input) const
......
......@@ -473,7 +473,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
this->GetGlobalGenerator()->CreateLinkLineComputer(
localGen.GetStateSnapshot().GetDirectory()));
this->GetLocalGenerator(),
this->GetLocalGenerator()->GetStateSnapshot().GetDirectory()));
localGen.GetTargetFlags(linkLineComputer.get(), this->GetConfigName(),
vars["LINK_LIBRARIES"], vars["FLAGS"],
......
......@@ -729,12 +729,10 @@ static Json::Value DumpTarget(cmGeneratorTarget* target,
std::string linkLanguageFlags;
std::string frameworkPath;
std::string linkPath;
CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
lg->GetGlobalGenerator()->CreateLinkLineComputer(
lg->GetStateSnapshot().GetDirectory()));
lg->GetTargetFlags(linkLineComputer.get(), config, linkLibs,
linkLanguageFlags, linkFlags, frameworkPath, linkPath,
target, false);
cmLinkLineComputer linkLineComputer(lg,
lg->GetStateSnapshot().GetDirectory());
lg->GetTargetFlags(&linkLineComputer, config, linkLibs, linkLanguageFlags,
linkFlags, frameworkPath, linkPath, target, false);
linkLibs = cmSystemTools::TrimWhitespace(linkLibs);
linkFlags = cmSystemTools::TrimWhitespace(linkFlags);
......
......@@ -583,9 +583,9 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
gg->CreateGenerationObjects();
cmGeneratorTarget* gtgt = gg->FindGeneratorTarget(tgt->GetName());
cmLocalGenerator* lg = gtgt->GetLocalGenerator();
CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
gg->CreateLinkLineComputer(lg->GetStateSnapshot().GetDirectory()));
lg->GetTargetFlags(linkLineComputer.get(), buildType, linkLibs, flags,
cmLinkLineComputer linkLineComputer(lg,
lg->GetStateSnapshot().GetDirectory());
lg->GetTargetFlags(&linkLineComputer, buildType, linkLibs, flags,
linkFlags, frameworkPath, linkPath, gtgt, false);
linkLibs = frameworkPath + linkPath + linkLibs;
......
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