diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmMessageCommand.cxx | 25 | ||||
-rw-r--r-- | Source/cmake.cxx | 2 | ||||
-rw-r--r-- | Source/cmake.h | 5 | ||||
-rw-r--r-- | Source/cmakemain.cxx | 1 |
4 files changed, 25 insertions, 8 deletions
diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 5fee5ca..24ac71a 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -112,16 +112,25 @@ bool cmMessageCommand(std::vector<std::string> const& args, auto message = cmJoin(cmMakeRange(i, args.cend()), ""); if (cmake::LogLevel::LOG_NOTICE <= level) { - // Check if any indentation has requested: - // `CMAKE_MESSAGE_INDENT` is a list of "padding" pieces - // to be joined and prepended to the message lines. auto indent = cmJoin(cmExpandedList(mf.GetSafeDefinition("CMAKE_MESSAGE_INDENT")), ""); - // Make every line of the `message` indented - // NOTE Can't reuse `cmDocumentationFormatter::PrintPreformatted` - // here cuz it appends `\n` to the EOM ;-( - cmSystemTools::ReplaceString(message, "\n", "\n" + indent); - message = indent + message; + if (!indent.empty()) { + cmSystemTools::ReplaceString(message, "\n", "\n" + indent); + message = indent + message; + } + + const auto showContext = mf.GetCMakeInstance()->GetShowLogContext() || + mf.IsOn("CMAKE_MESSAGE_CONTEXT_SHOW"); + if (showContext) { + // Output the current context (if any) + auto context = cmJoin( + cmExpandedList(mf.GetSafeDefinition("CMAKE_MESSAGE_CONTEXT")), "."); + if (!context.empty()) { + context = "[" + context + "] "; + cmSystemTools::ReplaceString(message, "\n", "\n" + context); + message = context + message; + } + } } switch (level) { diff --git a/Source/cmake.cxx b/Source/cmake.cxx index eb35aba..563d077 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -746,6 +746,8 @@ void cmake::SetArgs(const std::vector<std::string>& args) } this->SetLogLevel(logLevel); this->LogLevelWasSetViaCLI = true; + } else if (arg == "--log-context") { + this->SetShowLogContext(true); } else if (arg.find("--trace-expand", 0) == 0) { std::cout << "Running with expanded trace output on.\n"; this->SetTrace(true); diff --git a/Source/cmake.h b/Source/cmake.h index 1cf3592..c2f2cce 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -391,6 +391,10 @@ public: bool GetDebugOutput() { return this->DebugOutput; } void SetDebugOutputOn(bool b) { this->DebugOutput = b; } + //! Should `message` command display context. + bool GetShowLogContext() const { return this->LogContext; } + void SetShowLogContext(bool b) { this->LogContext = b; } + //! Do we want trace output during the cmake run. bool GetTrace() { return this->Trace; } void SetTrace(bool b) { this->Trace = b; } @@ -590,6 +594,7 @@ private: LogLevel MessageLogLevel = LogLevel::LOG_STATUS; bool LogLevelWasSetViaCLI = false; + bool LogContext = false; void UpdateConversionPathTable(); diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 6d3e6ee..baf975e 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -73,6 +73,7 @@ const char* cmDocumentationOptions[][2] = { { "--log-level=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE>", "Set the verbosity of messages from CMake files. " "--loglevel is also accepted for backward compatibility reasons." }, + { "--log-context", "Prepend log messages with context, if given" }, { "--debug-trycompile", "Do not delete the try_compile build tree. Only " "useful on one try_compile at a time." }, |