From ef796cc74322ff423da1ddef5e4dd52855dac8c7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 14 Jul 2020 15:54:01 -0400 Subject: cmGeneratorTarget: Skip computing link implementation for custom targets Targets created by `add_custom_target` cannot be used with `target_link_libraries` and so have no link implementation. --- Source/cmGeneratorTarget.cxx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 30af139..64d4ec4 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -2467,6 +2467,12 @@ private: cmGeneratorTarget::LinkClosure const* cmGeneratorTarget::GetLinkClosure( const std::string& config) const { + // There is no link implementation for targets that cannot compile sources. + if (!this->CanCompileSources()) { + static LinkClosure const empty = { {}, {} }; + return ∅ + } + std::string key(cmSystemTools::UpperCase(config)); auto i = this->LinkClosureMap.find(key); if (i == this->LinkClosureMap.end()) { @@ -2783,6 +2789,12 @@ const std::vector& cmGeneratorTarget::GetLinkImplementationClosure( const std::string& config) const { + // There is no link implementation for targets that cannot compile sources. + if (!this->CanCompileSources()) { + static std::vector const empty; + return empty; + } + LinkImplClosure& tgts = this->LinkImplClosureMap[config]; if (!tgts.Done) { tgts.Done = true; @@ -6856,8 +6868,8 @@ const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation( const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation( const std::string& config, bool secondPass) const { - // There is no link implementation for imported targets. - if (this->IsImported()) { + // There is no link implementation for targets that cannot compile sources. + if (!this->CanCompileSources()) { return nullptr; } @@ -7120,8 +7132,8 @@ cmLinkImplementationLibraries const* cmGeneratorTarget::GetLinkImplementationLibrariesInternal( const std::string& config, cmGeneratorTarget const* head) const { - // There is no link implementation for imported targets. - if (this->IsImported()) { + // There is no link implementation for targets that cannot compile sources. + if (!this->CanCompileSources()) { return nullptr; } -- cgit v0.12