mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-14 13:30:29 -05:00
cmLocalGenerator: Add a hook for compiler flags used at link time
When using a compiler to drive linking we add compiler flags from `CMAKE_<LANG>_FLAGS` in case they affect the way the compiler invokes the linker, but we don't add flags from other places that are meant only for compiling sources. Rather than calling the `AddLanguageFlags` method (which is used to add flags for compiling sources) directly, add an intermediate method that is used when adding the flags for linking. This will give us a way to add language-specific compiler flags needed when driving the linker in the same place on the command line as other compiler flags go.
This commit is contained in:
@@ -1002,7 +1002,7 @@ void cmLocalGenerator::GetTargetFlags(
|
|||||||
target->GetName().c_str());
|
target->GetName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->AddLanguageFlags(flags, target, linkLanguage, buildType);
|
this->AddLanguageFlagsForLinking(flags, target, linkLanguage, buildType);
|
||||||
if (pcli) {
|
if (pcli) {
|
||||||
this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
|
this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
|
||||||
frameworkPath, linkPath);
|
frameworkPath, linkPath);
|
||||||
@@ -1317,6 +1317,13 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmLocalGenerator::AddLanguageFlagsForLinking(
|
||||||
|
std::string& flags, cmGeneratorTarget const* target, const std::string& lang,
|
||||||
|
const std::string& config)
|
||||||
|
{
|
||||||
|
this->AddLanguageFlags(flags, target, lang, config);
|
||||||
|
}
|
||||||
|
|
||||||
cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
|
cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
|
||||||
const std::string& name) const
|
const std::string& name) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ public:
|
|||||||
|
|
||||||
void AddLanguageFlags(std::string& flags, cmGeneratorTarget const* target,
|
void AddLanguageFlags(std::string& flags, cmGeneratorTarget const* target,
|
||||||
const std::string& lang, const std::string& config);
|
const std::string& lang, const std::string& config);
|
||||||
|
void AddLanguageFlagsForLinking(std::string& flags,
|
||||||
|
cmGeneratorTarget const* target,
|
||||||
|
const std::string& lang,
|
||||||
|
const std::string& config);
|
||||||
void AddCMP0018Flags(std::string& flags, cmGeneratorTarget const* target,
|
void AddCMP0018Flags(std::string& flags, cmGeneratorTarget const* target,
|
||||||
std::string const& lang, const std::string& config);
|
std::string const& lang, const std::string& config);
|
||||||
void AddVisibilityPresetFlags(std::string& flags,
|
void AddVisibilityPresetFlags(std::string& flags,
|
||||||
|
|||||||
@@ -150,8 +150,8 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
|
|||||||
linkLanguage, *this->GeneratorTarget));
|
linkLanguage, *this->GeneratorTarget));
|
||||||
|
|
||||||
// Add language feature flags.
|
// Add language feature flags.
|
||||||
this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
|
this->LocalGenerator->AddLanguageFlagsForLinking(
|
||||||
linkLanguage, this->ConfigName);
|
flags, this->GeneratorTarget, linkLanguage, this->ConfigName);
|
||||||
|
|
||||||
this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
|
this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
|
||||||
linkLanguage, this->ConfigName);
|
linkLanguage, this->ConfigName);
|
||||||
@@ -434,8 +434,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add language feature flags.
|
// Add language feature flags.
|
||||||
this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
|
this->LocalGenerator->AddLanguageFlagsForLinking(
|
||||||
linkLanguage, this->ConfigName);
|
flags, this->GeneratorTarget, linkLanguage, this->ConfigName);
|
||||||
|
|
||||||
this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
|
this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
|
||||||
linkLanguage, this->ConfigName);
|
linkLanguage, this->ConfigName);
|
||||||
|
|||||||
@@ -397,8 +397,8 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
|
|||||||
|
|
||||||
// Add language-specific flags.
|
// Add language-specific flags.
|
||||||
std::string langFlags;
|
std::string langFlags;
|
||||||
this->LocalGenerator->AddLanguageFlags(langFlags, this->GeneratorTarget,
|
this->LocalGenerator->AddLanguageFlagsForLinking(
|
||||||
linkLanguage, this->ConfigName);
|
langFlags, this->GeneratorTarget, linkLanguage, this->ConfigName);
|
||||||
|
|
||||||
vars.LanguageCompileFlags = langFlags.c_str();
|
vars.LanguageCompileFlags = langFlags.c_str();
|
||||||
|
|
||||||
@@ -858,8 +858,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
|
|||||||
|
|
||||||
// Add language-specific flags.
|
// Add language-specific flags.
|
||||||
std::string langFlags;
|
std::string langFlags;
|
||||||
this->LocalGenerator->AddLanguageFlags(langFlags, this->GeneratorTarget,
|
this->LocalGenerator->AddLanguageFlagsForLinking(
|
||||||
linkLanguage, this->ConfigName);
|
langFlags, this->GeneratorTarget, linkLanguage, this->ConfigName);
|
||||||
|
|
||||||
this->LocalGenerator->AddArchitectureFlags(
|
this->LocalGenerator->AddArchitectureFlags(
|
||||||
langFlags, this->GeneratorTarget, linkLanguage, this->ConfigName);
|
langFlags, this->GeneratorTarget, linkLanguage, this->ConfigName);
|
||||||
|
|||||||
@@ -655,7 +655,8 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
|
|||||||
localGen.AddArchitectureFlags(t, &genTarget, cudaLinkLanguage, cfgName);
|
localGen.AddArchitectureFlags(t, &genTarget, cudaLinkLanguage, cfgName);
|
||||||
vars["ARCH_FLAGS"] = t;
|
vars["ARCH_FLAGS"] = t;
|
||||||
t = "";
|
t = "";
|
||||||
localGen.AddLanguageFlags(t, &genTarget, cudaLinkLanguage, cfgName);
|
localGen.AddLanguageFlagsForLinking(t, &genTarget, cudaLinkLanguage,
|
||||||
|
cfgName);
|
||||||
vars["LANGUAGE_COMPILE_FLAGS"] = t;
|
vars["LANGUAGE_COMPILE_FLAGS"] = t;
|
||||||
}
|
}
|
||||||
if (this->GetGeneratorTarget()->HasSOName(cfgName)) {
|
if (this->GetGeneratorTarget()->HasSOName(cfgName)) {
|
||||||
@@ -874,7 +875,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
|
|||||||
vars["ARCH_FLAGS"] = t;
|
vars["ARCH_FLAGS"] = t;
|
||||||
t = "";
|
t = "";
|
||||||
t += lwyuFlags;
|
t += lwyuFlags;
|
||||||
localGen.AddLanguageFlags(t, &genTarget, TargetLinkLanguage, cfgName);
|
localGen.AddLanguageFlagsForLinking(t, &genTarget, TargetLinkLanguage,
|
||||||
|
cfgName);
|
||||||
vars["LANGUAGE_COMPILE_FLAGS"] = t;
|
vars["LANGUAGE_COMPILE_FLAGS"] = t;
|
||||||
}
|
}
|
||||||
if (this->GetGeneratorTarget()->HasSOName(cfgName)) {
|
if (this->GetGeneratorTarget()->HasSOName(cfgName)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user