Skip to content

Commit

Permalink
cmake: Issue message independent of cmMakefile definition
Browse files Browse the repository at this point in the history
The makefile is only used when called by the cmMessageCommand, so inline
the use of it there.  It creates an undesirable dependency on
cmMakefile for issuing messages in the cmake instance.

This also makes it more explicit that the variable definitions only
affect the message() command.  If an AUTHOR_WARNING is issued for any
other reason, it is not affected.  To affect that, it is necessary to
set the cache variable instead of the regular variable.

This is an unfortunate interface quirk.  Perhaps for newly introduced
variables, the non-cache version should be ignored to encourage
consistency of setting the cache variables instead.
  • Loading branch information
steveire committed Jan 28, 2016
1 parent 5335d27 commit 86d1350
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 63 deletions.
11 changes: 6 additions & 5 deletions Source/cmMessageCommand.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
cmake::MessageType type = cmake::MESSAGE;
bool status = false;
bool fatal = false;
cmake* cm = this->Makefile->GetCMakeInstance();
if (*i == "SEND_ERROR")
{
type = cmake::FATAL_ERROR;
Expand All @@ -44,12 +43,13 @@ ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
}
else if (*i == "AUTHOR_WARNING")
{
if (cm->GetDevWarningsAsErrors(this->Makefile))
if (this->Makefile->IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") &&
!this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS"))
{
fatal = true;
type = cmake::AUTHOR_ERROR;
}
else if (!cm->GetSuppressDevWarnings(this->Makefile))
else if (!this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"))
{
type = cmake::AUTHOR_WARNING;
}
Expand All @@ -66,12 +66,13 @@ ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
}
else if (*i == "DEPRECATION")
{
if (cm->GetDeprecatedWarningsAsErrors(this->Makefile))
if (this->Makefile->IsOn("CMAKE_ERROR_DEPRECATED"))
{
fatal = true;
type = cmake::DEPRECATION_ERROR;
}
else if (!cm->GetSuppressDeprecatedWarnings(this->Makefile))
else if ((!this->Makefile->IsSet("CMAKE_WARN_DEPRECATED") ||
this->Makefile->IsOn("CMAKE_WARN_DEPRECATED")))
{
type = cmake::DEPRECATION_WARNING;
}
Expand Down
70 changes: 16 additions & 54 deletions Source/cmake.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2974,22 +2974,11 @@ void cmake::RunCheckForUnusedVariables()
#endif
}

bool cmake::GetSuppressDevWarnings(cmMakefile const* mf)
bool cmake::GetSuppressDevWarnings()
{
/*
* 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->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
}
else
{
const char* cacheEntryValue = this->State->GetCacheEntryValue(
"CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
return cmSystemTools::IsOn(cacheEntryValue);
}
const char* cacheEntryValue = this->State->GetCacheEntryValue(
"CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
return cmSystemTools::IsOn(cacheEntryValue);
}

void cmake::SetSuppressDevWarnings(bool b)
Expand All @@ -3013,23 +3002,11 @@ void cmake::SetSuppressDevWarnings(bool b)
cmState::INTERNAL);
}

bool cmake::GetSuppressDeprecatedWarnings(cmMakefile const* mf)
bool cmake::GetSuppressDeprecatedWarnings()
{
/*
* 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);
}
const char* cacheEntryValue = this->State->GetCacheEntryValue(
"CMAKE_WARN_DEPRECATED");
return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
}

void cmake::SetSuppressDeprecatedWarnings(bool b)
Expand All @@ -3053,19 +3030,11 @@ void cmake::SetSuppressDeprecatedWarnings(bool b)
cmState::INTERNAL);
}

bool cmake::GetDevWarningsAsErrors(cmMakefile const* mf)
bool cmake::GetDevWarningsAsErrors()
{
if (mf)
{
return (mf->IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") &&
!mf->IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS"));
}
else
{
const char* cacheEntryValue = this->State->GetCacheEntryValue(
"CMAKE_SUPPRESS_DEVELOPER_ERRORS");
return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
}
const char* cacheEntryValue = this->State->GetCacheEntryValue(
"CMAKE_SUPPRESS_DEVELOPER_ERRORS");
return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
}

void cmake::SetDevWarningsAsErrors(bool b)
Expand All @@ -3089,18 +3058,11 @@ void cmake::SetDevWarningsAsErrors(bool b)
cmState::INTERNAL);
}

bool cmake::GetDeprecatedWarningsAsErrors(cmMakefile const* mf)
bool cmake::GetDeprecatedWarningsAsErrors()
{
if (mf)
{
return mf->IsOn("CMAKE_ERROR_DEPRECATED");
}
else
{
const char* cacheEntryValue = this->State->GetCacheEntryValue(
"CMAKE_ERROR_DEPRECATED");
return cmSystemTools::IsOn(cacheEntryValue);
}
const char* cacheEntryValue = this->State->GetCacheEntryValue(
"CMAKE_ERROR_DEPRECATED");
return cmSystemTools::IsOn(cacheEntryValue);
}

void cmake::SetDeprecatedWarningsAsErrors(bool b)
Expand Down
8 changes: 4 additions & 4 deletions Source/cmake.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class cmake
* Returns false, by default, if developer warnings should be shown, true
* otherwise.
*/
bool GetSuppressDevWarnings(cmMakefile const* mf = NULL);
bool GetSuppressDevWarnings();
/*
* Set the state of the suppression of developer (author) warnings.
*/
Expand All @@ -326,7 +326,7 @@ class cmake
* Returns false, by default, if deprecated warnings should be shown, true
* otherwise.
*/
bool GetSuppressDeprecatedWarnings(cmMakefile const* mf = NULL);
bool GetSuppressDeprecatedWarnings();
/*
* Set the state of the suppression of deprecated warnings.
*/
Expand All @@ -337,7 +337,7 @@ class cmake
* Returns false, by default, if warnings should not be treated as errors,
* true otherwise.
*/
bool GetDevWarningsAsErrors(cmMakefile const* mf = NULL);
bool GetDevWarningsAsErrors();
/**
* Set the state of treating developer (author) warnings as errors.
*/
Expand All @@ -348,7 +348,7 @@ class cmake
* Returns false, by default, if warnings should not be treated as errors,
* true otherwise.
*/
bool GetDeprecatedWarningsAsErrors(cmMakefile const* mf = NULL);
bool GetDeprecatedWarningsAsErrors();
/**
* Set the state of treating developer (author) warnings as errors.
*/
Expand Down
2 changes: 2 additions & 0 deletions Tests/RunCMake/message/RunCMakeTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ include(RunCMake)

run_cmake(defaultmessage)
run_cmake(nomessage)
run_cmake(message-internal-warning)
run_cmake(nomessage-internal-warning)
run_cmake(warnmessage)
# message command sets fatal occurred flag, so check each type of error

Expand Down
13 changes: 13 additions & 0 deletions Tests/RunCMake/message/message-internal-warning-stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
^CMake Warning \(dev\) at message-internal-warning.cmake:3 \(include\):
A logical block opening on the line

.*Tests/RunCMake/message/message-internal-warning.cmake:4 \(macro\)

closes on the line

.*Tests/RunCMake/message/message-internal-warning.cmake:5 \(endmacro\)

with mis-matching arguments.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.$
5 changes: 5 additions & 0 deletions Tests/RunCMake/message/message-internal-warning.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON)

macro(mymacro)
endmacro(notmymacro)
Empty file.
5 changes: 5 additions & 0 deletions Tests/RunCMake/message/nomessage-internal-warning.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON CACHE BOOL "")

macro(mymacro)
endmacro(notmymacro)

0 comments on commit 86d1350

Please sign in to comment.