[cmake-developers] Add command line options for deprecation message control

Michael Scott michael.scott250 at gmail.com
Fri Sep 25 15:44:44 EDT 2015


Sorry I'm being a bit slow with this topic, it's release period at my 
office too :D so a busy time there as well.

> The cmake::Configure check for that runs before the scripts run so
> it is not possible to get script-provided values there.  Do you have
> a check in a new context that occurs later?  If so please provide the
> patch in progress and point out the problem.

The checks I'm adding in are in the cmake::PrintMessagePreamble method, 
I've included an initial version of the patch. This looks correct and 
seems to behave correctly when either the user uses the -W options, or 
doesn't change anything relating to warnings or errors. But, when the 
user sets the variables being checked for, in the CMake file itself, the 
checks don't pick up the set variables. I'm guessing because its only 
checking against the cache, and the normal usage of the set command 
doesn't set the variable in the cache?

This change causes the RunCMake.message and RunCMake.ObsoleteQtMacros 
tests for fail, as they do what is described just above.

Cheers,
Michael
-------------- next part --------------
From 9096cd7f2a0ff42db88c4adb25a403e75e381756 Mon Sep 17 00:00:00 2001
From: Michael Scott <michael.scott250 at gmail.com>
Date: Tue, 22 Sep 2015 22:43:24 +0100
Subject: [PATCH] Fix suppressing dev and deprecated messages via -W

Examine the dev and deprecated warning and error output variables when
printing message preambles, so that messages output outside of the
message command, via IssueMessage, are affected by the CMake '-W'
options again after the recent changes related to the -W options.
---
 Source/cmake.cxx                           | 34 ++++++++++++++++++++++++++++++
 Tests/RunCMake/CommandLine/Wdev-stderr.txt |  6 ++++++
 Tests/RunCMake/CommandLine/Wdev.cmake      |  5 +++++
 Tests/RunCMake/CommandLine/Wno-dev.cmake   |  5 +++++
 4 files changed, 50 insertions(+)

diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index f069481..dec254f 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -2591,18 +2591,52 @@ bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg)
   else if(t == cmake::DEPRECATION_ERROR)
     {
     msg << "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))
+      {
+      return false;
+      }
     }
   else if (t == cmake::DEPRECATION_WARNING)
     {
     msg << "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))
+      {
+      return false;
+      }
     }
   else if (t == cmake::AUTHOR_WARNING)
     {
     msg << "CMake Warning (dev)";
+
+    // if CMAKE_SUPPRESS_DEVELOPER_WARNINGS is on, suppress the message,
+    // otherwise show it
+    const char* suppress = this->State->GetCacheEntryValue(
+                                          "CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
+    if(cmSystemTools::IsOn(suppress))
+      {
+      return false;
+      }
     }
   else if (t == cmake::AUTHOR_ERROR)
     {
     msg << "CMake Error (dev)";
+
+    // if CMAKE_ERROR_DEVELOPER_WARNINGS is on, show the message, otherwise
+    // suppress it
+    const char* devErrors = this->State->GetCacheEntryValue(
+                                          "CMAKE_ERROR_DEVELOPER_WARNINGS");
+    if(cmSystemTools::IsOff(devErrors))
+      {
+      return false;
+      }
     }
   else
     {
diff --git a/Tests/RunCMake/CommandLine/Wdev-stderr.txt b/Tests/RunCMake/CommandLine/Wdev-stderr.txt
index f427303..92c1d23 100644
--- a/Tests/RunCMake/CommandLine/Wdev-stderr.txt
+++ b/Tests/RunCMake/CommandLine/Wdev-stderr.txt
@@ -2,4 +2,10 @@
   Some Author Warning
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
+
+CMake Warning \(dev\) at Wdev.cmake:6 \(include\):
+  include\(\) given empty file name \(ignored\).
+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/CommandLine/Wdev.cmake b/Tests/RunCMake/CommandLine/Wdev.cmake
index 0242086..9d2439b 100644
--- a/Tests/RunCMake/CommandLine/Wdev.cmake
+++ b/Tests/RunCMake/CommandLine/Wdev.cmake
@@ -1 +1,6 @@
 message(AUTHOR_WARNING "Some Author Warning")
+
+# with -Wdev this will also cause an AUTHOR_WARNING message, checks that
+# messages issued outside of the message command, by other CMake commands, also
+# are affected by -Wdev
+include("")
\ No newline at end of file
diff --git a/Tests/RunCMake/CommandLine/Wno-dev.cmake b/Tests/RunCMake/CommandLine/Wno-dev.cmake
index 0242086..05dcc1e 100644
--- a/Tests/RunCMake/CommandLine/Wno-dev.cmake
+++ b/Tests/RunCMake/CommandLine/Wno-dev.cmake
@@ -1 +1,6 @@
 message(AUTHOR_WARNING "Some Author Warning")
+
+# without -Wno-dev this will also cause an AUTHOR_WARNING message, checks that
+# messages issued outside of the message command, by other CMake commands, also
+# are affected by -Wno-dev
+include("")
\ No newline at end of file
-- 
2.1.4



More information about the cmake-developers mailing list