Преглед на файлове

Add -W options to control deprecated warning messages.

Add 'deprecated' warning options type, to allow setting
CMAKE_WARN_DEPRECATED via the -W '-Wdeprecated' and
'-Wno-deprecated' options.

Add tests for new options and updated documentation.
Michael Scott преди 10 години
родител
ревизия
da688bcb3b

+ 12 - 0
Help/manual/OPTIONS_BUILD.txt

@@ -84,3 +84,15 @@
 
  Enable warnings that are meant for the author of the CMakeLists.txt
  files.
+
+``-Wdeprecated``
+ Enable deprecated functionality warnings.
+
+ Enable warnings for usage of deprecated functionality, that are meant
+ for the author of the CMakeLists.txt files.
+
+``-Wno-deprecated``
+ Suppress deprecated functionality warnings.
+
+ Suppress warnings for usage of deprecated functionality, that are meant
+ for the author of the CMakeLists.txt files.

+ 5 - 0
Help/release/dev/cmake-W-options.rst

@@ -0,0 +1,5 @@
+cmake-W-options
+---------------
+
+* The :variable:`CMAKE_WARN_DEPRECATED` variable can now be set using the
+  ``-Wdeprecated`` and ``-Wno-deprecated`` :manual:`cmake(1)` options.

+ 6 - 3
Help/variable/CMAKE_WARN_DEPRECATED.rst

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

+ 20 - 0
Source/cmake.cxx

@@ -1263,6 +1263,26 @@ int cmake::Configure()
 {
   DiagLevel diagLevel;
 
+  if (this->DiagLevels.count("deprecated") == 1)
+    {
+
+    diagLevel = this->DiagLevels["deprecated"];
+    if (diagLevel == DIAG_IGNORE)
+      {
+      this->AddCacheEntry("CMAKE_WARN_DEPRECATED", "FALSE",
+                          "Whether to issue warnings for deprecated "
+                          "functionality.",
+                          cmState::INTERNAL);
+      }
+    else if (diagLevel == DIAG_WARN)
+      {
+      this->AddCacheEntry("CMAKE_WARN_DEPRECATED", "TRUE",
+                          "Whether to issue warnings for deprecated "
+                          "functionality.",
+                          cmState::INTERNAL);
+      }
+    }
+
   if (this->DiagLevels.count("dev") == 1)
     {
 

+ 3 - 1
Source/cmake.h

@@ -444,7 +444,9 @@ 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 deprecation warnings."},\
+  {"-Wno-deprecated", "Suppress deprecation warnings."}
 
 #define FOR_EACH_C_FEATURE(F) \
   F(c_function_prototypes) \

+ 8 - 0
Tests/RunCMake/CommandLine/RunCMakeTest.cmake

@@ -133,6 +133,14 @@ set(RunCMake_TEST_OPTIONS -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)
+
 # Dev warnings should be on by default
 run_cmake(Wdev)
 

+ 4 - 0
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\)

+ 1 - 0
Tests/RunCMake/CommandLine/Wdeprecated.cmake

@@ -0,0 +1 @@
+message(DEPRECATION "Some deprecated warning")

+ 1 - 0
Tests/RunCMake/CommandLine/Wno-deprecated.cmake

@@ -0,0 +1 @@
+message(DEPRECATION "Some deprecated warning")