summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-11-22 14:47:50 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-11-22 14:47:59 (GMT)
commit62172b4ab7dd06375b95f1ee9d467c015acd6c01 (patch)
tree3a6e8bf8cecd107f3954c886ef30bd4376238712 /Source
parenta449a840bdbb321433c3e5049323628816e8032f (diff)
parent26d813092bffdcda77976ab5ba59c114e3e2fda5 (diff)
downloadCMake-62172b4ab7dd06375b95f1ee9d467c015acd6c01.zip
CMake-62172b4ab7dd06375b95f1ee9d467c015acd6c01.tar.gz
CMake-62172b4ab7dd06375b95f1ee9d467c015acd6c01.tar.bz2
Merge topic 'custom-command-comment-genex'
26d813092b add_custom_{command,target}: add genex support for COMMENT 60a5a39022 cmCustomCommandGenerator: refactor GetComment to return std::string Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !7887
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCustomCommandGenerator.cxx22
-rw-r--r--Source/cmCustomCommandGenerator.h2
-rw-r--r--Source/cmGhsMultiTargetGenerator.cxx7
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx5
-rw-r--r--Source/cmLocalGenerator.cxx4
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx6
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx6
7 files changed, 36 insertions, 16 deletions
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx
index 57b009a..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(
@@ -463,9 +471,19 @@ std::string cmCustomCommandGenerator::GetInternalDepfile() const
return this->ComputeInternalDepfile(this->OutputConfig, depfile);
}
-const char* cmCustomCommandGenerator::GetComment() const
+cm::optional<std::string> cmCustomCommandGenerator::GetComment() const
{
- return this->CC->GetComment();
+ const char* comment = this->CC->GetComment();
+ if (!comment) {
+ return cm::nullopt;
+ }
+ if (!*comment) {
+ return std::string();
+ }
+
+ cmGeneratorExpression ge(*this->LG->GetCMakeInstance(),
+ this->CC->GetBacktrace());
+ return EvaluateComment(comment, ge, this->LG, this->OutputConfig);
}
std::string cmCustomCommandGenerator::GetWorkingDirectory() const
diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h
index 73a8d38..4453654 100644
--- a/Source/cmCustomCommandGenerator.h
+++ b/Source/cmCustomCommandGenerator.h
@@ -58,7 +58,7 @@ public:
unsigned int GetNumberOfCommands() const;
std::string GetCommand(unsigned int c) const;
void AppendArguments(unsigned int c, std::string& cmd) const;
- const char* GetComment() const;
+ cm::optional<std::string> GetComment() const;
std::string GetWorkingDirectory() const;
std::vector<std::string> const& GetOutputs() const;
std::vector<std::string> const& GetByproducts() const;
diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index 138d3f1..8471dfe 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -9,6 +9,8 @@
#include <utility>
#include <vector>
+#include <cm/optional>
+
#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmGeneratedFileStream.h"
@@ -411,9 +413,8 @@ void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
cmdLines.push_back("@echo off");
#endif
// Echo the custom command's comment text.
- const char* comment = ccg.GetComment();
- if (comment && *comment) {
- std::string echocmd = cmStrCat("echo ", comment);
+ if (cm::optional<std::string> comment = ccg.GetComment()) {
+ std::string echocmd = cmStrCat("echo ", *comment);
cmdLines.push_back(std::move(echocmd));
}
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index aeb5074..e928551 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -13,6 +13,7 @@
#include <utility>
#include <cm/memory>
+#include <cm/optional>
#include <cmext/algorithm>
#include <cmext/string_view>
@@ -2280,11 +2281,11 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
}
makefileStream << "\n";
- if (const char* comment = ccg.GetComment()) {
+ if (cm::optional<std::string> comment = ccg.GetComment()) {
std::string echo_cmd =
cmStrCat("echo ",
(this->CurrentLocalGenerator->EscapeForShell(
- comment, ccg.GetCC().GetEscapeAllowMakeVars())));
+ *comment, ccg.GetCC().GetEscapeAllowMakeVars())));
makefileStream << "\t" << echo_cmd << "\n";
}
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 4d5371f..5bf9d32 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -3474,8 +3474,8 @@ std::string cmLocalGenerator::ConstructComment(
cmCustomCommandGenerator const& ccg, const char* default_comment) const
{
// Check for a comment provided with the command.
- if (ccg.GetComment()) {
- return ccg.GetComment();
+ if (cm::optional<std::string> comment = ccg.GetComment()) {
+ return *comment;
}
// Construct a reasonable default comment if possible.
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index de1d3cd..7172d34 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -10,6 +10,7 @@
#include <utility>
#include <cm/memory>
+#include <cm/optional>
#include <cm/string_view>
#include <cm/vector>
#include <cmext/algorithm>
@@ -945,9 +946,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
// post-build command comments. Custom build step commands have
// their comments generated elsewhere.
if (echo_comment) {
- const char* comment = ccg.GetComment();
- if (comment && *comment) {
- this->AppendEcho(commands, comment,
+ if (cm::optional<std::string> comment = ccg.GetComment()) {
+ this->AppendEcho(commands, *comment,
cmLocalUnixMakefileGenerator3::EchoGenerate);
}
}
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index 383045d..538c036 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -10,6 +10,7 @@
#include <utility>
#include <cm/memory>
+#include <cm/optional>
#include <cmext/algorithm>
#include <windows.h>
@@ -592,9 +593,8 @@ public:
{
cmCustomCommandGenerator ccg(cc, this->Config, this->LG);
if (this->First) {
- const char* comment = ccg.GetComment();
- if (comment && *comment) {
- this->Stream << "\nDescription=\"" << this->LG->EscapeForXML(comment)
+ if (cm::optional<std::string> comment = ccg.GetComment()) {
+ this->Stream << "\nDescription=\"" << this->LG->EscapeForXML(*comment)
<< "\"";
}
this->Stream << "\nCommandLine=\"";