diff options
author | Peter Würth <wuerth.peter@freenet.de> | 2022-11-18 11:29:47 (GMT) |
---|---|---|
committer | Peter Würth <wuerth.peter@freenet.de> | 2022-11-19 12:32:56 (GMT) |
commit | 26d813092bffdcda77976ab5ba59c114e3e2fda5 (patch) | |
tree | 13704e2e7a4ca069d7ff331fece81150929bd580 /Source | |
parent | 60a5a39022c8c2504173d635732110b2550b7f91 (diff) | |
download | CMake-26d813092bffdcda77976ab5ba59c114e3e2fda5.zip CMake-26d813092bffdcda77976ab5ba59c114e3e2fda5.tar.gz CMake-26d813092bffdcda77976ab5ba59c114e3e2fda5.tar.bz2 |
add_custom_{command,target}: add genex support for COMMENT
Evaluate and expand generator expressions in the `COMMENT` argument of
the `add_custom_command()` and `add_custom_target()` commands.
This allows to include generator expressions, e.g. a targets location
$<TARGET_...> or the current configuration $<CONFIG>, in the build-time
messages.
Fixes #22507
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCustomCommandGenerator.cxx | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 54f0bab..14c22e3 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -148,6 +148,14 @@ std::string EvaluateDepfile(std::string const& path, std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(path); return cge->Evaluate(lg, config); } + +std::string EvaluateComment(const char* comment, + cmGeneratorExpression const& ge, + cmLocalGenerator* lg, std::string const& config) +{ + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(comment); + return cge->Evaluate(lg, config); +} } cmCustomCommandGenerator::cmCustomCommandGenerator( @@ -465,10 +473,17 @@ std::string cmCustomCommandGenerator::GetInternalDepfile() const cm::optional<std::string> cmCustomCommandGenerator::GetComment() const { - if (const char* comment = this->CC->GetComment()) { - return comment; + const char* comment = this->CC->GetComment(); + if (!comment) { + return cm::nullopt; + } + if (!*comment) { + return std::string(); } - return cm::nullopt; + + cmGeneratorExpression ge(*this->LG->GetCMakeInstance(), + this->CC->GetBacktrace()); + return EvaluateComment(comment, ge, this->LG, this->OutputConfig); } std::string cmCustomCommandGenerator::GetWorkingDirectory() const |