diff options
author | Robert Maynard <rmaynard@nvidia.com> | 2023-04-11 19:49:52 (GMT) |
---|---|---|
committer | Robert Maynard <rmaynard@nvidia.com> | 2023-05-04 13:39:06 (GMT) |
commit | c42630ee62df80e649211e99c510cab7ac28fc0b (patch) | |
tree | 8b450a62d4e4c9559b8fe03b11575bde8d154608 /Source | |
parent | 0fb923c46041d67110c8e0907afdf66b3b25f25a (diff) | |
download | CMake-c42630ee62df80e649211e99c510cab7ac28fc0b.zip CMake-c42630ee62df80e649211e99c510cab7ac28fc0b.tar.gz CMake-c42630ee62df80e649211e99c510cab7ac28fc0b.tar.bz2 |
cmGeneratorExpressionNode: implement `COMPILE_ONLY` genex
This generator expression is the inverse of `LINK_ONLY` and only coveys
usage requirements for the purposes of compilation. Its intended use is
to avoid needing to export targets that do not have link usage
requirements (e.g., header-only libraries) when used by another target.
See: #15415
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorExpressionDAGChecker.cxx | 8 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionDAGChecker.h | 4 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 8 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 4 |
4 files changed, 18 insertions, 6 deletions
diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index 82a6c57..d51dbd0 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -27,6 +27,7 @@ cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker( , Content(content) , Backtrace(std::move(backtrace)) , TransitivePropertiesOnly(false) + , CMP0131(false) { this->Initialize(); } @@ -41,6 +42,7 @@ cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker( , Content(content) , Backtrace() , TransitivePropertiesOnly(false) + , CMP0131(false) { this->Initialize(); } @@ -143,6 +145,12 @@ bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnly() const return this->Top()->TransitivePropertiesOnly; } +bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnlyCMP0131() + const +{ + return this->Top()->CMP0131; +} + bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression() const { return cmHasLiteralPrefix(this->Property, "TARGET_GENEX_EVAL:") || diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index df1e005..1919b01 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -90,6 +90,9 @@ struct cmGeneratorExpressionDAGChecker bool GetTransitivePropertiesOnly() const; void SetTransitivePropertiesOnly() { this->TransitivePropertiesOnly = true; } + bool GetTransitivePropertiesOnlyCMP0131() const; + void SetTransitivePropertiesOnlyCMP0131() { this->CMP0131 = true; } + cmGeneratorExpressionDAGChecker const* Top() const; cmGeneratorTarget const* TopTarget() const; @@ -105,4 +108,5 @@ private: const cmListFileBacktrace Backtrace; Result CheckResult; bool TransitivePropertiesOnly; + bool CMP0131; }; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index a221498..ca61f75 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -1363,14 +1363,13 @@ static const struct CompileOnlyNode : public cmGeneratorExpressionNode { if (!dagChecker) { reportError(context, content->GetOriginalExpression(), - "$<COMPILE_ONLY:...> may only be used via linking"); + "$<COMPILE_ONLY:...> may only be used for linking"); return std::string(); } - // Linking checks for the inverse, so compiling is the opposite. if (dagChecker->GetTransitivePropertiesOnly()) { return parameters.front(); } - return std::string(); + return std::string{}; } } compileOnlyNode; @@ -1389,8 +1388,7 @@ static const struct LinkOnlyNode : public cmGeneratorExpressionNode "$<LINK_ONLY:...> may only be used for linking"); return std::string(); } - // Compile-only checks for the inverse, so linking is the opposite. - if (!dagChecker->GetTransitivePropertiesOnly()) { + if (!dagChecker->GetTransitivePropertiesOnlyCMP0131()) { return parameters.front(); } return std::string(); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 90cddb5..7e5ef0a 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -6791,6 +6791,7 @@ void cmGeneratorTarget::ExpandLinkItems( // requirements. if (interfaceFor == LinkInterfaceFor::Usage) { dagChecker.SetTransitivePropertiesOnly(); + dagChecker.SetTransitivePropertiesOnlyCMP0131(); } cmMakefile const* mf = this->LocalGenerator->GetMakefile(); LookupLinkItemScope scope{ this->LocalGenerator }; @@ -8229,6 +8230,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( // The $<LINK_ONLY> expression may be used to specify link dependencies // that are otherwise excluded from usage requirements. if (implFor == LinkInterfaceFor::Usage) { + dagChecker.SetTransitivePropertiesOnly(); switch (this->GetPolicyStatusCMP0131()) { case cmPolicies::WARN: case cmPolicies::OLD: @@ -8236,7 +8238,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::NEW: - dagChecker.SetTransitivePropertiesOnly(); + dagChecker.SetTransitivePropertiesOnlyCMP0131(); break; } } |