summaryrefslogtreecommitdiffstats
path: root/Source
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
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')
-rw-r--r--Source/cmComputeLinkDepends.cxx25
-rw-r--r--Source/cmComputeLinkDepends.h1
-rw-r--r--Source/cmComputeTargetDepends.cxx17
-rw-r--r--Source/cmComputeTargetDepends.h3
4 files changed, 39 insertions, 7 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())
{
diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h
index 3e42580..5777110 100644
--- a/Source/cmComputeLinkDepends.h
+++ b/Source/cmComputeLinkDepends.h
@@ -85,6 +85,7 @@ private:
void AddLinkEntries(int depender_index,
std::vector<std::string> const& libs);
std::string CleanItemName(std::string const& item);
+ cmTarget* FindTargetToLink(const char* name);
// One entry for each unique item.
std::vector<LinkEntry> EntryList;
diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx
index 19d99da..7a6e81f 100644
--- a/Source/cmComputeTargetDepends.cxx
+++ b/Source/cmComputeTargetDepends.cxx
@@ -214,7 +214,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
// Don't emit the same library twice for this target.
if(emitted.insert(lib->first).second)
{
- this->AddTargetDepend(depender_index, lib->first.c_str());
+ this->AddTargetDepend(depender_index, lib->first.c_str(), true);
}
}
@@ -226,14 +226,15 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
// Don't emit the same utility twice for this target.
if(emitted.insert(*util).second)
{
- this->AddTargetDepend(depender_index, util->c_str());
+ this->AddTargetDepend(depender_index, util->c_str(), false);
}
}
}
//----------------------------------------------------------------------------
void cmComputeTargetDepends::AddTargetDepend(int depender_index,
- const char* dependee_name)
+ const char* dependee_name,
+ bool linking)
{
// Get the depender.
cmTarget* depender = this->Targets[depender_index];
@@ -248,6 +249,16 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index,
dependee = this->GlobalGenerator->FindTarget(0, dependee_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(linking && dependee &&
+ dependee->GetType() == cmTarget::EXECUTABLE &&
+ !dependee->IsExecutableWithExports())
+ {
+ dependee = 0;
+ }
+
// If not found then skip then the dependee.
if(!dependee)
{
diff --git a/Source/cmComputeTargetDepends.h b/Source/cmComputeTargetDepends.h
index 707256e..e3e15e1 100644
--- a/Source/cmComputeTargetDepends.h
+++ b/Source/cmComputeTargetDepends.h
@@ -48,7 +48,8 @@ private:
void CollectTargets();
void CollectDepends();
void CollectTargetDepends(int depender_index);
- void AddTargetDepend(int depender_index, const char* dependee_name);
+ void AddTargetDepend(int depender_index, const char* dependee_name,
+ bool linking);
void ComputeFinalDepends(cmComputeComponentGraph const& ccg);
cmGlobalGenerator* GlobalGenerator;