cmGeneratorTarget: Move FindTargetToLink from cmTarget.

This commit is contained in:
Stephen Kelly 2015-10-10 12:23:19 +02:00
parent 61c02decce
commit bf2d061ad3
6 changed files with 47 additions and 41 deletions

View File

@ -634,8 +634,9 @@ cmComputeLinkDepends::AddLinkEntries(
}
//----------------------------------------------------------------------------
cmTarget const* cmComputeLinkDepends::FindTargetToLink(int depender_index,
const std::string& name)
cmGeneratorTarget const*
cmComputeLinkDepends::FindTargetToLink(int depender_index,
const std::string& name)
{
// Look for a target in the scope of the depender.
cmGeneratorTarget const* from = this->Target;
@ -647,7 +648,7 @@ cmTarget const* cmComputeLinkDepends::FindTargetToLink(int depender_index,
from = depender;
}
}
return from->Target->FindTargetToLink(name);
return from->FindTargetToLink(name);
}
//----------------------------------------------------------------------------

View File

@ -73,8 +73,8 @@ private:
void AddDirectLinkEntries();
template <typename T>
void AddLinkEntries(int depender_index, std::vector<T> const& libs);
cmTarget const* FindTargetToLink(int depender_index,
const std::string& name);
cmGeneratorTarget const* FindTargetToLink(int depender_index,
const std::string& name);
// One entry for each unique item.
std::vector<LinkEntry> EntryList;

View File

@ -4427,7 +4427,7 @@ void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
{
continue;
}
items.push_back(cmLinkItem(name, this->Target->FindTargetToLink(name)));
items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
}
}
@ -5398,7 +5398,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
// The entry is meant for this configuration.
impl.Libraries.push_back(
cmLinkImplItem(name, this->Target->FindTargetToLink(name),
cmLinkImplItem(name, this->FindTargetToLink(name),
*btIt, evaluated != *le));
}
@ -5430,11 +5430,47 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
}
// Support OLD behavior for CMP0003.
impl.WrongConfigLibraries.push_back(
cmLinkItem(name, this->Target->FindTargetToLink(name)));
cmLinkItem(name, this->FindTargetToLink(name)));
}
}
}
//----------------------------------------------------------------------------
cmGeneratorTarget*
cmGeneratorTarget::FindTargetToLink(std::string const& name) const
{
cmTarget const* tgt = this->Makefile->FindTargetToUse(name);
// Skip targets that will not really be linked. This is probably a
// name conflict between an external library and an executable
// within the project.
if(tgt && tgt->GetType() == cmTarget::EXECUTABLE &&
!tgt->IsExecutableWithExports())
{
tgt = 0;
}
if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY)
{
std::ostringstream e;
e << "Target \"" << this->GetName() << "\" links to "
"OBJECT library \"" << tgt->GetName() << "\" but this is not "
"allowed. "
"One may link only to STATIC or SHARED libraries, or to executables "
"with the ENABLE_EXPORTS property set.";
cmake* cm = this->Makefile->GetCMakeInstance();
cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
this->Target->GetBacktrace());
tgt = 0;
}
if (!tgt)
{
return 0;
}
return this->GlobalGenerator->GetGeneratorTarget(tgt);
}
//----------------------------------------------------------------------------
std::string
cmGeneratorTarget::GetPDBDirectory(const std::string& config) const

View File

@ -216,6 +216,8 @@ public:
cmOptionalLinkImplementation& impl,
const cmGeneratorTarget* head) const;
cmGeneratorTarget* FindTargetToLink(std::string const& name) 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

View File

@ -2669,37 +2669,6 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config,
}
}
//----------------------------------------------------------------------------
cmTarget const* cmTarget::FindTargetToLink(std::string const& name) const
{
cmTarget const* tgt = this->Makefile->FindTargetToUse(name);
// Skip targets that will not really be linked. This is probably a
// name conflict between an external library and an executable
// within the project.
if(tgt && tgt->GetType() == cmTarget::EXECUTABLE &&
!tgt->IsExecutableWithExports())
{
tgt = 0;
}
if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY)
{
std::ostringstream e;
e << "Target \"" << this->GetName() << "\" links to "
"OBJECT library \"" << tgt->GetName() << "\" but this is not "
"allowed. "
"One may link only to STATIC or SHARED libraries, or to executables "
"with the ENABLE_EXPORTS property set.";
cmake* cm = this->Makefile->GetCMakeInstance();
cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
tgt = 0;
}
// Return the target found, if any.
return tgt;
}
//----------------------------------------------------------------------------
std::string cmTarget::CheckCMP0004(std::string const& item) const
{

View File

@ -223,8 +223,6 @@ public:
void GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const;
cmTarget const* FindTargetToLink(std::string const& name) const;
/** Strip off leading and trailing whitespace from an item named in
the link dependencies of this target. */
std::string CheckCMP0004(std::string const& item) const;