Commit 30c2e1dd authored by Brad King's avatar Brad King
Browse files

cmTarget: Fix diagnostic of target_link_libraries in wrong directory (#15626)

Since commit v3.3.0-rc1~62^2~5 (cmTarget: Store only cmListFileContext
for CMP0023 handling, 2015-05-18) a call to target_link_libraries on a
target that was defined in another (non-ancestor) directory crashes
because no execution context is left active.  Fix this by getting the
execution context from the actual cmMakefile where the current
target_link_libraries call takes place.  Test this by verifying that
such calls correctly produce an error diagnostic instead of crashing.
parent a6916a6c
...@@ -1231,7 +1231,8 @@ static std::string targetNameGenex(const std::string& lib) ...@@ -1231,7 +1231,8 @@ static std::string targetNameGenex(const std::string& lib)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmTarget::PushTLLCommandTrace(TLLSignature signature) bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
cmListFileContext const& lfc)
{ {
bool ret = true; bool ret = true;
if (!this->TLLCommands.empty()) if (!this->TLLCommands.empty())
...@@ -1241,7 +1242,6 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature) ...@@ -1241,7 +1242,6 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
ret = false; ret = false;
} }
} }
cmListFileContext lfc = this->Makefile->GetExecutionContext();
if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc) if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc)
{ {
this->TLLCommands.push_back(std::make_pair(signature, lfc)); this->TLLCommands.push_back(std::make_pair(signature, lfc));
......
...@@ -207,7 +207,8 @@ public: ...@@ -207,7 +207,8 @@ public:
KeywordTLLSignature, KeywordTLLSignature,
PlainTLLSignature PlainTLLSignature
}; };
bool PushTLLCommandTrace(TLLSignature signature); bool PushTLLCommandTrace(TLLSignature signature,
cmListFileContext const& lfc);
void GetTllSignatureTraces(std::ostringstream &s, TLLSignature sig) const; void GetTllSignatureTraces(std::ostringstream &s, TLLSignature sig) const;
void MergeLinkLibraries( cmMakefile& mf, const std::string& selfname, void MergeLinkLibraries( cmMakefile& mf, const std::string& selfname,
......
...@@ -368,7 +368,8 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, ...@@ -368,7 +368,8 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
|| this->CurrentProcessingState == ProcessingKeywordPublicInterface || this->CurrentProcessingState == ProcessingKeywordPublicInterface
|| this->CurrentProcessingState == ProcessingKeywordLinkInterface) || this->CurrentProcessingState == ProcessingKeywordLinkInterface)
? cmTarget::KeywordTLLSignature : cmTarget::PlainTLLSignature; ? cmTarget::KeywordTLLSignature : cmTarget::PlainTLLSignature;
if (!this->Target->PushTLLCommandTrace(sig)) if (!this->Target->PushTLLCommandTrace(
sig, this->Makefile->GetExecutionContext()))
{ {
std::ostringstream e; std::ostringstream e;
const char *modal = 0; const char *modal = 0;
......
...@@ -6,3 +6,4 @@ run_cmake(CMP0023-WARN-2) ...@@ -6,3 +6,4 @@ run_cmake(CMP0023-WARN-2)
run_cmake(CMP0023-NEW-2) run_cmake(CMP0023-NEW-2)
run_cmake(MixedSignature) run_cmake(MixedSignature)
run_cmake(Separate-PRIVATE-LINK_PRIVATE-uses) run_cmake(Separate-PRIVATE-LINK_PRIVATE-uses)
run_cmake(SubDirTarget)
^CMake Error at SubDirTarget.cmake:[0-9]+ \(target_link_libraries\):
Attempt to add link library "m" to target "subexe" which is not built in
this directory.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$
enable_language(C)
add_subdirectory(SubDirTarget)
target_link_libraries(subexe m)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment