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

Add policy CMP0036 to disallow build_name

Brad King преди 12 години
родител
ревизия
6c9194488a

+ 3 - 1
Help/command/build_name.rst

@@ -1,7 +1,9 @@
 build_name
 ----------
 
-Deprecated.  Use ${CMAKE_SYSTEM} and ${CMAKE_CXX_COMPILER} instead.
+Disallowed.  See CMake Policy :policy:`CMP0036`.
+
+Use ${CMAKE_SYSTEM} and ${CMAKE_CXX_COMPILER} instead.
 
 ::
 

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

@@ -65,3 +65,4 @@ All Policies
    /policy/CMP0033
    /policy/CMP0034
    /policy/CMP0035
+   /policy/CMP0036

+ 12 - 0
Help/policy/CMP0036.rst

@@ -0,0 +1,12 @@
+CMP0036
+-------
+
+The :command:`build_name` command should not be called.
+
+This command was added in May 2001 to compute a name for the current
+operating system and compiler combination.  The command has long been
+documented as discouraged and replaced by the :variable:`CMAKE_SYSTEM`
+and :variable:`CMAKE_<LANG>_COMPILER` variables.
+
+.. |disallowed_version| replace:: 3.0.0
+.. include:: DISALLOWED_COMMAND.txt

+ 3 - 0
Source/cmBuildNameCommand.cxx

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

+ 4 - 34
Source/cmBuildNameCommand.h

@@ -14,46 +14,16 @@
 
 #include "cmCommand.h"
 
-/** \class cmBuildNameCommand
- * \brief build_name command
- *
- * cmBuildNameCommand implements the build_name CMake command
- */
 class cmBuildNameCommand : public cmCommand
 {
 public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  virtual cmCommand* Clone()
-    {
-    return new cmBuildNameCommand;
-    }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
+  cmTypeMacro(cmBuildNameCommand, cmCommand);
+  virtual cmCommand* Clone() { return new cmBuildNameCommand; }
   virtual bool InitialPass(std::vector<std::string> const& args,
                            cmExecutionStatus &status);
-
-  /**
-   * This determines if the command is invoked when in script mode.
-   */
-  virtual bool IsScriptable() const { return true; }
-
-  /**
-   * The name of the command as specified in CMakeList.txt.
-   */
   virtual const char* GetName() const {return "build_name";}
-
-  /** This command is kept for compatibility with older CMake versions. */
-  virtual bool IsDiscouraged() const
-    {
-    return true;
-    }
-
-  cmTypeMacro(cmBuildNameCommand, cmCommand);
+  virtual bool IsScriptable() const { return true; }
+  virtual bool IsDiscouraged() const { return true; }
 };
 
 

+ 5 - 0
Source/cmPolicies.cxx

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

+ 1 - 0
Source/cmPolicies.h

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

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

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

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

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

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

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0036 NEW)
+build_name()

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

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

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

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

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

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0036 OLD)
+build_name()

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

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

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

@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0036-WARN.cmake:1 \(build_name\):
+  Policy CMP0036 is not set: The build_name command should not be called.
+  Run "cmake --help-policy CMP0036" 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 CMP0036-WARN.cmake:1 \(build_name\):
+  build_name called with incorrect number of arguments
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

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

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

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

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