cmTarget: Add method to lookup other targets in a target's scope
Move the main implementation of cmComputeLinkDepends::FindTargetToLink into cmTarget.
This commit is contained in:
parent
47ab3ca641
commit
069d60fe03
|
@ -623,40 +623,15 @@ cmTarget const* cmComputeLinkDepends::FindTargetToLink(int depender_index,
|
||||||
const std::string& name)
|
const std::string& name)
|
||||||
{
|
{
|
||||||
// Look for a target in the scope of the depender.
|
// Look for a target in the scope of the depender.
|
||||||
cmMakefile* mf = this->Makefile;
|
cmTarget const* from = this->Target;
|
||||||
if(depender_index >= 0)
|
if(depender_index >= 0)
|
||||||
{
|
{
|
||||||
if(cmTarget const* depender = this->EntryList[depender_index].Target)
|
if(cmTarget const* depender = this->EntryList[depender_index].Target)
|
||||||
{
|
{
|
||||||
mf = depender->GetMakefile();
|
from = depender;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmTarget const* tgt = mf->FindTargetToUse(name);
|
return from->FindTargetToLink(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)
|
|
||||||
{
|
|
||||||
cmOStringStream e;
|
|
||||||
e << "Target \"" << this->Target->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.";
|
|
||||||
this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
|
|
||||||
this->Target->GetBacktrace());
|
|
||||||
tgt = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the target found, if any.
|
|
||||||
return tgt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -6680,6 +6680,37 @@ cmTarget::ComputeLinkImplementationLanguages(const std::string& 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)
|
||||||
|
{
|
||||||
|
cmOStringStream 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
|
std::string cmTarget::CheckCMP0004(std::string const& item) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -308,6 +308,8 @@ public:
|
||||||
};
|
};
|
||||||
LinkClosure const* GetLinkClosure(const std::string& config) const;
|
LinkClosure const* GetLinkClosure(const std::string& config) const;
|
||||||
|
|
||||||
|
cmTarget const* FindTargetToLink(std::string const& name) const;
|
||||||
|
|
||||||
/** Strip off leading and trailing whitespace from an item named in
|
/** Strip off leading and trailing whitespace from an item named in
|
||||||
the link dependencies of this target. */
|
the link dependencies of this target. */
|
||||||
std::string CheckCMP0004(std::string const& item) const;
|
std::string CheckCMP0004(std::string const& item) const;
|
||||||
|
|
Loading…
Reference in New Issue