diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index 0e73bd2078..8fd07d7760 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -305,3 +305,42 @@ Available output expressions are: Content of ``...`` converted to shell path style. For example, slashes are converted to backslashes in Windows shells and drive letters are converted to posix paths in MSYS shells. The ``...`` must be an absolute path. +``$`` + Content of ``...`` evaluated as a generator expression in the current + context. This enables consumption of generator expressions + whose evaluation results itself in generator expressions. +``$`` + Content of ``...`` evaluated as a generator expression in the context of + ``tgt`` target. This enables consumption of custom target properties that + themselves contain generator expressions. + + Having the capability to evaluate generator expressions is very useful when + you want to manage custom properties supporting generator expressions. + For example: + + .. code-block:: cmake + + add_library(foo ...) + + set_property(TARGET foo PROPERTY + CUSTOM_KEYS $<$:FOO_EXTRA_THINGS> + ) + + add_custom_target(printFooKeys + COMMAND ${CMAKE_COMMAND} -E echo $ + ) + + This naive implementation of the ``printFooKeys`` custom command is wrong + because ``CUSTOM_KEYS`` target property is not evaluated and the content + is passed as is (i.e. ``$<$:FOO_EXTRA_THINGS>``). + + To have the expected result (i.e. ``FOO_EXTRA_THINGS`` if config is + ``Debug``), it is required to evaluate the output of + ``$``: + + .. code-block:: cmake + + add_custom_target(printFooKeys + COMMAND ${CMAKE_COMMAND} -E + echo $> + ) diff --git a/Help/release/dev/genex-GENEX_EVAL.rst b/Help/release/dev/genex-GENEX_EVAL.rst new file mode 100644 index 0000000000..0869c93ab2 --- /dev/null +++ b/Help/release/dev/genex-GENEX_EVAL.rst @@ -0,0 +1,7 @@ +genex-GENEX_EVAL +---------------- + +* New ``$`` and ``$`` + :manual:`generator expression ` + had been added to enable consumption of generator expressions whose + evaluation results itself in generator expressions. diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index f0eafb46a5..face282289 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -154,6 +154,18 @@ bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnly() return top->TransitivePropertiesOnly; } +bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression() +{ + const cmGeneratorExpressionDAGChecker* top = this; + const cmGeneratorExpressionDAGChecker* parent = this->Parent; + while (parent) { + top = parent; + parent = parent->Parent; + } + + return top->Property == "TARGET_GENEX_EVAL" || top->Property == "GENEX_EVAL"; +} + bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(const char* tgt) { const cmGeneratorExpressionDAGChecker* top = this; diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index 3f73fca8af..a3a8f69c39 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -61,6 +61,7 @@ struct cmGeneratorExpressionDAGChecker void ReportError(cmGeneratorExpressionContext* context, const std::string& expr); + bool EvaluatingGenexExpression(); bool EvaluatingLinkLibraries(const char* tgt = nullptr); #define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) bool METHOD() const; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 89ed4f03db..399e89417c 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -365,6 +365,113 @@ static const struct TargetNameIfExistsNode : public cmGeneratorExpressionNode } } targetNameIfExistsNode; +struct GenexEvaluator : public cmGeneratorExpressionNode +{ + GenexEvaluator() {} + +protected: + std::string EvaluateExpression( + const std::string& genexOperator, const std::string& expression, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagCheckerParent) const + { + if (context->HeadTarget) { + cmGeneratorExpressionDAGChecker dagChecker( + context->Backtrace, context->HeadTarget->GetName(), genexOperator, + content, dagCheckerParent); + switch (dagChecker.Check()) { + case cmGeneratorExpressionDAGChecker::SELF_REFERENCE: + case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE: { + dagChecker.ReportError(context, content->GetOriginalExpression()); + return std::string(); + } + case cmGeneratorExpressionDAGChecker::ALREADY_SEEN: + case cmGeneratorExpressionDAGChecker::DAG: + break; + } + + return this->EvaluateDependentExpression( + expression, context->LG, context, context->HeadTarget, + context->CurrentTarget, &dagChecker); + } + + return this->EvaluateDependentExpression( + expression, context->LG, context, context->HeadTarget, + context->CurrentTarget, dagCheckerParent); + } +}; + +static const struct TargetGenexEvalNode : public GenexEvaluator +{ + TargetGenexEvalNode() {} + + int NumExpectedParameters() const override { return 2; } + + bool AcceptsArbitraryContentParameter() const override { return true; } + + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagCheckerParent) const override + { + const std::string& targetName = parameters.front(); + if (targetName.empty() || + !cmGeneratorExpression::IsValidTargetName(targetName)) { + reportError(context, content->GetOriginalExpression(), + "$ expression requires a " + "non-empty valid target name."); + return std::string(); + } + + const auto* target = context->LG->FindGeneratorTargetToUse(targetName); + if (!target) { + std::ostringstream e; + e << "$ target \"" << targetName + << "\" not found."; + reportError(context, content->GetOriginalExpression(), e.str()); + return std::string(); + } + + const std::string& expression = parameters[1]; + if (expression.empty()) { + return expression; + } + + cmGeneratorExpressionContext targetContext( + context->LG, context->Config, context->Quiet, target, target, + context->EvaluateForBuildsystem, context->Backtrace, context->Language); + + return this->EvaluateExpression("TARGET_GENEX_EVAL", expression, + &targetContext, content, dagCheckerParent); + } +} targetGenexEvalNode; + +static const struct GenexEvalNode : public GenexEvaluator +{ + GenexEvalNode() {} + + int NumExpectedParameters() const override { return 1; } + + bool AcceptsArbitraryContentParameter() const override { return true; } + + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagCheckerParent) const override + { + const std::string& expression = parameters[0]; + if (expression.empty()) { + return expression; + } + + return this->EvaluateExpression("GENEX_EVAL", expression, context, content, + dagCheckerParent); + } +} genexEvalNode; + static const struct LowerCaseNode : public cmGeneratorExpressionNode { LowerCaseNode() {} @@ -1124,7 +1231,9 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode const char* prop = target->GetProperty(propertyName); if (dagCheckerParent) { - if (dagCheckerParent->EvaluatingLinkLibraries()) { + if (dagCheckerParent->EvaluatingGenexExpression()) { + // No check required. + } else if (dagCheckerParent->EvaluatingLinkLibraries()) { #define TRANSITIVE_PROPERTY_COMPARE(PROPERTY) \ (#PROPERTY == propertyName || "INTERFACE_" #PROPERTY == propertyName) || if (CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME( @@ -1933,6 +2042,8 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( nodeMap["TARGET_POLICY"] = &targetPolicyNode; nodeMap["TARGET_EXISTS"] = &targetExistsNode; nodeMap["TARGET_NAME_IF_EXISTS"] = &targetNameIfExistsNode; + nodeMap["TARGET_GENEX_EVAL"] = &targetGenexEvalNode; + nodeMap["GENEX_EVAL"] = &genexEvalNode; nodeMap["BUILD_INTERFACE"] = &buildInterfaceNode; nodeMap["INSTALL_INTERFACE"] = &installInterfaceNode; nodeMap["INSTALL_PREFIX"] = &installPrefixNode; diff --git a/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-check.cmake b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-check.cmake new file mode 100644 index 0000000000..df7674051a --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-check.cmake @@ -0,0 +1,6 @@ +file(READ "${RunCMake_TEST_BINARY_DIR}/GENEX_EVAL-generated.txt" content) + +set(expected "BEFORE_PROPERTY1_AFTER") +if(NOT content STREQUAL expected) + set(RunCMake_TEST_FAILED "actual content:\n [[${content}]]\nbut expected:\n [[${expected}]]") +endif() diff --git a/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion1-result.txt b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion1-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion1-stderr.txt b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion1-stderr.txt new file mode 100644 index 0000000000..012dff6580 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion1-stderr.txt @@ -0,0 +1,26 @@ +^CMake Error at GENEX_EVAL-recursion1.cmake:7 \(add_custom_target\): + Error evaluating generator expression: + + \$> + + Dependency loop found. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Error at GENEX_EVAL-recursion1.cmake:7 \(add_custom_target\): + Loop step 1 + + \$> + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Error at GENEX_EVAL-recursion1.cmake:7 \(add_custom_target\): + Loop step 2 + + \$> + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion1.cmake b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion1.cmake new file mode 100644 index 0000000000..6596a81ab5 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion1.cmake @@ -0,0 +1,9 @@ + +enable_language(C) + +add_library (recursion SHARED empty.c) +set_property (TARGET recursion PROPERTY CUSTOM_PROPERTY "$>") + +add_custom_target (drive + COMMAND echo "$>" + DEPENDS recursion) diff --git a/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion2-result.txt b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion2-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion2-stderr.txt b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion2-stderr.txt new file mode 100644 index 0000000000..fd954e6cc2 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion2-stderr.txt @@ -0,0 +1,26 @@ +^CMake Error at GENEX_EVAL-recursion2.cmake:8 \(add_custom_target\): + Error evaluating generator expression: + + \$> + + Dependency loop found. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Error at GENEX_EVAL-recursion2.cmake:8 \(add_custom_target\): + Loop step 1 + + \$> + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Error at GENEX_EVAL-recursion2.cmake:8 \(add_custom_target\): + Loop step 2 + + \$> + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion2.cmake b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion2.cmake new file mode 100644 index 0000000000..773749f2c1 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL-recursion2.cmake @@ -0,0 +1,10 @@ + +enable_language(C) + +add_library(recursion SHARED empty.c) +set_property (TARGET recursion PROPERTY CUSTOM_PROPERTY1 "$>") +set_property (TARGET recursion PROPERTY CUSTOM_PROPERTY2 "$>") + +add_custom_target (drive + COMMAND echo "$>" + DEPENDS recursion) diff --git a/Tests/RunCMake/GeneratorExpression/GENEX_EVAL.cmake b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL.cmake new file mode 100644 index 0000000000..ab8988b269 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/GENEX_EVAL.cmake @@ -0,0 +1,11 @@ + +cmake_policy(VERSION 3.11) + +enable_language(C) + +add_library (example SHARED empty.c) +set_property (TARGET example PROPERTY CUSTOM_PROPERTY1 "PROPERTY1") +set_property (TARGET example PROPERTY CUSTOM_PROPERTY2 "$") +set_property (TARGET example PROPERTY CUSTOM_PROPERTY3 "$_AFTER>") + +file(GENERATE OUTPUT "GENEX_EVAL-generated.txt" CONTENT "$>") diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake index 5636d00067..3905c5f993 100644 --- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake @@ -42,6 +42,15 @@ run_cmake(TARGET_NAME_IF_EXISTS-no-arg) run_cmake(TARGET_NAME_IF_EXISTS-empty-arg) run_cmake(TARGET_NAME_IF_EXISTS) run_cmake(TARGET_NAME_IF_EXISTS-not-a-target) +run_cmake(TARGET_GENEX_EVAL-no-arg) +run_cmake(TARGET_GENEX_EVAL-no-target) +run_cmake(TARGET_GENEX_EVAL-non-valid-target) +run_cmake(TARGET_GENEX_EVAL-recursion1) +run_cmake(TARGET_GENEX_EVAL-recursion2) +run_cmake(TARGET_GENEX_EVAL) +run_cmake(GENEX_EVAL-recursion1) +run_cmake(GENEX_EVAL-recursion2) +run_cmake(GENEX_EVAL) run_cmake(ImportedTarget-TARGET_BUNDLE_DIR) run_cmake(ImportedTarget-TARGET_BUNDLE_CONTENT_DIR) diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-check.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-check.cmake new file mode 100644 index 0000000000..124a583e24 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-check.cmake @@ -0,0 +1,6 @@ +file(READ "${RunCMake_TEST_BINARY_DIR}/TARGET_GENEX_EVAL-generated.txt" content) + +set(expected "BEFORE_PROPERTY1_AFTER") +if(NOT content STREQUAL expected) + set(RunCMake_TEST_FAILED "actual content:\n [[${content}]]\nbut expected:\n [[${expected}]]") +endif() diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-arg-result.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-arg-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-arg-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-arg-stderr.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-arg-stderr.txt new file mode 100644 index 0000000000..9b0844f9f6 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-arg-stderr.txt @@ -0,0 +1,9 @@ +^CMake Error at TARGET_GENEX_EVAL-no-arg.cmake:4 \(add_custom_command\): + Error evaluating generator expression: + + \$ + + \$ expression requires 2 comma separated parameters, but + got 1 instead. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-arg.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-arg.cmake new file mode 100644 index 0000000000..2dc13ea5eb --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-arg.cmake @@ -0,0 +1,7 @@ + +cmake_policy(VERSION 3.11) + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.c" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$.c" +) +add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c") diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-target-result.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-target-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-target-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-target-stderr.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-target-stderr.txt new file mode 100644 index 0000000000..647fd85c6d --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-target-stderr.txt @@ -0,0 +1,9 @@ +^CMake Error at TARGET_GENEX_EVAL-no-target.cmake:2 \(add_custom_command\): + Error evaluating generator expression: + + \$ + + \$ expression requires a non-empty valid target + name. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-target.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-target.cmake new file mode 100644 index 0000000000..df4f0eac68 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-no-target.cmake @@ -0,0 +1,5 @@ + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.c" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$.c" +) +add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c") diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-non-valid-target-result.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-non-valid-target-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-non-valid-target-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-non-valid-target-stderr.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-non-valid-target-stderr.txt new file mode 100644 index 0000000000..cc44d4b9cf --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-non-valid-target-stderr.txt @@ -0,0 +1,8 @@ +^CMake Error at TARGET_GENEX_EVAL-non-valid-target.cmake:2 \(add_custom_command\): + Error evaluating generator expression: + + \$ + + \$ target "bad-target" not found. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-non-valid-target.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-non-valid-target.cmake new file mode 100644 index 0000000000..8db7375932 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-non-valid-target.cmake @@ -0,0 +1,5 @@ + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.c" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$.c" +) +add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c") diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion1-result.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion1-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion1-stderr.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion1-stderr.txt new file mode 100644 index 0000000000..bba22340cb --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion1-stderr.txt @@ -0,0 +1,9 @@ +^CMake Error at TARGET_GENEX_EVAL-recursion1.cmake:7 \(add_custom_target\): + Error evaluating generator expression: + + \$> + + Self reference on target "recursion". + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion1.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion1.cmake new file mode 100644 index 0000000000..b75d211757 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion1.cmake @@ -0,0 +1,9 @@ + +enable_language(C) + +add_library (recursion SHARED empty.c) +set_property (TARGET recursion PROPERTY CUSTOM_PROPERTY "$>") + +add_custom_target (drive + COMMAND echo "$>" + DEPENDS recursion) diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion2-result.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion2-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion2-stderr.txt b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion2-stderr.txt new file mode 100644 index 0000000000..73f6b77e97 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion2-stderr.txt @@ -0,0 +1,26 @@ +^CMake Error at TARGET_GENEX_EVAL-recursion2.cmake:10 \(add_custom_target\): + Error evaluating generator expression: + + \$> + + Dependency loop found. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Error at TARGET_GENEX_EVAL-recursion2.cmake:10 \(add_custom_target\): + Loop step 1 + + \$> + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Error at TARGET_GENEX_EVAL-recursion2.cmake:10 \(add_custom_target\): + Loop step 2 + + \$> + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion2.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion2.cmake new file mode 100644 index 0000000000..a28dfc34dc --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL-recursion2.cmake @@ -0,0 +1,12 @@ + +enable_language(C) + +add_library (recursion1 SHARED empty.c) +set_property (TARGET recursion1 PROPERTY CUSTOM_PROPERTY1 "$>") + +add_library (recursion2 SHARED empty.c) +set_property (TARGET recursion2 PROPERTY CUSTOM_PROPERTY2 "$>") + +add_custom_target (drive + COMMAND echo "$>" + DEPENDS recursion) diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL.cmake new file mode 100644 index 0000000000..68b3712579 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/TARGET_GENEX_EVAL.cmake @@ -0,0 +1,10 @@ + +cmake_policy(VERSION 3.11) + +enable_language(C) + +add_library (example SHARED empty.c) +set_property (TARGET example PROPERTY CUSTOM_PROPERTY1 "PROPERTY1") +set_property (TARGET example PROPERTY CUSTOM_PROPERTY2 "BEFORE_$_AFTER") + +file(GENERATE OUTPUT "TARGET_GENEX_EVAL-generated.txt" CONTENT "$>")