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.
This commit is contained in:
Michael Scott 2015-11-08 12:20:47 +00:00 committed by Brad King
parent aa427a4239
commit deec3a3f06
8 changed files with 102 additions and 24 deletions

View File

@ -105,7 +105,8 @@ cmMakefile::~cmMakefile()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefile::IssueMessage(cmake::MessageType t, void cmMakefile::IssueMessage(cmake::MessageType t,
std::string const& text) const std::string const& text,
bool force) const
{ {
// Collect context information. // Collect context information.
if(!this->ExecutionStatusStack.empty()) if(!this->ExecutionStatusStack.empty())
@ -114,7 +115,8 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
{ {
this->ExecutionStatusStack.back()->SetNestedError(true); this->ExecutionStatusStack.back()->SetNestedError(true);
} }
this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace()); this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace(),
force);
} }
else else
{ {
@ -129,7 +131,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
} }
lfc.Line = 0; lfc.Line = 0;
this->GetCMakeInstance()->IssueMessage(t, text, lfc); this->GetCMakeInstance()->IssueMessage(t, text, lfc, force);
} }
} }

View File

@ -709,7 +709,8 @@ public:
}; };
void IssueMessage(cmake::MessageType t, 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. */ /** Set whether or not to report a CMP0000 violation. */
void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; } void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }

View File

@ -43,7 +43,14 @@ bool cmMessageCommand
} }
else if (*i == "AUTHOR_WARNING") 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; ++i;
} }
else if (*i == "STATUS") else if (*i == "STATUS")
@ -73,7 +80,8 @@ bool cmMessageCommand
if (type != cmake::MESSAGE) 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 else
{ {

View File

@ -2485,6 +2485,45 @@ static bool cmakeCheckStampList(const char* stampList)
return true; 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) bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg)
{ {
// Construct the message header. // Construct the message header.
@ -2508,20 +2547,13 @@ bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg)
{ {
msg << "CMake Deprecation Warning"; msg << "CMake Deprecation Warning";
} }
else if (t == cmake::AUTHOR_WARNING)
{
msg << "CMake Warning (dev)";
}
else else
{ {
msg << "CMake Warning"; 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; return true;
} }
@ -2579,10 +2611,16 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmake::IssueMessage(cmake::MessageType t, std::string const& text, void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileBacktrace const& bt) cmListFileBacktrace const& bt,
bool force)
{ {
cmListFileBacktrace backtrace = bt; cmListFileBacktrace backtrace = bt;
if (!force && !this->IsMessageTypeVisible(t))
{
return;
}
std::ostringstream msg; std::ostringstream msg;
if (!this->PrintMessagePreamble(t, 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, 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; std::ostringstream msg;
if (!this->PrintMessagePreamble(t, msg)) if (!this->PrintMessagePreamble(t, msg))
{ {

View File

@ -311,9 +311,11 @@ class cmake
/** Display a message to the user. */ /** Display a message to the user. */
void IssueMessage(cmake::MessageType t, std::string const& text, 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, void IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileContext const& lfc); cmListFileContext const& lfc,
bool force = false);
///! run the --build option ///! run the --build option
int Build(const std::string& dir, int Build(const std::string& dir,
@ -419,6 +421,12 @@ private:
// Print a list of valid generators to stderr. // Print a list of valid generators to stderr.
void PrintGeneratorList(); 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); bool PrintMessagePreamble(cmake::MessageType t, std::ostream& msg);
}; };

View File

@ -1,2 +1,6 @@
message(DEPRECATION "This is not issued") message(DEPRECATION "This is not issued")
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON)
message(AUTHOR_WARNING "This is not issued")

View File

@ -1,4 +1,11 @@
CMake Deprecation Warning at warnmessage.cmake:4 \(message\): ^CMake Deprecation Warning at warnmessage.cmake:4 \(message\):
This is a warning This is a deprecation warning
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) 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.$

View File

@ -1,4 +1,8 @@
set(CMAKE_WARN_DEPRECATED ON) 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")