From 5bf85e25178f5d9f19d2f30cf66f088c21e1114a Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Thu, 10 Oct 2019 23:28:12 +1100 Subject: message: Add new CMAKE_MESSAGE_LOG_LEVEL variable --- Help/command/message.rst | 3 +++ Help/manual/cmake-variables.7.rst | 1 + Help/manual/cmake.1.rst | 5 +++++ Help/release/dev/feature-CMAKE_MESSAGE_CONTEXT | 6 ++++++ Help/variable/CMAKE_MESSAGE_LOG_LEVEL.rst | 15 +++++++++++++++ Source/cmMessageCommand.cxx | 9 +++++++++ Source/cmake.cxx | 2 ++ Source/cmake.h | 3 +++ Tests/RunCMake/message/RunCMakeTest.cmake | 5 +++++ .../message/message-log-level-override-stderr.txt | 12 ++++++++++++ .../message/message-log-level-override-stdout.txt | 3 +++ 11 files changed, 64 insertions(+) create mode 100644 Help/release/dev/feature-CMAKE_MESSAGE_CONTEXT create mode 100644 Help/variable/CMAKE_MESSAGE_LOG_LEVEL.rst create mode 100644 Tests/RunCMake/message/message-log-level-override-stderr.txt create mode 100644 Tests/RunCMake/message/message-log-level-override-stdout.txt diff --git a/Help/command/message.rst b/Help/command/message.rst index c614286..1acf30a 100644 --- a/Help/command/message.rst +++ b/Help/command/message.rst @@ -59,6 +59,9 @@ The :manual:`curses interface ` 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 diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 9b24b5a..782a0f0 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -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 diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 4ab55a0..08b7534 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -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. diff --git a/Help/release/dev/feature-CMAKE_MESSAGE_CONTEXT b/Help/release/dev/feature-CMAKE_MESSAGE_CONTEXT new file mode 100644 index 0000000..eb24e20 --- /dev/null +++ b/Help/release/dev/feature-CMAKE_MESSAGE_CONTEXT @@ -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. diff --git a/Help/variable/CMAKE_MESSAGE_LOG_LEVEL.rst b/Help/variable/CMAKE_MESSAGE_LOG_LEVEL.rst new file mode 100644 index 0000000..1d4cfe6 --- /dev/null +++ b/Help/variable/CMAKE_MESSAGE_LOG_LEVEL.rst @@ -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. diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 15c007c..5fee5ca 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -95,6 +95,15 @@ bool cmMessageCommand(std::vector 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; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 50f47af..eb35aba 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -733,6 +733,7 @@ void cmake::SetArgs(const std::vector& 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& 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); diff --git a/Source/cmake.h b/Source/cmake.h index 687c105..1cf3592 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -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 TraceOnlyThisSources; LogLevel MessageLogLevel = LogLevel::LOG_STATUS; + bool LogLevelWasSetViaCLI = false; void UpdateConversionPathTable(); diff --git a/Tests/RunCMake/message/RunCMakeTest.cmake b/Tests/RunCMake/message/RunCMakeTest.cmake index 9198a25..50271d4 100644 --- a/Tests/RunCMake/message/RunCMakeTest.cmake +++ b/Tests/RunCMake/message/RunCMakeTest.cmake @@ -56,6 +56,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 ) diff --git a/Tests/RunCMake/message/message-log-level-override-stderr.txt b/Tests/RunCMake/message/message-log-level-override-stderr.txt new file mode 100644 index 0000000..efec736 --- /dev/null +++ b/Tests/RunCMake/message/message-log-level-override-stderr.txt @@ -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$ diff --git a/Tests/RunCMake/message/message-log-level-override-stdout.txt b/Tests/RunCMake/message/message-log-level-override-stdout.txt new file mode 100644 index 0000000..feee110 --- /dev/null +++ b/Tests/RunCMake/message/message-log-level-override-stdout.txt @@ -0,0 +1,3 @@ +-- STATUS message +-- VERBOSE message +-- DEBUG message$ -- cgit v0.12