summaryrefslogtreecommitdiffstats
path: root/Source/cmMessageCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-01-16 19:32:36 (GMT)
committerBrad King <brad.king@kitware.com>2023-01-18 16:37:11 (GMT)
commita78cba51978fbc805993604767c1902a249482ff (patch)
treeb4df0181bf56b68135e52c3745f60ab10c9d229c /Source/cmMessageCommand.cxx
parent645671d36f5cf0fa411d98a637f4edbc3d896c57 (diff)
downloadCMake-a78cba51978fbc805993604767c1902a249482ff.zip
CMake-a78cba51978fbc805993604767c1902a249482ff.tar.gz
CMake-a78cba51978fbc805993604767c1902a249482ff.tar.bz2
message: Add CONFIGURE_LOG mode to record a message in the configure log
Provide a replacement for `file(APPEND .../CMake{Output,Error}.log)` that records messages in the configure log. Issue: #23200
Diffstat (limited to 'Source/cmMessageCommand.cxx')
-rw-r--r--Source/cmMessageCommand.cxx28
1 files changed, 28 insertions, 0 deletions
diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx
index fa29ec9..205f01f 100644
--- a/Source/cmMessageCommand.cxx
+++ b/Source/cmMessageCommand.cxx
@@ -8,6 +8,7 @@
#include <cm/string_view>
#include <cmext/string_view>
+#include "cmConfigureLog.h"
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
@@ -64,6 +65,25 @@ void ReportCheckResult(cm::string_view what, std::string result,
}
}
+namespace {
+#ifndef CMAKE_BOOTSTRAP
+void WriteMessageEvent(cmConfigureLog& log, cmMakefile const& mf,
+ std::string const& message)
+{
+ // Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames.
+ static const std::vector<unsigned long> LogVersionsWithMessageV1{ 1 };
+
+ if (log.IsAnyLogVersionEnabled(LogVersionsWithMessageV1)) {
+ log.BeginEvent("message-v1");
+ log.WriteBacktrace(mf);
+ log.WriteChecks(mf);
+ log.WriteLiteralTextBlock("message"_s, message);
+ log.EndEvent();
+ }
+}
+#endif
+}
+
} // anonymous namespace
// cmLibraryCommand
@@ -121,6 +141,14 @@ bool cmMessageCommand(std::vector<std::string> const& args,
level = Message::LogLevel::LOG_STATUS;
checkingType = CheckingType::CHECK_FAIL;
++i;
+ } else if (*i == "CONFIGURE_LOG") {
+#ifndef CMAKE_BOOTSTRAP
+ if (cmConfigureLog* log = mf.GetCMakeInstance()->GetConfigureLog()) {
+ ++i;
+ WriteMessageEvent(*log, mf, cmJoin(cmMakeRange(i, args.cend()), ""_s));
+ }
+#endif
+ return true;
} else if (*i == "STATUS") {
level = Message::LogLevel::LOG_STATUS;
++i;