瀏覽代碼

modernize: manage cmCommand instances using unique_ptr.

Marc Chevrier 6 年之前
父節點
當前提交
1591f138f1
共有 100 個文件被更改,包括 793 次插入322 次删除
  1. 7 4
      Source/CTest/cmCTestBuildCommand.h
  2. 7 4
      Source/CTest/cmCTestConfigureCommand.h
  3. 7 4
      Source/CTest/cmCTestCoverageCommand.h
  4. 7 5
      Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h
  5. 8 4
      Source/CTest/cmCTestMemCheckCommand.h
  6. 7 4
      Source/CTest/cmCTestReadCustomFilesCommand.h
  7. 7 4
      Source/CTest/cmCTestRunScriptCommand.h
  8. 26 16
      Source/CTest/cmCTestScriptHandler.cxx
  9. 3 1
      Source/CTest/cmCTestScriptHandler.h
  10. 7 4
      Source/CTest/cmCTestSleepCommand.h
  11. 7 4
      Source/CTest/cmCTestStartCommand.h
  12. 7 3
      Source/CTest/cmCTestSubmitCommand.cxx
  13. 3 2
      Source/CTest/cmCTestSubmitCommand.h
  14. 7 4
      Source/CTest/cmCTestTestCommand.h
  15. 29 29
      Source/CTest/cmCTestTestHandler.cxx
  16. 7 4
      Source/CTest/cmCTestUpdateCommand.h
  17. 7 4
      Source/CTest/cmCTestUploadCommand.h
  18. 6 1
      Source/cmAddCompileDefinitionsCommand.h
  19. 6 1
      Source/cmAddCompileOptionsCommand.h
  20. 6 1
      Source/cmAddCustomCommandCommand.h
  21. 6 1
      Source/cmAddCustomTargetCommand.h
  22. 6 1
      Source/cmAddDefinitionsCommand.h
  23. 6 1
      Source/cmAddDependenciesCommand.h
  24. 6 1
      Source/cmAddExecutableCommand.h
  25. 6 1
      Source/cmAddLibraryCommand.h
  26. 6 1
      Source/cmAddLinkOptionsCommand.h
  27. 6 1
      Source/cmAddSubDirectoryCommand.h
  28. 6 1
      Source/cmAddTestCommand.h
  29. 6 1
      Source/cmAuxSourceDirectoryCommand.h
  30. 6 1
      Source/cmBreakCommand.h
  31. 6 1
      Source/cmBuildCommand.h
  32. 6 1
      Source/cmBuildNameCommand.h
  33. 4 2
      Source/cmCMakeHostSystemInformationCommand.h
  34. 6 1
      Source/cmCMakeMinimumRequired.h
  35. 6 1
      Source/cmCMakePolicyCommand.h
  36. 2 1
      Source/cmCommand.h
  37. 160 109
      Source/cmCommands.cxx
  38. 6 1
      Source/cmConfigureFileCommand.h
  39. 6 1
      Source/cmContinueCommand.h
  40. 6 1
      Source/cmCreateTestSourceList.h
  41. 6 1
      Source/cmDefinePropertyCommand.h
  42. 11 8
      Source/cmDisallowedCommand.h
  43. 6 1
      Source/cmEnableLanguageCommand.h
  44. 6 1
      Source/cmEnableTestingCommand.h
  45. 6 1
      Source/cmExecProgramCommand.h
  46. 0 1
      Source/cmExecuteProcessCommand.cxx
  47. 6 1
      Source/cmExecuteProcessCommand.h
  48. 6 1
      Source/cmExportCommand.h
  49. 4 2
      Source/cmExportLibraryDependenciesCommand.h
  50. 6 1
      Source/cmFLTKWrapUICommand.h
  51. 6 1
      Source/cmFileCommand.h
  52. 7 3
      Source/cmFindFileCommand.h
  53. 7 2
      Source/cmFindLibraryCommand.h
  54. 7 2
      Source/cmFindPackageCommand.h
  55. 7 2
      Source/cmFindPathCommand.h
  56. 7 2
      Source/cmFindProgramCommand.h
  57. 6 1
      Source/cmForEachCommand.h
  58. 8 5
      Source/cmFunctionCommand.cxx
  59. 6 1
      Source/cmFunctionCommand.h
  60. 6 1
      Source/cmGetCMakePropertyCommand.h
  61. 6 1
      Source/cmGetDirectoryPropertyCommand.h
  62. 6 1
      Source/cmGetFilenameComponentCommand.h
  63. 6 1
      Source/cmGetPropertyCommand.h
  64. 6 1
      Source/cmGetSourceFilePropertyCommand.h
  65. 6 1
      Source/cmGetTargetPropertyCommand.h
  66. 6 1
      Source/cmGetTestPropertyCommand.h
  67. 0 2
      Source/cmIfCommand.cxx
  68. 6 1
      Source/cmIfCommand.h
  69. 6 1
      Source/cmIncludeCommand.h
  70. 6 1
      Source/cmIncludeDirectoryCommand.h
  71. 6 1
      Source/cmIncludeExternalMSProjectCommand.h
  72. 6 1
      Source/cmIncludeGuardCommand.h
  73. 6 1
      Source/cmIncludeRegularExpressionCommand.h
  74. 6 1
      Source/cmInstallCommand.h
  75. 6 1
      Source/cmInstallFilesCommand.h
  76. 6 1
      Source/cmInstallProgramsCommand.h
  77. 6 1
      Source/cmInstallTargetsCommand.h
  78. 6 1
      Source/cmLinkDirectoriesCommand.h
  79. 6 1
      Source/cmLinkLibrariesCommand.h
  80. 6 1
      Source/cmListCommand.h
  81. 6 1
      Source/cmLoadCacheCommand.h
  82. 9 5
      Source/cmLoadCommandCommand.cxx
  83. 6 1
      Source/cmLoadCommandCommand.h
  84. 7 5
      Source/cmMacroCommand.cxx
  85. 6 1
      Source/cmMacroCommand.h
  86. 6 1
      Source/cmMakeDirectoryCommand.h
  87. 3 4
      Source/cmMakefile.cxx
  88. 1 1
      Source/cmMakefile.h
  89. 6 1
      Source/cmMarkAsAdvancedCommand.h
  90. 6 1
      Source/cmMathCommand.h
  91. 6 1
      Source/cmMessageCommand.h
  92. 6 1
      Source/cmOptionCommand.h
  93. 6 1
      Source/cmOutputRequiredFilesCommand.h
  94. 6 1
      Source/cmParseArgumentsCommand.h
  95. 6 1
      Source/cmProjectCommand.h
  96. 6 1
      Source/cmQTWrapCPPCommand.h
  97. 6 1
      Source/cmQTWrapUICommand.h
  98. 6 1
      Source/cmRemoveCommand.h
  99. 6 1
      Source/cmRemoveDefinitionsCommand.h
  100. 6 1
      Source/cmReturnCommand.h

+ 7 - 4
Source/CTest/cmCTestBuildCommand.h

@@ -6,13 +6,16 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestHandlerCommand.h"
 #include "cmCTestHandlerCommand.h"
+#include "cmCommand.h"
 
 
 #include <string>
 #include <string>
+#include <utility>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 class cmCTestBuildHandler;
 class cmCTestBuildHandler;
 class cmCTestGenericHandler;
 class cmCTestGenericHandler;
-class cmCommand;
 class cmExecutionStatus;
 class cmExecutionStatus;
 class cmGlobalGenerator;
 class cmGlobalGenerator;
 
 
@@ -30,12 +33,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestBuildCommand* ni = new cmCTestBuildCommand;
+    auto ni = cm::make_unique<cmCTestBuildCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 7 - 4
Source/CTest/cmCTestConfigureCommand.h

@@ -6,11 +6,14 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestHandlerCommand.h"
 #include "cmCTestHandlerCommand.h"
+#include "cmCommand.h"
 
 
 #include <string>
 #include <string>
+#include <utility>
+
+#include "cm_memory.hxx"
 
 
 class cmCTestGenericHandler;
 class cmCTestGenericHandler;
-class cmCommand;
 
 
 /** \class cmCTestConfigure
 /** \class cmCTestConfigure
  * \brief Run a ctest script
  * \brief Run a ctest script
@@ -25,12 +28,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestConfigureCommand* ni = new cmCTestConfigureCommand;
+    auto ni = cm::make_unique<cmCTestConfigureCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 7 - 4
Source/CTest/cmCTestCoverageCommand.h

@@ -6,12 +6,15 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestHandlerCommand.h"
 #include "cmCTestHandlerCommand.h"
+#include "cmCommand.h"
 
 
 #include <set>
 #include <set>
 #include <string>
 #include <string>
+#include <utility>
+
+#include "cm_memory.hxx"
 
 
 class cmCTestGenericHandler;
 class cmCTestGenericHandler;
-class cmCommand;
 
 
 /** \class cmCTestCoverage
 /** \class cmCTestCoverage
  * \brief Run a ctest script
  * \brief Run a ctest script
@@ -26,12 +29,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestCoverageCommand* ni = new cmCTestCoverageCommand;
+    auto ni = cm::make_unique<cmCTestCoverageCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 7 - 5
Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h

@@ -6,11 +6,14 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestCommand.h"
 #include "cmCTestCommand.h"
+#include "cmCommand.h"
 
 
 #include <string>
 #include <string>
+#include <utility>
 #include <vector>
 #include <vector>
 
 
-class cmCommand;
+#include "cm_memory.hxx"
+
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
 /** \class cmCTestEmptyBinaryDirectory
 /** \class cmCTestEmptyBinaryDirectory
@@ -27,13 +30,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestEmptyBinaryDirectoryCommand* ni =
-      new cmCTestEmptyBinaryDirectoryCommand;
+    auto ni = cm::make_unique<cmCTestEmptyBinaryDirectoryCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 8 - 4
Source/CTest/cmCTestMemCheckCommand.h

@@ -5,10 +5,14 @@
 
 
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
+#include <utility>
+
+#include "cm_memory.hxx"
+
 #include "cmCTestTestCommand.h"
 #include "cmCTestTestCommand.h"
+#include "cmCommand.h"
 
 
 class cmCTestGenericHandler;
 class cmCTestGenericHandler;
-class cmCommand;
 
 
 /** \class cmCTestMemCheck
 /** \class cmCTestMemCheck
  * \brief Run a ctest script
  * \brief Run a ctest script
@@ -23,12 +27,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestMemCheckCommand* ni = new cmCTestMemCheckCommand;
+    auto ni = cm::make_unique<cmCTestMemCheckCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
 protected:
 protected:

+ 7 - 4
Source/CTest/cmCTestReadCustomFilesCommand.h

@@ -6,11 +6,14 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestCommand.h"
 #include "cmCTestCommand.h"
+#include "cmCommand.h"
 
 
 #include <string>
 #include <string>
+#include <utility>
 #include <vector>
 #include <vector>
 
 
-class cmCommand;
+#include "cm_memory.hxx"
+
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
 /** \class cmCTestReadCustomFiles
 /** \class cmCTestReadCustomFiles
@@ -27,11 +30,11 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestReadCustomFilesCommand* ni = new cmCTestReadCustomFilesCommand;
+    auto ni = cm::make_unique<cmCTestReadCustomFilesCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 7 - 4
Source/CTest/cmCTestRunScriptCommand.h

@@ -6,11 +6,14 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestCommand.h"
 #include "cmCTestCommand.h"
+#include "cmCommand.h"
 
 
 #include <string>
 #include <string>
+#include <utility>
 #include <vector>
 #include <vector>
 
 
-class cmCommand;
+#include "cm_memory.hxx"
+
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
 /** \class cmCTestRunScript
 /** \class cmCTestRunScript
@@ -27,12 +30,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestRunScriptCommand* ni = new cmCTestRunScriptCommand;
+    auto ni = cm::make_unique<cmCTestRunScriptCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 26 - 16
Source/CTest/cmCTestScriptHandler.cxx

@@ -12,6 +12,8 @@
 #include <string.h>
 #include <string.h>
 #include <utility>
 #include <utility>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCTestBuildCommand.h"
 #include "cmCTestBuildCommand.h"
 #include "cmCTestCommand.h"
 #include "cmCTestCommand.h"
@@ -27,6 +29,7 @@
 #include "cmCTestTestCommand.h"
 #include "cmCTestTestCommand.h"
 #include "cmCTestUpdateCommand.h"
 #include "cmCTestUpdateCommand.h"
 #include "cmCTestUploadCommand.h"
 #include "cmCTestUploadCommand.h"
+#include "cmCommand.h"
 #include "cmDuration.h"
 #include "cmDuration.h"
 #include "cmFunctionBlocker.h"
 #include "cmFunctionBlocker.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratedFileStream.h"
@@ -167,12 +170,12 @@ void cmCTestScriptHandler::UpdateElapsedTime()
   }
   }
 }
 }
 
 
-void cmCTestScriptHandler::AddCTestCommand(std::string const& name,
-                                           cmCTestCommand* command)
+void cmCTestScriptHandler::AddCTestCommand(
+  std::string const& name, std::unique_ptr<cmCTestCommand> command)
 {
 {
   command->CTest = this->CTest;
   command->CTest = this->CTest;
   command->CTestScriptHandler = this;
   command->CTestScriptHandler = this;
-  this->CMake->GetState()->AddBuiltinCommand(name, command);
+  this->CMake->GetState()->AddBuiltinCommand(name, std::move(command));
 }
 }
 
 
 int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
 int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
@@ -295,21 +298,28 @@ void cmCTestScriptHandler::CreateCMake()
       }
       }
     });
     });
 
 
-  this->AddCTestCommand("ctest_build", new cmCTestBuildCommand);
-  this->AddCTestCommand("ctest_configure", new cmCTestConfigureCommand);
-  this->AddCTestCommand("ctest_coverage", new cmCTestCoverageCommand);
+  this->AddCTestCommand("ctest_build", cm::make_unique<cmCTestBuildCommand>());
+  this->AddCTestCommand("ctest_configure",
+                        cm::make_unique<cmCTestConfigureCommand>());
+  this->AddCTestCommand("ctest_coverage",
+                        cm::make_unique<cmCTestCoverageCommand>());
   this->AddCTestCommand("ctest_empty_binary_directory",
   this->AddCTestCommand("ctest_empty_binary_directory",
-                        new cmCTestEmptyBinaryDirectoryCommand);
-  this->AddCTestCommand("ctest_memcheck", new cmCTestMemCheckCommand);
+                        cm::make_unique<cmCTestEmptyBinaryDirectoryCommand>());
+  this->AddCTestCommand("ctest_memcheck",
+                        cm::make_unique<cmCTestMemCheckCommand>());
   this->AddCTestCommand("ctest_read_custom_files",
   this->AddCTestCommand("ctest_read_custom_files",
-                        new cmCTestReadCustomFilesCommand);
-  this->AddCTestCommand("ctest_run_script", new cmCTestRunScriptCommand);
-  this->AddCTestCommand("ctest_sleep", new cmCTestSleepCommand);
-  this->AddCTestCommand("ctest_start", new cmCTestStartCommand);
-  this->AddCTestCommand("ctest_submit", new cmCTestSubmitCommand);
-  this->AddCTestCommand("ctest_test", new cmCTestTestCommand);
-  this->AddCTestCommand("ctest_update", new cmCTestUpdateCommand);
-  this->AddCTestCommand("ctest_upload", new cmCTestUploadCommand);
+                        cm::make_unique<cmCTestReadCustomFilesCommand>());
+  this->AddCTestCommand("ctest_run_script",
+                        cm::make_unique<cmCTestRunScriptCommand>());
+  this->AddCTestCommand("ctest_sleep", cm::make_unique<cmCTestSleepCommand>());
+  this->AddCTestCommand("ctest_start", cm::make_unique<cmCTestStartCommand>());
+  this->AddCTestCommand("ctest_submit",
+                        cm::make_unique<cmCTestSubmitCommand>());
+  this->AddCTestCommand("ctest_test", cm::make_unique<cmCTestTestCommand>());
+  this->AddCTestCommand("ctest_update",
+                        cm::make_unique<cmCTestUpdateCommand>());
+  this->AddCTestCommand("ctest_upload",
+                        cm::make_unique<cmCTestUploadCommand>());
 }
 }
 
 
 // this sets up some variables for the script to use, creates the required
 // this sets up some variables for the script to use, creates the required

+ 3 - 1
Source/CTest/cmCTestScriptHandler.h

@@ -9,6 +9,7 @@
 #include "cmDuration.h"
 #include "cmDuration.h"
 
 
 #include <chrono>
 #include <chrono>
+#include <memory>
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
@@ -131,7 +132,8 @@ private:
   int RunConfigurationDashboard();
   int RunConfigurationDashboard();
 
 
   // Add ctest command
   // Add ctest command
-  void AddCTestCommand(std::string const& name, cmCTestCommand* command);
+  void AddCTestCommand(std::string const& name,
+                       std::unique_ptr<cmCTestCommand> command);
 
 
   // Try to remove the binary directory once
   // Try to remove the binary directory once
   static bool TryToRemoveBinaryDirectoryOnce(const std::string& directoryPath);
   static bool TryToRemoveBinaryDirectoryOnce(const std::string& directoryPath);

+ 7 - 4
Source/CTest/cmCTestSleepCommand.h

@@ -6,11 +6,14 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestCommand.h"
 #include "cmCTestCommand.h"
+#include "cmCommand.h"
 
 
 #include <string>
 #include <string>
+#include <utility>
 #include <vector>
 #include <vector>
 
 
-class cmCommand;
+#include "cm_memory.hxx"
+
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
 /** \class cmCTestSleep
 /** \class cmCTestSleep
@@ -27,12 +30,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestSleepCommand* ni = new cmCTestSleepCommand;
+    auto ni = cm::make_unique<cmCTestSleepCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 7 - 4
Source/CTest/cmCTestStartCommand.h

@@ -6,12 +6,15 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestCommand.h"
 #include "cmCTestCommand.h"
+#include "cmCommand.h"
 
 
 #include <iosfwd>
 #include <iosfwd>
 #include <string>
 #include <string>
+#include <utility>
 #include <vector>
 #include <vector>
 
 
-class cmCommand;
+#include "cm_memory.hxx"
+
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
 /** \class cmCTestStart
 /** \class cmCTestStart
@@ -27,14 +30,14 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestStartCommand* ni = new cmCTestStartCommand;
+    auto ni = cm::make_unique<cmCTestStartCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CreateNewTag = this->CreateNewTag;
     ni->CreateNewTag = this->CreateNewTag;
     ni->Quiet = this->Quiet;
     ni->Quiet = this->Quiet;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 7 - 3
Source/CTest/cmCTestSubmitCommand.cxx

@@ -4,11 +4,15 @@
 
 
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCTestSubmitHandler.h"
 #include "cmCTestSubmitHandler.h"
+#include "cmCommand.h"
 #include "cmMakefile.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
 #include "cmMessageType.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 
 
 #include <sstream>
 #include <sstream>
+#include <utility>
+
+#include "cm_memory.hxx"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
@@ -27,12 +31,12 @@ cmCTestSubmitCommand::cmCTestSubmitCommand()
 /**
 /**
  * This is a virtual constructor for the command.
  * This is a virtual constructor for the command.
  */
  */
-cmCommand* cmCTestSubmitCommand::Clone()
+std::unique_ptr<cmCommand> cmCTestSubmitCommand::Clone()
 {
 {
-  cmCTestSubmitCommand* ni = new cmCTestSubmitCommand;
+  auto ni = cm::make_unique<cmCTestSubmitCommand>();
   ni->CTest = this->CTest;
   ni->CTest = this->CTest;
   ni->CTestScriptHandler = this->CTestScriptHandler;
   ni->CTestScriptHandler = this->CTestScriptHandler;
-  return ni;
+  return std::unique_ptr<cmCommand>(std::move(ni));
 }
 }
 
 
 cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
 cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()

+ 3 - 2
Source/CTest/cmCTestSubmitCommand.h

@@ -8,12 +8,13 @@
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCTestHandlerCommand.h"
 #include "cmCTestHandlerCommand.h"
 
 
+#include <memory>
 #include <set>
 #include <set>
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
-class cmCTestGenericHandler;
 class cmCommand;
 class cmCommand;
+class cmCTestGenericHandler;
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
 /** \class cmCTestSubmit
 /** \class cmCTestSubmit
@@ -26,7 +27,7 @@ class cmCTestSubmitCommand : public cmCTestHandlerCommand
 {
 {
 public:
 public:
   cmCTestSubmitCommand();
   cmCTestSubmitCommand();
-  cmCommand* Clone() override;
+  std::unique_ptr<cmCommand> Clone() override;
 
 
   bool InitialPass(std::vector<std::string> const& args,
   bool InitialPass(std::vector<std::string> const& args,
                    cmExecutionStatus& status) override;
                    cmExecutionStatus& status) override;

+ 7 - 4
Source/CTest/cmCTestTestCommand.h

@@ -6,11 +6,14 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestHandlerCommand.h"
 #include "cmCTestHandlerCommand.h"
+#include "cmCommand.h"
 
 
 #include <string>
 #include <string>
+#include <utility>
+
+#include "cm_memory.hxx"
 
 
 class cmCTestGenericHandler;
 class cmCTestGenericHandler;
-class cmCommand;
 
 
 /** \class cmCTestTest
 /** \class cmCTestTest
  * \brief Run a ctest script
  * \brief Run a ctest script
@@ -25,12 +28,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestTestCommand* ni = new cmCTestTestCommand;
+    auto ni = cm::make_unique<cmCTestTestCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 29 - 29
Source/CTest/cmCTestTestHandler.cxx

@@ -11,12 +11,14 @@
 #include <functional>
 #include <functional>
 #include <iomanip>
 #include <iomanip>
 #include <iterator>
 #include <iterator>
-#include <memory>
 #include <set>
 #include <set>
 #include <sstream>
 #include <sstream>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <time.h>
 #include <time.h>
+#include <utility>
+
+#include "cm_memory.hxx"
 
 
 #include "cmAlgorithms.h"
 #include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTest.h"
@@ -43,11 +45,11 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
+    auto c = cm::make_unique<cmCTestSubdirCommand>();
     c->TestHandler = this->TestHandler;
     c->TestHandler = this->TestHandler;
-    return c;
+    return std::unique_ptr<cmCommand>(std::move(c));
   }
   }
 
 
   /**
   /**
@@ -122,11 +124,11 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestAddSubdirectoryCommand* c = new cmCTestAddSubdirectoryCommand;
+    auto c = cm::make_unique<cmCTestAddSubdirectoryCommand>();
     c->TestHandler = this->TestHandler;
     c->TestHandler = this->TestHandler;
-    return c;
+    return std::unique_ptr<cmCommand>(std::move(c));
   }
   }
 
 
   /**
   /**
@@ -187,11 +189,11 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestAddTestCommand* c = new cmCTestAddTestCommand;
+    auto c = cm::make_unique<cmCTestAddTestCommand>();
     c->TestHandler = this->TestHandler;
     c->TestHandler = this->TestHandler;
-    return c;
+    return std::unique_ptr<cmCommand>(std::move(c));
   }
   }
 
 
   /**
   /**
@@ -220,11 +222,11 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestSetTestsPropertiesCommand* c = new cmCTestSetTestsPropertiesCommand;
+    auto c = cm::make_unique<cmCTestSetTestsPropertiesCommand>();
     c->TestHandler = this->TestHandler;
     c->TestHandler = this->TestHandler;
-    return c;
+    return std::unique_ptr<cmCommand>(std::move(c));
   }
   }
 
 
   /**
   /**
@@ -249,12 +251,11 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestSetDirectoryPropertiesCommand* c =
-      new cmCTestSetDirectoryPropertiesCommand;
+    auto c = cm::make_unique<cmCTestSetDirectoryPropertiesCommand>();
     c->TestHandler = this->TestHandler;
     c->TestHandler = this->TestHandler;
-    return c;
+    return std::unique_ptr<cmCommand>(std::move(c));
   }
   }
 
 
   /**
   /**
@@ -1686,32 +1687,31 @@ void cmCTestTestHandler::GetListOfTests()
                    this->CTest->GetConfigType().c_str());
                    this->CTest->GetConfigType().c_str());
 
 
   // Add handler for ADD_TEST
   // Add handler for ADD_TEST
-  cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
+  auto newCom1 = cm::make_unique<cmCTestAddTestCommand>();
   newCom1->TestHandler = this;
   newCom1->TestHandler = this;
-  cm.GetState()->AddBuiltinCommand("add_test", newCom1);
+  cm.GetState()->AddBuiltinCommand("add_test", std::move(newCom1));
 
 
   // Add handler for SUBDIRS
   // Add handler for SUBDIRS
-  cmCTestSubdirCommand* newCom2 = new cmCTestSubdirCommand;
+  auto newCom2 = cm::make_unique<cmCTestSubdirCommand>();
   newCom2->TestHandler = this;
   newCom2->TestHandler = this;
-  cm.GetState()->AddBuiltinCommand("subdirs", newCom2);
+  cm.GetState()->AddBuiltinCommand("subdirs", std::move(newCom2));
 
 
   // Add handler for ADD_SUBDIRECTORY
   // Add handler for ADD_SUBDIRECTORY
-  cmCTestAddSubdirectoryCommand* newCom3 = new cmCTestAddSubdirectoryCommand;
+  auto newCom3 = cm::make_unique<cmCTestAddSubdirectoryCommand>();
   newCom3->TestHandler = this;
   newCom3->TestHandler = this;
-  cm.GetState()->AddBuiltinCommand("add_subdirectory", newCom3);
+  cm.GetState()->AddBuiltinCommand("add_subdirectory", std::move(newCom3));
 
 
   // Add handler for SET_TESTS_PROPERTIES
   // Add handler for SET_TESTS_PROPERTIES
-  cmCTestSetTestsPropertiesCommand* newCom4 =
-    new cmCTestSetTestsPropertiesCommand;
+  auto newCom4 = cm::make_unique<cmCTestSetTestsPropertiesCommand>();
   newCom4->TestHandler = this;
   newCom4->TestHandler = this;
-  cm.GetState()->AddBuiltinCommand("set_tests_properties", newCom4);
+  cm.GetState()->AddBuiltinCommand("set_tests_properties", std::move(newCom4));
 
 
   // Add handler for SET_DIRECTORY_PROPERTIES
   // Add handler for SET_DIRECTORY_PROPERTIES
   cm.GetState()->RemoveBuiltinCommand("set_directory_properties");
   cm.GetState()->RemoveBuiltinCommand("set_directory_properties");
-  cmCTestSetDirectoryPropertiesCommand* newCom5 =
-    new cmCTestSetDirectoryPropertiesCommand;
+  auto newCom5 = cm::make_unique<cmCTestSetDirectoryPropertiesCommand>();
   newCom5->TestHandler = this;
   newCom5->TestHandler = this;
-  cm.GetState()->AddBuiltinCommand("set_directory_properties", newCom5);
+  cm.GetState()->AddBuiltinCommand("set_directory_properties",
+                                   std::move(newCom5));
 
 
   const char* testFilename;
   const char* testFilename;
   if (cmSystemTools::FileExists("CTestTestfile.cmake")) {
   if (cmSystemTools::FileExists("CTestTestfile.cmake")) {

+ 7 - 4
Source/CTest/cmCTestUpdateCommand.h

@@ -6,11 +6,14 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestHandlerCommand.h"
 #include "cmCTestHandlerCommand.h"
+#include "cmCommand.h"
 
 
 #include <string>
 #include <string>
+#include <utility>
+
+#include "cm_memory.hxx"
 
 
 class cmCTestGenericHandler;
 class cmCTestGenericHandler;
-class cmCommand;
 
 
 /** \class cmCTestUpdate
 /** \class cmCTestUpdate
  * \brief Run a ctest script
  * \brief Run a ctest script
@@ -25,12 +28,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestUpdateCommand* ni = new cmCTestUpdateCommand;
+    auto ni = cm::make_unique<cmCTestUpdateCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 7 - 4
Source/CTest/cmCTestUploadCommand.h

@@ -6,12 +6,15 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include "cmCTestHandlerCommand.h"
 #include "cmCTestHandlerCommand.h"
+#include "cmCommand.h"
 
 
 #include <set>
 #include <set>
 #include <string>
 #include <string>
+#include <utility>
+
+#include "cm_memory.hxx"
 
 
 class cmCTestGenericHandler;
 class cmCTestGenericHandler;
-class cmCommand;
 
 
 /** \class cmCTestUpload
 /** \class cmCTestUpload
  * \brief Run a ctest script
  * \brief Run a ctest script
@@ -25,12 +28,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmCTestUploadCommand* ni = new cmCTestUploadCommand;
+    auto ni = cm::make_unique<cmCTestUploadCommand>();
     ni->CTest = this->CTest;
     ni->CTest = this->CTest;
     ni->CTestScriptHandler = this->CTestScriptHandler;
     ni->CTestScriptHandler = this->CTestScriptHandler;
-    return ni;
+    return std::unique_ptr<cmCommand>(std::move(ni));
   }
   }
 
 
   /**
   /**

+ 6 - 1
Source/cmAddCompileDefinitionsCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -18,7 +20,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddCompileDefinitionsCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddCompileDefinitionsCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddCompileOptionsCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -18,7 +20,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddCompileOptionsCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddCompileOptionsCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddCustomCommandCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddCustomCommandCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddCustomCommandCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddCustomTargetCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -25,7 +27,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddCustomTargetCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddCustomTargetCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddDefinitionsCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddDefinitionsCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddDefinitionsCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddDependenciesCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddDependenciesCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddDependenciesCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddExecutableCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddExecutableCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddExecutableCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddLibraryCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddLibraryCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddLibraryCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddLinkOptionsCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -18,7 +20,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddLinkOptionsCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddLinkOptionsCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddSubDirectoryCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -25,7 +27,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddSubDirectoryCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddSubDirectoryCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAddTestCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAddTestCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAddTestCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmAuxSourceDirectoryCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -27,7 +29,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmAuxSourceDirectoryCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmAuxSourceDirectoryCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmBreakCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmBreakCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmBreakCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmBuildCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmBuildCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmBuildCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmBuildNameCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -15,7 +17,10 @@ class cmExecutionStatus;
 class cmBuildNameCommand : public cmCommand
 class cmBuildNameCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmBuildNameCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmBuildNameCommand>();
+  }
   bool InitialPass(std::vector<std::string> const& args,
   bool InitialPass(std::vector<std::string> const& args,
                    cmExecutionStatus& status) override;
                    cmExecutionStatus& status) override;
 };
 };

+ 4 - 2
Source/cmCMakeHostSystemInformationCommand.h

@@ -9,6 +9,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -28,9 +30,9 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    return new cmCMakeHostSystemInformationCommand;
+    return cm::make_unique<cmCMakeHostSystemInformationCommand>();
   }
   }
 
 
   /**
   /**

+ 6 - 1
Source/cmCMakeMinimumRequired.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmCMakeMinimumRequired; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmCMakeMinimumRequired>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmCMakePolicyCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmCMakePolicyCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmCMakePolicyCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 2 - 1
Source/cmCommand.h

@@ -5,6 +5,7 @@
 
 
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
+#include <memory>
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
@@ -75,7 +76,7 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  virtual cmCommand* Clone() = 0;
+  virtual std::unique_ptr<cmCommand> Clone() = 0;
 
 
   /**
   /**
    * Return the last error string.
    * Return the last error string.

+ 160 - 109
Source/cmCommands.cxx

@@ -1,5 +1,8 @@
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
+
+#include "cm_memory.hxx"
+
 #include "cmCommands.h"
 #include "cmCommands.h"
 #include "cmPolicies.h"
 #include "cmPolicies.h"
 #include "cmState.h"
 #include "cmState.h"
@@ -17,6 +20,7 @@
 #include "cmBuildCommand.h"
 #include "cmBuildCommand.h"
 #include "cmCMakeMinimumRequired.h"
 #include "cmCMakeMinimumRequired.h"
 #include "cmCMakePolicyCommand.h"
 #include "cmCMakePolicyCommand.h"
+#include "cmCommand.h"
 #include "cmConfigureFileCommand.h"
 #include "cmConfigureFileCommand.h"
 #include "cmContinueCommand.h"
 #include "cmContinueCommand.h"
 #include "cmCreateTestSourceList.h"
 #include "cmCreateTestSourceList.h"
@@ -112,52 +116,64 @@
 
 
 void GetScriptingCommands(cmState* state)
 void GetScriptingCommands(cmState* state)
 {
 {
-  state->AddBuiltinCommand("break", new cmBreakCommand);
+  state->AddBuiltinCommand("break", cm::make_unique<cmBreakCommand>());
   state->AddBuiltinCommand("cmake_minimum_required",
   state->AddBuiltinCommand("cmake_minimum_required",
-                           new cmCMakeMinimumRequired);
-  state->AddBuiltinCommand("cmake_policy", new cmCMakePolicyCommand);
-  state->AddBuiltinCommand("configure_file", new cmConfigureFileCommand);
-  state->AddBuiltinCommand("continue", new cmContinueCommand);
-  state->AddBuiltinCommand("exec_program", new cmExecProgramCommand);
-  state->AddBuiltinCommand("execute_process", new cmExecuteProcessCommand);
-  state->AddBuiltinCommand("file", new cmFileCommand);
-  state->AddBuiltinCommand("find_file", new cmFindFileCommand);
-  state->AddBuiltinCommand("find_library", new cmFindLibraryCommand);
-  state->AddBuiltinCommand("find_package", new cmFindPackageCommand);
-  state->AddBuiltinCommand("find_path", new cmFindPathCommand);
-  state->AddBuiltinCommand("find_program", new cmFindProgramCommand);
-  state->AddBuiltinCommand("foreach", new cmForEachCommand);
-  state->AddBuiltinCommand("function", new cmFunctionCommand);
+                           cm::make_unique<cmCMakeMinimumRequired>());
+  state->AddBuiltinCommand("cmake_policy",
+                           cm::make_unique<cmCMakePolicyCommand>());
+  state->AddBuiltinCommand("configure_file",
+                           cm::make_unique<cmConfigureFileCommand>());
+  state->AddBuiltinCommand("continue", cm::make_unique<cmContinueCommand>());
+  state->AddBuiltinCommand("exec_program",
+                           cm::make_unique<cmExecProgramCommand>());
+  state->AddBuiltinCommand("execute_process",
+                           cm::make_unique<cmExecuteProcessCommand>());
+  state->AddBuiltinCommand("file", cm::make_unique<cmFileCommand>());
+  state->AddBuiltinCommand("find_file", cm::make_unique<cmFindFileCommand>());
+  state->AddBuiltinCommand("find_library",
+                           cm::make_unique<cmFindLibraryCommand>());
+  state->AddBuiltinCommand("find_package",
+                           cm::make_unique<cmFindPackageCommand>());
+  state->AddBuiltinCommand("find_path", cm::make_unique<cmFindPathCommand>());
+  state->AddBuiltinCommand("find_program",
+                           cm::make_unique<cmFindProgramCommand>());
+  state->AddBuiltinCommand("foreach", cm::make_unique<cmForEachCommand>());
+  state->AddBuiltinCommand("function", cm::make_unique<cmFunctionCommand>());
   state->AddBuiltinCommand("get_cmake_property",
   state->AddBuiltinCommand("get_cmake_property",
-                           new cmGetCMakePropertyCommand);
+                           cm::make_unique<cmGetCMakePropertyCommand>());
   state->AddBuiltinCommand("get_directory_property",
   state->AddBuiltinCommand("get_directory_property",
-                           new cmGetDirectoryPropertyCommand);
+                           cm::make_unique<cmGetDirectoryPropertyCommand>());
   state->AddBuiltinCommand("get_filename_component",
   state->AddBuiltinCommand("get_filename_component",
-                           new cmGetFilenameComponentCommand);
-  state->AddBuiltinCommand("get_property", new cmGetPropertyCommand);
-  state->AddBuiltinCommand("if", new cmIfCommand);
-  state->AddBuiltinCommand("include", new cmIncludeCommand);
-  state->AddBuiltinCommand("include_guard", new cmIncludeGuardCommand);
-  state->AddBuiltinCommand("list", new cmListCommand);
-  state->AddBuiltinCommand("macro", new cmMacroCommand);
-  state->AddBuiltinCommand("make_directory", new cmMakeDirectoryCommand);
-  state->AddBuiltinCommand("mark_as_advanced", new cmMarkAsAdvancedCommand);
-  state->AddBuiltinCommand("math", new cmMathCommand);
-  state->AddBuiltinCommand("message", new cmMessageCommand);
-  state->AddBuiltinCommand("option", new cmOptionCommand);
+                           cm::make_unique<cmGetFilenameComponentCommand>());
+  state->AddBuiltinCommand("get_property",
+                           cm::make_unique<cmGetPropertyCommand>());
+  state->AddBuiltinCommand("if", cm::make_unique<cmIfCommand>());
+  state->AddBuiltinCommand("include", cm::make_unique<cmIncludeCommand>());
+  state->AddBuiltinCommand("include_guard",
+                           cm::make_unique<cmIncludeGuardCommand>());
+  state->AddBuiltinCommand("list", cm::make_unique<cmListCommand>());
+  state->AddBuiltinCommand("macro", cm::make_unique<cmMacroCommand>());
+  state->AddBuiltinCommand("make_directory",
+                           cm::make_unique<cmMakeDirectoryCommand>());
+  state->AddBuiltinCommand("mark_as_advanced",
+                           cm::make_unique<cmMarkAsAdvancedCommand>());
+  state->AddBuiltinCommand("math", cm::make_unique<cmMathCommand>());
+  state->AddBuiltinCommand("message", cm::make_unique<cmMessageCommand>());
+  state->AddBuiltinCommand("option", cm::make_unique<cmOptionCommand>());
   state->AddBuiltinCommand("cmake_parse_arguments",
   state->AddBuiltinCommand("cmake_parse_arguments",
-                           new cmParseArgumentsCommand);
-  state->AddBuiltinCommand("return", new cmReturnCommand);
+                           cm::make_unique<cmParseArgumentsCommand>());
+  state->AddBuiltinCommand("return", cm::make_unique<cmReturnCommand>());
   state->AddBuiltinCommand("separate_arguments",
   state->AddBuiltinCommand("separate_arguments",
-                           new cmSeparateArgumentsCommand);
-  state->AddBuiltinCommand("set", new cmSetCommand);
+                           cm::make_unique<cmSeparateArgumentsCommand>());
+  state->AddBuiltinCommand("set", cm::make_unique<cmSetCommand>());
   state->AddBuiltinCommand("set_directory_properties",
   state->AddBuiltinCommand("set_directory_properties",
-                           new cmSetDirectoryPropertiesCommand);
-  state->AddBuiltinCommand("set_property", new cmSetPropertyCommand);
-  state->AddBuiltinCommand("site_name", new cmSiteNameCommand);
-  state->AddBuiltinCommand("string", new cmStringCommand);
-  state->AddBuiltinCommand("unset", new cmUnsetCommand);
-  state->AddBuiltinCommand("while", new cmWhileCommand);
+                           cm::make_unique<cmSetDirectoryPropertiesCommand>());
+  state->AddBuiltinCommand("set_property",
+                           cm::make_unique<cmSetPropertyCommand>());
+  state->AddBuiltinCommand("site_name", cm::make_unique<cmSiteNameCommand>());
+  state->AddBuiltinCommand("string", cm::make_unique<cmStringCommand>());
+  state->AddBuiltinCommand("unset", cm::make_unique<cmUnsetCommand>());
+  state->AddBuiltinCommand("while", cm::make_unique<cmWhileCommand>());
 
 
   state->AddUnexpectedCommand(
   state->AddUnexpectedCommand(
     "else",
     "else",
@@ -195,17 +211,21 @@ void GetScriptingCommands(cmState* state)
     "match the opening WHILE command.");
     "match the opening WHILE command.");
 
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
 #if defined(CMAKE_BUILD_WITH_CMAKE)
-  state->AddBuiltinCommand("cmake_host_system_information",
-                           new cmCMakeHostSystemInformationCommand);
-  state->AddBuiltinCommand("remove", new cmRemoveCommand);
-  state->AddBuiltinCommand("variable_watch", new cmVariableWatchCommand);
-  state->AddBuiltinCommand("write_file", new cmWriteFileCommand);
+  state->AddBuiltinCommand(
+    "cmake_host_system_information",
+    cm::make_unique<cmCMakeHostSystemInformationCommand>());
+  state->AddBuiltinCommand("remove", cm::make_unique<cmRemoveCommand>());
+  state->AddBuiltinCommand("variable_watch",
+                           cm::make_unique<cmVariableWatchCommand>());
+  state->AddBuiltinCommand("write_file",
+                           cm::make_unique<cmWriteFileCommand>());
 
 
   state->AddDisallowedCommand(
   state->AddDisallowedCommand(
-    "build_name", new cmBuildNameCommand, cmPolicies::CMP0036,
+    "build_name", cm::make_unique<cmBuildNameCommand>(), cmPolicies::CMP0036,
     "The build_name command should not be called; see CMP0036.");
     "The build_name command should not be called; see CMP0036.");
   state->AddDisallowedCommand(
   state->AddDisallowedCommand(
-    "use_mangled_mesa", new cmUseMangledMesaCommand, cmPolicies::CMP0030,
+    "use_mangled_mesa", cm::make_unique<cmUseMangledMesaCommand>(),
+    cmPolicies::CMP0030,
     "The use_mangled_mesa command should not be called; see CMP0030.");
     "The use_mangled_mesa command should not be called; see CMP0030.");
 
 
 #endif
 #endif
@@ -214,100 +234,131 @@ void GetScriptingCommands(cmState* state)
 void GetProjectCommands(cmState* state)
 void GetProjectCommands(cmState* state)
 {
 {
   state->AddBuiltinCommand("add_custom_command",
   state->AddBuiltinCommand("add_custom_command",
-                           new cmAddCustomCommandCommand);
-  state->AddBuiltinCommand("add_custom_target", new cmAddCustomTargetCommand);
-  state->AddBuiltinCommand("add_definitions", new cmAddDefinitionsCommand);
-  state->AddBuiltinCommand("add_dependencies", new cmAddDependenciesCommand);
-  state->AddBuiltinCommand("add_executable", new cmAddExecutableCommand);
-  state->AddBuiltinCommand("add_library", new cmAddLibraryCommand);
-  state->AddBuiltinCommand("add_subdirectory", new cmAddSubDirectoryCommand);
-  state->AddBuiltinCommand("add_test", new cmAddTestCommand);
-  state->AddBuiltinCommand("build_command", new cmBuildCommand);
+                           cm::make_unique<cmAddCustomCommandCommand>());
+  state->AddBuiltinCommand("add_custom_target",
+                           cm::make_unique<cmAddCustomTargetCommand>());
+  state->AddBuiltinCommand("add_definitions",
+                           cm::make_unique<cmAddDefinitionsCommand>());
+  state->AddBuiltinCommand("add_dependencies",
+                           cm::make_unique<cmAddDependenciesCommand>());
+  state->AddBuiltinCommand("add_executable",
+                           cm::make_unique<cmAddExecutableCommand>());
+  state->AddBuiltinCommand("add_library",
+                           cm::make_unique<cmAddLibraryCommand>());
+  state->AddBuiltinCommand("add_subdirectory",
+                           cm::make_unique<cmAddSubDirectoryCommand>());
+  state->AddBuiltinCommand("add_test", cm::make_unique<cmAddTestCommand>());
+  state->AddBuiltinCommand("build_command", cm::make_unique<cmBuildCommand>());
   state->AddBuiltinCommand("create_test_sourcelist",
   state->AddBuiltinCommand("create_test_sourcelist",
-                           new cmCreateTestSourceList);
-  state->AddBuiltinCommand("define_property", new cmDefinePropertyCommand);
-  state->AddBuiltinCommand("enable_language", new cmEnableLanguageCommand);
-  state->AddBuiltinCommand("enable_testing", new cmEnableTestingCommand);
+                           cm::make_unique<cmCreateTestSourceList>());
+  state->AddBuiltinCommand("define_property",
+                           cm::make_unique<cmDefinePropertyCommand>());
+  state->AddBuiltinCommand("enable_language",
+                           cm::make_unique<cmEnableLanguageCommand>());
+  state->AddBuiltinCommand("enable_testing",
+                           cm::make_unique<cmEnableTestingCommand>());
   state->AddBuiltinCommand("get_source_file_property",
   state->AddBuiltinCommand("get_source_file_property",
-                           new cmGetSourceFilePropertyCommand);
+                           cm::make_unique<cmGetSourceFilePropertyCommand>());
   state->AddBuiltinCommand("get_target_property",
   state->AddBuiltinCommand("get_target_property",
-                           new cmGetTargetPropertyCommand);
-  state->AddBuiltinCommand("get_test_property", new cmGetTestPropertyCommand);
+                           cm::make_unique<cmGetTargetPropertyCommand>());
+  state->AddBuiltinCommand("get_test_property",
+                           cm::make_unique<cmGetTestPropertyCommand>());
   state->AddBuiltinCommand("include_directories",
   state->AddBuiltinCommand("include_directories",
-                           new cmIncludeDirectoryCommand);
-  state->AddBuiltinCommand("include_regular_expression",
-                           new cmIncludeRegularExpressionCommand);
-  state->AddBuiltinCommand("install", new cmInstallCommand);
-  state->AddBuiltinCommand("install_files", new cmInstallFilesCommand);
-  state->AddBuiltinCommand("install_targets", new cmInstallTargetsCommand);
-  state->AddBuiltinCommand("link_directories", new cmLinkDirectoriesCommand);
-  state->AddBuiltinCommand("project", new cmProjectCommand);
-  state->AddBuiltinCommand("set_source_files_properties",
-                           new cmSetSourceFilesPropertiesCommand);
+                           cm::make_unique<cmIncludeDirectoryCommand>());
+  state->AddBuiltinCommand(
+    "include_regular_expression",
+    cm::make_unique<cmIncludeRegularExpressionCommand>());
+  state->AddBuiltinCommand("install", cm::make_unique<cmInstallCommand>());
+  state->AddBuiltinCommand("install_files",
+                           cm::make_unique<cmInstallFilesCommand>());
+  state->AddBuiltinCommand("install_targets",
+                           cm::make_unique<cmInstallTargetsCommand>());
+  state->AddBuiltinCommand("link_directories",
+                           cm::make_unique<cmLinkDirectoriesCommand>());
+  state->AddBuiltinCommand("project", cm::make_unique<cmProjectCommand>());
+  state->AddBuiltinCommand(
+    "set_source_files_properties",
+    cm::make_unique<cmSetSourceFilesPropertiesCommand>());
   state->AddBuiltinCommand("set_target_properties",
   state->AddBuiltinCommand("set_target_properties",
-                           new cmSetTargetPropertiesCommand);
+                           cm::make_unique<cmSetTargetPropertiesCommand>());
   state->AddBuiltinCommand("set_tests_properties",
   state->AddBuiltinCommand("set_tests_properties",
-                           new cmSetTestsPropertiesCommand);
-  state->AddBuiltinCommand("subdirs", new cmSubdirCommand);
-  state->AddBuiltinCommand("target_compile_definitions",
-                           new cmTargetCompileDefinitionsCommand);
+                           cm::make_unique<cmSetTestsPropertiesCommand>());
+  state->AddBuiltinCommand("subdirs", cm::make_unique<cmSubdirCommand>());
+  state->AddBuiltinCommand(
+    "target_compile_definitions",
+    cm::make_unique<cmTargetCompileDefinitionsCommand>());
   state->AddBuiltinCommand("target_compile_features",
   state->AddBuiltinCommand("target_compile_features",
-                           new cmTargetCompileFeaturesCommand);
+                           cm::make_unique<cmTargetCompileFeaturesCommand>());
   state->AddBuiltinCommand("target_compile_options",
   state->AddBuiltinCommand("target_compile_options",
-                           new cmTargetCompileOptionsCommand);
-  state->AddBuiltinCommand("target_include_directories",
-                           new cmTargetIncludeDirectoriesCommand);
+                           cm::make_unique<cmTargetCompileOptionsCommand>());
+  state->AddBuiltinCommand(
+    "target_include_directories",
+    cm::make_unique<cmTargetIncludeDirectoriesCommand>());
   state->AddBuiltinCommand("target_link_libraries",
   state->AddBuiltinCommand("target_link_libraries",
-                           new cmTargetLinkLibrariesCommand);
-  state->AddBuiltinCommand("target_sources", new cmTargetSourcesCommand);
-  state->AddBuiltinCommand("try_compile", new cmTryCompileCommand);
-  state->AddBuiltinCommand("try_run", new cmTryRunCommand);
+                           cm::make_unique<cmTargetLinkLibrariesCommand>());
+  state->AddBuiltinCommand("target_sources",
+                           cm::make_unique<cmTargetSourcesCommand>());
+  state->AddBuiltinCommand("try_compile",
+                           cm::make_unique<cmTryCompileCommand>());
+  state->AddBuiltinCommand("try_run", cm::make_unique<cmTryRunCommand>());
 
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
 #if defined(CMAKE_BUILD_WITH_CMAKE)
   state->AddBuiltinCommand("add_compile_definitions",
   state->AddBuiltinCommand("add_compile_definitions",
-                           new cmAddCompileDefinitionsCommand);
+                           cm::make_unique<cmAddCompileDefinitionsCommand>());
   state->AddBuiltinCommand("add_compile_options",
   state->AddBuiltinCommand("add_compile_options",
-                           new cmAddCompileOptionsCommand);
+                           cm::make_unique<cmAddCompileOptionsCommand>());
   state->AddBuiltinCommand("aux_source_directory",
   state->AddBuiltinCommand("aux_source_directory",
-                           new cmAuxSourceDirectoryCommand);
-  state->AddBuiltinCommand("export", new cmExportCommand);
-  state->AddBuiltinCommand("fltk_wrap_ui", new cmFLTKWrapUICommand);
-  state->AddBuiltinCommand("include_external_msproject",
-                           new cmIncludeExternalMSProjectCommand);
-  state->AddBuiltinCommand("install_programs", new cmInstallProgramsCommand);
-  state->AddBuiltinCommand("add_link_options", new cmAddLinkOptionsCommand);
-  state->AddBuiltinCommand("link_libraries", new cmLinkLibrariesCommand);
+                           cm::make_unique<cmAuxSourceDirectoryCommand>());
+  state->AddBuiltinCommand("export", cm::make_unique<cmExportCommand>());
+  state->AddBuiltinCommand("fltk_wrap_ui",
+                           cm::make_unique<cmFLTKWrapUICommand>());
+  state->AddBuiltinCommand(
+    "include_external_msproject",
+    cm::make_unique<cmIncludeExternalMSProjectCommand>());
+  state->AddBuiltinCommand("install_programs",
+                           cm::make_unique<cmInstallProgramsCommand>());
+  state->AddBuiltinCommand("add_link_options",
+                           cm::make_unique<cmAddLinkOptionsCommand>());
+  state->AddBuiltinCommand("link_libraries",
+                           cm::make_unique<cmLinkLibrariesCommand>());
   state->AddBuiltinCommand("target_link_options",
   state->AddBuiltinCommand("target_link_options",
-                           new cmTargetLinkOptionsCommand);
+                           cm::make_unique<cmTargetLinkOptionsCommand>());
   state->AddBuiltinCommand("target_link_directories",
   state->AddBuiltinCommand("target_link_directories",
-                           new cmTargetLinkDirectoriesCommand);
-  state->AddBuiltinCommand("load_cache", new cmLoadCacheCommand);
-  state->AddBuiltinCommand("qt_wrap_cpp", new cmQTWrapCPPCommand);
-  state->AddBuiltinCommand("qt_wrap_ui", new cmQTWrapUICommand);
+                           cm::make_unique<cmTargetLinkDirectoriesCommand>());
+  state->AddBuiltinCommand("load_cache",
+                           cm::make_unique<cmLoadCacheCommand>());
+  state->AddBuiltinCommand("qt_wrap_cpp",
+                           cm::make_unique<cmQTWrapCPPCommand>());
+  state->AddBuiltinCommand("qt_wrap_ui", cm::make_unique<cmQTWrapUICommand>());
   state->AddBuiltinCommand("remove_definitions",
   state->AddBuiltinCommand("remove_definitions",
-                           new cmRemoveDefinitionsCommand);
-  state->AddBuiltinCommand("source_group", new cmSourceGroupCommand);
+                           cm::make_unique<cmRemoveDefinitionsCommand>());
+  state->AddBuiltinCommand("source_group",
+                           cm::make_unique<cmSourceGroupCommand>());
 
 
   state->AddDisallowedCommand(
   state->AddDisallowedCommand(
-    "export_library_dependencies", new cmExportLibraryDependenciesCommand,
-    cmPolicies::CMP0033,
+    "export_library_dependencies",
+    cm::make_unique<cmExportLibraryDependenciesCommand>(), cmPolicies::CMP0033,
     "The export_library_dependencies command should not be called; "
     "The export_library_dependencies command should not be called; "
     "see CMP0033.");
     "see CMP0033.");
   state->AddDisallowedCommand(
   state->AddDisallowedCommand(
-    "load_command", new cmLoadCommandCommand, cmPolicies::CMP0031,
+    "load_command", cm::make_unique<cmLoadCommandCommand>(),
+    cmPolicies::CMP0031,
     "The load_command command should not be called; see CMP0031.");
     "The load_command command should not be called; see CMP0031.");
   state->AddDisallowedCommand(
   state->AddDisallowedCommand(
-    "output_required_files", new cmOutputRequiredFilesCommand,
+    "output_required_files", cm::make_unique<cmOutputRequiredFilesCommand>(),
     cmPolicies::CMP0032,
     cmPolicies::CMP0032,
     "The output_required_files command should not be called; see CMP0032.");
     "The output_required_files command should not be called; see CMP0032.");
   state->AddDisallowedCommand(
   state->AddDisallowedCommand(
-    "subdir_depends", new cmSubdirDependsCommand, cmPolicies::CMP0029,
+    "subdir_depends", cm::make_unique<cmSubdirDependsCommand>(),
+    cmPolicies::CMP0029,
     "The subdir_depends command should not be called; see CMP0029.");
     "The subdir_depends command should not be called; see CMP0029.");
   state->AddDisallowedCommand(
   state->AddDisallowedCommand(
-    "utility_source", new cmUtilitySourceCommand, cmPolicies::CMP0034,
+    "utility_source", cm::make_unique<cmUtilitySourceCommand>(),
+    cmPolicies::CMP0034,
     "The utility_source command should not be called; see CMP0034.");
     "The utility_source command should not be called; see CMP0034.");
   state->AddDisallowedCommand(
   state->AddDisallowedCommand(
-    "variable_requires", new cmVariableRequiresCommand, cmPolicies::CMP0035,
+    "variable_requires", cm::make_unique<cmVariableRequiresCommand>(),
+    cmPolicies::CMP0035,
     "The variable_requires command should not be called; see CMP0035.");
     "The variable_requires command should not be called; see CMP0035.");
 #endif
 #endif
 }
 }

+ 6 - 1
Source/cmConfigureFileCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 #include "cmNewLineStyle.h"
 #include "cmNewLineStyle.h"
 
 
@@ -16,7 +18,10 @@ class cmExecutionStatus;
 class cmConfigureFileCommand : public cmCommand
 class cmConfigureFileCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmConfigureFileCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmConfigureFileCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmContinueCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmContinueCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmContinueCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmCreateTestSourceList.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmCreateTestSourceList; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmCreateTestSourceList>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmDefinePropertyCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -15,7 +17,10 @@ class cmExecutionStatus;
 class cmDefinePropertyCommand : public cmCommand
 class cmDefinePropertyCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmDefinePropertyCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmDefinePropertyCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 11 - 8
Source/cmDisallowedCommand.h

@@ -6,8 +6,11 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
 #include <string>
 #include <string>
+#include <utility>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 #include "cmPolicies.h"
 #include "cmPolicies.h"
 
 
@@ -16,20 +19,20 @@ class cmExecutionStatus;
 class cmDisallowedCommand : public cmCommand
 class cmDisallowedCommand : public cmCommand
 {
 {
 public:
 public:
-  cmDisallowedCommand(cmCommand* command, cmPolicies::PolicyID policy,
-                      const char* message)
-    : Command(command)
+  cmDisallowedCommand(std::unique_ptr<cmCommand> command,
+                      cmPolicies::PolicyID policy, const char* message)
+    : Command(std::move(command))
     , Policy(policy)
     , Policy(policy)
     , Message(message)
     , Message(message)
   {
   {
   }
   }
 
 
-  ~cmDisallowedCommand() override { delete this->Command; }
+  ~cmDisallowedCommand() override = default;
 
 
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    return new cmDisallowedCommand(this->Command->Clone(), this->Policy,
-                                   this->Message);
+    return cm::make_unique<cmDisallowedCommand>(this->Command->Clone(),
+                                                this->Policy, this->Message);
   }
   }
 
 
   bool InitialPass(std::vector<std::string> const& args,
   bool InitialPass(std::vector<std::string> const& args,
@@ -40,7 +43,7 @@ public:
   bool HasFinalPass() const override { return this->Command->HasFinalPass(); }
   bool HasFinalPass() const override { return this->Command->HasFinalPass(); }
 
 
 private:
 private:
-  cmCommand* Command;
+  std::unique_ptr<cmCommand> Command;
   cmPolicies::PolicyID Policy;
   cmPolicies::PolicyID Policy;
   const char* Message;
   const char* Message;
 };
 };

+ 6 - 1
Source/cmEnableLanguageCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -26,7 +28,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmEnableLanguageCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmEnableLanguageCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmEnableTestingCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -31,7 +33,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmEnableTestingCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmEnableTestingCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmExecProgramCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 #include "cmProcessOutput.h"
 #include "cmProcessOutput.h"
 
 
@@ -27,7 +29,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmExecProgramCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmExecProgramCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 0 - 1
Source/cmExecuteProcessCommand.cxx

@@ -8,7 +8,6 @@
 #include <algorithm>
 #include <algorithm>
 #include <ctype.h> /* isspace */
 #include <ctype.h> /* isspace */
 #include <iostream>
 #include <iostream>
-#include <memory>
 #include <stdio.h>
 #include <stdio.h>
 #include <vector>
 #include <vector>
 
 

+ 6 - 1
Source/cmExecuteProcessCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmExecuteProcessCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmExecuteProcessCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmExportCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -18,7 +20,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmExportCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmExportCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 4 - 2
Source/cmExportLibraryDependenciesCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -15,9 +17,9 @@ class cmExecutionStatus;
 class cmExportLibraryDependenciesCommand : public cmCommand
 class cmExportLibraryDependenciesCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    return new cmExportLibraryDependenciesCommand;
+    return cm::make_unique<cmExportLibraryDependenciesCommand>();
   }
   }
   bool InitialPass(std::vector<std::string> const& args,
   bool InitialPass(std::vector<std::string> const& args,
                    cmExecutionStatus& status) override;
                    cmExecutionStatus& status) override;

+ 6 - 1
Source/cmFLTKWrapUICommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -25,7 +27,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmFLTKWrapUICommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmFLTKWrapUICommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmFileCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -22,7 +24,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmFileCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmFileCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 7 - 3
Source/cmFindFileCommand.h

@@ -5,9 +5,10 @@
 
 
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
-#include "cmFindPathCommand.h"
+#include "cm_memory.hxx"
 
 
-class cmCommand;
+#include "cmCommand.h"
+#include "cmFindPathCommand.h"
 
 
 /** \class cmFindFileCommand
 /** \class cmFindFileCommand
  * \brief Define a command to search for an executable program.
  * \brief Define a command to search for an executable program.
@@ -24,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmFindFileCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmFindFileCommand>();
+  }
 };
 };
 
 
 #endif
 #endif

+ 7 - 2
Source/cmFindLibraryCommand.h

@@ -8,9 +8,11 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
+#include "cmCommand.h"
 #include "cmFindBase.h"
 #include "cmFindBase.h"
 
 
-class cmCommand;
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
 /** \class cmFindLibraryCommand
 /** \class cmFindLibraryCommand
@@ -27,7 +29,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmFindLibraryCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmFindLibraryCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 7 - 2
Source/cmFindPackageCommand.h

@@ -3,6 +3,7 @@
 #ifndef cmFindPackageCommand_h
 #ifndef cmFindPackageCommand_h
 #define cmFindPackageCommand_h
 #define cmFindPackageCommand_h
 
 
+#include "cmCommand.h"
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmPolicies.h"
 #include "cmPolicies.h"
 
 
@@ -14,6 +15,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 // IWYU insists we should forward-declare instead of including <functional>,
 // IWYU insists we should forward-declare instead of including <functional>,
 // but we cannot forward-declare reliably because some C++ standard libraries
 // but we cannot forward-declare reliably because some C++ standard libraries
 // put the template in an inline namespace.
 // put the template in an inline namespace.
@@ -27,7 +30,6 @@ namespace std {
 
 
 #include "cmFindCommon.h"
 #include "cmFindCommon.h"
 
 
-class cmCommand;
 class cmExecutionStatus;
 class cmExecutionStatus;
 class cmSearchPath;
 class cmSearchPath;
 
 
@@ -65,7 +67,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmFindPackageCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmFindPackageCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 7 - 2
Source/cmFindPathCommand.h

@@ -8,9 +8,11 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
+#include "cmCommand.h"
 #include "cmFindBase.h"
 #include "cmFindBase.h"
 
 
-class cmCommand;
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
 /** \class cmFindPathCommand
 /** \class cmFindPathCommand
@@ -27,7 +29,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmFindPathCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmFindPathCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 7 - 2
Source/cmFindProgramCommand.h

@@ -8,9 +8,11 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
+#include "cmCommand.h"
 #include "cmFindBase.h"
 #include "cmFindBase.h"
 
 
-class cmCommand;
 class cmExecutionStatus;
 class cmExecutionStatus;
 
 
 /** \class cmFindProgramCommand
 /** \class cmFindProgramCommand
@@ -28,7 +30,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmFindProgramCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmFindProgramCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmForEachCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 #include "cmFunctionBlocker.h"
 #include "cmFunctionBlocker.h"
 #include "cmListFileCache.h"
 #include "cmListFileCache.h"
@@ -39,7 +41,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmForEachCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmForEachCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 8 - 5
Source/cmFunctionCommand.cxx

@@ -3,6 +3,9 @@
 #include "cmFunctionCommand.h"
 #include "cmFunctionCommand.h"
 
 
 #include <sstream>
 #include <sstream>
+#include <utility>
+
+#include "cm_memory.hxx"
 
 
 #include "cmAlgorithms.h"
 #include "cmAlgorithms.h"
 #include "cmExecutionStatus.h"
 #include "cmExecutionStatus.h"
@@ -18,15 +21,15 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmFunctionHelperCommand* newC = new cmFunctionHelperCommand;
+    auto newC = cm::make_unique<cmFunctionHelperCommand>();
     // we must copy when we clone
     // we must copy when we clone
     newC->Args = this->Args;
     newC->Args = this->Args;
     newC->Functions = this->Functions;
     newC->Functions = this->Functions;
     newC->Policies = this->Policies;
     newC->Policies = this->Policies;
     newC->FilePath = this->FilePath;
     newC->FilePath = this->FilePath;
-    return newC;
+    return std::unique_ptr<cmCommand>(std::move(newC));
   }
   }
 
 
   /**
   /**
@@ -129,12 +132,12 @@ bool cmFunctionFunctionBlocker::IsFunctionBlocked(
     // if this is the endfunction for this function then execute
     // if this is the endfunction for this function then execute
     if (!this->Depth) {
     if (!this->Depth) {
       // create a new command and add it to cmake
       // create a new command and add it to cmake
-      cmFunctionHelperCommand* f = new cmFunctionHelperCommand();
+      auto f = cm::make_unique<cmFunctionHelperCommand>();
       f->Args = this->Args;
       f->Args = this->Args;
       f->Functions = this->Functions;
       f->Functions = this->Functions;
       f->FilePath = this->GetStartingContext().FilePath;
       f->FilePath = this->GetStartingContext().FilePath;
       mf.RecordPolicies(f->Policies);
       mf.RecordPolicies(f->Policies);
-      mf.GetState()->AddScriptedCommand(this->Args[0], f);
+      mf.GetState()->AddScriptedCommand(this->Args[0], std::move(f));
       // remove the function blocker now that the function is defined
       // remove the function blocker now that the function is defined
       mf.RemoveFunctionBlocker(this, lff);
       mf.RemoveFunctionBlocker(this, lff);
       return true;
       return true;

+ 6 - 1
Source/cmFunctionCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 #include "cmFunctionBlocker.h"
 #include "cmFunctionBlocker.h"
 #include "cmListFileCache.h"
 #include "cmListFileCache.h"
@@ -34,7 +36,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmFunctionCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmFunctionCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmGetCMakePropertyCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -15,7 +17,10 @@ class cmExecutionStatus;
 class cmGetCMakePropertyCommand : public cmCommand
 class cmGetCMakePropertyCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmGetCMakePropertyCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmGetCMakePropertyCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmGetDirectoryPropertyCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -15,7 +17,10 @@ class cmExecutionStatus;
 class cmGetDirectoryPropertyCommand : public cmCommand
 class cmGetDirectoryPropertyCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmGetDirectoryPropertyCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmGetDirectoryPropertyCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmGetFilenameComponentCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmGetFilenameComponentCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmGetFilenameComponentCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmGetPropertyCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -17,7 +19,10 @@ class cmGetPropertyCommand : public cmCommand
 public:
 public:
   cmGetPropertyCommand();
   cmGetPropertyCommand();
 
 
-  cmCommand* Clone() override { return new cmGetPropertyCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmGetPropertyCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmGetSourceFilePropertyCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -15,7 +17,10 @@ class cmExecutionStatus;
 class cmGetSourceFilePropertyCommand : public cmCommand
 class cmGetSourceFilePropertyCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmGetSourceFilePropertyCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmGetSourceFilePropertyCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmGetTargetPropertyCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -15,7 +17,10 @@ class cmExecutionStatus;
 class cmGetTargetPropertyCommand : public cmCommand
 class cmGetTargetPropertyCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmGetTargetPropertyCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmGetTargetPropertyCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmGetTestPropertyCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -15,7 +17,10 @@ class cmExecutionStatus;
 class cmGetTestPropertyCommand : public cmCommand
 class cmGetTestPropertyCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmGetTestPropertyCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmGetTestPropertyCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 0 - 2
Source/cmIfCommand.cxx

@@ -11,8 +11,6 @@
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 #include "cmake.h"
 #include "cmake.h"
 
 
-#include <memory>
-
 static std::string cmIfCommandError(
 static std::string cmIfCommandError(
   std::vector<cmExpandedCommandArgument> const& args)
   std::vector<cmExpandedCommandArgument> const& args)
 {
 {

+ 6 - 1
Source/cmIfCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 #include "cmFunctionBlocker.h"
 #include "cmFunctionBlocker.h"
 #include "cmListFileCache.h"
 #include "cmListFileCache.h"
@@ -38,7 +40,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmIfCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmIfCommand>();
+  }
 
 
   /**
   /**
    * This overrides the default InvokeInitialPass implementation.
    * This overrides the default InvokeInitialPass implementation.

+ 6 - 1
Source/cmIncludeCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmIncludeCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmIncludeCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmIncludeDirectoryCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmIncludeDirectoryCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmIncludeDirectoryCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmIncludeExternalMSProjectCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -25,7 +27,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmIncludeExternalMSProjectCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmIncludeExternalMSProjectCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmIncludeGuardCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmIncludeGuardCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmIncludeGuardCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmIncludeRegularExpressionCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmIncludeRegularExpressionCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmIncludeRegularExpressionCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmInstallCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -25,7 +27,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmInstallCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmInstallCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmInstallFilesCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmInstallFilesCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmInstallFilesCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmInstallProgramsCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmInstallProgramsCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmInstallProgramsCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmInstallTargetsCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -25,7 +27,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmInstallTargetsCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmInstallTargetsCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmLinkDirectoriesCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -26,7 +28,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmLinkDirectoriesCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmLinkDirectoriesCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmLinkLibrariesCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -25,7 +27,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmLinkLibrariesCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmLinkLibrariesCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmListCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -22,7 +24,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmListCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmListCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmLoadCacheCommand.h

@@ -9,6 +9,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmLoadCacheCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmLoadCacheCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 9 - 5
Source/cmLoadCommandCommand.cxx

@@ -3,10 +3,14 @@
 #include "cmLoadCommandCommand.h"
 #include "cmLoadCommandCommand.h"
 
 
 #include <signal.h>
 #include <signal.h>
+
 #include <sstream>
 #include <sstream>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
+#include <utility>
+
+#include "cm_memory.hxx"
 
 
 #include "cmCPluginAPI.cxx"
 #include "cmCPluginAPI.cxx"
 #include "cmCPluginAPI.h"
 #include "cmCPluginAPI.h"
@@ -39,12 +43,12 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmLoadedCommand* newC = new cmLoadedCommand;
+    auto newC = cm::make_unique<cmLoadedCommand>();
     // we must copy when we clone
     // we must copy when we clone
     memcpy(&newC->info, &this->info, sizeof(info));
     memcpy(&newC->info, &this->info, sizeof(info));
-    return newC;
+    return std::unique_ptr<cmLoadedCommand>(std::move(newC));
   }
   }
 
 
   /**
   /**
@@ -237,9 +241,9 @@ bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& args,
   // function blocker
   // function blocker
   if (initFunction) {
   if (initFunction) {
     // create a function blocker and set it up
     // create a function blocker and set it up
-    cmLoadedCommand* f = new cmLoadedCommand();
+    auto f = cm::make_unique<cmLoadedCommand>();
     (*initFunction)(&f->info);
     (*initFunction)(&f->info);
-    this->Makefile->GetState()->AddScriptedCommand(args[0], f);
+    this->Makefile->GetState()->AddScriptedCommand(args[0], std::move(f));
     return true;
     return true;
   }
   }
   this->SetError("Attempt to load command failed. "
   this->SetError("Attempt to load command failed. "

+ 6 - 1
Source/cmLoadCommandCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -15,7 +17,10 @@ class cmExecutionStatus;
 class cmLoadCommandCommand : public cmCommand
 class cmLoadCommandCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmLoadCommandCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmLoadCommandCommand>();
+  }
   bool InitialPass(std::vector<std::string> const& args,
   bool InitialPass(std::vector<std::string> const& args,
                    cmExecutionStatus& status) override;
                    cmExecutionStatus& status) override;
 };
 };

+ 7 - 5
Source/cmMacroCommand.cxx

@@ -6,6 +6,8 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <utility>
 #include <utility>
 
 
+#include "cm_memory.hxx"
+
 #include "cmAlgorithms.h"
 #include "cmAlgorithms.h"
 #include "cmExecutionStatus.h"
 #include "cmExecutionStatus.h"
 #include "cmMakefile.h"
 #include "cmMakefile.h"
@@ -21,15 +23,15 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override
+  std::unique_ptr<cmCommand> Clone() override
   {
   {
-    cmMacroHelperCommand* newC = new cmMacroHelperCommand;
+    auto newC = cm::make_unique<cmMacroHelperCommand>();
     // we must copy when we clone
     // we must copy when we clone
     newC->Args = this->Args;
     newC->Args = this->Args;
     newC->Functions = this->Functions;
     newC->Functions = this->Functions;
     newC->FilePath = this->FilePath;
     newC->FilePath = this->FilePath;
     newC->Policies = this->Policies;
     newC->Policies = this->Policies;
-    return newC;
+    return std::unique_ptr<cmCommand>(std::move(newC));
   }
   }
 
 
   /**
   /**
@@ -164,12 +166,12 @@ bool cmMacroFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
     if (!this->Depth) {
     if (!this->Depth) {
       mf.AppendProperty("MACROS", this->Args[0].c_str());
       mf.AppendProperty("MACROS", this->Args[0].c_str());
       // create a new command and add it to cmake
       // create a new command and add it to cmake
-      cmMacroHelperCommand* f = new cmMacroHelperCommand();
+      auto f = cm::make_unique<cmMacroHelperCommand>();
       f->Args = this->Args;
       f->Args = this->Args;
       f->Functions = this->Functions;
       f->Functions = this->Functions;
       f->FilePath = this->GetStartingContext().FilePath;
       f->FilePath = this->GetStartingContext().FilePath;
       mf.RecordPolicies(f->Policies);
       mf.RecordPolicies(f->Policies);
-      mf.GetState()->AddScriptedCommand(this->Args[0], f);
+      mf.GetState()->AddScriptedCommand(this->Args[0], std::move(f));
       // remove the function blocker now that the macro is defined
       // remove the function blocker now that the macro is defined
       mf.RemoveFunctionBlocker(this, lff);
       mf.RemoveFunctionBlocker(this, lff);
       return true;
       return true;

+ 6 - 1
Source/cmMacroCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 #include "cmFunctionBlocker.h"
 #include "cmFunctionBlocker.h"
 #include "cmListFileCache.h"
 #include "cmListFileCache.h"
@@ -34,7 +36,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmMacroCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmMacroCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmMakeDirectoryCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -27,7 +29,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmMakeDirectoryCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmMakeDirectoryCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 3 - 4
Source/cmMakefile.cxx

@@ -118,7 +118,6 @@ cmMakefile::~cmMakefile()
   cmDeleteAll(this->SourceFiles);
   cmDeleteAll(this->SourceFiles);
   cmDeleteAll(this->Tests);
   cmDeleteAll(this->Tests);
   cmDeleteAll(this->ImportedTargetsOwned);
   cmDeleteAll(this->ImportedTargetsOwned);
-  cmDeleteAll(this->FinalPassCommands);
   cmDeleteAll(this->FunctionBlockers);
   cmDeleteAll(this->FunctionBlockers);
   cmDeleteAll(this->EvaluationFiles);
   cmDeleteAll(this->EvaluationFiles);
 }
 }
@@ -418,7 +417,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
         }
         }
       } else if (pcmd->HasFinalPass()) {
       } else if (pcmd->HasFinalPass()) {
         // use the command
         // use the command
-        this->FinalPassCommands.push_back(pcmd.release());
+        this->FinalPassCommands.push_back(std::move(pcmd));
       }
       }
     }
     }
   } else {
   } else {
@@ -776,8 +775,8 @@ void cmMakefile::FinalPass()
 
 
   // give all the commands a chance to do something
   // give all the commands a chance to do something
   // after the file has been parsed before generation
   // after the file has been parsed before generation
-  for (cmCommand* fpCommand : this->FinalPassCommands) {
-    fpCommand->FinalPass();
+  for (auto& command : this->FinalPassCommands) {
+    command->FinalPass();
   }
   }
 
 
   // go through all configured files and see which ones still exist.
   // go through all configured files and see which ones still exist.

+ 1 - 1
Source/cmMakefile.h

@@ -937,7 +937,7 @@ protected:
   size_t ObjectLibrariesSourceGroupIndex;
   size_t ObjectLibrariesSourceGroupIndex;
 #endif
 #endif
 
 
-  std::vector<cmCommand*> FinalPassCommands;
+  std::vector<std::unique_ptr<cmCommand>> FinalPassCommands;
   cmGlobalGenerator* GlobalGenerator;
   cmGlobalGenerator* GlobalGenerator;
   bool IsFunctionBlocked(const cmListFileFunction& lff,
   bool IsFunctionBlocked(const cmListFileFunction& lff,
                          cmExecutionStatus& status);
                          cmExecutionStatus& status);

+ 6 - 1
Source/cmMarkAsAdvancedCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmMarkAsAdvancedCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmMarkAsAdvancedCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmMathCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -19,7 +21,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmMathCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmMathCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmMessageCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -22,7 +24,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmMessageCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmMessageCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmOptionCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmOptionCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmOptionCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmOutputRequiredFilesCommand.h

@@ -10,6 +10,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmDependInformation;
 class cmDependInformation;
@@ -18,7 +20,10 @@ class cmExecutionStatus;
 class cmOutputRequiredFilesCommand : public cmCommand
 class cmOutputRequiredFilesCommand : public cmCommand
 {
 {
 public:
 public:
-  cmCommand* Clone() override { return new cmOutputRequiredFilesCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmOutputRequiredFilesCommand>();
+  }
   bool InitialPass(std::vector<std::string> const& args,
   bool InitialPass(std::vector<std::string> const& args,
                    cmExecutionStatus& status) override;
                    cmExecutionStatus& status) override;
 
 

+ 6 - 1
Source/cmParseArgumentsCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -21,7 +23,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmParseArgumentsCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmParseArgumentsCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmProjectCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -26,7 +28,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmProjectCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmProjectCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmQTWrapCPPCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -24,7 +26,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmQTWrapCPPCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmQTWrapCPPCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmQTWrapUICommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmQTWrapUICommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmQTWrapUICommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmRemoveCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmRemoveCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmRemoveCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmRemoveDefinitionsCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -25,7 +27,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmRemoveDefinitionsCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmRemoveDefinitionsCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

+ 6 - 1
Source/cmReturnCommand.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#include "cm_memory.hxx"
+
 #include "cmCommand.h"
 #include "cmCommand.h"
 
 
 class cmExecutionStatus;
 class cmExecutionStatus;
@@ -23,7 +25,10 @@ public:
   /**
   /**
    * This is a virtual constructor for the command.
    * This is a virtual constructor for the command.
    */
    */
-  cmCommand* Clone() override { return new cmReturnCommand; }
+  std::unique_ptr<cmCommand> Clone() override
+  {
+    return cm::make_unique<cmReturnCommand>();
+  }
 
 
   /**
   /**
    * This is called when the command is first encountered in
    * This is called when the command is first encountered in

Some files were not shown because too many files changed in this diff