Explicitly enable deprecated warnings by default.

Explicitly enable deprecated warnings by default, via the
cmake::GetSuppressDeprecatedWarnings method, which signals
suppression is turned off unless the CMake variables are set
as required.

Add tests and update the documentation for the new
functionality.
This commit is contained in:
Michael Scott 2015-11-29 13:34:07 +00:00 committed by Brad King
parent e8974b62d7
commit aac633d5e5
8 changed files with 54 additions and 12 deletions

View File

@ -6,3 +6,7 @@ cmake-W-options
* The ``-Wdev`` and ``-Wno-dev`` :manual:`cmake(1)` options now also enable * The ``-Wdev`` and ``-Wno-dev`` :manual:`cmake(1)` options now also enable
and suppress the deprecated warnings output by default. and suppress the deprecated warnings output by default.
* Warnings about deprecated functionality are now enabled by default.
They may be suppressed with ``-Wno-deprecated`` or by setting the
:variable:`CMAKE_WARN_DEPRECATED` variable to false.

View File

@ -3,8 +3,8 @@ CMAKE_WARN_DEPRECATED
Whether to issue warnings for deprecated functionality. Whether to issue warnings for deprecated functionality.
If ``TRUE``, use of deprecated functionality will issue warnings. If not ``FALSE``, use of deprecated functionality will issue warnings.
If this variable is not set, CMake behaves as if it were set to ``FALSE``. If this variable is not set, CMake behaves as if it were set to ``TRUE``.
When running :manual:`cmake(1)`, this option can be enabled with the When running :manual:`cmake(1)`, this option can be enabled with the
``-Wdeprecated`` option, or disabled with the ``-Wno-deprecated`` option. ``-Wdeprecated`` option, or disabled with the ``-Wno-deprecated`` option.

View File

@ -66,13 +66,17 @@ bool cmMessageCommand
fatal = true; fatal = true;
type = cmake::DEPRECATION_ERROR; type = cmake::DEPRECATION_ERROR;
} }
else if (this->Makefile->IsOn("CMAKE_WARN_DEPRECATED")) else
{ {
type = cmake::DEPRECATION_WARNING; if (this->Makefile->GetCMakeInstance()->GetSuppressDeprecatedWarnings(
this->Makefile))
{
return true;
} }
else else
{ {
return true; type = cmake::DEPRECATION_WARNING;
}
} }
++i; ++i;
} }

View File

@ -2581,10 +2581,7 @@ bool cmake::IsMessageTypeVisible(cmake::MessageType t)
} }
else if (t == cmake::DEPRECATION_WARNING) else if (t == cmake::DEPRECATION_WARNING)
{ {
// if CMAKE_WARN_DEPRECATED is on, show the message, otherwise suppress it if (this->GetSuppressDeprecatedWarnings())
const char* warnDeprecated = this->State->GetInitializedCacheValue(
"CMAKE_WARN_DEPRECATED");
if(cmSystemTools::IsOff(warnDeprecated))
{ {
isVisible = false; isVisible = false;
} }
@ -2916,3 +2913,22 @@ bool cmake::GetSuppressDevWarnings(cmMakefile const* mf)
return cmSystemTools::IsOn(cacheEntryValue); return cmSystemTools::IsOn(cacheEntryValue);
} }
} }
bool cmake::GetSuppressDeprecatedWarnings(cmMakefile const* mf)
{
/*
* The suppression CMake variable may be set in the CMake configuration file
* itself, so we have to check what its set to in the makefile if we can.
*/
if (mf)
{
return (mf->IsSet("CMAKE_WARN_DEPRECATED") &&
!mf->IsOn("CMAKE_WARN_DEPRECATED"));
}
else
{
const char* cacheEntryValue = this->State->GetCacheEntryValue(
"CMAKE_WARN_DEPRECATED");
return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
}
}

View File

@ -316,6 +316,13 @@ class cmake
*/ */
bool GetSuppressDevWarnings(cmMakefile const* mf = NULL); bool GetSuppressDevWarnings(cmMakefile const* mf = NULL);
/*
* Get the state of the suppression of deprecated warnings.
* Returns false, by default, if deprecated warnings should be shown, true
* otherwise.
*/
bool GetSuppressDeprecatedWarnings(cmMakefile const* mf = NULL);
/** 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(),

View File

@ -157,6 +157,9 @@ unset(RunCMake_TEST_OPTIONS)
# Dev warnings should be on by default # Dev warnings should be on by default
run_cmake(Wdev) run_cmake(Wdev)
# Deprecated warnings should be on by default
run_cmake(Wdeprecated)
# Conflicting -W options should honor the last value # Conflicting -W options should honor the last value
set(RunCMake_TEST_OPTIONS -Wno-dev -Wdev) set(RunCMake_TEST_OPTIONS -Wno-dev -Wdev)
run_cmake(Wdev) run_cmake(Wdev)

View File

@ -1,4 +1,10 @@
^CMake Warning \(dev\) at defaultmessage.cmake:4 \(message\): ^CMake Deprecation Warning at defaultmessage.cmake:2 \(message\):
This is a deprecation warning
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
CMake Warning \(dev\) at defaultmessage.cmake:4 \(message\):
This is a author warning This is a author warning
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)

View File

@ -1,4 +1,6 @@
set(CMAKE_WARN_DEPRECATED OFF)
message(DEPRECATION "This is not issued") message(DEPRECATION "This is not issued")
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON) set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON)