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

Michael Scott michael.scott250 at gmail.com
Tue Jun 23 15:57:35 EDT 2015


Hi,

I've implemented some changes to cmake.cxx and cmake.h, to implement 
setting the CMAKE_ERROR_DEPRECATED and CMAKE_WARN_DEPRECATED variables 
via command line options, for the Mantis issue 0014669, in a generic GCC 
style pattern. I've taken on board the previous suggestions, including 
adding tests for the new options and updating the cmake application 
options documentation. I've attached the proposed patch to this email, 
please let me know if there are any incorrect changes in the patch.

Michael Scott
-------------- next part --------------
From 2fc8c47ff2112a1f28d4f3c8513e29c94ecb6a9d Mon Sep 17 00:00:00 2001
From: Michael Scott <michael.scott250 at gmail.com>
Date: Sat, 13 Jun 2015 18:34:31 +0100
Subject: [PATCH] Refactored the -Wdev and -Wno-dev to use a generic -W parser,
 which follows the GCC pattern. Included support for setting
 CMAKE_ERROR_DEPRECATED and CMAKE_WARN_DEPRECATED via the deprecated warning.
 Added tests for new options and updated cmake application documentation to
 list new options.

---
 Help/manual/OPTIONS_BUILD.txt                      |  25 +++++
 Source/cmake.cxx                                   | 107 +++++++++++++++++----
 Source/cmake.h                                     |  23 +++--
 Tests/RunCMake/CommandLine/RunCMakeTest.cmake      |  20 ++++
 Tests/RunCMake/CommandLine/W_bad-arg1-result.txt   |   1 +
 Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt   |   2 +
 Tests/RunCMake/CommandLine/W_bad-arg2-result.txt   |   1 +
 Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt   |   2 +
 Tests/RunCMake/CommandLine/W_bad-arg3-result.txt   |   1 +
 Tests/RunCMake/CommandLine/W_bad-arg3-stderr.txt   |   2 +
 Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt  |   4 +
 Tests/RunCMake/CommandLine/Wdeprecated.cmake       |   1 +
 .../CommandLine/Werror_deprecated-result.txt       |   1 +
 .../CommandLine/Werror_deprecated-stderr.txt       |   4 +
 Tests/RunCMake/CommandLine/Werror_deprecated.cmake |   1 +
 Tests/RunCMake/CommandLine/Wno-deprecated.cmake    |   1 +
 .../CommandLine/Wno-error_deprecated.cmake         |   1 +
 17 files changed, 171 insertions(+), 26 deletions(-)
 create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg1-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg2-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg3-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg3-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLine/Wdeprecated.cmake
 create mode 100644 Tests/RunCMake/CommandLine/Werror_deprecated-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLine/Werror_deprecated.cmake
 create mode 100644 Tests/RunCMake/CommandLine/Wno-deprecated.cmake
 create mode 100644 Tests/RunCMake/CommandLine/Wno-error_deprecated.cmake

diff --git a/Help/manual/OPTIONS_BUILD.txt b/Help/manual/OPTIONS_BUILD.txt
index 4207db4..62eeb09 100644
--- a/Help/manual/OPTIONS_BUILD.txt
+++ b/Help/manual/OPTIONS_BUILD.txt
@@ -84,3 +84,28 @@
 
  Enable warnings that are meant for the author of the CMakeLists.txt
  files.
+
+``-Wdeprecated``
+ Enable deprecated macro and function warnings.
+
+ Enable warnings for usage of deprecated macros and functions, that are meant 
+ for the author of the CMakeLists.txt files. 
+
+``-Wno-deprecated``
+ Suppress deprecated macro and function warnings.
+ 
+ Suppress warnings for usage of deprecated macros and functions, that are meant 
+ for the author of the CMakeLists.txt files. 
+
+``-Werror=deprecated``
+ Make deprecated macro and function warnings errors.
+
+ Make warnings for usage of deprecated macros and functions, that are meant 
+ for the author of the CMakeLists.txt files, errors. 
+
+``-Wno-error=deprecated``
+ Make deprecated macro and function warnings not errors.
+ 
+ Make warnings for usage of deprecated macros and functions, that are meant 
+ for the author of the CMakeLists.txt files, not errors. 
+ 
\ No newline at end of file
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index eeb6575..54317ae 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -125,8 +125,6 @@ cmake::cmake()
   this->WarnUnused = false;
   this->WarnUnusedCli = true;
   this->CheckSystemVars = false;
-  this->SuppressDevWarnings = false;
-  this->DoSuppressDevWarnings = false;
   this->DebugOutput = false;
   this->DebugTryCompile = false;
   this->ClearBuildSystem = false;
@@ -251,15 +249,69 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
         return false;
         }
       }
-    else if(arg.find("-Wno-dev",0) == 0)
+    else if(cmHasLiteralPrefix(arg, "-W"))
       {
-      this->SuppressDevWarnings = true;
-      this->DoSuppressDevWarnings = true;
+      std::string entry = arg.substr(2);
+      if (entry.empty())
+        {
+        ++i;
+        if (i < args.size())
+          {
+          entry = args[i];
+          }
+        else
+          {
+          cmSystemTools::Error("-W must be followed with [no-][error=]<name>.");
+          return false;
+        }
       }
-    else if(arg.find("-Wdev",0) == 0)
-      {
-      this->SuppressDevWarnings = false;
-      this->DoSuppressDevWarnings = true;
+
+      std::string name;
+      bool foundNo = false;
+      bool foundError = false;
+      unsigned int nameStartPosition = 0;
+
+      if (entry.find("no-", nameStartPosition) == 0)
+        {
+        foundNo = true;
+        nameStartPosition += 3;
+        }
+
+      if (entry.find("error=", nameStartPosition) == 0)
+        {
+        foundError = true;
+        nameStartPosition += 6;
+        }
+
+      name = entry.substr(nameStartPosition);
+      if (name.empty())
+        {
+        cmSystemTools::Error("No warning name provided.");
+        return false;
+        }
+
+      if (!foundNo && !foundError)
+        {
+        // -W<name>
+        this->WarningLevels[name] = std::max(this->WarningLevels[name],
+                                             WarningLevel::WARNING_LEVEL);
+        }
+      else if (foundNo && !foundError)
+        {
+         // -Wno<name>
+         this->WarningLevels[name] = WarningLevel::IGNORE_LEVEL;
+        }
+      else if (!foundNo && foundError)
+        {
+        // -Werror=<name>
+        this->WarningLevels[name] = WarningLevel::ERROR_LEVEL;
+        }
+      else
+        {
+        // -Wno-error=<name>
+        this->WarningLevels[name] = std::min(this->WarningLevels[name],
+                                             WarningLevel::WARNING_LEVEL);
+        }
       }
     else if(arg.find("-U",0) == 0)
       {
@@ -587,11 +639,7 @@ void cmake::SetArgs(const std::vector<std::string>& args,
       // skip for now
       i++;
       }
-    else if(arg.find("-Wno-dev",0) == 0)
-      {
-      // skip for now
-      }
-    else if(arg.find("-Wdev",0) == 0)
+    else if(arg.find("-W",0) == 0)
       {
       // skip for now
       }
@@ -1171,9 +1219,33 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
 
 int cmake::Configure()
 {
-  if(this->DoSuppressDevWarnings)
+  WarningLevel warningLevel;
+
+  if (this->WarningLevels.count("deprecated") == 1)
     {
-    if(this->SuppressDevWarnings)
+    warningLevel = this->WarningLevels["deprecated"];
+    if (warningLevel == WARNING_LEVEL)
+      {
+      this->CacheManager->
+        AddCacheEntry("CMAKE_WARN_DEPRECATED", "TRUE",
+                      "Whether to issue deprecation warnings for"
+                      " macros and functions.",
+                      cmState::BOOL);
+      }
+    else if (warningLevel == ERROR_LEVEL)
+      {
+      this->CacheManager->
+        AddCacheEntry("CMAKE_ERROR_DEPRECATED", "TRUE",
+                      "Whether to issue deprecation errors for macros"
+                      " and functions.",
+                      cmState::BOOL);
+      }
+    }
+
+  if (this->WarningLevels.count("dev") == 1)
+    {
+    warningLevel = this->WarningLevels["dev"];
+    if (warningLevel == IGNORE_LEVEL)
       {
       this->CacheManager->
         AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
@@ -1181,7 +1253,7 @@ int cmake::Configure()
                       " the author of the CMakeLists.txt files.",
                       cmState::INTERNAL);
       }
-    else
+    else if (warningLevel == WARNING_LEVEL)
       {
       this->CacheManager->
         AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
@@ -1190,6 +1262,7 @@ int cmake::Configure()
                       cmState::INTERNAL);
       }
     }
+
   int ret = this->ActualConfigure();
   const char* delCacheVars = this->State
                     ->GetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
diff --git a/Source/cmake.h b/Source/cmake.h
index f0f9411..3b51222 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -69,6 +69,12 @@ class cmake
     DEPRECATION_WARNING
   };
 
+  enum WarningLevel
+  {
+    IGNORE_LEVEL,
+    WARNING_LEVEL,
+    ERROR_LEVEL
+  };
 
   /** \brief Describes the working modes of cmake */
   enum WorkingMode
@@ -290,12 +296,6 @@ class cmake
   std::string const& GetCMakeEditCommand() const
     { return this->CMakeEditCommand; }
 
-  void SetSuppressDevWarnings(bool v)
-    {
-      this->SuppressDevWarnings = v;
-      this->DoSuppressDevWarnings = true;
-    }
-
   /** Display a message to the user.  */
   void IssueMessage(cmake::MessageType t, std::string const& text,
         cmListFileBacktrace const& backtrace = cmListFileBacktrace());
@@ -339,8 +339,7 @@ protected:
   cmPolicies *Policies;
   cmGlobalGenerator *GlobalGenerator;
   cmCacheManager *CacheManager;
-  bool SuppressDevWarnings;
-  bool DoSuppressDevWarnings;
+  std::map<std::string, WarningLevel> WarningLevels;
   std::string GeneratorPlatform;
   std::string GeneratorToolset;
 
@@ -415,7 +414,13 @@ private:
   {"-T <toolset-name>", "Specify toolset name if supported by generator."}, \
   {"-A <platform-name>", "Specify platform name if supported by generator."}, \
   {"-Wno-dev", "Suppress developer warnings."},\
-  {"-Wdev", "Enable developer warnings."}
+  {"-Wdev", "Enable developer warnings."},\
+  {"-Wdeprecated", "Enable deprecated macro and function warnings."},\
+  {"-Wno-deprecated", "Suppress deprecated macro and function warnings."},\
+  {"-Werror=deprecated", "Make deprecated macro and function warnings " \
+                         "errors."},\
+  {"-Wno-error=deprecated", "Make deprecated macro and function warnings " \
+                            "not errors."}
 
 #define FOR_EACH_C_FEATURE(F) \
   F(c_function_prototypes) \
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index 69beed9..2d69db4 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -115,6 +115,26 @@ set(RunCMake_TEST_OPTIONS -Wno-dev -Wdev)
 run_cmake(Wdev)
 unset(RunCMake_TEST_OPTIONS)
 
+set(RunCMake_TEST_OPTIONS -Wdeprecated)
+run_cmake(Wdeprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Wno-deprecated)
+run_cmake(Wno-deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Werror=deprecated)
+run_cmake(Werror_deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Wno-error=deprecated)
+run_cmake(Wno-error_deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
+run_cmake_command(W_bad-arg1 ${CMAKE_COMMAND} -W)
+run_cmake_command(W_bad-arg2 ${CMAKE_COMMAND} -Wno-)
+run_cmake_command(W_bad-arg3 ${CMAKE_COMMAND} -Werror=)
+
 set(RunCMake_TEST_OPTIONS --debug-output)
 run_cmake(debug-output)
 unset(RunCMake_TEST_OPTIONS)
diff --git a/Tests/RunCMake/CommandLine/W_bad-arg1-result.txt b/Tests/RunCMake/CommandLine/W_bad-arg1-result.txt
new file mode 100644
index 0000000..56a6051
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/W_bad-arg1-result.txt
@@ -0,0 +1 @@
+1
\ No newline at end of file
diff --git a/Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt b/Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt
new file mode 100644
index 0000000..e912728
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error: -W must be followed with \[no-\]\[error=\]<name>.
+CMake Error: Problem processing arguments. Aborting.
diff --git a/Tests/RunCMake/CommandLine/W_bad-arg2-result.txt b/Tests/RunCMake/CommandLine/W_bad-arg2-result.txt
new file mode 100644
index 0000000..56a6051
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/W_bad-arg2-result.txt
@@ -0,0 +1 @@
+1
\ No newline at end of file
diff --git a/Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt b/Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt
new file mode 100644
index 0000000..cc643df
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error: No warning name provided.
+CMake Error: Problem processing arguments. Aborting.
diff --git a/Tests/RunCMake/CommandLine/W_bad-arg3-result.txt b/Tests/RunCMake/CommandLine/W_bad-arg3-result.txt
new file mode 100644
index 0000000..56a6051
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/W_bad-arg3-result.txt
@@ -0,0 +1 @@
+1
\ No newline at end of file
diff --git a/Tests/RunCMake/CommandLine/W_bad-arg3-stderr.txt b/Tests/RunCMake/CommandLine/W_bad-arg3-stderr.txt
new file mode 100644
index 0000000..cc643df
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/W_bad-arg3-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error: No warning name provided.
+CMake Error: Problem processing arguments. Aborting.
diff --git a/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt b/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt
new file mode 100644
index 0000000..e9be1dc
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Deprecation Warning at Wdeprecated.cmake:1 \(message\):
+  Some deprecated warning
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CommandLine/Wdeprecated.cmake b/Tests/RunCMake/CommandLine/Wdeprecated.cmake
new file mode 100644
index 0000000..4f65d99
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wdeprecated.cmake
@@ -0,0 +1 @@
+message(DEPRECATION "Some deprecated warning")
\ No newline at end of file
diff --git a/Tests/RunCMake/CommandLine/Werror_deprecated-result.txt b/Tests/RunCMake/CommandLine/Werror_deprecated-result.txt
new file mode 100644
index 0000000..56a6051
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Werror_deprecated-result.txt
@@ -0,0 +1 @@
+1
\ No newline at end of file
diff --git a/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt b/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt
new file mode 100644
index 0000000..6acdc73
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Deprecation Error at Werror_deprecated.cmake:1 \(message\):
+  Some deprecated warning
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CommandLine/Werror_deprecated.cmake b/Tests/RunCMake/CommandLine/Werror_deprecated.cmake
new file mode 100644
index 0000000..4f65d99
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Werror_deprecated.cmake
@@ -0,0 +1 @@
+message(DEPRECATION "Some deprecated warning")
\ No newline at end of file
diff --git a/Tests/RunCMake/CommandLine/Wno-deprecated.cmake b/Tests/RunCMake/CommandLine/Wno-deprecated.cmake
new file mode 100644
index 0000000..4f65d99
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wno-deprecated.cmake
@@ -0,0 +1 @@
+message(DEPRECATION "Some deprecated warning")
\ No newline at end of file
diff --git a/Tests/RunCMake/CommandLine/Wno-error_deprecated.cmake b/Tests/RunCMake/CommandLine/Wno-error_deprecated.cmake
new file mode 100644
index 0000000..4f65d99
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/Wno-error_deprecated.cmake
@@ -0,0 +1 @@
+message(DEPRECATION "Some deprecated warning")
\ No newline at end of file
-- 
2.1.4



More information about the cmake-developers mailing list