cmGeneratorTarget: Move GetLinkerLanguage from cmTarget.

This commit is contained in:
Stephen Kelly 2015-08-04 19:19:49 +02:00
parent 6da99de323
commit 7c809fa2a6
16 changed files with 54 additions and 50 deletions

View File

@ -265,8 +265,10 @@ cmComputeLinkInformation
"runtime search path"); "runtime search path");
this->OrderDependentRPath = 0; this->OrderDependentRPath = 0;
cmGeneratorTarget *gtgt = this->GlobalGenerator
->GetGeneratorTarget(this->Target);
// Get the language used for linking this target. // Get the language used for linking this target.
this->LinkLanguage = this->Target->GetLinkerLanguage(config); this->LinkLanguage = gtgt->GetLinkerLanguage(config);
if(this->LinkLanguage.empty()) if(this->LinkLanguage.empty())
{ {
// The Compute method will do nothing, so skip the rest of the // The Compute method will do nothing, so skip the rest of the
@ -322,9 +324,6 @@ cmComputeLinkInformation
(this->Makefile-> (this->Makefile->
GetSafeDefinition("CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH")); GetSafeDefinition("CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH"));
cmGeneratorTarget *gtgt = this->Target->GetMakefile()
->GetGlobalGenerator()
->GetGeneratorTarget(this->Target);
this->RuntimeUseChrpath = gtgt->IsChrpathUsed(config); this->RuntimeUseChrpath = gtgt->IsChrpathUsed(config);
// Get options needed to help find dependent libraries. // Get options needed to help find dependent libraries.

View File

@ -990,6 +990,9 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
assert(target); assert(target);
cmGeneratorTarget* gtgt =
context->Makefile->GetGlobalGenerator()->GetGeneratorTarget(target);
if (propertyName == "LINKER_LANGUAGE") if (propertyName == "LINKER_LANGUAGE")
{ {
if (target->LinkLanguagePropagatesToDependents() && if (target->LinkLanguagePropagatesToDependents() &&
@ -1001,7 +1004,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
"link libraries for a static library"); "link libraries for a static library");
return std::string(); return std::string();
} }
return target->GetLinkerLanguage(context->Config); return gtgt->GetLinkerLanguage(context->Config);
} }
cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace, cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
@ -1128,9 +1131,6 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
} }
} }
cmGeneratorTarget* gtgt =
context->Makefile->GetGlobalGenerator()->GetGeneratorTarget(target);
if (!prop) if (!prop)
{ {
if (target->IsImported() if (target->IsImported()
@ -1600,7 +1600,7 @@ struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
cmGeneratorExpressionContext *context, cmGeneratorExpressionContext *context,
const GeneratorExpressionContent *content) const GeneratorExpressionContent *content)
{ {
std::string language = target->Target->GetLinkerLanguage(context->Config); std::string language = target->GetLinkerLanguage(context->Config);
std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB"; std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";

View File

@ -709,8 +709,7 @@ bool cmGeneratorTarget::HasSOName(const std::string& config) const
return ((this->GetType() == cmTarget::SHARED_LIBRARY || return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
this->GetType() == cmTarget::MODULE_LIBRARY) && this->GetType() == cmTarget::MODULE_LIBRARY) &&
!this->GetPropertyAsBool("NO_SONAME") && !this->GetPropertyAsBool("NO_SONAME") &&
this->Makefile->GetSONameFlag( this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
this->Target->GetLinkerLanguage(config)));
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -752,7 +751,7 @@ cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
} }
// Check for rpath support on this platform. // Check for rpath support on this platform.
std::string ll = this->Target->GetLinkerLanguage(config); std::string ll = this->GetLinkerLanguage(config);
if(!ll.empty()) if(!ll.empty())
{ {
std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_"; std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
@ -823,7 +822,7 @@ bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
#if defined(CMAKE_USE_ELF_PARSER) #if defined(CMAKE_USE_ELF_PARSER)
// Enable if the rpath flag uses a separator and the target uses ELF // Enable if the rpath flag uses a separator and the target uses ELF
// binaries. // binaries.
std::string ll = this->Target->GetLinkerLanguage(config); std::string ll = this->GetLinkerLanguage(config);
if(!ll.empty()) if(!ll.empty())
{ {
std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_"; std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
@ -1986,7 +1985,7 @@ void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
const char* suffixVar = this->Target->GetSuffixVariableInternal(implib); const char* suffixVar = this->Target->GetSuffixVariableInternal(implib);
// Check for language-specific default prefix and suffix. // Check for language-specific default prefix and suffix.
std::string ll = this->Target->GetLinkerLanguage(config); std::string ll = this->GetLinkerLanguage(config);
if(!ll.empty()) if(!ll.empty())
{ {
if(!targetSuffix && suffixVar && *suffixVar) if(!targetSuffix && suffixVar && *suffixVar)
@ -2055,6 +2054,13 @@ void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
} }
//----------------------------------------------------------------------------
std::string
cmGeneratorTarget::GetLinkerLanguage(const std::string& config) const
{
return this->Target->GetLinkClosure(config)->LinkerLanguage;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmGeneratorTarget::GetPDBName(const std::string& config) const std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
{ {

View File

@ -258,6 +258,9 @@ public:
/** Return true if builtin chrpath will work for this target */ /** Return true if builtin chrpath will work for this target */
bool IsChrpathUsed(const std::string& config) const; bool IsChrpathUsed(const std::string& config) const;
///! Return the preferred linker language for this target
std::string GetLinkerLanguage(const std::string& config = "") const;
struct SourceFileFlags struct SourceFileFlags
GetTargetSourceFileFlags(const cmSourceFile* sf) const; GetTargetSourceFileFlags(const cmSourceFile* sf) const;

View File

@ -128,7 +128,8 @@ void cmGhsMultiTargetGenerator::Generate()
{ {
config = "RELEASE"; config = "RELEASE";
} }
const std::string language(this->Target->GetLinkerLanguage(config)); const std::string language(
this->GeneratorTarget->GetLinkerLanguage(config));
config = cmSystemTools::UpperCase(config); config = cmSystemTools::UpperCase(config);
this->DynamicDownload = this->DetermineIfDynamicDownload(config, language); this->DynamicDownload = this->DetermineIfDynamicDownload(config, language);
if (this->DynamicDownload) if (this->DynamicDownload)

View File

@ -1376,7 +1376,8 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
return; return;
} }
std::string llang = cmtarget.GetLinkerLanguage("NOCONFIG"); cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&cmtarget);
std::string llang = gtgt->GetLinkerLanguage("NOCONFIG");
if(llang.empty()) { return; } if(llang.empty()) { return; }
// If the language is compiled as a source trust Xcode to link with it. // If the language is compiled as a source trust Xcode to link with it.
@ -1824,7 +1825,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
AddCompileOptions(flags, &target, lang, configName); AddCompileOptions(flags, &target, lang, configName);
} }
std::string llang = target.GetLinkerLanguage(configName); cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
std::string llang = gtgt->GetLinkerLanguage(configName);
if(binary && llang.empty()) if(binary && llang.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
@ -1850,7 +1852,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
// Add the export symbol definition for shared library objects. // Add the export symbol definition for shared library objects.
this->AppendDefines(ppDefs, exportMacro); this->AppendDefines(ppDefs, exportMacro);
} }
cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
std::vector<std::string> targetDefines; std::vector<std::string> targetDefines;
target.GetCompileDefinitions(targetDefines, configName, "C"); target.GetCompileDefinitions(targetDefines, configName, "C");
this->AppendDefines(ppDefs, targetDefines); this->AppendDefines(ppDefs, targetDefines);

View File

@ -1353,7 +1353,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
linkFlags += this->Makefile->GetSafeDefinition(build); linkFlags += this->Makefile->GetSafeDefinition(build);
linkFlags += " "; linkFlags += " ";
} }
std::string linkLanguage = target->Target->GetLinkerLanguage(buildType); std::string linkLanguage = target->GetLinkerLanguage(buildType);
if(linkLanguage.empty()) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error

View File

@ -1270,10 +1270,10 @@ void cmLocalVisualStudio6Generator
std::vector<std::string> configs; std::vector<std::string> configs;
target.GetMakefile()->GetConfigurations(configs); target.GetMakefile()->GetConfigurations(configs);
std::vector<std::string>::const_iterator it = configs.begin(); std::vector<std::string>::const_iterator it = configs.begin();
const std::string& linkLanguage = target.GetLinkerLanguage(*it); const std::string& linkLanguage = gt->GetLinkerLanguage(*it);
for ( ; it != configs.end(); ++it) for ( ; it != configs.end(); ++it)
{ {
const std::string& configLinkLanguage = target.GetLinkerLanguage(*it); const std::string& configLinkLanguage = gt->GetLinkerLanguage(*it);
if (configLinkLanguage != linkLanguage) if (configLinkLanguage != linkLanguage)
{ {
cmSystemTools::Error cmSystemTools::Error
@ -1703,10 +1703,10 @@ void cmLocalVisualStudio6Generator
std::vector<std::string> configs; std::vector<std::string> configs;
target.GetMakefile()->GetConfigurations(configs); target.GetMakefile()->GetConfigurations(configs);
std::vector<std::string>::const_iterator it = configs.begin(); std::vector<std::string>::const_iterator it = configs.begin();
const std::string& linkLanguage = target.GetLinkerLanguage(*it); const std::string& linkLanguage = gt->GetLinkerLanguage(*it);
for ( ; it != configs.end(); ++it) for ( ; it != configs.end(); ++it)
{ {
const std::string& configLinkLanguage = target.GetLinkerLanguage(*it); const std::string& configLinkLanguage = gt->GetLinkerLanguage(*it);
if (configLinkLanguage != linkLanguage) if (configLinkLanguage != linkLanguage)
{ {
cmSystemTools::Error cmSystemTools::Error

View File

@ -664,6 +664,10 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
const char* configType = "10"; const char* configType = "10";
const char* projectType = 0; const char* projectType = 0;
bool targetBuilds = true; bool targetBuilds = true;
cmGeneratorTarget* gt =
this->GlobalGenerator->GetGeneratorTarget(&target);
switch(target.GetType()) switch(target.GetType())
{ {
case cmTarget::OBJECT_LIBRARY: case cmTarget::OBJECT_LIBRARY:
@ -696,7 +700,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
{ {
const std::string& linkLanguage = (this->FortranProject? const std::string& linkLanguage = (this->FortranProject?
std::string("Fortran"): std::string("Fortran"):
target.GetLinkerLanguage(configName)); gt->GetLinkerLanguage(configName));
if(linkLanguage.empty()) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
@ -758,8 +762,6 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
targetOptions.Parse(flags.c_str()); targetOptions.Parse(flags.c_str());
targetOptions.Parse(defineFlags.c_str()); targetOptions.Parse(defineFlags.c_str());
targetOptions.ParseFinish(); targetOptions.ParseFinish();
cmGeneratorTarget* gt =
this->GlobalGenerator->GetGeneratorTarget(&target);
std::vector<std::string> targetDefines; std::vector<std::string> targetDefines;
target.GetCompileDefinitions(targetDefines, configName, "CXX"); target.GetCompileDefinitions(targetDefines, configName, "CXX");
targetOptions.AddDefines(targetDefines); targetOptions.AddDefines(targetDefines);
@ -1635,7 +1637,7 @@ cmLocalVisualStudio7GeneratorFCInfo
lg->GlobalGenerator->GetLanguageFromExtension lg->GlobalGenerator->GetLanguageFromExtension
(sf.GetExtension().c_str()); (sf.GetExtension().c_str());
const std::string& sourceLang = lg->GetSourceFileLanguage(sf); const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
const std::string& linkLanguage = target.GetLinkerLanguage(i->c_str()); const std::string& linkLanguage = gt->GetLinkerLanguage(i->c_str());
bool needForceLang = false; bool needForceLang = false;
// source file does not match its extension language // source file does not match its extension language
if(lang != sourceLang) if(lang != sourceLang)

View File

@ -161,7 +161,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Get the language to use for linking this executable. // Get the language to use for linking this executable.
std::string linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
// Make sure we have a link language. // Make sure we have a link language.
if(linkLanguage.empty()) if(linkLanguage.empty())

View File

@ -133,7 +133,7 @@ void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules() void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
{ {
std::string linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
std::string linkRuleVar = "CMAKE_"; std::string linkRuleVar = "CMAKE_";
linkRuleVar += linkLanguage; linkRuleVar += linkLanguage;
linkRuleVar += "_CREATE_STATIC_LIBRARY"; linkRuleVar += "_CREATE_STATIC_LIBRARY";
@ -159,7 +159,7 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
return; return;
} }
std::string linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
std::string linkRuleVar = "CMAKE_"; std::string linkRuleVar = "CMAKE_";
linkRuleVar += linkLanguage; linkRuleVar += linkLanguage;
linkRuleVar += "_CREATE_SHARED_LIBRARY"; linkRuleVar += "_CREATE_SHARED_LIBRARY";
@ -183,7 +183,7 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink) void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
{ {
std::string linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
std::string linkRuleVar = "CMAKE_"; std::string linkRuleVar = "CMAKE_";
linkRuleVar += linkLanguage; linkRuleVar += linkLanguage;
linkRuleVar += "_CREATE_SHARED_MODULE"; linkRuleVar += "_CREATE_SHARED_MODULE";
@ -206,7 +206,7 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink) void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
{ {
std::string linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
std::string linkRuleVar = "CMAKE_"; std::string linkRuleVar = "CMAKE_";
linkRuleVar += linkLanguage; linkRuleVar += linkLanguage;
linkRuleVar += "_CREATE_MACOSX_FRAMEWORK"; linkRuleVar += "_CREATE_MACOSX_FRAMEWORK";
@ -238,7 +238,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
// Get the language to use for linking this library. // Get the language to use for linking this library.
std::string linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
// Make sure we have a link language. // Make sure we have a link language.
if(linkLanguage.empty()) if(linkLanguage.empty())

View File

@ -1509,7 +1509,7 @@ std::string cmMakefileTargetGenerator::GetLinkRule(
if(this->Target->HasImplibGNUtoMS()) if(this->Target->HasImplibGNUtoMS())
{ {
std::string ruleVar = "CMAKE_"; std::string ruleVar = "CMAKE_";
ruleVar += this->Target->GetLinkerLanguage(this->ConfigName); ruleVar += this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
ruleVar += "_GNUtoMS_RULE"; ruleVar += "_GNUtoMS_RULE";
if(const char* rule = this->Makefile->GetDefinition(ruleVar)) if(const char* rule = this->Makefile->GetDefinition(ruleVar))
{ {
@ -1663,7 +1663,8 @@ cmMakefileTargetGenerator
{ {
// Lookup the response file reference flag. // Lookup the response file reference flag.
std::string responseFlagVar = "CMAKE_"; std::string responseFlagVar = "CMAKE_";
responseFlagVar += this->Target->GetLinkerLanguage(this->ConfigName); responseFlagVar += this->GeneratorTarget
->GetLinkerLanguage(this->ConfigName);
responseFlagVar += "_RESPONSE_FILE_LINK_FLAG"; responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
const char* responseFlag = const char* responseFlag =
this->Makefile->GetDefinition(responseFlagVar); this->Makefile->GetDefinition(responseFlagVar);
@ -1707,7 +1708,8 @@ cmMakefileTargetGenerator
// Lookup the response file reference flag. // Lookup the response file reference flag.
std::string responseFlagVar = "CMAKE_"; std::string responseFlagVar = "CMAKE_";
responseFlagVar += this->Target->GetLinkerLanguage(this->ConfigName); responseFlagVar += this->GeneratorTarget
->GetLinkerLanguage(this->ConfigName);
responseFlagVar += "_RESPONSE_FILE_LINK_FLAG"; responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
const char* responseFlag = const char* responseFlag =
this->Makefile->GetDefinition(responseFlagVar); this->Makefile->GetDefinition(responseFlagVar);

View File

@ -40,8 +40,7 @@ cmNinjaNormalTargetGenerator(cmGeneratorTarget* target)
, TargetNamePDB() , TargetNamePDB()
, TargetLinkLanguage("") , TargetLinkLanguage("")
{ {
this->TargetLinkLanguage = target->Target this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName());
->GetLinkerLanguage(this->GetConfigName());
if (target->GetType() == cmTarget::EXECUTABLE) if (target->GetType() == cmTarget::EXECUTABLE)
this->GetGeneratorTarget()->GetExecutableNames(this->TargetNameOut, this->GetGeneratorTarget()->GetExecutableNames(this->TargetNameOut,
this->TargetNameReal, this->TargetNameReal,

View File

@ -3217,12 +3217,6 @@ private:
std::set<cmTarget const*> Visited; std::set<cmTarget const*> Visited;
}; };
//----------------------------------------------------------------------------
std::string cmTarget::GetLinkerLanguage(const std::string& config) const
{
return this->GetLinkClosure(config)->LinkerLanguage;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmTarget::LinkClosure const* cmTarget::LinkClosure const*
cmTarget::GetLinkClosure(const std::string& config) const cmTarget::GetLinkClosure(const std::string& config) const

View File

@ -365,9 +365,6 @@ public:
void void
GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const; GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const;
///! Return the preferred linker language for this target
std::string GetLinkerLanguage(const std::string& config = "") const;
/** Whether this library has \@rpath and platform supports it. */ /** Whether this library has \@rpath and platform supports it. */
bool HasMacOSXRpathInstallNameDir(const std::string& config) const; bool HasMacOSXRpathInstallNameDir(const std::string& config) const;

View File

@ -1627,7 +1627,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
this->GlobalGenerator->GetLanguageFromExtension this->GlobalGenerator->GetLanguageFromExtension
(sf.GetExtension().c_str()); (sf.GetExtension().c_str());
std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf); std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
const std::string& linkLanguage = this->Target->GetLinkerLanguage(); const std::string& linkLanguage = this->GeneratorTarget->GetLinkerLanguage();
bool needForceLang = false; bool needForceLang = false;
// source file does not match its extension language // source file does not match its extension language
if(lang != sourceLang) if(lang != sourceLang)
@ -1888,7 +1888,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
std::string flags; std::string flags;
const std::string& linkLanguage = const std::string& linkLanguage =
this->Target->GetLinkerLanguage(configName.c_str()); this->GeneratorTarget->GetLinkerLanguage(configName.c_str());
if(linkLanguage.empty()) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
@ -2371,7 +2371,7 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
Options& linkOptions = *pOptions; Options& linkOptions = *pOptions;
const std::string& linkLanguage = const std::string& linkLanguage =
this->Target->GetLinkerLanguage(config.c_str()); this->GeneratorTarget->GetLinkerLanguage(config.c_str());
if(linkLanguage.empty()) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error