From bf2d061ad37088be9ea6f135a980d14c4e76064b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 10 Oct 2015 12:23:19 +0200 Subject: cmGeneratorTarget: Move FindTargetToLink from cmTarget. --- Source/cmComputeLinkDepends.cxx | 7 ++++--- Source/cmComputeLinkDepends.h | 4 ++-- Source/cmGeneratorTarget.cxx | 42 ++++++++++++++++++++++++++++++++++++++--- Source/cmGeneratorTarget.h | 2 ++ Source/cmTarget.cxx | 31 ------------------------------ Source/cmTarget.h | 2 -- 6 files changed, 47 insertions(+), 41 deletions(-) diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 4d7b01e..5604c53 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -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); } //---------------------------------------------------------------------------- diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index 33ba0b8..d9760aa 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -73,8 +73,8 @@ private: void AddDirectLinkEntries(); template void AddLinkEntries(int depender_index, std::vector 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 EntryList; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index ef79d74..d472c6c 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -4427,7 +4427,7 @@ void cmGeneratorTarget::LookupLinkItems(std::vector 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,12 +5430,48 @@ 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 { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 70612f2..cd994c0 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -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 diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 31a9aa7..bebdd77 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2670,37 +2670,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 { // Strip whitespace off the library names because we used to do this diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 0c1bbd2..3bb1ccd 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -223,8 +223,6 @@ public: void GetObjectLibrariesCMP0026(std::vector& 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; -- cgit v0.12