summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2016-10-08 12:21:38 +0200
committerStephen Kelly <steveire@gmail.com>2016-10-10 20:38:58 +0200
commit0c978063259fb013856b617d680cebcdee51ab1a (patch)
treec943813035b6d0a51f7d60d4c4129f4033227eaa /Source
parent0152a01f11fc46f645fd765cc7b1be76cc07b52a (diff)
downloadcmake-0c978063259fb013856b617d680cebcdee51ab1a.tar.gz
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.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGhsMultiTargetGenerator.cxx1
-rw-r--r--Source/cmGlobalGenerator.cxx8
-rw-r--r--Source/cmGlobalGenerator.h5
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx3
-rw-r--r--Source/cmGlobalNinjaGenerator.h5
-rw-r--r--Source/cmLinkLineComputer.cxx49
-rw-r--r--Source/cmLinkLineComputer.h17
-rw-r--r--Source/cmLocalGenerator.cxx19
-rw-r--r--Source/cmMSVC60LinkLineComputer.cxx5
-rw-r--r--Source/cmMSVC60LinkLineComputer.h3
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx4
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx5
-rw-r--r--Source/cmMakefileTargetGenerator.cxx8
-rw-r--r--Source/cmMakefileTargetGenerator.h3
-rw-r--r--Source/cmNinjaLinkLineComputer.cxx5
-rw-r--r--Source/cmNinjaLinkLineComputer.h3
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx3
-rw-r--r--Source/cmServerProtocol.cxx10
-rw-r--r--Source/cmake.cxx6
19 files changed, 113 insertions, 49 deletions
diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index 959bfc1c48..04c45e56c1 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -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(
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 2266e44786..1aa6af14e8 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -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()
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 126eb6f703..38eaa761ff 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -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.
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 65a1f253d7..67df0381b9 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -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);
}
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index 87faf452d4..6b77a2bbbb 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -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
diff --git a/Source/cmLinkLineComputer.cxx b/Source/cmLinkLineComputer.cxx
index 7103a5b8d5..b2b56bf2f3 100644
--- a/Source/cmLinkLineComputer.cxx
+++ b/Source/cmLinkLineComputer.cxx
@@ -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);
+}
diff --git a/Source/cmLinkLineComputer.h b/Source/cmLinkLineComputer.h
index bd4c7405e8..2317385063 100644
--- a/Source/cmLinkLineComputer.h
+++ b/Source/cmLinkLineComputer.h
@@ -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
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 25755d7fa3..0d2fe86ff0 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -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;
diff --git a/Source/cmMSVC60LinkLineComputer.cxx b/Source/cmMSVC60LinkLineComputer.cxx
index 89432ff219..2b6df2a491 100644
--- a/Source/cmMSVC60LinkLineComputer.cxx
+++ b/Source/cmMSVC60LinkLineComputer.cxx
@@ -5,8 +5,9 @@
#include "cmSystemTools.h"
-cmMSVC60LinkLineComputer::cmMSVC60LinkLineComputer(cmState::Directory stateDir)
- : cmLinkLineComputer(stateDir)
+cmMSVC60LinkLineComputer::cmMSVC60LinkLineComputer(
+ cmOutputConverter* outputConverter, cmState::Directory stateDir)
+ : cmLinkLineComputer(outputConverter, stateDir)
{
}
diff --git a/Source/cmMSVC60LinkLineComputer.h b/Source/cmMSVC60LinkLineComputer.h
index c159b616c4..ca9da31a7a 100644
--- a/Source/cmMSVC60LinkLineComputer.h
+++ b/Source/cmMSVC60LinkLineComputer.h
@@ -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;
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index 09967ff20c..eaa50616f1 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -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;
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index e32f3a7255..ccc6d9f253 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -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);
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index c74b381d03..d9102a6816 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -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(
diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h
index 05de7ff500..0930d896de 100644
--- a/Source/cmMakefileTargetGenerator.h
+++ b/Source/cmMakefileTargetGenerator.h
@@ -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
diff --git a/Source/cmNinjaLinkLineComputer.cxx b/Source/cmNinjaLinkLineComputer.cxx
index dd742387d7..3dcb20b3ab 100644
--- a/Source/cmNinjaLinkLineComputer.cxx
+++ b/Source/cmNinjaLinkLineComputer.cxx
@@ -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)
{
}
diff --git a/Source/cmNinjaLinkLineComputer.h b/Source/cmNinjaLinkLineComputer.h
index d86f214b78..a108568d6b 100644
--- a/Source/cmNinjaLinkLineComputer.h
+++ b/Source/cmNinjaLinkLineComputer.h
@@ -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
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 9c22353785..a458bbb40f 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -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"],
diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx
index a58510e602..d537cfd507 100644
--- a/Source/cmServerProtocol.cxx
+++ b/Source/cmServerProtocol.cxx
@@ -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);
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 046b5f1842..50f77f4057 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -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;