Browse Source

Add policy CMP0031 to disallow load_command

Brad King 12 years ago
parent
commit
aa76518f8b

+ 2 - 0
Help/command/load_command.rst

@@ -1,6 +1,8 @@
 load_command
 ------------
 
+Disallowed.  See CMake Policy :policy:`CMP0031`.
+
 Load a command into a running CMake.
 
 ::

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

@@ -60,3 +60,4 @@ All Policies
    /policy/CMP0028
    /policy/CMP0029
    /policy/CMP0030
+   /policy/CMP0031

+ 13 - 0
Help/policy/CMP0031.rst

@@ -0,0 +1,13 @@
+CMP0031
+-------
+
+The :command:`load_command` command should not be called.
+
+This command was added in August 2002 to allow projects to add
+arbitrary commands implemented in C or C++.  However, it does
+not work when the toolchain in use does not match the ABI of
+the CMake process.  It has been mostly superseded by the
+:command:`macro` and :command:`function` commands.
+
+.. |disallowed_version| replace:: 3.0.0
+.. include:: DISALLOWED_COMMAND.txt

+ 3 - 0
Source/cmLoadCommandCommand.cxx

@@ -189,6 +189,9 @@ cmLoadedCommand::~cmLoadedCommand()
 bool cmLoadCommandCommand
 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
 {
+  if(this->Disallowed(cmPolicies::CMP0031,
+      "The load_command command should not be called; see CMP0031."))
+    { return true; }
   if(args.size() < 1 )
     {
     return true;

+ 2 - 22
Source/cmLoadCommandCommand.h

@@ -14,34 +14,14 @@
 
 #include "cmCommand.h"
 
-/** \class cmLoadCommandCommand
- * \brief Load in a Command plugin
- *
- * cmLoadCommandCommand loads a command into CMake
- */
 class cmLoadCommandCommand : public cmCommand
 {
 public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  virtual cmCommand* Clone()
-    {
-    return new cmLoadCommandCommand;
-    }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
+  virtual cmCommand* Clone() { return new cmLoadCommandCommand; }
   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 "load_command";}
-
+  virtual bool IsDiscouraged() const { return true; }
   cmTypeMacro(cmLoadCommandCommand, cmCommand);
 };
 

+ 5 - 0
Source/cmPolicies.cxx

@@ -256,6 +256,11 @@ cmPolicies::cmPolicies()
     CMP0030, "CMP0030",
     "The use_mangled_mesa command should not be called.",
     3,0,0,0, cmPolicies::WARN);
+
+  this->DefinePolicy(
+    CMP0031, "CMP0031",
+    "The load_command command should not be called.",
+    3,0,0,0, cmPolicies::WARN);
 }
 
 cmPolicies::~cmPolicies()

+ 1 - 0
Source/cmPolicies.h

@@ -82,6 +82,7 @@ public:
     CMP0028, ///< Double colon in target name means ALIAS or IMPORTED target.
     CMP0029, ///< Disallow command: subdir_depends
     CMP0030, ///< Disallow command: use_mangled_mesa
+    CMP0031, ///< Disallow command: load_command
 
     /** \brief Always the last entry.
      *

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

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

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

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

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

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0031 NEW)
+load_command()

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

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

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

@@ -0,0 +1,4 @@
+CMake Error at CMP0031-OLD.cmake:2 \(load_command\):
+  load_command Attempt to load command failed from file.*bogus_command.*
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

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

@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0031 OLD)
+load_command(bogus_command)

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

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

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

@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0031-WARN.cmake:1 \(load_command\):
+  Policy CMP0031 is not set: The load_command command should not be called.
+  Run "cmake --help-policy CMP0031" 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 CMP0031-WARN.cmake:1 \(load_command\):
+  load_command Attempt to load command failed from file.*bogus_command.*
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

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

@@ -0,0 +1 @@
+load_command(bogus_command)

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

@@ -3,6 +3,7 @@ include(RunCMake)
 foreach(p
     CMP0029
     CMP0030
+    CMP0031
     )
   run_cmake(${p}-WARN)
   run_cmake(${p}-OLD)