From 39dba8a2449e3f866088b13faf3d6cbf60852751 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 31 May 2022 15:14:37 -0400 Subject: cmLocalGenerator: Adopt AppendModuleDefinitionFlag method Migrate from `cmCommonTargetGenerator::AddModuleDefinitionFlag`. --- Source/cmCommonTargetGenerator.cxx | 28 -------------------------- Source/cmCommonTargetGenerator.h | 5 ----- Source/cmLocalGenerator.cxx | 26 ++++++++++++++++++++++++ Source/cmLocalGenerator.h | 4 ++++ Source/cmMakefileExecutableTargetGenerator.cxx | 5 +++-- Source/cmMakefileLibraryTargetGenerator.cxx | 10 +++++---- Source/cmNinjaNormalTargetGenerator.cxx | 4 ++-- 7 files changed, 41 insertions(+), 41 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..15563fe 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -3137,6 +3137,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..3426de9 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -1164,8 +1164,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( this->addPoolNinjaVariable("JOB_POOL_LINK", gt, vars); - this->AddModuleDefinitionFlag(linkLineComputer.get(), vars["LINK_FLAGS"], - config); + localGen.AppendModuleDefinitionFlag(vars["LINK_FLAGS"], gt, + linkLineComputer.get(), config); this->UseLWYU = this->GetLocalGenerator()->AppendLWYUFlags( vars["LINK_FLAGS"], this->GetGeneratorTarget(), -- cgit v0.12