summaryrefslogtreecommitdiffstats
path: root/Source/cmComputeLinkDepends.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-08-06 21:48:53 (GMT)
committerBrad King <brad.king@kitware.com>2008-08-06 21:48:53 (GMT)
commitd76b20bf3ae9b045fc3c17f8d5e33fccd997b175 (patch)
tree745768d27e4635a946234eec29cc72cce255d678 /Source/cmComputeLinkDepends.cxx
parent37a009b7f704e26e2a76485d74c3ee5612f208d7 (diff)
downloadCMake-d76b20bf3ae9b045fc3c17f8d5e33fccd997b175.zip
CMake-d76b20bf3ae9b045fc3c17f8d5e33fccd997b175.tar.gz
CMake-d76b20bf3ae9b045fc3c17f8d5e33fccd997b175.tar.bz2
BUG: Avoid bogus dependency on executable targets
When an executable target within the project is named in target_link_libraries for another target, but the executable does not have the ENABLE_EXPORTS property set, then the executable cannot really be linked. This is probably a case where the user intends to link to a third-party library that happens to have the same name as an executable target in the project (or else will get an error at build time). We need to avoid making the other target depend on the executable target incorrectly, since the executable may actually want to link to that target and this is not a circular depenency.
Diffstat (limited to 'Source/cmComputeLinkDepends.cxx')
-rw-r--r--Source/cmComputeLinkDepends.cxx25
1 files changed, 22 insertions, 3 deletions
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index 72dd198..177ec58 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -292,7 +292,7 @@ int cmComputeLinkDepends::AddLinkEntry(std::string const& item)
int index = lei->second;
LinkEntry& entry = this->EntryList[index];
entry.Item = item;
- entry.Target = this->Makefile->FindTargetToUse(entry.Item.c_str());
+ entry.Target = this->FindTargetToLink(entry.Item.c_str());
// If the item has dependencies queue it to follow them.
if(entry.Target)
@@ -387,7 +387,7 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
// Initialize the item entry.
LinkEntry& entry = this->EntryList[lei->second];
entry.Item = dep.Item;
- entry.Target = this->Makefile->FindTargetToUse(dep.Item.c_str());
+ entry.Target = this->FindTargetToLink(dep.Item.c_str());
// This item was added specifically because it is a dependent
// shared library. It may get special treatment
@@ -655,6 +655,25 @@ std::string cmComputeLinkDepends::CleanItemName(std::string const& item)
}
//----------------------------------------------------------------------------
+cmTarget* cmComputeLinkDepends::FindTargetToLink(const char* name)
+{
+ // Look for a target.
+ cmTarget* 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;
+ }
+
+ // Return the target found, if any.
+ return tgt;
+}
+
+//----------------------------------------------------------------------------
void cmComputeLinkDepends::InferDependencies()
{
// The inferred dependency sets for each item list the possible
@@ -862,7 +881,7 @@ void cmComputeLinkDepends::CheckWrongConfigItem(std::string const& item)
// For CMake 2.4 bug-compatibility we need to consider the output
// directories of targets linked in another configuration as link
// directories.
- if(cmTarget* tgt = this->Makefile->FindTargetToUse(item.c_str()))
+ if(cmTarget* tgt = this->FindTargetToLink(item.c_str()))
{
if(!tgt->IsImported())
{