cmGeneratorTarget: Move GetLanguages from cmTarget.

This commit is contained in:
Stephen Kelly 2015-08-05 17:37:50 +02:00
parent 0431f2c4d7
commit 69329fff70
9 changed files with 71 additions and 59 deletions

View File

@ -4415,6 +4415,57 @@ cmGeneratorTarget::GetLinkImplementation(const std::string& config) const
return &impl;
}
//----------------------------------------------------------------------------
void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
const std::string& config) const
{
std::vector<cmSourceFile*> sourceFiles;
this->Target->GetSourceFiles(sourceFiles, config);
for(std::vector<cmSourceFile*>::const_iterator
i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
{
const std::string& lang = (*i)->GetLanguage();
if(!lang.empty())
{
languages.insert(lang);
}
}
std::vector<cmGeneratorTarget*> objectLibraries;
std::vector<cmSourceFile const*> externalObjects;
if (!this->Makefile->IsConfigured())
{
std::vector<cmTarget*> objectTargets;
this->Target->GetObjectLibrariesCMP0026(objectTargets);
objectLibraries.reserve(objectTargets.size());
for (std::vector<cmTarget*>::const_iterator it = objectTargets.begin();
it != objectTargets.end(); ++it)
{
objectLibraries.push_back(this->GlobalGenerator
->GetGeneratorTarget(*it));
}
}
else
{
this->GetExternalObjects(externalObjects, config);
for(std::vector<cmSourceFile const*>::const_iterator
i = externalObjects.begin(); i != externalObjects.end(); ++i)
{
std::string objLib = (*i)->GetObjectLibrary();
if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
{
objectLibraries.push_back(this->GlobalGenerator
->GetGeneratorTarget(tgt));
}
}
}
for(std::vector<cmGeneratorTarget*>::const_iterator
i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
{
(*i)->GetLanguages(languages, config);
}
}
//----------------------------------------------------------------------------
void cmGeneratorTarget::ComputeLinkImplementationLanguages(
const std::string& config,
@ -4423,7 +4474,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLanguages(
// This target needs runtime libraries for its source languages.
std::set<std::string> languages;
// Get languages used in our source files.
this->Target->GetLanguages(languages, config);
this->GetLanguages(languages, config);
// Copy the set of langauges to the link implementation.
impl.Languages.insert(impl.Languages.begin(),
languages.begin(), languages.end());

View File

@ -205,6 +205,14 @@ public:
cmOptionalLinkImplementation& impl
) const;
// Compute the set of languages compiled by the target. This is
// computed every time it is called because the languages can change
// when source file properties are changed and we do not have enough
// information to forward these property changes to the targets
// until we have per-target object file properties.
void GetLanguages(std::set<std::string>& languages,
std::string const& config) const;
bool HaveBuildTreeRPATH(const std::string& config) const;
/** Full path with trailing slash to the top-level directory

View File

@ -1134,7 +1134,8 @@ bool cmGlobalUnixMakefileGenerator3
::NeedRequiresStep(cmTarget const& target)
{
std::set<std::string> languages;
target.GetLanguages(languages,
cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&target);
gtgt->GetLanguages(languages,
target.GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
for(std::set<std::string>::const_iterator l = languages.begin();
l != languages.end(); ++l)

View File

@ -836,6 +836,8 @@ void RegisterVisualStudioMacros(const std::string& macrosFile,
bool
cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmTarget const& target)
{
cmGeneratorTarget* gt = this->GetGeneratorTarget(&target);
// check to see if this is a fortran build
std::set<std::string> languages;
{
@ -846,7 +848,7 @@ cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmTarget const& target)
return false;
}
}
target.GetLanguages(languages, "");
gt->GetLanguages(languages, "");
if(languages.size() == 1)
{
if(*languages.begin() == "Fortran")

View File

@ -1805,7 +1805,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
// Compute the compilation flags for each language.
std::set<std::string> languages;
target.GetLanguages(languages, configName);
cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
gtgt->GetLanguages(languages, configName);
std::map<std::string, std::string> cflags;
for (std::set<std::string>::iterator li = languages.begin();
li != languages.end(); ++li)
@ -1827,7 +1828,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
AddCompileOptions(flags, &target, lang, configName);
}
cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
std::string llang = gtgt->GetLinkerLanguage(configName);
if(binary && llang.empty())
{

View File

@ -1257,7 +1257,9 @@ cmLocalUnixMakefileGenerator3
{
// Get the set of source languages in the target.
std::set<std::string> languages;
target.GetLanguages(languages,
cmGeneratorTarget *gtgt =
this->GlobalGenerator->GetGeneratorTarget(&target);
gtgt->GetLanguages(languages,
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
fout << "\n"
<< "# Per-language clean rules from dependency scanning.\n"

View File

@ -276,7 +276,7 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
{
// write language flags for target
std::set<std::string> languages;
this->Target->GetLanguages(languages,
this->GeneratorTarget->GetLanguages(languages,
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
// put the compiler in the rules.make file so that if it changes
// things rebuild

View File

@ -3130,50 +3130,6 @@ cmTarget::GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const
}
}
//----------------------------------------------------------------------------
void cmTarget::GetLanguages(std::set<std::string>& languages,
const std::string& config) const
{
std::vector<cmSourceFile*> sourceFiles;
this->GetSourceFiles(sourceFiles, config);
for(std::vector<cmSourceFile*>::const_iterator
i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
{
const std::string& lang = (*i)->GetLanguage();
if(!lang.empty())
{
languages.insert(lang);
}
}
std::vector<cmTarget*> objectLibraries;
std::vector<cmSourceFile const*> externalObjects;
if (!this->Makefile->IsConfigured())
{
this->GetObjectLibrariesCMP0026(objectLibraries);
}
else
{
cmGeneratorTarget* gt = this->Makefile->GetGlobalGenerator()
->GetGeneratorTarget(this);
gt->GetExternalObjects(externalObjects, config);
for(std::vector<cmSourceFile const*>::const_iterator
i = externalObjects.begin(); i != externalObjects.end(); ++i)
{
std::string objLib = (*i)->GetObjectLibrary();
if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
{
objectLibraries.push_back(tgt);
}
}
}
for(std::vector<cmTarget*>::const_iterator
i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
{
(*i)->GetLanguages(languages, config);
}
}
//----------------------------------------------------------------------------
cmTarget::ImportInfo const*
cmTarget::GetImportInfo(const std::string& config) const

View File

@ -305,14 +305,6 @@ public:
If no macro should be defined null is returned. */
const char* GetExportMacro() const;
// Compute the set of languages compiled by the target. This is
// computed every time it is called because the languages can change
// when source file properties are changed and we do not have enough
// information to forward these property changes to the targets
// until we have per-target object file properties.
void GetLanguages(std::set<std::string>& languages,
std::string const& config) const;
/** Return whether this target is an executable with symbol exports
enabled. */
bool IsExecutableWithExports() const;