diff options
author | Michael Scott <michael.scott250@gmail.com> | 2015-11-08 12:20:47 +0000 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-11-30 15:00:08 -0500 |
commit | deec3a3f06d341cfe0bef4e856b263eff347cc72 (patch) | |
tree | 3eb1f0268a400ea4fd0573c6431825ecaa0b392c | |
parent | aa427a4239eb691d4129ebc383ab7b0d61b5b94e (diff) | |
download | cmake-deec3a3f06d341cfe0bef4e856b263eff347cc72.tar.gz |
Make message suppression more consistent.
Make the message suppression more consistent, by adding a check
for the message related CMake variables in cmake::IssueMessage,
which allows callers of IssueMessage other than the message
command to behave as expected. Also added a check for
CMAKE_SUPPRESS_DEVELOPER_WARNINGS in the message command to
mirror the deprecated message type behaviour.
Added a 'force' flag to the cmake::IssueMessage method, to
make the message suppression consistent, when setting the
message related CMake variables directly in a CMake file.
Expand message command tests to cover the AUTHOR_WARNING message
type as well.
-rw-r--r-- | Source/cmMakefile.cxx | 8 | ||||
-rw-r--r-- | Source/cmMakefile.h | 3 | ||||
-rw-r--r-- | Source/cmMessageCommand.cxx | 12 | ||||
-rw-r--r-- | Source/cmake.cxx | 70 | ||||
-rw-r--r-- | Source/cmake.h | 12 | ||||
-rw-r--r-- | Tests/RunCMake/message/nomessage.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/message/warnmessage-stderr.txt | 11 | ||||
-rw-r--r-- | Tests/RunCMake/message/warnmessage.cmake | 6 |
8 files changed, 102 insertions, 24 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 47e1731ac6..1b0a99ae84 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -105,7 +105,8 @@ cmMakefile::~cmMakefile() //---------------------------------------------------------------------------- void cmMakefile::IssueMessage(cmake::MessageType t, - std::string const& text) const + std::string const& text, + bool force) const { // Collect context information. if(!this->ExecutionStatusStack.empty()) @@ -114,7 +115,8 @@ void cmMakefile::IssueMessage(cmake::MessageType t, { this->ExecutionStatusStack.back()->SetNestedError(true); } - this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace()); + this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace(), + force); } else { @@ -129,7 +131,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t, lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); } lfc.Line = 0; - this->GetCMakeInstance()->IssueMessage(t, text, lfc); + this->GetCMakeInstance()->IssueMessage(t, text, lfc, force); } } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index fa1534d957..362ea75fb5 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -709,7 +709,8 @@ public: }; void IssueMessage(cmake::MessageType t, - std::string const& text) const; + std::string const& text, + bool force = false) const; /** Set whether or not to report a CMP0000 violation. */ void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; } diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 2854a82bd3..1c65ef7dd0 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -43,7 +43,14 @@ bool cmMessageCommand } else if (*i == "AUTHOR_WARNING") { - type = cmake::AUTHOR_WARNING; + if (this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) + { + return true; + } + else + { + type = cmake::AUTHOR_WARNING; + } ++i; } else if (*i == "STATUS") @@ -73,7 +80,8 @@ bool cmMessageCommand if (type != cmake::MESSAGE) { - this->Makefile->IssueMessage(type, message); + // we've overriden the message type, above, so force IssueMessage to use it + this->Makefile->IssueMessage(type, message, true); } else { diff --git a/Source/cmake.cxx b/Source/cmake.cxx index ee1e878660..62476a11a1 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2485,6 +2485,45 @@ static bool cmakeCheckStampList(const char* stampList) return true; } +bool cmake::IsMessageTypeVisible(cmake::MessageType t) +{ + bool isVisible = true; + + if(t == cmake::DEPRECATION_ERROR) + { + // if CMAKE_ERROR_DEPRECATED is on, show the message, otherwise suppress it + const char* errorDeprecated = this->State->GetCacheEntryValue( + "CMAKE_ERROR_DEPRECATED"); + if(cmSystemTools::IsOff(errorDeprecated)) + { + isVisible = false; + } + } + else if (t == cmake::DEPRECATION_WARNING) + { + // if CMAKE_WARN_DEPRECATED is on, show the message, otherwise suppress it + const char* warnDeprecated = this->State->GetInitializedCacheValue( + "CMAKE_WARN_DEPRECATED"); + if(cmSystemTools::IsOff(warnDeprecated)) + { + isVisible = false; + } + } + else if (t == cmake::AUTHOR_WARNING) + { + // if CMAKE_SUPPRESS_DEVELOPER_WARNINGS is on, suppress the message, + // otherwise show it + const char* suppressDevWarnings = this->State->GetCacheEntryValue( + "CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); + if(cmSystemTools::IsOn(suppressDevWarnings)) + { + isVisible = false; + } + } + + return isVisible; +} + bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg) { // Construct the message header. @@ -2508,20 +2547,13 @@ bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg) { msg << "CMake Deprecation Warning"; } + else if (t == cmake::AUTHOR_WARNING) + { + msg << "CMake Warning (dev)"; + } else { msg << "CMake Warning"; - if(t == cmake::AUTHOR_WARNING) - { - // Allow suppression of these warnings. - const char* suppress = this->State->GetCacheEntryValue( - "CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); - if(suppress && cmSystemTools::IsOn(suppress)) - { - return false; - } - msg << " (dev)"; - } } return true; } @@ -2579,10 +2611,16 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg) //---------------------------------------------------------------------------- void cmake::IssueMessage(cmake::MessageType t, std::string const& text, - cmListFileBacktrace const& bt) + cmListFileBacktrace const& bt, + bool force) { cmListFileBacktrace backtrace = bt; + if (!force && !this->IsMessageTypeVisible(t)) + { + return; + } + std::ostringstream msg; if (!this->PrintMessagePreamble(t, msg)) { @@ -2602,8 +2640,14 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text, //---------------------------------------------------------------------------- void cmake::IssueMessage(cmake::MessageType t, std::string const& text, - cmListFileContext const& lfc) + cmListFileContext const& lfc, + bool force) { + if (!force && !this->IsMessageTypeVisible(t)) + { + return; + } + std::ostringstream msg; if (!this->PrintMessagePreamble(t, msg)) { diff --git a/Source/cmake.h b/Source/cmake.h index c584ad97e3..0630daa841 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -311,9 +311,11 @@ class cmake /** Display a message to the user. */ void IssueMessage(cmake::MessageType t, std::string const& text, - cmListFileBacktrace const& backtrace = cmListFileBacktrace()); + cmListFileBacktrace const& backtrace = cmListFileBacktrace(), + bool force = false); void IssueMessage(cmake::MessageType t, std::string const& text, - cmListFileContext const& lfc); + cmListFileContext const& lfc, + bool force = false); ///! run the --build option int Build(const std::string& dir, @@ -419,6 +421,12 @@ private: // Print a list of valid generators to stderr. void PrintGeneratorList(); + /* + * Check if messages of this type should be output, based on the state of the + * warning and error output CMake variables, in the cache. + */ + bool IsMessageTypeVisible(cmake::MessageType t); + bool PrintMessagePreamble(cmake::MessageType t, std::ostream& msg); }; diff --git a/Tests/RunCMake/message/nomessage.cmake b/Tests/RunCMake/message/nomessage.cmake index bcc97be656..582ab4dd79 100644 --- a/Tests/RunCMake/message/nomessage.cmake +++ b/Tests/RunCMake/message/nomessage.cmake @@ -1,2 +1,6 @@ message(DEPRECATION "This is not issued") + +set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON) + +message(AUTHOR_WARNING "This is not issued") diff --git a/Tests/RunCMake/message/warnmessage-stderr.txt b/Tests/RunCMake/message/warnmessage-stderr.txt index 5c44566372..e60af6e43b 100644 --- a/Tests/RunCMake/message/warnmessage-stderr.txt +++ b/Tests/RunCMake/message/warnmessage-stderr.txt @@ -1,4 +1,11 @@ -CMake Deprecation Warning at warnmessage.cmake:4 \(message\): - This is a warning +^CMake Deprecation Warning at warnmessage.cmake:4 \(message\): + This is a deprecation warning Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) + + +CMake Warning \(dev\) at warnmessage.cmake:8 \(message\): + This is a author warning +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/message/warnmessage.cmake b/Tests/RunCMake/message/warnmessage.cmake index 4c421a1299..53f2a43646 100644 --- a/Tests/RunCMake/message/warnmessage.cmake +++ b/Tests/RunCMake/message/warnmessage.cmake @@ -1,4 +1,8 @@ set(CMAKE_WARN_DEPRECATED ON) -message(DEPRECATION "This is a warning") +message(DEPRECATION "This is a deprecation warning") + +set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS OFF) + +message(AUTHOR_WARNING "This is a author warning") |