Commit f6fd0abc authored by Brad King's avatar Brad King
Browse files

Genex: Diagnose invalid LINK_ONLY usage instead of crashing

When `$<LINK_ONLY:...>` is used outside of linking we may evaluate it
without a `dagChecker`.  Do not dereference the NULL pointer and issue a
diagnostic instead.

Closes: #16287
parent f6428725
...@@ -672,15 +672,20 @@ static const struct LinkOnlyNode : public cmGeneratorExpressionNode ...@@ -672,15 +672,20 @@ static const struct LinkOnlyNode : public cmGeneratorExpressionNode
LinkOnlyNode() {} LinkOnlyNode() {}
std::string Evaluate(const std::vector<std::string>& parameters, std::string Evaluate(const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* /*context*/, cmGeneratorExpressionContext* context,
const GeneratorExpressionContent* /*content*/, const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* dagChecker) const cmGeneratorExpressionDAGChecker* dagChecker) const
{ {
if (!dagChecker) {
reportError(context, content->GetOriginalExpression(),
"$<LINK_ONLY:...> may only be used for linking");
return std::string();
if (!dagChecker->GetTransitivePropertiesOnly()) { if (!dagChecker->GetTransitivePropertiesOnly()) {
return parameters.front(); return parameters.front();
} }
return ""; return std::string();
} }
} linkOnlyNode; } linkOnlyNode;
CMake Error at LINK_ONLY-not-linking.cmake:1 \(add_custom_target\):
Error evaluating generator expression:
\$<LINK_ONLY:...> may only be used for linking
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_custom_target(Custom ALL COMMAND ${CMAKE_COMMAND} -E echo $<LINK_ONLY:something>)
...@@ -29,6 +29,7 @@ run_cmake(COMPILE_LANGUAGE-unknown-lang) ...@@ -29,6 +29,7 @@ run_cmake(COMPILE_LANGUAGE-unknown-lang)
run_cmake(TARGET_FILE-recursion) run_cmake(TARGET_FILE-recursion)
run_cmake(OUTPUT_NAME-recursion) run_cmake(OUTPUT_NAME-recursion)
run_cmake(ImportedTarget-TARGET_PDB_FILE) run_cmake(ImportedTarget-TARGET_PDB_FILE)
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