diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 47e1731ac..1b0a99ae8 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 fa1534d95..362ea75fb 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 2854a82bd..1c65ef7dd 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 ee1e87866..62476a11a 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 c584ad97e..0630daa84 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 bcc97be65..582ab4dd7 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 5c4456637..e60af6e43 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 4c421a129..53f2a4364 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")