From 0a61116f527d78bc21a1a111f03e2c801386e5ba Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 12 Apr 2024 11:00:51 -0400 Subject: cmGeneratorTarget: Remove EvaluateInterfaceProperty argument default Pass it explicitly at the call sites. --- Source/cmGeneratorExpressionNode.cxx | 10 ++++++---- Source/cmGeneratorTarget.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 5c97e22..0114d82 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -2714,8 +2714,9 @@ static std::string getLinkedTargetsContent( target->GetLocalGenerator(), context->Config, context->Quiet, target, target, context->EvaluateForBuildsystem, lib.Backtrace, context->Language); - std::string libResult = - lib.Target->EvaluateInterfaceProperty(prop, &libContext, dagChecker); + std::string libResult = lib.Target->EvaluateInterfaceProperty( + prop, &libContext, dagChecker, + cmGeneratorTarget::LinkInterfaceFor::Usage); if (!libResult.empty()) { if (result.empty()) { result = std::move(libResult); @@ -2920,8 +2921,9 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode if (isInterfaceProperty) { return cmGeneratorExpression::StripEmptyListElements( - target->EvaluateInterfaceProperty(propertyName, context, - dagCheckerParent)); + target->EvaluateInterfaceProperty( + propertyName, context, dagCheckerParent, + cmGeneratorTarget::LinkInterfaceFor::Usage)); } cmGeneratorExpressionDAGChecker dagChecker( diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index fd4b2ec..fc65b15 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -883,7 +883,7 @@ public: std::string EvaluateInterfaceProperty( std::string const& prop, cmGeneratorExpressionContext* context, cmGeneratorExpressionDAGChecker* dagCheckerParent, - LinkInterfaceFor interfaceFor = LinkInterfaceFor::Usage) const; + LinkInterfaceFor interfaceFor) const; bool HaveInstallTreeRPATH(const std::string& config) const; -- cgit v0.12 From 91a25de5206b53a4a1fd61d8d2bf13a76fce7ad0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 11 Apr 2024 13:49:12 -0400 Subject: cmGeneratorExpression: Add comments on implementation details Clarify the purpose of some genex code that collects properties over the transitive link closure. --- Source/cmGeneratorExpressionDAGChecker.cxx | 3 +++ Source/cmGeneratorExpressionNode.cxx | 4 ++++ Source/cmGeneratorTarget.cxx | 1 + 3 files changed, 8 insertions(+) diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index da5785e..5343c98 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -141,12 +141,15 @@ bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnlyCMP0131() bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression() const { + // Corresponds to GenexEvaluator::EvaluateExpression. return cmHasLiteralPrefix(this->Property, "TARGET_GENEX_EVAL:") || cmHasLiteralPrefix(this->Property, "GENEX_EVAL:"); } bool cmGeneratorExpressionDAGChecker::EvaluatingPICExpression() const { + // Corresponds to checkInterfacePropertyCompatibility's special case + // that evaluates the value of POSITION_INDEPENDENT_CODE as a genex. return this->Top->Property == "INTERFACE_POSITION_INDEPENDENT_CODE"; } diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 0114d82..1ac658c 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -547,6 +547,7 @@ static const struct TargetGenexEvalNode : public GenexEvaluator return expression; } + // Replace the surrounding context with the named target. cmGeneratorExpressionContext targetContext( context->LG, context->Config, context->Quiet, target, target, context->EvaluateForBuildsystem, context->Backtrace, context->Language); @@ -2897,6 +2898,9 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode bool evaluatingLinkLibraries = false; if (dagCheckerParent) { + // This $ node has been reached while evaluating + // another target property value. Check that the outermost evaluation + // expects such nested evaluations. if (dagCheckerParent->EvaluatingGenexExpression() || dagCheckerParent->EvaluatingPICExpression() || dagCheckerParent->EvaluatingLinkerLauncher()) { diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 2ec1a29..b32d0b8 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -6375,6 +6375,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt, std::string interfaceProperty = "INTERFACE_" + p; std::unique_ptr genexInterpreter; if (p == "POSITION_INDEPENDENT_CODE") { + // Corresponds to EvaluatingPICExpression. genexInterpreter = cm::make_unique( tgt->GetLocalGenerator(), config, tgt); } -- cgit v0.12 From 5f7d8192da570730040227a1a1122c1eeb8c125c Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 11 Apr 2024 09:34:17 -0400 Subject: cmGeneratorExpression: Inline evaluation helper at only call site --- Source/cmGeneratorExpression.cxx | 7 ------- Source/cmGeneratorExpression.h | 5 ----- 2 files changed, 12 deletions(-) diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 04decd2..0b96c3f 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -70,13 +70,6 @@ const std::string& cmCompiledGeneratorExpression::Evaluate( currentTarget ? currentTarget : headTarget, this->EvaluateForBuildsystem, this->Backtrace, language); - return this->EvaluateWithContext(context, dagChecker); -} - -const std::string& cmCompiledGeneratorExpression::EvaluateWithContext( - cmGeneratorExpressionContext& context, - cmGeneratorExpressionDAGChecker* dagChecker) const -{ if (!this->NeedsEvaluation) { return this->Input; } diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index e22b8ab..71855c9 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -17,7 +17,6 @@ class cmake; class cmCompiledGeneratorExpression; class cmGeneratorTarget; -struct cmGeneratorExpressionContext; struct cmGeneratorExpressionDAGChecker; struct cmGeneratorExpressionEvaluator; @@ -151,10 +150,6 @@ public: std::map& mapping); private: - const std::string& EvaluateWithContext( - cmGeneratorExpressionContext& context, - cmGeneratorExpressionDAGChecker* dagChecker) const; - cmCompiledGeneratorExpression(cmake& cmakeInstance, cmListFileBacktrace backtrace, std::string input); -- cgit v0.12 From 895efd4e7a7090527c1e331ddbf1f8d3a06e5b7a Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 12 Apr 2024 11:48:41 -0400 Subject: cmGeneratorExpression: Consolidate recognition of transitive properties --- Source/cmGeneratorExpressionDAGChecker.cxx | 24 ++++++++++++++++-------- Source/cmGeneratorExpressionDAGChecker.h | 2 ++ Source/cmGeneratorExpressionNode.cxx | 6 ++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index 5343c98..fda7ec3 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -37,16 +37,19 @@ cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker( , Content(content) , Backtrace(std::move(backtrace)) { - const auto* top = this->Top; - this->CheckResult = this->CheckGraph(); + if (parent) { + this->TopIsTransitiveProperty = parent->TopIsTransitiveProperty; + } else { +#define TEST_TRANSITIVE_PROPERTY_METHOD(METHOD) this->METHOD() || + this->TopIsTransitiveProperty = (CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD( + TEST_TRANSITIVE_PROPERTY_METHOD) false); // NOLINT(*) +#undef TEST_TRANSITIVE_PROPERTY_METHOD + } -#define TEST_TRANSITIVE_PROPERTY_METHOD(METHOD) top->METHOD() || + this->CheckResult = this->CheckGraph(); - if (this->CheckResult == DAG && - (CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD( - TEST_TRANSITIVE_PROPERTY_METHOD) false)) // NOLINT(*) -#undef TEST_TRANSITIVE_PROPERTY_METHOD - { + if (this->CheckResult == DAG && this->EvaluatingTransitiveProperty()) { + const auto* top = this->Top; auto it = top->Seen.find(this->Target); if (it != top->Seen.end()) { const std::set& propSet = it->second; @@ -139,6 +142,11 @@ bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnlyCMP0131() return this->Top->CMP0131; } +bool cmGeneratorExpressionDAGChecker::EvaluatingTransitiveProperty() const +{ + return this->TopIsTransitiveProperty; +} + bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression() const { // Corresponds to GenexEvaluator::EvaluateExpression. diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index 2f88386..068ba6b 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -66,6 +66,7 @@ struct cmGeneratorExpressionDAGChecker void ReportError(cmGeneratorExpressionContext* context, const std::string& expr); + bool EvaluatingTransitiveProperty() const; bool EvaluatingGenexExpression() const; bool EvaluatingPICExpression() const; bool EvaluatingCompileExpression() const; @@ -109,4 +110,5 @@ private: Result CheckResult; bool TransitivePropertiesOnly = false; bool CMP0131 = false; + bool TopIsTransitiveProperty = false; }; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 1ac658c..0df086b 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -2916,10 +2916,8 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode return std::string(); } } else { -#define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) dagCheckerParent->METHOD() || - assert(CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD( - ASSERT_TRANSITIVE_PROPERTY_METHOD) false); // NOLINT(clang-tidy) -#undef ASSERT_TRANSITIVE_PROPERTY_METHOD + assert(dagCheckerParent + ->EvaluatingTransitiveProperty()); // NOLINT(clang-tidy) } } -- cgit v0.12