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 attached the proposed patch to this email, does this look like a sensible implementation?

Michael Scott
From ae4f9a42ff5e8d3156010287d013099e75c0cde4 Mon Sep 17 00:00:00 2001
From: Michael Scott <michael.scott...@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.

---
 Source/cmake.cxx | 146 +++++++++++++++++++++++++++++++++++++++++--------------
 Source/cmake.h   |  23 +++++----
 2 files changed, 124 insertions(+), 45 deletions(-)

diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index eeb6575..27ceb5a 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,16 +249,71 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& 
args)
         return false;
         }
       }
-    else if(arg.find("-Wno-dev",0) == 0)
-      {
-      this->SuppressDevWarnings = true;
-      this->DoSuppressDevWarnings = true;
-      }
-    else if(arg.find("-Wdev",0) == 0)
-      {
-      this->SuppressDevWarnings = false;
-      this->DoSuppressDevWarnings = true;
-      }
+    else if(arg.find("-W", 0) == 0)
+      {
+       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;
+                 }
+               }
+
+               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)
       {
       std::string entryPattern = arg.substr(2);
@@ -587,11 +640,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,25 +1220,50 @@ int cmake::HandleDeleteCacheVariables(const 
std::string& var)
 
 int cmake::Configure()
 {
-  if(this->DoSuppressDevWarnings)
-    {
-    if(this->SuppressDevWarnings)
-      {
-      this->CacheManager->
-        AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
-                      "Suppress Warnings that are meant for"
-                      " the author of the CMakeLists.txt files.",
-                      cmState::INTERNAL);
-      }
-    else
-      {
-      this->CacheManager->
-        AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
-                      "Suppress Warnings that are meant for"
-                      " the author of the CMakeLists.txt files.",
-                      cmState::INTERNAL);
-      }
-    }
+  WarningLevel warningLevel;
+
+  if (this->WarningLevels.count("deprecated") == 1)
+    {
+    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",
+                                                   "Suppress Warnings that are 
meant for"
+                                                   " the author of the 
CMakeLists.txt files.",
+                                                   cmState::INTERNAL);
+    }
+    else if (warningLevel == WARNING_LEVEL)
+         {
+         this->CacheManager->
+                         AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", 
"FALSE",
+                                                   "Suppress Warnings that are 
meant for"
+                                                   " the author of the 
CMakeLists.txt files.",
+                                                   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..d62c6a2 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) \
-- 
2.1.4

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to