Browse Source

Add policy CMP0035 to disallow variable_requires

Brad King 12 years ago
parent
commit
3969bb23aa

+ 3 - 1
Help/command/variable_requires.rst

@@ -1,7 +1,9 @@
 variable_requires
 -----------------
 
-Deprecated. Use the if() command instead.
+Disallowed.  See CMake Policy :policy:`CMP0035`.
+
+Use the if() command instead.
 
 Assert satisfaction of an option's required variables.
 

+ 1 - 0
Help/manual/cmake-policies.7.rst

@@ -64,3 +64,4 @@ All Policies
    /policy/CMP0032
    /policy/CMP0033
    /policy/CMP0034
+   /policy/CMP0035

+ 10 - 0
Help/policy/CMP0035.rst

@@ -0,0 +1,10 @@
+CMP0035
+-------
+
+The :command:`variable_requires` command should not be called.
+
+This command was introduced in November 2001 to perform some conditional
+logic.  It has long been replaced by the :command:`if` command.
+
+.. |disallowed_version| replace:: 3.0.0
+.. include:: DISALLOWED_COMMAND.txt

+ 5 - 0
Source/cmPolicies.cxx

@@ -276,6 +276,11 @@ cmPolicies::cmPolicies()
     CMP0034, "CMP0034",
     "The utility_source command should not be called.",
     3,0,0,0, cmPolicies::WARN);
+
+  this->DefinePolicy(
+    CMP0035, "CMP0035",
+    "The variable_requires command should not be called.",
+    3,0,0,0, cmPolicies::WARN);
 }
 
 cmPolicies::~cmPolicies()

+ 1 - 0
Source/cmPolicies.h

@@ -86,6 +86,7 @@ public:
     CMP0032, ///< Disallow command: output_required_files
     CMP0033, ///< Disallow command: export_library_dependencies
     CMP0034, ///< Disallow command: utility_source
+    CMP0035, ///< Disallow command: variable_requires
 
     /** \brief Always the last entry.
      *

+ 3 - 0
Source/cmVariableRequiresCommand.cxx

@@ -16,6 +16,9 @@
 bool cmVariableRequiresCommand
 ::InitialPass(std::vector<std::string>const& args, cmExecutionStatus &)
 {
+  if(this->Disallowed(cmPolicies::CMP0035,
+      "The variable_requires command should not be called; see CMP0035."))
+    { return true; }
   if(args.size() < 3 )
     {
     this->SetError("called with incorrect number of arguments");

+ 3 - 28
Source/cmVariableRequiresCommand.h

@@ -14,40 +14,15 @@
 
 #include "cmCommand.h"
 
-/** \class cmVariableRequiresCommand
- * \brief Displays a message to the user
- *
- */
 class cmVariableRequiresCommand : public cmCommand
 {
 public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  virtual cmCommand* Clone()
-    {
-    return new cmVariableRequiresCommand;
-    }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
+  cmTypeMacro(cmVariableRequiresCommand, cmCommand);
+  virtual cmCommand* Clone() { return new cmVariableRequiresCommand; }
   virtual bool InitialPass(std::vector<std::string> const& args,
                            cmExecutionStatus &status);
-
-  /**
-   * The name of the command as specified in CMakeList.txt.
-   */
   virtual const char* GetName() const { return "variable_requires";}
-
-  /** This command is kept for compatibility with older CMake versions. */
-  virtual bool IsDiscouraged() const
-    {
-    return true;
-    }
-
-  cmTypeMacro(cmVariableRequiresCommand, cmCommand);
+  virtual bool IsDiscouraged() const { return true; }
 };
 
 

+ 1 - 0
Tests/RunCMake/DisallowedCommands/CMP0035-NEW-result.txt

@@ -0,0 +1 @@
+1

+ 4 - 0
Tests/RunCMake/DisallowedCommands/CMP0035-NEW-stderr.txt

@@ -0,0 +1,4 @@
+CMake Error at CMP0035-NEW.cmake:2 \(variable_requires\):
+  The variable_requires command should not be called; see CMP0035.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

+ 2 - 0
Tests/RunCMake/DisallowedCommands/CMP0035-NEW.cmake

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0035 NEW)
+variable_requires()

+ 1 - 0
Tests/RunCMake/DisallowedCommands/CMP0035-OLD-result.txt

@@ -0,0 +1 @@
+1

+ 4 - 0
Tests/RunCMake/DisallowedCommands/CMP0035-OLD-stderr.txt

@@ -0,0 +1,4 @@
+CMake Error at CMP0035-OLD.cmake:2 \(variable_requires\):
+  variable_requires called with incorrect number of arguments
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

+ 2 - 0
Tests/RunCMake/DisallowedCommands/CMP0035-OLD.cmake

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0035 OLD)
+variable_requires()

+ 1 - 0
Tests/RunCMake/DisallowedCommands/CMP0035-WARN-result.txt

@@ -0,0 +1 @@
+1

+ 12 - 0
Tests/RunCMake/DisallowedCommands/CMP0035-WARN-stderr.txt

@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0035-WARN.cmake:1 \(variable_requires\):
+  Policy CMP0035 is not set: The variable_requires command should not be
+  called.  Run "cmake --help-policy CMP0035" for policy details.  Use the
+  cmake_policy command to set the policy and suppress this warning.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
+
+CMake Error at CMP0035-WARN.cmake:1 \(variable_requires\):
+  variable_requires called with incorrect number of arguments
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

+ 1 - 0
Tests/RunCMake/DisallowedCommands/CMP0035-WARN.cmake

@@ -0,0 +1 @@
+variable_requires()

+ 1 - 0
Tests/RunCMake/DisallowedCommands/RunCMakeTest.cmake

@@ -7,6 +7,7 @@ foreach(p
     CMP0032
     CMP0033
     CMP0034
+    CMP0035
     )
   run_cmake(${p}-WARN)
   run_cmake(${p}-OLD)