cmComputeLinkDepends: Port some API to cmGeneratorTarget.

This commit is contained in:
Stephen Kelly 2015-10-08 00:41:15 +02:00
parent 3e428fdcb4
commit 064c248811
4 changed files with 31 additions and 39 deletions

View File

@ -268,7 +268,7 @@ cmComputeLinkDepends::Compute()
{ {
int i = *li; int i = *li;
LinkEntry const& e = this->EntryList[i]; LinkEntry const& e = this->EntryList[i];
cmTarget const* t = e.Target; cmGeneratorTarget const* t = e.Target;
// Entries that we know the linker will re-use do not need to be repeated. // Entries that we know the linker will re-use do not need to be repeated.
bool uniquify = t && t->GetType() == cmTarget::SHARED_LIBRARY; bool uniquify = t && t->GetType() == cmTarget::SHARED_LIBRARY;
if(!uniquify || emmitted.insert(i).second) if(!uniquify || emmitted.insert(i).second)
@ -320,7 +320,8 @@ int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item)
int index = lei->second; int index = lei->second;
LinkEntry& entry = this->EntryList[index]; LinkEntry& entry = this->EntryList[index];
entry.Item = item; entry.Item = item;
entry.Target = item.Target; entry.Target =
item.Target ? this->GlobalGenerator->GetGeneratorTarget(item.Target) : 0;
entry.IsFlag = (!entry.Target && item[0] == '-' && item[1] != 'l' && entry.IsFlag = (!entry.Target && item[0] == '-' && item[1] != 'l' &&
item.substr(0, 10) != "-framework"); item.substr(0, 10) != "-framework");
@ -362,11 +363,9 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry const& qe)
// Follow the item's dependencies. // Follow the item's dependencies.
if(entry.Target) if(entry.Target)
{ {
cmGeneratorTarget* gtgt =
this->GlobalGenerator->GetGeneratorTarget(entry.Target);
// Follow the target dependencies. // Follow the target dependencies.
if(cmLinkInterface const* iface = if(cmLinkInterface const* iface =
gtgt->GetLinkInterface(this->Config, this->Target->Target)) entry.Target->GetLinkInterface(this->Config, this->Target->Target))
{ {
const bool isIface = const bool isIface =
entry.Target->GetType() == cmTarget::INTERFACE_LIBRARY; entry.Target->GetType() == cmTarget::INTERFACE_LIBRARY;
@ -444,7 +443,9 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
// Initialize the item entry. // Initialize the item entry.
LinkEntry& entry = this->EntryList[lei->second]; LinkEntry& entry = this->EntryList[lei->second];
entry.Item = dep.Item; entry.Item = dep.Item;
entry.Target = dep.Item.Target; entry.Target =
dep.Item.Target ?
this->GlobalGenerator->GetGeneratorTarget(dep.Item.Target) : 0;
// This item was added specifically because it is a dependent // This item was added specifically because it is a dependent
// shared library. It may get special treatment // shared library. It may get special treatment
@ -463,10 +464,8 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
// Target items may have their own dependencies. // Target items may have their own dependencies.
if(entry.Target) if(entry.Target)
{ {
cmGeneratorTarget* gtgt =
this->GlobalGenerator->GetGeneratorTarget(entry.Target);
if(cmLinkInterface const* iface = if(cmLinkInterface const* iface =
gtgt->GetLinkInterface(this->Config, this->Target->Target)) entry.Target->GetLinkInterface(this->Config, this->Target->Target))
{ {
// Follow public and private dependencies transitively. // Follow public and private dependencies transitively.
this->FollowSharedDeps(index, iface, true); this->FollowSharedDeps(index, iface, true);
@ -639,15 +638,16 @@ 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.
cmTarget const* from = this->Target->Target; cmGeneratorTarget const* from = this->Target;
if(depender_index >= 0) if(depender_index >= 0)
{ {
if(cmTarget const* depender = this->EntryList[depender_index].Target) if(cmGeneratorTarget const* depender =
this->EntryList[depender_index].Target)
{ {
from = depender; from = depender;
} }
} }
return from->FindTargetToLink(name); return from->Target->FindTargetToLink(name);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -934,12 +934,10 @@ int cmComputeLinkDepends::ComputeComponentCount(NodeList const& nl)
int count = 2; int count = 2;
for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni) for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
{ {
if(cmTarget const* target = this->EntryList[*ni].Target) if(cmGeneratorTarget const* target = this->EntryList[*ni].Target)
{ {
cmGeneratorTarget* gtgt =
this->GlobalGenerator->GetGeneratorTarget(target);
if(cmLinkInterface const* iface = if(cmLinkInterface const* iface =
gtgt->GetLinkInterface(this->Config, this->Target->Target)) target->GetLinkInterface(this->Config, this->Target->Target))
{ {
if(iface->Multiplicity > count) if(iface->Multiplicity > count)
{ {

View File

@ -23,7 +23,6 @@ class cmComputeComponentGraph;
class cmGlobalGenerator; class cmGlobalGenerator;
class cmMakefile; class cmMakefile;
class cmGeneratorTarget; class cmGeneratorTarget;
class cmTarget;
class cmake; class cmake;
/** \class cmComputeLinkDepends /** \class cmComputeLinkDepends
@ -40,7 +39,7 @@ public:
struct LinkEntry struct LinkEntry
{ {
std::string Item; std::string Item;
cmTarget const* Target; cmGeneratorTarget const* Target;
bool IsSharedDep; bool IsSharedDep;
bool IsFlag; bool IsFlag;
LinkEntry(): Item(), Target(0), IsSharedDep(false), IsFlag(false) {} LinkEntry(): Item(), Target(0), IsSharedDep(false), IsFlag(false) {}

View File

@ -632,11 +632,11 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmComputeLinkInformation::AddItem(std::string const& item, void cmComputeLinkInformation::AddItem(std::string const& item,
cmTarget const* tgt) cmGeneratorTarget const* tgt)
{ {
// Compute the proper name to use to link this library. // Compute the proper name to use to link this library.
const std::string& config = this->Config; const std::string& config = this->Config;
bool impexe = (tgt && tgt->IsExecutableWithExports()); bool impexe = (tgt && tgt->Target->IsExecutableWithExports());
if(impexe && !this->UseImportLibrary && !this->LoaderFlag) if(impexe && !this->UseImportLibrary && !this->LoaderFlag)
{ {
// Skip linking to executables on platforms with no import // Skip linking to executables on platforms with no import
@ -644,9 +644,8 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
return; return;
} }
if(tgt && tgt->IsLinkable()) if(tgt && tgt->Target->IsLinkable())
{ {
cmGeneratorTarget *gtgt = this->GlobalGenerator->GetGeneratorTarget(tgt);
// This is a CMake target. Ask the target for its real name. // This is a CMake target. Ask the target for its real name.
if(impexe && this->LoaderFlag) if(impexe && this->LoaderFlag)
{ {
@ -656,10 +655,10 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
std::string linkItem; std::string linkItem;
linkItem = this->LoaderFlag; linkItem = this->LoaderFlag;
std::string exe = gtgt->GetFullPath(config, this->UseImportLibrary, std::string exe = tgt->GetFullPath(config, this->UseImportLibrary,
true); true);
linkItem += exe; linkItem += exe;
this->Items.push_back(Item(linkItem, true, tgt)); this->Items.push_back(Item(linkItem, true, tgt->Target));
this->Depends.push_back(exe); this->Depends.push_back(exe);
} }
else if(tgt->GetType() == cmTarget::INTERFACE_LIBRARY) else if(tgt->GetType() == cmTarget::INTERFACE_LIBRARY)
@ -667,7 +666,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
// Add the interface library as an item so it can be considered as part // Add the interface library as an item so it can be considered as part
// of COMPATIBLE_INTERFACE_ enforcement. The generators will ignore // of COMPATIBLE_INTERFACE_ enforcement. The generators will ignore
// this for the actual link line. // this for the actual link line.
this->Items.push_back(Item(std::string(), true, tgt)); this->Items.push_back(Item(std::string(), true, tgt->Target));
} }
else else
{ {
@ -677,15 +676,15 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
(impexe || tgt->GetType() == cmTarget::SHARED_LIBRARY)); (impexe || tgt->GetType() == cmTarget::SHARED_LIBRARY));
// Pass the full path to the target file. // Pass the full path to the target file.
std::string lib = gtgt->GetFullPath(config, implib, true); std::string lib = tgt->GetFullPath(config, implib, true);
if(!this->LinkDependsNoShared || if(!this->LinkDependsNoShared ||
tgt->GetType() != cmTarget::SHARED_LIBRARY) tgt->GetType() != cmTarget::SHARED_LIBRARY)
{ {
this->Depends.push_back(lib); this->Depends.push_back(lib);
} }
this->AddTargetItem(lib, tgt); this->AddTargetItem(lib, tgt->Target);
this->AddLibraryRuntimeInfo(lib, tgt); this->AddLibraryRuntimeInfo(lib, tgt->Target);
} }
} }
else else
@ -716,7 +715,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmComputeLinkInformation::AddSharedDepItem(std::string const& item, void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
cmTarget const* tgt) const cmGeneratorTarget* tgt)
{ {
// If dropping shared library dependencies, ignore them. // If dropping shared library dependencies, ignore them.
if(this->SharedDependencyMode == SharedDepModeNone) if(this->SharedDependencyMode == SharedDepModeNone)
@ -760,18 +759,14 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
return; return;
} }
cmGeneratorTarget *gtgt = 0;
// Get a full path to the dependent shared library. // Get a full path to the dependent shared library.
// Add it to the runtime path computation so that the target being // Add it to the runtime path computation so that the target being
// linked will be able to find it. // linked will be able to find it.
std::string lib; std::string lib;
if(tgt) if(tgt)
{ {
gtgt = this->GlobalGenerator->GetGeneratorTarget(tgt); lib = tgt->GetFullPath(this->Config, this->UseImportLibrary);
this->AddLibraryRuntimeInfo(lib, tgt->Target);
lib = gtgt->GetFullPath(this->Config, this->UseImportLibrary);
this->AddLibraryRuntimeInfo(lib, tgt);
} }
else else
{ {
@ -795,9 +790,9 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
} }
if(order) if(order)
{ {
if(gtgt) if(tgt)
{ {
std::string soName = gtgt->GetSOName(this->Config); std::string soName = tgt->GetSOName(this->Config);
const char* soname = soName.empty()? 0 : soName.c_str(); const char* soname = soName.empty()? 0 : soName.c_str();
order->AddRuntimeLibrary(lib, soname); order->AddRuntimeLibrary(lib, soname);
} }

View File

@ -62,8 +62,8 @@ public:
std::string const& GetRPathLinkFlag() const { return this->RPathLinkFlag; } std::string const& GetRPathLinkFlag() const { return this->RPathLinkFlag; }
std::string GetRPathLinkString(); std::string GetRPathLinkString();
private: private:
void AddItem(std::string const& item, cmTarget const* tgt); void AddItem(std::string const& item, const cmGeneratorTarget* tgt);
void AddSharedDepItem(std::string const& item, cmTarget const* tgt); void AddSharedDepItem(std::string const& item, cmGeneratorTarget const* tgt);
// Output information. // Output information.
ItemVector Items; ItemVector Items;