message: Add new CMAKE_MESSAGE_LOG_LEVEL variable

This commit is contained in:
Alex Turbov 2019-10-10 23:28:12 +11:00 committed by Craig Scott
parent aa59badd6f
commit 5bf85e2517
11 changed files with 64 additions and 0 deletions

@ -59,6 +59,9 @@ The :manual:`curses interface <ccmake(1)>` shows ``STATUS`` to ``TRACE``
messages one at a time on a status line and other messages in an
interactive pop-up box. The ``--log-level`` command-line option to each of
these tools can be used to control which messages will be shown.
To make a log level persist between CMake runs, the
:variable:`CMAKE_MESSAGE_LOG_LEVEL` variable can be set instead.
Note that the command line option takes precedence over the cache variable.
Messages of log levels ``NOTICE`` and below will also have each line preceded
by the content of the :variable:`CMAKE_MESSAGE_INDENT` variable (converted to

@ -205,6 +205,7 @@ Variables that Change Behavior
/variable/CMAKE_MFC_FLAG
/variable/CMAKE_MAXIMUM_RECURSION_DEPTH
/variable/CMAKE_MESSAGE_INDENT
/variable/CMAKE_MESSAGE_LOG_LEVEL
/variable/CMAKE_MODULE_PATH
/variable/CMAKE_POLICY_DEFAULT_CMPNNNN
/variable/CMAKE_POLICY_WARNING_CMPNNNN

@ -206,6 +206,11 @@ Options
The :command:`message` command will only output messages of the specified
log level or higher. The default log level is ``STATUS``.
To make a log level persist between CMake runs, set
:variable:`CMAKE_MESSAGE_LOG_LEVEL` as a cache variable instead.
If both the command line option and the variable are given, the command line
option takes precedence.
For backward compatibility reasons, ``--loglevel`` is also accepted as a
synonym for this option.

@ -0,0 +1,6 @@
feature-CMAKE_MESSAGE_CONTEXT
-----------------------------
* The :variable:`CMAKE_MESSAGE_LOG_LEVEL` variable can now be used
to persist a log level between CMake runs, unlike the ``--log-level``
command line option which only applies to that particular run.

@ -0,0 +1,15 @@
CMAKE_MESSAGE_LOG_LEVEL
-----------------------
When set, this variable specifies the logging level used by the
:command:`message` command. Valid values are the same as those for the
``--log-level`` command line option of the :manual:`cmake(1)` program.
If this variable is set and the ``--log-level`` command line option is
given, the command line option takes precedence.
The main advantage to using this variable is to make a log level persist
between CMake runs. Setting it as a cache variable will ensure that
subsequent CMake runs will continue to use the chosen log level.
Projects should not set this variable, it is intended for users so that
they may control the log level according to their own needs.

@ -95,6 +95,15 @@ bool cmMessageCommand(std::vector<std::string> const& args,
assert("Expected a valid log level here" &&
desiredLevel != cmake::LogLevel::LOG_UNDEFINED);
// Command line option takes precedence over the cache variable
if (!mf.GetCMakeInstance()->WasLogLevelSetViaCLI()) {
const auto desiredLevelFromCache =
cmake::StringToLogLevel(mf.GetSafeDefinition("CMAKE_MESSAGE_LOG_LEVEL"));
if (desiredLevelFromCache != cmake::LogLevel::LOG_UNDEFINED) {
desiredLevel = desiredLevelFromCache;
}
}
if (desiredLevel < level) {
// Suppress the message
return true;

@ -733,6 +733,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
return;
}
this->SetLogLevel(logLevel);
this->LogLevelWasSetViaCLI = true;
} else if (arg.find("--loglevel=", 0) == 0) {
// This is supported for backward compatibility. This option only
// appeared in the 3.15.x release series and was renamed to
@ -744,6 +745,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
return;
}
this->SetLogLevel(logLevel);
this->LogLevelWasSetViaCLI = true;
} else if (arg.find("--trace-expand", 0) == 0) {
std::cout << "Running with expanded trace output on.\n";
this->SetTrace(true);

@ -380,6 +380,8 @@ public:
*/
cmFileTimeCache* GetFileTimeCache() { return this->FileTimeCache.get(); }
bool WasLogLevelSetViaCLI() const { return this->LogLevelWasSetViaCLI; }
//! Get the selected log level for `message()` commands during the cmake run.
LogLevel GetLogLevel() const { return this->MessageLogLevel; }
void SetLogLevel(LogLevel level) { this->MessageLogLevel = level; }
@ -587,6 +589,7 @@ private:
std::vector<std::string> TraceOnlyThisSources;
LogLevel MessageLogLevel = LogLevel::LOG_STATUS;
bool LogLevelWasSetViaCLI = false;
void UpdateConversionPathTable();

@ -55,6 +55,11 @@ foreach(opt IN ITEMS loglevel log-level)
)
endforeach()
run_cmake_command(
message-log-level-override
${CMAKE_COMMAND} --log-level=debug -DCMAKE_MESSAGE_LOG_LEVEL=TRACE -P ${RunCMake_SOURCE_DIR}/message-all-loglevels.cmake
)
run_cmake_command(
message-indent
${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/message-indent.cmake

@ -0,0 +1,12 @@
^CMake Deprecation Warning at.*/Tests/RunCMake/message/message-all-loglevels\.cmake:2 \(message\):
Deprecation warning
+
CMake Warning \(dev\) at.*/Tests/RunCMake/message/message-all-loglevels\.cmake:3 \(message\):
Author warning message
This warning is for project developers\. Use -Wno-dev to suppress it\.
+
CMake Warning at.*/Tests/RunCMake/message/message-all-loglevels\.cmake:4 \(message\):
Warning message
+
Default NOTICE message
NOTICE message$

@ -0,0 +1,3 @@
-- STATUS message
-- VERBOSE message
-- DEBUG message$