summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-01 13:35:51 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-06-01 13:35:57 (GMT)
commit199db6117bb64dfae657308b36942dda7ed77866 (patch)
tree382457d2615b8bee83175842edc165fad97a3284 /Source
parentf3be15e4382c17d0441a4fa69f44482d888e9c9d (diff)
parent6cc417586ed0e3f86d0cde88bcdcae32cb7a0ea5 (diff)
downloadCMake-199db6117bb64dfae657308b36942dda7ed77866.zip
CMake-199db6117bb64dfae657308b36942dda7ed77866.tar.gz
CMake-199db6117bb64dfae657308b36942dda7ed77866.tar.bz2
Merge topic 'ninja-dedup-def'
6cc417586e Ninja: Avoid duplicating /DEF: linker flag with MSVC tools 39dba8a244 cmLocalGenerator: Adopt AppendModuleDefinitionFlag method Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7307
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCommonTargetGenerator.cxx28
-rw-r--r--Source/cmCommonTargetGenerator.h5
-rw-r--r--Source/cmLocalGenerator.cxx44
-rw-r--r--Source/cmLocalGenerator.h4
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx5
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx10
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx3
7 files changed, 41 insertions, 58 deletions
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx
index b172c20..ba95168 100644
--- a/Source/cmCommonTargetGenerator.cxx
+++ b/Source/cmCommonTargetGenerator.cxx
@@ -9,7 +9,6 @@
#include "cmComputeLinkInformation.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalCommonGenerator.h"
-#include "cmLinkLineComputer.h"
#include "cmLocalCommonGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
@@ -47,33 +46,6 @@ cmValue cmCommonTargetGenerator::GetFeature(const std::string& feature,
return this->GeneratorTarget->GetFeature(feature, config);
}
-void cmCommonTargetGenerator::AddModuleDefinitionFlag(
- cmLinkLineComputer* linkLineComputer, std::string& flags,
- const std::string& config)
-{
- cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
- this->GeneratorTarget->GetModuleDefinitionInfo(config);
- if (!mdi || mdi->DefFile.empty()) {
- return;
- }
-
- // TODO: Create a per-language flag variable.
- cmValue defFileFlag =
- this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
- if (!defFileFlag) {
- return;
- }
-
- // Append the flag and value. Use ConvertToLinkReference to help
- // vs6's "cl -link" pass it to the linker.
- std::string flag =
- cmStrCat(*defFileFlag,
- this->LocalCommonGenerator->ConvertToOutputFormat(
- linkLineComputer->ConvertToLinkReference(mdi->DefFile),
- cmOutputConverter::SHELL));
- this->LocalCommonGenerator->AppendFlags(flags, flag);
-}
-
void cmCommonTargetGenerator::AppendFortranFormatFlags(
std::string& flags, cmSourceFile const& source)
{
diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h
index 1b804b4..e8c5a19 100644
--- a/Source/cmCommonTargetGenerator.h
+++ b/Source/cmCommonTargetGenerator.h
@@ -13,7 +13,6 @@
class cmGeneratorTarget;
class cmGlobalCommonGenerator;
-class cmLinkLineComputer;
class cmLocalCommonGenerator;
class cmMakefile;
class cmSourceFile;
@@ -33,10 +32,6 @@ protected:
// Feature query methods.
cmValue GetFeature(const std::string& feature, const std::string& config);
- // Helper to add flag for windows .def file.
- void AddModuleDefinitionFlag(cmLinkLineComputer* linkLineComputer,
- std::string& flags, const std::string& config);
-
cmGeneratorTarget* GeneratorTarget;
cmMakefile* Makefile;
cmLocalCommonGenerator* LocalCommonGenerator;
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index d2c81ae..7928a46 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1448,22 +1448,6 @@ void cmLocalGenerator::GetTargetFlags(
sharedLibFlags += this->Makefile->GetSafeDefinition(build);
sharedLibFlags += " ";
}
- if (this->Makefile->IsOn("WIN32") &&
- !(this->Makefile->IsOn("CYGWIN") ||
- this->Makefile->IsOn("MINGW"))) {
- std::vector<cmSourceFile*> sources;
- target->GetSourceFiles(sources, config);
- std::string defFlag =
- this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
- for (cmSourceFile* sf : sources) {
- if (sf->GetExtension() == "def") {
- sharedLibFlags += defFlag;
- sharedLibFlags +=
- this->ConvertToOutputFormat(sf->ResolveFullPath(), SHELL);
- sharedLibFlags += " ";
- }
- }
- }
}
cmValue targetLinkFlags = target->GetProperty("LINK_FLAGS");
@@ -1577,6 +1561,8 @@ void cmLocalGenerator::GetTargetFlags(
this->AppendPositionIndependentLinkerFlags(extraLinkFlags, target, config,
linkLanguage);
this->AppendIPOLinkerFlags(extraLinkFlags, target, config, linkLanguage);
+ this->AppendModuleDefinitionFlag(extraLinkFlags, target, linkLineComputer,
+ config);
if (!extraLinkFlags.empty()) {
linkFlags.emplace_back(std::move(extraLinkFlags));
@@ -3137,6 +3123,32 @@ void cmLocalGenerator::AppendPositionIndependentLinkerFlags(
}
}
+void cmLocalGenerator::AppendModuleDefinitionFlag(
+ std::string& flags, cmGeneratorTarget const* target,
+ cmLinkLineComputer* linkLineComputer, std::string const& config)
+{
+ cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
+ target->GetModuleDefinitionInfo(config);
+ if (!mdi || mdi->DefFile.empty()) {
+ return;
+ }
+
+ cmValue defFileFlag =
+ this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
+ if (!defFileFlag) {
+ return;
+ }
+
+ // Append the flag and value. Use ConvertToLinkReference to help
+ // vs6's "cl -link" pass it to the linker.
+ std::string flag =
+ cmStrCat(*defFileFlag,
+ this->ConvertToOutputFormat(
+ linkLineComputer->ConvertToLinkReference(mdi->DefFile),
+ cmOutputConverter::SHELL));
+ this->AppendFlags(flags, flag);
+}
+
bool cmLocalGenerator::AppendLWYUFlags(std::string& flags,
const cmGeneratorTarget* target,
const std::string& lang)
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index da3c9fd..7cae1fc 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -178,6 +178,10 @@ public:
cmGeneratorTarget* target,
const std::string& config,
const std::string& lang);
+ void AppendModuleDefinitionFlag(std::string& flags,
+ cmGeneratorTarget const* target,
+ cmLinkLineComputer* linkLineComputer,
+ std::string const& config);
bool AppendLWYUFlags(std::string& flags, const cmGeneratorTarget* target,
const std::string& lang);
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index 244f56e..3849c6f 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -407,8 +407,9 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory());
- this->AddModuleDefinitionFlag(linkLineComputer.get(), linkFlags,
- this->GetConfigName());
+ this->LocalGenerator->AppendModuleDefinitionFlag(
+ linkFlags, this->GeneratorTarget, linkLineComputer.get(),
+ this->GetConfigName());
}
this->LocalGenerator->AppendIPOLinkerFlags(
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index 21b91e0..f30ec27 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -175,8 +175,9 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory());
- this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags,
- this->GetConfigName());
+ this->LocalGenerator->AppendModuleDefinitionFlag(
+ extraFlags, this->GeneratorTarget, linkLineComputer.get(),
+ this->GetConfigName());
this->UseLWYU = this->LocalGenerator->AppendLWYUFlags(
extraFlags, this->GeneratorTarget, linkLanguage);
@@ -209,8 +210,9 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory());
- this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags,
- this->GetConfigName());
+ this->LocalGenerator->AppendModuleDefinitionFlag(
+ extraFlags, this->GeneratorTarget, linkLineComputer.get(),
+ this->GetConfigName());
this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
}
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 4f6da0e..d4f1608 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -1164,9 +1164,6 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
this->addPoolNinjaVariable("JOB_POOL_LINK", gt, vars);
- this->AddModuleDefinitionFlag(linkLineComputer.get(), vars["LINK_FLAGS"],
- config);
-
this->UseLWYU = this->GetLocalGenerator()->AppendLWYUFlags(
vars["LINK_FLAGS"], this->GetGeneratorTarget(),
this->TargetLinkLanguage(config));