diff options
author | Brad King <brad.king@kitware.com> | 2023-05-05 16:42:08 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-05-05 16:42:23 (GMT) |
commit | 5924630e6d4a383ef76412a6f560fbe852837e50 (patch) | |
tree | fbab8184157448c3251e09feee8e4ce5c0b6234e /Source | |
parent | 2b5b09556c08bdbcd949e600daa3059f63da240a (diff) | |
parent | c42630ee62df80e649211e99c510cab7ac28fc0b (diff) | |
download | CMake-5924630e6d4a383ef76412a6f560fbe852837e50.zip CMake-5924630e6d4a383ef76412a6f560fbe852837e50.tar.gz CMake-5924630e6d4a383ef76412a6f560fbe852837e50.tar.bz2 |
Merge topic 'compile-only-genex'
c42630ee62 cmGeneratorExpressionNode: implement `COMPILE_ONLY` genex
0fb923c460 cmGeneratorExpressionNode: implement `COMPILE_ONLY` genex
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !8411
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmExportFileGenerator.cxx | 16 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionDAGChecker.cxx | 8 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionDAGChecker.h | 4 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 25 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 4 | ||||
-rw-r--r-- | Source/cmTargetLinkLibrariesCommand.cxx | 1 |
6 files changed, 56 insertions, 2 deletions
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 2ad2b47..22276ae 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -735,6 +735,22 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpression( lastPos = nameStartPos + libName.size() + 1; } + while (errorString.empty() && + (pos = input.find("$<COMPILE_ONLY:", lastPos)) != std::string::npos) { + std::string::size_type nameStartPos = pos + cmStrLen("$<COMPILE_ONLY:"); + std::string::size_type endPos = input.find('>', nameStartPos); + if (endPos == std::string::npos) { + errorString = "$<COMPILE_ONLY:...> expression incomplete"; + break; + } + std::string libName = input.substr(nameStartPos, endPos - nameStartPos); + if (cmGeneratorExpression::IsValidTargetName(libName) && + this->AddTargetNamespace(libName, target, lg)) { + input.replace(nameStartPos, endPos - nameStartPos, libName); + } + lastPos = nameStartPos + libName.size() + 1; + } + this->ReplaceInstallPrefix(input); if (!errorString.empty()) { 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 4f5a663..bb4fc7e 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -2046,6 +2046,28 @@ static const VersionNode<cmSystemTools::OP_LESS> versionLessNode; static const VersionNode<cmSystemTools::OP_LESS_EQUAL> versionLessEqNode; static const VersionNode<cmSystemTools::OP_EQUAL> versionEqualNode; +static const struct CompileOnlyNode : public cmGeneratorExpressionNode +{ + CompileOnlyNode() {} // NOLINT(modernize-use-equals-default) + + std::string Evaluate( + const std::vector<std::string>& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override + { + if (!dagChecker) { + reportError(context, content->GetOriginalExpression(), + "$<COMPILE_ONLY:...> may only be used for linking"); + return std::string(); + } + if (dagChecker->GetTransitivePropertiesOnly()) { + return parameters.front(); + } + return std::string{}; + } +} compileOnlyNode; + static const struct LinkOnlyNode : public cmGeneratorExpressionNode { LinkOnlyNode() {} // NOLINT(modernize-use-equals-default) @@ -2061,7 +2083,7 @@ static const struct LinkOnlyNode : public cmGeneratorExpressionNode "$<LINK_ONLY:...> may only be used for linking"); return std::string(); } - if (!dagChecker->GetTransitivePropertiesOnly()) { + if (!dagChecker->GetTransitivePropertiesOnlyCMP0131()) { return parameters.front(); } return std::string(); @@ -4501,6 +4523,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( { "BUILD_LOCAL_INTERFACE", &buildLocalInterfaceNode }, { "INSTALL_PREFIX", &installPrefixNode }, { "JOIN", &joinNode }, + { "COMPILE_ONLY", &compileOnlyNode }, { "LINK_ONLY", &linkOnlyNode }, { "COMPILE_LANG_AND_ID", &languageAndIdNode }, { "COMPILE_LANGUAGE", &languageNode }, diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 897619c..28ba60f 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 }; @@ -8228,6 +8229,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: @@ -8235,7 +8237,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::NEW: - dagChecker.SetTransitivePropertiesOnly(); + dagChecker.SetTransitivePropertiesOnlyCMP0131(); break; } } diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 0b123b2..03d7c9f 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -552,6 +552,7 @@ bool TLL::HandleLibrary(ProcessingState currentProcessingState, currentProcessingState == ProcessingPlainPrivateInterface) { if (this->Target->GetType() == cmStateEnums::STATIC_LIBRARY || this->Target->GetType() == cmStateEnums::OBJECT_LIBRARY) { + // TODO: Detect and no-op `$<COMPILE_ONLY>` genexes here. std::string configLib = this->Target->GetDebugGeneratorExpressions(lib, llt); if (cmGeneratorExpression::IsValidTargetName(lib) || |