summaryrefslogtreecommitdiff
path: root/Source/cmake.cxx
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2019-04-27 17:31:03 +1000
committerCraig Scott <craig.scott@crascit.com>2019-04-28 22:45:44 +1000
commit6cc93b370ef59208b9b468ebc9d84cc02e3cbd85 (patch)
treed3dfd8c1ae2826e369ce504ffb483388cb6ddeaf /Source/cmake.cxx
parent377d1b7896e07a171bcfe8da6d9dcda6545052c2 (diff)
downloadcmake-6cc93b370ef59208b9b468ebc9d84cc02e3cbd85.tar.gz
message(): Add support for log levels
Relates: #18943 Co-Authored-By: Craig Scott <craig.scott@crascit.com>
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r--Source/cmake.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index fc24ac08ca..121d12d931 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -718,6 +718,14 @@ void cmake::SetArgs(const std::vector<std::string>& args)
} else if (arg.find("--debug-output", 0) == 0) {
std::cout << "Running with debug output on.\n";
this->SetDebugOutputOn(true);
+ } else if (arg.find("--loglevel=", 0) == 0) {
+ const auto logLevel =
+ StringToLogLevel(arg.substr(sizeof("--loglevel=") - 1));
+ if (logLevel == LogLevel::LOG_UNDEFINED) {
+ cmSystemTools::Error("Invalid level specified for --loglevel");
+ return;
+ }
+ this->SetLogLevel(logLevel);
} else if (arg.find("--trace-expand", 0) == 0) {
std::cout << "Running with expanded trace output on.\n";
this->SetTrace(true);
@@ -828,6 +836,25 @@ void cmake::SetArgs(const std::vector<std::string>& args)
}
}
+cmake::LogLevel cmake::StringToLogLevel(const std::string& levelStr)
+{
+ using LevelsPair = std::pair<std::string, LogLevel>;
+ static const std::vector<LevelsPair> levels = {
+ { "error", LogLevel::LOG_ERROR }, { "warning", LogLevel::LOG_WARNING },
+ { "notice", LogLevel::LOG_NOTICE }, { "status", LogLevel::LOG_STATUS },
+ { "verbose", LogLevel::LOG_VERBOSE }, { "debug", LogLevel::LOG_DEBUG },
+ { "trace", LogLevel::LOG_TRACE }
+ };
+
+ const auto levelStrLowCase = cmSystemTools::LowerCase(levelStr);
+
+ const auto it = std::find_if(levels.cbegin(), levels.cend(),
+ [&levelStrLowCase](const LevelsPair& p) {
+ return p.first == levelStrLowCase;
+ });
+ return (it != levels.cend()) ? it->second : LogLevel::LOG_UNDEFINED;
+}
+
void cmake::SetDirectoriesFromFile(const char* arg)
{
// Check if the argument refers to a CMakeCache.txt or