From 6491d2503c942b9dfb4db94dba6569e400b57a95 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Sun, 12 Jul 2020 15:25:18 +0200 Subject: Genex $: Extend contexts supported When genex $ for properties like INCLUDE_DIRECTORIES is evaluated as part of add_custom_command or add_custom_target, genex $ and $ should be supported. Fixes: #20926 --- Source/cmGeneratorExpressionDAGChecker.cxx | 8 ++++++++ Source/cmGeneratorExpressionDAGChecker.h | 1 + Source/cmGeneratorExpressionNode.cxx | 9 ++++++--- .../COMPILE_LANGUAGE-TARGET_PROPERTY.cmake | 17 +++++++++++++++++ .../RunCMake/GenEx-COMPILE_LANGUAGE/RunCMakeTest.cmake | 1 + .../COMPILE_LANG_AND_ID-TARGET_PROPERTY.cmake | 17 +++++++++++++++++ .../GenEx-COMPILE_LANG_AND_ID/RunCMakeTest.cmake | 1 + 7 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 Tests/RunCMake/GenEx-COMPILE_LANGUAGE/COMPILE_LANGUAGE-TARGET_PROPERTY.cmake create mode 100644 Tests/RunCMake/GenEx-COMPILE_LANG_AND_ID/COMPILE_LANG_AND_ID-TARGET_PROPERTY.cmake diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index 4f379cd..e223f15 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -154,6 +154,14 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingPICExpression() const return this->Top()->Property == "INTERFACE_POSITION_INDEPENDENT_CODE"; } +bool cmGeneratorExpressionDAGChecker::EvaluatingCompileExpression() const +{ + cm::string_view property(this->Top()->Property); + + return property == "INCLUDE_DIRECTORIES"_s || + property == "COMPILE_DEFINITIONS"_s || property == "COMPILE_OPTIONS"_s; +} + bool cmGeneratorExpressionDAGChecker::EvaluatingLinkExpression() const { cm::string_view property(this->Top()->Property); diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index c2c5b6b..ac2314c 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -68,6 +68,7 @@ struct cmGeneratorExpressionDAGChecker bool EvaluatingGenexExpression() const; bool EvaluatingPICExpression() const; + bool EvaluatingCompileExpression() const; bool EvaluatingLinkExpression() const; bool EvaluatingLinkOptionsExpression() const; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 4adc6a2..a1a0ae8 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -967,9 +967,10 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode const std::vector& parameters, cmGeneratorExpressionContext* context, const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override + cmGeneratorExpressionDAGChecker* dagChecker) const override { - if (context->Language.empty()) { + if (context->Language.empty() && + (!dagChecker || !dagChecker->EvaluatingCompileExpression())) { reportError( context, content->GetOriginalExpression(), "$ may only be used to specify include " @@ -1014,7 +1015,9 @@ static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode const GeneratorExpressionContent* content, cmGeneratorExpressionDAGChecker* dagChecker) const override { - if (!context->HeadTarget || context->Language.empty()) { + if (!context->HeadTarget || + (context->Language.empty() && + (!dagChecker || !dagChecker->EvaluatingCompileExpression()))) { // reportError(context, content->GetOriginalExpression(), ""); reportError( context, content->GetOriginalExpression(), diff --git a/Tests/RunCMake/GenEx-COMPILE_LANGUAGE/COMPILE_LANGUAGE-TARGET_PROPERTY.cmake b/Tests/RunCMake/GenEx-COMPILE_LANGUAGE/COMPILE_LANGUAGE-TARGET_PROPERTY.cmake new file mode 100644 index 0000000..293ddda --- /dev/null +++ b/Tests/RunCMake/GenEx-COMPILE_LANGUAGE/COMPILE_LANGUAGE-TARGET_PROPERTY.cmake @@ -0,0 +1,17 @@ +enable_language(C) + +add_library (lib SHARED empty.c) +set_target_properties(lib PROPERTIES + INCLUDE_DIRECTORIES "$<$:/usr/include>" + COMPILE_DEFINITIONS "$<$:DEF>" + COMPILE_OPTIONS "$<$:-O>") + +add_custom_target(drive + COMMAND ${CMAKE_COMMAND} -E echo $ + $ + $) + +add_custom_command(TARGET drive PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E echo $ + $ + $) diff --git a/Tests/RunCMake/GenEx-COMPILE_LANGUAGE/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-COMPILE_LANGUAGE/RunCMakeTest.cmake index 6691fdf..15a5e79 100644 --- a/Tests/RunCMake/GenEx-COMPILE_LANGUAGE/RunCMakeTest.cmake +++ b/Tests/RunCMake/GenEx-COMPILE_LANGUAGE/RunCMakeTest.cmake @@ -8,3 +8,4 @@ run_cmake(COMPILE_LANGUAGE-add_executable) run_cmake(COMPILE_LANGUAGE-add_library) run_cmake(COMPILE_LANGUAGE-add_test) run_cmake(COMPILE_LANGUAGE-unknown-lang) +run_cmake(COMPILE_LANGUAGE-TARGET_PROPERTY) diff --git a/Tests/RunCMake/GenEx-COMPILE_LANG_AND_ID/COMPILE_LANG_AND_ID-TARGET_PROPERTY.cmake b/Tests/RunCMake/GenEx-COMPILE_LANG_AND_ID/COMPILE_LANG_AND_ID-TARGET_PROPERTY.cmake new file mode 100644 index 0000000..6a718d6 --- /dev/null +++ b/Tests/RunCMake/GenEx-COMPILE_LANG_AND_ID/COMPILE_LANG_AND_ID-TARGET_PROPERTY.cmake @@ -0,0 +1,17 @@ +enable_language(C) + +add_library (lib SHARED empty.c) +set_target_properties(lib PROPERTIES + INCLUDE_DIRECTORIES "$<$:/usr/include>" + COMPILE_DEFINITIONS "$<$:DEF>" + COMPILE_OPTIONS "$<$:-O>") + +add_custom_target(drive + COMMAND ${CMAKE_COMMAND} -E echo $ + $ + $) + +add_custom_command(TARGET drive PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E echo $ + $ + $) diff --git a/Tests/RunCMake/GenEx-COMPILE_LANG_AND_ID/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-COMPILE_LANG_AND_ID/RunCMakeTest.cmake index a0a7bb9..68bd05d 100644 --- a/Tests/RunCMake/GenEx-COMPILE_LANG_AND_ID/RunCMakeTest.cmake +++ b/Tests/RunCMake/GenEx-COMPILE_LANG_AND_ID/RunCMakeTest.cmake @@ -8,3 +8,4 @@ run_cmake(COMPILE_LANG_AND_ID-add_executable) run_cmake(COMPILE_LANG_AND_ID-add_library) run_cmake(COMPILE_LANG_AND_ID-add_test) run_cmake(COMPILE_LANG_AND_ID-unknown-lang) +run_cmake(COMPILE_LANG_AND_ID-TARGET_PROPERTY) -- cgit v0.12