From 1591f138f1a40fccdde7fb2796ee2d2d8f3f97bb Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Thu, 4 Jul 2019 18:14:22 +0200 Subject: modernize: manage cmCommand instances using unique_ptr. --- Source/CTest/cmCTestBuildCommand.h | 11 +- Source/CTest/cmCTestConfigureCommand.h | 11 +- Source/CTest/cmCTestCoverageCommand.h | 11 +- Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h | 12 +- Source/CTest/cmCTestMemCheckCommand.h | 12 +- Source/CTest/cmCTestReadCustomFilesCommand.h | 11 +- Source/CTest/cmCTestRunScriptCommand.h | 11 +- Source/CTest/cmCTestScriptHandler.cxx | 42 ++-- Source/CTest/cmCTestScriptHandler.h | 4 +- Source/CTest/cmCTestSleepCommand.h | 11 +- Source/CTest/cmCTestStartCommand.h | 11 +- Source/CTest/cmCTestSubmitCommand.cxx | 10 +- Source/CTest/cmCTestSubmitCommand.h | 5 +- Source/CTest/cmCTestTestCommand.h | 11 +- Source/CTest/cmCTestTestHandler.cxx | 58 ++--- Source/CTest/cmCTestUpdateCommand.h | 11 +- Source/CTest/cmCTestUploadCommand.h | 11 +- Source/cmAddCompileDefinitionsCommand.h | 7 +- Source/cmAddCompileOptionsCommand.h | 7 +- Source/cmAddCustomCommandCommand.h | 7 +- Source/cmAddCustomTargetCommand.h | 7 +- Source/cmAddDefinitionsCommand.h | 7 +- Source/cmAddDependenciesCommand.h | 7 +- Source/cmAddExecutableCommand.h | 7 +- Source/cmAddLibraryCommand.h | 7 +- Source/cmAddLinkOptionsCommand.h | 7 +- Source/cmAddSubDirectoryCommand.h | 7 +- Source/cmAddTestCommand.h | 7 +- Source/cmAuxSourceDirectoryCommand.h | 7 +- Source/cmBreakCommand.h | 7 +- Source/cmBuildCommand.h | 7 +- Source/cmBuildNameCommand.h | 7 +- Source/cmCMakeHostSystemInformationCommand.h | 6 +- Source/cmCMakeMinimumRequired.h | 7 +- Source/cmCMakePolicyCommand.h | 7 +- Source/cmCommand.h | 3 +- Source/cmCommands.cxx | 269 +++++++++++++--------- Source/cmConfigureFileCommand.h | 7 +- Source/cmContinueCommand.h | 7 +- Source/cmCreateTestSourceList.h | 7 +- Source/cmDefinePropertyCommand.h | 7 +- Source/cmDisallowedCommand.h | 19 +- Source/cmEnableLanguageCommand.h | 7 +- Source/cmEnableTestingCommand.h | 7 +- Source/cmExecProgramCommand.h | 7 +- Source/cmExecuteProcessCommand.cxx | 1 - Source/cmExecuteProcessCommand.h | 7 +- Source/cmExportCommand.h | 7 +- Source/cmExportLibraryDependenciesCommand.h | 6 +- Source/cmFLTKWrapUICommand.h | 7 +- Source/cmFileCommand.h | 7 +- Source/cmFindFileCommand.h | 10 +- Source/cmFindLibraryCommand.h | 9 +- Source/cmFindPackageCommand.h | 9 +- Source/cmFindPathCommand.h | 9 +- Source/cmFindProgramCommand.h | 9 +- Source/cmForEachCommand.h | 7 +- Source/cmFunctionCommand.cxx | 13 +- Source/cmFunctionCommand.h | 7 +- Source/cmGetCMakePropertyCommand.h | 7 +- Source/cmGetDirectoryPropertyCommand.h | 7 +- Source/cmGetFilenameComponentCommand.h | 7 +- Source/cmGetPropertyCommand.h | 7 +- Source/cmGetSourceFilePropertyCommand.h | 7 +- Source/cmGetTargetPropertyCommand.h | 7 +- Source/cmGetTestPropertyCommand.h | 7 +- Source/cmIfCommand.cxx | 2 - Source/cmIfCommand.h | 7 +- Source/cmIncludeCommand.h | 7 +- Source/cmIncludeDirectoryCommand.h | 7 +- Source/cmIncludeExternalMSProjectCommand.h | 7 +- Source/cmIncludeGuardCommand.h | 7 +- Source/cmIncludeRegularExpressionCommand.h | 7 +- Source/cmInstallCommand.h | 7 +- Source/cmInstallFilesCommand.h | 7 +- Source/cmInstallProgramsCommand.h | 7 +- Source/cmInstallTargetsCommand.h | 7 +- Source/cmLinkDirectoriesCommand.h | 7 +- Source/cmLinkLibrariesCommand.h | 7 +- Source/cmListCommand.h | 7 +- Source/cmLoadCacheCommand.h | 7 +- Source/cmLoadCommandCommand.cxx | 14 +- Source/cmLoadCommandCommand.h | 7 +- Source/cmMacroCommand.cxx | 12 +- Source/cmMacroCommand.h | 7 +- Source/cmMakeDirectoryCommand.h | 7 +- Source/cmMakefile.cxx | 7 +- Source/cmMakefile.h | 2 +- Source/cmMarkAsAdvancedCommand.h | 7 +- Source/cmMathCommand.h | 7 +- Source/cmMessageCommand.h | 7 +- Source/cmOptionCommand.h | 7 +- Source/cmOutputRequiredFilesCommand.h | 7 +- Source/cmParseArgumentsCommand.h | 7 +- Source/cmProjectCommand.h | 7 +- Source/cmQTWrapCPPCommand.h | 7 +- Source/cmQTWrapUICommand.h | 7 +- Source/cmRemoveCommand.h | 7 +- Source/cmRemoveDefinitionsCommand.h | 7 +- Source/cmReturnCommand.h | 7 +- Source/cmSeparateArgumentsCommand.h | 7 +- Source/cmSetCommand.h | 7 +- Source/cmSetDirectoryPropertiesCommand.h | 7 +- Source/cmSetPropertyCommand.h | 7 +- Source/cmSetSourceFilesPropertiesCommand.h | 7 +- Source/cmSetTargetPropertiesCommand.h | 7 +- Source/cmSetTestsPropertiesCommand.h | 7 +- Source/cmSiteNameCommand.h | 7 +- Source/cmSourceGroupCommand.h | 7 +- Source/cmState.cxx | 52 ++--- Source/cmState.h | 13 +- Source/cmStringCommand.cxx | 1 - Source/cmStringCommand.h | 7 +- Source/cmSubdirCommand.h | 7 +- Source/cmSubdirDependsCommand.h | 7 +- Source/cmTargetCompileDefinitionsCommand.h | 9 +- Source/cmTargetCompileFeaturesCommand.h | 9 +- Source/cmTargetCompileOptionsCommand.h | 9 +- Source/cmTargetIncludeDirectoriesCommand.h | 9 +- Source/cmTargetLinkDirectoriesCommand.h | 9 +- Source/cmTargetLinkLibrariesCommand.h | 7 +- Source/cmTargetLinkOptionsCommand.h | 9 +- Source/cmTargetSourcesCommand.h | 9 +- Source/cmTryCompileCommand.h | 9 +- Source/cmTryRunCommand.h | 9 +- Source/cmUVProcessChain.cxx | 2 +- Source/cmUnexpectedCommand.h | 6 +- Source/cmUnsetCommand.h | 7 +- Source/cmUseMangledMesaCommand.h | 7 +- Source/cmUtilitySourceCommand.h | 7 +- Source/cmVariableRequiresCommand.h | 7 +- Source/cmVariableWatchCommand.h | 7 +- Source/cmWhileCommand.cxx | 2 - Source/cmWhileCommand.h | 7 +- Source/cmWriteFileCommand.h | 7 +- Tests/CMakeLib/testUVProcessChain.cxx | 1 - 136 files changed, 1014 insertions(+), 399 deletions(-) diff --git a/Source/CTest/cmCTestBuildCommand.h b/Source/CTest/cmCTestBuildCommand.h index 77b0549..a62c301 100644 --- a/Source/CTest/cmCTestBuildCommand.h +++ b/Source/CTest/cmCTestBuildCommand.h @@ -6,13 +6,16 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestHandlerCommand.h" +#include "cmCommand.h" #include +#include #include +#include "cm_memory.hxx" + class cmCTestBuildHandler; class cmCTestGenericHandler; -class cmCommand; class cmExecutionStatus; class cmGlobalGenerator; @@ -30,12 +33,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestBuildCommand* ni = new cmCTestBuildCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestConfigureCommand.h b/Source/CTest/cmCTestConfigureCommand.h index 0cbcbfa..4677c83 100644 --- a/Source/CTest/cmCTestConfigureCommand.h +++ b/Source/CTest/cmCTestConfigureCommand.h @@ -6,11 +6,14 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestHandlerCommand.h" +#include "cmCommand.h" #include +#include + +#include "cm_memory.hxx" class cmCTestGenericHandler; -class cmCommand; /** \class cmCTestConfigure * \brief Run a ctest script @@ -25,12 +28,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestConfigureCommand* ni = new cmCTestConfigureCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestCoverageCommand.h b/Source/CTest/cmCTestCoverageCommand.h index 1ae2d86..08f31f7 100644 --- a/Source/CTest/cmCTestCoverageCommand.h +++ b/Source/CTest/cmCTestCoverageCommand.h @@ -6,12 +6,15 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestHandlerCommand.h" +#include "cmCommand.h" #include #include +#include + +#include "cm_memory.hxx" class cmCTestGenericHandler; -class cmCommand; /** \class cmCTestCoverage * \brief Run a ctest script @@ -26,12 +29,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestCoverageCommand* ni = new cmCTestCoverageCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h index 9425ece..84250cb 100644 --- a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h +++ b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h @@ -6,11 +6,14 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestCommand.h" +#include "cmCommand.h" #include +#include #include -class cmCommand; +#include "cm_memory.hxx" + class cmExecutionStatus; /** \class cmCTestEmptyBinaryDirectory @@ -27,13 +30,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestEmptyBinaryDirectoryCommand* ni = - new cmCTestEmptyBinaryDirectoryCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestMemCheckCommand.h b/Source/CTest/cmCTestMemCheckCommand.h index b6b3c40..837a687 100644 --- a/Source/CTest/cmCTestMemCheckCommand.h +++ b/Source/CTest/cmCTestMemCheckCommand.h @@ -5,10 +5,14 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include + +#include "cm_memory.hxx" + #include "cmCTestTestCommand.h" +#include "cmCommand.h" class cmCTestGenericHandler; -class cmCommand; /** \class cmCTestMemCheck * \brief Run a ctest script @@ -23,12 +27,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestMemCheckCommand* ni = new cmCTestMemCheckCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } protected: diff --git a/Source/CTest/cmCTestReadCustomFilesCommand.h b/Source/CTest/cmCTestReadCustomFilesCommand.h index ba25c51..db2ac5e 100644 --- a/Source/CTest/cmCTestReadCustomFilesCommand.h +++ b/Source/CTest/cmCTestReadCustomFilesCommand.h @@ -6,11 +6,14 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestCommand.h" +#include "cmCommand.h" #include +#include #include -class cmCommand; +#include "cm_memory.hxx" + class cmExecutionStatus; /** \class cmCTestReadCustomFiles @@ -27,11 +30,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestReadCustomFilesCommand* ni = new cmCTestReadCustomFilesCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestRunScriptCommand.h b/Source/CTest/cmCTestRunScriptCommand.h index 9d8b4b5..6961f6e 100644 --- a/Source/CTest/cmCTestRunScriptCommand.h +++ b/Source/CTest/cmCTestRunScriptCommand.h @@ -6,11 +6,14 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestCommand.h" +#include "cmCommand.h" #include +#include #include -class cmCommand; +#include "cm_memory.hxx" + class cmExecutionStatus; /** \class cmCTestRunScript @@ -27,12 +30,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestRunScriptCommand* ni = new cmCTestRunScriptCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index a739f44..861bd06 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -12,6 +12,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCTest.h" #include "cmCTestBuildCommand.h" #include "cmCTestCommand.h" @@ -27,6 +29,7 @@ #include "cmCTestTestCommand.h" #include "cmCTestUpdateCommand.h" #include "cmCTestUploadCommand.h" +#include "cmCommand.h" #include "cmDuration.h" #include "cmFunctionBlocker.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 command) { command->CTest = this->CTest; 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) @@ -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()); + this->AddCTestCommand("ctest_configure", + cm::make_unique()); + this->AddCTestCommand("ctest_coverage", + cm::make_unique()); this->AddCTestCommand("ctest_empty_binary_directory", - new cmCTestEmptyBinaryDirectoryCommand); - this->AddCTestCommand("ctest_memcheck", new cmCTestMemCheckCommand); + cm::make_unique()); + this->AddCTestCommand("ctest_memcheck", + cm::make_unique()); 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()); + this->AddCTestCommand("ctest_run_script", + cm::make_unique()); + this->AddCTestCommand("ctest_sleep", cm::make_unique()); + this->AddCTestCommand("ctest_start", cm::make_unique()); + this->AddCTestCommand("ctest_submit", + cm::make_unique()); + this->AddCTestCommand("ctest_test", cm::make_unique()); + this->AddCTestCommand("ctest_update", + cm::make_unique()); + this->AddCTestCommand("ctest_upload", + cm::make_unique()); } // this sets up some variables for the script to use, creates the required diff --git a/Source/CTest/cmCTestScriptHandler.h b/Source/CTest/cmCTestScriptHandler.h index d93b5f8..b2e8cbf 100644 --- a/Source/CTest/cmCTestScriptHandler.h +++ b/Source/CTest/cmCTestScriptHandler.h @@ -9,6 +9,7 @@ #include "cmDuration.h" #include +#include #include #include @@ -131,7 +132,8 @@ private: int RunConfigurationDashboard(); // Add ctest command - void AddCTestCommand(std::string const& name, cmCTestCommand* command); + void AddCTestCommand(std::string const& name, + std::unique_ptr command); // Try to remove the binary directory once static bool TryToRemoveBinaryDirectoryOnce(const std::string& directoryPath); diff --git a/Source/CTest/cmCTestSleepCommand.h b/Source/CTest/cmCTestSleepCommand.h index 5cd185a..7b17081 100644 --- a/Source/CTest/cmCTestSleepCommand.h +++ b/Source/CTest/cmCTestSleepCommand.h @@ -6,11 +6,14 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestCommand.h" +#include "cmCommand.h" #include +#include #include -class cmCommand; +#include "cm_memory.hxx" + class cmExecutionStatus; /** \class cmCTestSleep @@ -27,12 +30,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestSleepCommand* ni = new cmCTestSleepCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestStartCommand.h b/Source/CTest/cmCTestStartCommand.h index 542f27c..7c71f36 100644 --- a/Source/CTest/cmCTestStartCommand.h +++ b/Source/CTest/cmCTestStartCommand.h @@ -6,12 +6,15 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestCommand.h" +#include "cmCommand.h" #include #include +#include #include -class cmCommand; +#include "cm_memory.hxx" + class cmExecutionStatus; /** \class cmCTestStart @@ -27,14 +30,14 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestStartCommand* ni = new cmCTestStartCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; ni->CreateNewTag = this->CreateNewTag; ni->Quiet = this->Quiet; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestSubmitCommand.cxx b/Source/CTest/cmCTestSubmitCommand.cxx index afc3e67..bf43d88 100644 --- a/Source/CTest/cmCTestSubmitCommand.cxx +++ b/Source/CTest/cmCTestSubmitCommand.cxx @@ -4,11 +4,15 @@ #include "cmCTest.h" #include "cmCTestSubmitHandler.h" +#include "cmCommand.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmSystemTools.h" #include +#include + +#include "cm_memory.hxx" class cmExecutionStatus; @@ -27,12 +31,12 @@ cmCTestSubmitCommand::cmCTestSubmitCommand() /** * This is a virtual constructor for the command. */ -cmCommand* cmCTestSubmitCommand::Clone() +std::unique_ptr cmCTestSubmitCommand::Clone() { - cmCTestSubmitCommand* ni = new cmCTestSubmitCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler() diff --git a/Source/CTest/cmCTestSubmitCommand.h b/Source/CTest/cmCTestSubmitCommand.h index 1e27046..5bbcd39 100644 --- a/Source/CTest/cmCTestSubmitCommand.h +++ b/Source/CTest/cmCTestSubmitCommand.h @@ -8,12 +8,13 @@ #include "cmCTest.h" #include "cmCTestHandlerCommand.h" +#include #include #include #include -class cmCTestGenericHandler; class cmCommand; +class cmCTestGenericHandler; class cmExecutionStatus; /** \class cmCTestSubmit @@ -26,7 +27,7 @@ class cmCTestSubmitCommand : public cmCTestHandlerCommand { public: cmCTestSubmitCommand(); - cmCommand* Clone() override; + std::unique_ptr Clone() override; bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; diff --git a/Source/CTest/cmCTestTestCommand.h b/Source/CTest/cmCTestTestCommand.h index 11c0db9..d74136c 100644 --- a/Source/CTest/cmCTestTestCommand.h +++ b/Source/CTest/cmCTestTestCommand.h @@ -6,11 +6,14 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestHandlerCommand.h" +#include "cmCommand.h" #include +#include + +#include "cm_memory.hxx" class cmCTestGenericHandler; -class cmCommand; /** \class cmCTestTest * \brief Run a ctest script @@ -25,12 +28,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestTestCommand* ni = new cmCTestTestCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 46ef809..9916ca3 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -11,12 +11,14 @@ #include #include #include -#include #include #include #include #include #include +#include + +#include "cm_memory.hxx" #include "cmAlgorithms.h" #include "cmCTest.h" @@ -43,11 +45,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestSubdirCommand* c = new cmCTestSubdirCommand; + auto c = cm::make_unique(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr(std::move(c)); } /** @@ -122,11 +124,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestAddSubdirectoryCommand* c = new cmCTestAddSubdirectoryCommand; + auto c = cm::make_unique(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr(std::move(c)); } /** @@ -187,11 +189,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestAddTestCommand* c = new cmCTestAddTestCommand; + auto c = cm::make_unique(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr(std::move(c)); } /** @@ -220,11 +222,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestSetTestsPropertiesCommand* c = new cmCTestSetTestsPropertiesCommand; + auto c = cm::make_unique(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr(std::move(c)); } /** @@ -249,12 +251,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestSetDirectoryPropertiesCommand* c = - new cmCTestSetDirectoryPropertiesCommand; + auto c = cm::make_unique(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr(std::move(c)); } /** @@ -1686,32 +1687,31 @@ void cmCTestTestHandler::GetListOfTests() this->CTest->GetConfigType().c_str()); // Add handler for ADD_TEST - cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand; + auto newCom1 = cm::make_unique(); newCom1->TestHandler = this; - cm.GetState()->AddBuiltinCommand("add_test", newCom1); + cm.GetState()->AddBuiltinCommand("add_test", std::move(newCom1)); // Add handler for SUBDIRS - cmCTestSubdirCommand* newCom2 = new cmCTestSubdirCommand; + auto newCom2 = cm::make_unique(); newCom2->TestHandler = this; - cm.GetState()->AddBuiltinCommand("subdirs", newCom2); + cm.GetState()->AddBuiltinCommand("subdirs", std::move(newCom2)); // Add handler for ADD_SUBDIRECTORY - cmCTestAddSubdirectoryCommand* newCom3 = new cmCTestAddSubdirectoryCommand; + auto newCom3 = cm::make_unique(); newCom3->TestHandler = this; - cm.GetState()->AddBuiltinCommand("add_subdirectory", newCom3); + cm.GetState()->AddBuiltinCommand("add_subdirectory", std::move(newCom3)); // Add handler for SET_TESTS_PROPERTIES - cmCTestSetTestsPropertiesCommand* newCom4 = - new cmCTestSetTestsPropertiesCommand; + auto newCom4 = cm::make_unique(); 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 cm.GetState()->RemoveBuiltinCommand("set_directory_properties"); - cmCTestSetDirectoryPropertiesCommand* newCom5 = - new cmCTestSetDirectoryPropertiesCommand; + auto newCom5 = cm::make_unique(); newCom5->TestHandler = this; - cm.GetState()->AddBuiltinCommand("set_directory_properties", newCom5); + cm.GetState()->AddBuiltinCommand("set_directory_properties", + std::move(newCom5)); const char* testFilename; if (cmSystemTools::FileExists("CTestTestfile.cmake")) { diff --git a/Source/CTest/cmCTestUpdateCommand.h b/Source/CTest/cmCTestUpdateCommand.h index 3b2f3e1..55c4b80 100644 --- a/Source/CTest/cmCTestUpdateCommand.h +++ b/Source/CTest/cmCTestUpdateCommand.h @@ -6,11 +6,14 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestHandlerCommand.h" +#include "cmCommand.h" #include +#include + +#include "cm_memory.hxx" class cmCTestGenericHandler; -class cmCommand; /** \class cmCTestUpdate * \brief Run a ctest script @@ -25,12 +28,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestUpdateCommand* ni = new cmCTestUpdateCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestUploadCommand.h b/Source/CTest/cmCTestUploadCommand.h index 0d3b06e..2bb072f 100644 --- a/Source/CTest/cmCTestUploadCommand.h +++ b/Source/CTest/cmCTestUploadCommand.h @@ -6,12 +6,15 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestHandlerCommand.h" +#include "cmCommand.h" #include #include +#include + +#include "cm_memory.hxx" class cmCTestGenericHandler; -class cmCommand; /** \class cmCTestUpload * \brief Run a ctest script @@ -25,12 +28,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmCTestUploadCommand* ni = new cmCTestUploadCommand; + auto ni = cm::make_unique(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr(std::move(ni)); } /** diff --git a/Source/cmAddCompileDefinitionsCommand.h b/Source/cmAddCompileDefinitionsCommand.h index e985dca..5f90ed9 100644 --- a/Source/cmAddCompileDefinitionsCommand.h +++ b/Source/cmAddCompileDefinitionsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -18,7 +20,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddCompileDefinitionsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddCompileOptionsCommand.h b/Source/cmAddCompileOptionsCommand.h index 3d53d09..b34b7fc 100644 --- a/Source/cmAddCompileOptionsCommand.h +++ b/Source/cmAddCompileOptionsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -18,7 +20,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddCompileOptionsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddCustomCommandCommand.h b/Source/cmAddCustomCommandCommand.h index 6af4f10..931aeab 100644 --- a/Source/cmAddCustomCommandCommand.h +++ b/Source/cmAddCustomCommandCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddCustomCommandCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddCustomTargetCommand.h b/Source/cmAddCustomTargetCommand.h index 1a55116..db577bc 100644 --- a/Source/cmAddCustomTargetCommand.h +++ b/Source/cmAddCustomTargetCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddCustomTargetCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddDefinitionsCommand.h b/Source/cmAddDefinitionsCommand.h index 7b75638..0e32c83 100644 --- a/Source/cmAddDefinitionsCommand.h +++ b/Source/cmAddDefinitionsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddDefinitionsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddDependenciesCommand.h b/Source/cmAddDependenciesCommand.h index e10df71..ce912d3 100644 --- a/Source/cmAddDependenciesCommand.h +++ b/Source/cmAddDependenciesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddDependenciesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddExecutableCommand.h b/Source/cmAddExecutableCommand.h index bdf607d..ec57c3f 100644 --- a/Source/cmAddExecutableCommand.h +++ b/Source/cmAddExecutableCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddExecutableCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h index aa21261..56dab41 100644 --- a/Source/cmAddLibraryCommand.h +++ b/Source/cmAddLibraryCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddLibraryCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddLinkOptionsCommand.h b/Source/cmAddLinkOptionsCommand.h index 30fff00..8e46be6 100644 --- a/Source/cmAddLinkOptionsCommand.h +++ b/Source/cmAddLinkOptionsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -18,7 +20,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddLinkOptionsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddSubDirectoryCommand.h b/Source/cmAddSubDirectoryCommand.h index 0ea4423..664334e 100644 --- a/Source/cmAddSubDirectoryCommand.h +++ b/Source/cmAddSubDirectoryCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddSubDirectoryCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAddTestCommand.h b/Source/cmAddTestCommand.h index bea3f3d..3d37d2b 100644 --- a/Source/cmAddTestCommand.h +++ b/Source/cmAddTestCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAddTestCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAuxSourceDirectoryCommand.h b/Source/cmAuxSourceDirectoryCommand.h index 3742e3e..973a464 100644 --- a/Source/cmAuxSourceDirectoryCommand.h +++ b/Source/cmAuxSourceDirectoryCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -27,7 +29,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmAuxSourceDirectoryCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmBreakCommand.h b/Source/cmBreakCommand.h index 3b18567..e6f218e 100644 --- a/Source/cmBreakCommand.h +++ b/Source/cmBreakCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmBreakCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmBuildCommand.h b/Source/cmBuildCommand.h index e0529a4..d373103 100644 --- a/Source/cmBuildCommand.h +++ b/Source/cmBuildCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmBuildCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmBuildNameCommand.h b/Source/cmBuildNameCommand.h index 4bb72d1..bd2d146 100644 --- a/Source/cmBuildNameCommand.h +++ b/Source/cmBuildNameCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmBuildNameCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmBuildNameCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; }; diff --git a/Source/cmCMakeHostSystemInformationCommand.h b/Source/cmCMakeHostSystemInformationCommand.h index b871641..8ea2d55 100644 --- a/Source/cmCMakeHostSystemInformationCommand.h +++ b/Source/cmCMakeHostSystemInformationCommand.h @@ -9,6 +9,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -28,9 +30,9 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - return new cmCMakeHostSystemInformationCommand; + return cm::make_unique(); } /** diff --git a/Source/cmCMakeMinimumRequired.h b/Source/cmCMakeMinimumRequired.h index f9b61e1..3881133 100644 --- a/Source/cmCMakeMinimumRequired.h +++ b/Source/cmCMakeMinimumRequired.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmCMakeMinimumRequired; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmCMakePolicyCommand.h b/Source/cmCMakePolicyCommand.h index cca1406..919402c 100644 --- a/Source/cmCMakePolicyCommand.h +++ b/Source/cmCMakePolicyCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmCMakePolicyCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmCommand.h b/Source/cmCommand.h index 9ccd773..cdd2aba 100644 --- a/Source/cmCommand.h +++ b/Source/cmCommand.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include #include @@ -75,7 +76,7 @@ public: /** * This is a virtual constructor for the command. */ - virtual cmCommand* Clone() = 0; + virtual std::unique_ptr Clone() = 0; /** * Return the last error string. diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 63c5397..96c7105 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -1,5 +1,8 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ + +#include "cm_memory.hxx" + #include "cmCommands.h" #include "cmPolicies.h" #include "cmState.h" @@ -17,6 +20,7 @@ #include "cmBuildCommand.h" #include "cmCMakeMinimumRequired.h" #include "cmCMakePolicyCommand.h" +#include "cmCommand.h" #include "cmConfigureFileCommand.h" #include "cmContinueCommand.h" #include "cmCreateTestSourceList.h" @@ -112,52 +116,64 @@ void GetScriptingCommands(cmState* state) { - state->AddBuiltinCommand("break", new cmBreakCommand); + state->AddBuiltinCommand("break", cm::make_unique()); 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()); + state->AddBuiltinCommand("cmake_policy", + cm::make_unique()); + state->AddBuiltinCommand("configure_file", + cm::make_unique()); + state->AddBuiltinCommand("continue", cm::make_unique()); + state->AddBuiltinCommand("exec_program", + cm::make_unique()); + state->AddBuiltinCommand("execute_process", + cm::make_unique()); + state->AddBuiltinCommand("file", cm::make_unique()); + state->AddBuiltinCommand("find_file", cm::make_unique()); + state->AddBuiltinCommand("find_library", + cm::make_unique()); + state->AddBuiltinCommand("find_package", + cm::make_unique()); + state->AddBuiltinCommand("find_path", cm::make_unique()); + state->AddBuiltinCommand("find_program", + cm::make_unique()); + state->AddBuiltinCommand("foreach", cm::make_unique()); + state->AddBuiltinCommand("function", cm::make_unique()); state->AddBuiltinCommand("get_cmake_property", - new cmGetCMakePropertyCommand); + cm::make_unique()); state->AddBuiltinCommand("get_directory_property", - new cmGetDirectoryPropertyCommand); + cm::make_unique()); 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()); + state->AddBuiltinCommand("get_property", + cm::make_unique()); + state->AddBuiltinCommand("if", cm::make_unique()); + state->AddBuiltinCommand("include", cm::make_unique()); + state->AddBuiltinCommand("include_guard", + cm::make_unique()); + state->AddBuiltinCommand("list", cm::make_unique()); + state->AddBuiltinCommand("macro", cm::make_unique()); + state->AddBuiltinCommand("make_directory", + cm::make_unique()); + state->AddBuiltinCommand("mark_as_advanced", + cm::make_unique()); + state->AddBuiltinCommand("math", cm::make_unique()); + state->AddBuiltinCommand("message", cm::make_unique()); + state->AddBuiltinCommand("option", cm::make_unique()); state->AddBuiltinCommand("cmake_parse_arguments", - new cmParseArgumentsCommand); - state->AddBuiltinCommand("return", new cmReturnCommand); + cm::make_unique()); + state->AddBuiltinCommand("return", cm::make_unique()); state->AddBuiltinCommand("separate_arguments", - new cmSeparateArgumentsCommand); - state->AddBuiltinCommand("set", new cmSetCommand); + cm::make_unique()); + state->AddBuiltinCommand("set", cm::make_unique()); 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()); + state->AddBuiltinCommand("set_property", + cm::make_unique()); + state->AddBuiltinCommand("site_name", cm::make_unique()); + state->AddBuiltinCommand("string", cm::make_unique()); + state->AddBuiltinCommand("unset", cm::make_unique()); + state->AddBuiltinCommand("while", cm::make_unique()); state->AddUnexpectedCommand( "else", @@ -195,17 +211,21 @@ void GetScriptingCommands(cmState* state) "match the opening WHILE command."); #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()); + state->AddBuiltinCommand("remove", cm::make_unique()); + state->AddBuiltinCommand("variable_watch", + cm::make_unique()); + state->AddBuiltinCommand("write_file", + cm::make_unique()); state->AddDisallowedCommand( - "build_name", new cmBuildNameCommand, cmPolicies::CMP0036, + "build_name", cm::make_unique(), cmPolicies::CMP0036, "The build_name command should not be called; see CMP0036."); state->AddDisallowedCommand( - "use_mangled_mesa", new cmUseMangledMesaCommand, cmPolicies::CMP0030, + "use_mangled_mesa", cm::make_unique(), + cmPolicies::CMP0030, "The use_mangled_mesa command should not be called; see CMP0030."); #endif @@ -214,100 +234,131 @@ void GetScriptingCommands(cmState* state) void GetProjectCommands(cmState* state) { 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()); + state->AddBuiltinCommand("add_custom_target", + cm::make_unique()); + state->AddBuiltinCommand("add_definitions", + cm::make_unique()); + state->AddBuiltinCommand("add_dependencies", + cm::make_unique()); + state->AddBuiltinCommand("add_executable", + cm::make_unique()); + state->AddBuiltinCommand("add_library", + cm::make_unique()); + state->AddBuiltinCommand("add_subdirectory", + cm::make_unique()); + state->AddBuiltinCommand("add_test", cm::make_unique()); + state->AddBuiltinCommand("build_command", cm::make_unique()); 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()); + state->AddBuiltinCommand("define_property", + cm::make_unique()); + state->AddBuiltinCommand("enable_language", + cm::make_unique()); + state->AddBuiltinCommand("enable_testing", + cm::make_unique()); state->AddBuiltinCommand("get_source_file_property", - new cmGetSourceFilePropertyCommand); + cm::make_unique()); state->AddBuiltinCommand("get_target_property", - new cmGetTargetPropertyCommand); - state->AddBuiltinCommand("get_test_property", new cmGetTestPropertyCommand); + cm::make_unique()); + state->AddBuiltinCommand("get_test_property", + cm::make_unique()); 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()); + state->AddBuiltinCommand( + "include_regular_expression", + cm::make_unique()); + state->AddBuiltinCommand("install", cm::make_unique()); + state->AddBuiltinCommand("install_files", + cm::make_unique()); + state->AddBuiltinCommand("install_targets", + cm::make_unique()); + state->AddBuiltinCommand("link_directories", + cm::make_unique()); + state->AddBuiltinCommand("project", cm::make_unique()); + state->AddBuiltinCommand( + "set_source_files_properties", + cm::make_unique()); state->AddBuiltinCommand("set_target_properties", - new cmSetTargetPropertiesCommand); + cm::make_unique()); state->AddBuiltinCommand("set_tests_properties", - new cmSetTestsPropertiesCommand); - state->AddBuiltinCommand("subdirs", new cmSubdirCommand); - state->AddBuiltinCommand("target_compile_definitions", - new cmTargetCompileDefinitionsCommand); + cm::make_unique()); + state->AddBuiltinCommand("subdirs", cm::make_unique()); + state->AddBuiltinCommand( + "target_compile_definitions", + cm::make_unique()); state->AddBuiltinCommand("target_compile_features", - new cmTargetCompileFeaturesCommand); + cm::make_unique()); state->AddBuiltinCommand("target_compile_options", - new cmTargetCompileOptionsCommand); - state->AddBuiltinCommand("target_include_directories", - new cmTargetIncludeDirectoriesCommand); + cm::make_unique()); + state->AddBuiltinCommand( + "target_include_directories", + cm::make_unique()); 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()); + state->AddBuiltinCommand("target_sources", + cm::make_unique()); + state->AddBuiltinCommand("try_compile", + cm::make_unique()); + state->AddBuiltinCommand("try_run", cm::make_unique()); #if defined(CMAKE_BUILD_WITH_CMAKE) state->AddBuiltinCommand("add_compile_definitions", - new cmAddCompileDefinitionsCommand); + cm::make_unique()); state->AddBuiltinCommand("add_compile_options", - new cmAddCompileOptionsCommand); + cm::make_unique()); 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()); + state->AddBuiltinCommand("export", cm::make_unique()); + state->AddBuiltinCommand("fltk_wrap_ui", + cm::make_unique()); + state->AddBuiltinCommand( + "include_external_msproject", + cm::make_unique()); + state->AddBuiltinCommand("install_programs", + cm::make_unique()); + state->AddBuiltinCommand("add_link_options", + cm::make_unique()); + state->AddBuiltinCommand("link_libraries", + cm::make_unique()); state->AddBuiltinCommand("target_link_options", - new cmTargetLinkOptionsCommand); + cm::make_unique()); 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()); + state->AddBuiltinCommand("load_cache", + cm::make_unique()); + state->AddBuiltinCommand("qt_wrap_cpp", + cm::make_unique()); + state->AddBuiltinCommand("qt_wrap_ui", cm::make_unique()); state->AddBuiltinCommand("remove_definitions", - new cmRemoveDefinitionsCommand); - state->AddBuiltinCommand("source_group", new cmSourceGroupCommand); + cm::make_unique()); + state->AddBuiltinCommand("source_group", + cm::make_unique()); state->AddDisallowedCommand( - "export_library_dependencies", new cmExportLibraryDependenciesCommand, - cmPolicies::CMP0033, + "export_library_dependencies", + cm::make_unique(), cmPolicies::CMP0033, "The export_library_dependencies command should not be called; " "see CMP0033."); state->AddDisallowedCommand( - "load_command", new cmLoadCommandCommand, cmPolicies::CMP0031, + "load_command", cm::make_unique(), + cmPolicies::CMP0031, "The load_command command should not be called; see CMP0031."); state->AddDisallowedCommand( - "output_required_files", new cmOutputRequiredFilesCommand, + "output_required_files", cm::make_unique(), cmPolicies::CMP0032, "The output_required_files command should not be called; see CMP0032."); state->AddDisallowedCommand( - "subdir_depends", new cmSubdirDependsCommand, cmPolicies::CMP0029, + "subdir_depends", cm::make_unique(), + cmPolicies::CMP0029, "The subdir_depends command should not be called; see CMP0029."); state->AddDisallowedCommand( - "utility_source", new cmUtilitySourceCommand, cmPolicies::CMP0034, + "utility_source", cm::make_unique(), + cmPolicies::CMP0034, "The utility_source command should not be called; see CMP0034."); state->AddDisallowedCommand( - "variable_requires", new cmVariableRequiresCommand, cmPolicies::CMP0035, + "variable_requires", cm::make_unique(), + cmPolicies::CMP0035, "The variable_requires command should not be called; see CMP0035."); #endif } diff --git a/Source/cmConfigureFileCommand.h b/Source/cmConfigureFileCommand.h index 5603c50..b3a99d7 100644 --- a/Source/cmConfigureFileCommand.h +++ b/Source/cmConfigureFileCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmNewLineStyle.h" @@ -16,7 +18,10 @@ class cmExecutionStatus; class cmConfigureFileCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmConfigureFileCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmContinueCommand.h b/Source/cmContinueCommand.h index d383d1d..a85010a 100644 --- a/Source/cmContinueCommand.h +++ b/Source/cmContinueCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmContinueCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmCreateTestSourceList.h b/Source/cmCreateTestSourceList.h index 005b32c..5aa6af4 100644 --- a/Source/cmCreateTestSourceList.h +++ b/Source/cmCreateTestSourceList.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmCreateTestSourceList; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmDefinePropertyCommand.h b/Source/cmDefinePropertyCommand.h index a9c1856..36f97df 100644 --- a/Source/cmDefinePropertyCommand.h +++ b/Source/cmDefinePropertyCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmDefinePropertyCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmDefinePropertyCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmDisallowedCommand.h b/Source/cmDisallowedCommand.h index d85c00f..eed59ca 100644 --- a/Source/cmDisallowedCommand.h +++ b/Source/cmDisallowedCommand.h @@ -6,8 +6,11 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include #include +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmPolicies.h" @@ -16,20 +19,20 @@ class cmExecutionStatus; class cmDisallowedCommand : public cmCommand { public: - cmDisallowedCommand(cmCommand* command, cmPolicies::PolicyID policy, - const char* message) - : Command(command) + cmDisallowedCommand(std::unique_ptr command, + cmPolicies::PolicyID policy, const char* message) + : Command(std::move(command)) , Policy(policy) , Message(message) { } - ~cmDisallowedCommand() override { delete this->Command; } + ~cmDisallowedCommand() override = default; - cmCommand* Clone() override + std::unique_ptr Clone() override { - return new cmDisallowedCommand(this->Command->Clone(), this->Policy, - this->Message); + return cm::make_unique(this->Command->Clone(), + this->Policy, this->Message); } bool InitialPass(std::vector const& args, @@ -40,7 +43,7 @@ public: bool HasFinalPass() const override { return this->Command->HasFinalPass(); } private: - cmCommand* Command; + std::unique_ptr Command; cmPolicies::PolicyID Policy; const char* Message; }; diff --git a/Source/cmEnableLanguageCommand.h b/Source/cmEnableLanguageCommand.h index 97645a9..dc43e34 100644 --- a/Source/cmEnableLanguageCommand.h +++ b/Source/cmEnableLanguageCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -26,7 +28,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmEnableLanguageCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmEnableTestingCommand.h b/Source/cmEnableTestingCommand.h index 88a17b9..fd50ebc 100644 --- a/Source/cmEnableTestingCommand.h +++ b/Source/cmEnableTestingCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -31,7 +33,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmEnableTestingCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmExecProgramCommand.h b/Source/cmExecProgramCommand.h index ae0fa9b..70f833a 100644 --- a/Source/cmExecProgramCommand.h +++ b/Source/cmExecProgramCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmProcessOutput.h" @@ -27,7 +29,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmExecProgramCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 121f33f..689fc20 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -8,7 +8,6 @@ #include #include /* isspace */ #include -#include #include #include diff --git a/Source/cmExecuteProcessCommand.h b/Source/cmExecuteProcessCommand.h index b415deb..1d5445f 100644 --- a/Source/cmExecuteProcessCommand.h +++ b/Source/cmExecuteProcessCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmExecuteProcessCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmExportCommand.h b/Source/cmExportCommand.h index 99f9932..50463af 100644 --- a/Source/cmExportCommand.h +++ b/Source/cmExportCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -18,7 +20,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmExportCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmExportLibraryDependenciesCommand.h b/Source/cmExportLibraryDependenciesCommand.h index 8414866..5255d63 100644 --- a/Source/cmExportLibraryDependenciesCommand.h +++ b/Source/cmExportLibraryDependenciesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,9 +17,9 @@ class cmExecutionStatus; class cmExportLibraryDependenciesCommand : public cmCommand { public: - cmCommand* Clone() override + std::unique_ptr Clone() override { - return new cmExportLibraryDependenciesCommand; + return cm::make_unique(); } bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; diff --git a/Source/cmFLTKWrapUICommand.h b/Source/cmFLTKWrapUICommand.h index 044755e..bff4f01 100644 --- a/Source/cmFLTKWrapUICommand.h +++ b/Source/cmFLTKWrapUICommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmFLTKWrapUICommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h index cfff894..d4b980e 100644 --- a/Source/cmFileCommand.h +++ b/Source/cmFileCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -22,7 +24,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmFileCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmFindFileCommand.h b/Source/cmFindFileCommand.h index 4309449..152b505 100644 --- a/Source/cmFindFileCommand.h +++ b/Source/cmFindFileCommand.h @@ -5,9 +5,10 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include "cmFindPathCommand.h" +#include "cm_memory.hxx" -class cmCommand; +#include "cmCommand.h" +#include "cmFindPathCommand.h" /** \class cmFindFileCommand * \brief Define a command to search for an executable program. @@ -24,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmFindFileCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } }; #endif diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h index fb8a700..af17d60 100644 --- a/Source/cmFindLibraryCommand.h +++ b/Source/cmFindLibraryCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmFindBase.h" -class cmCommand; class cmExecutionStatus; /** \class cmFindLibraryCommand @@ -27,7 +29,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmFindLibraryCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 316ca0f..f6645ae 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -3,6 +3,7 @@ #ifndef cmFindPackageCommand_h #define cmFindPackageCommand_h +#include "cmCommand.h" #include "cmConfigure.h" // IWYU pragma: keep #include "cmPolicies.h" @@ -14,6 +15,8 @@ #include #include +#include "cm_memory.hxx" + // IWYU insists we should forward-declare instead of including , // but we cannot forward-declare reliably because some C++ standard libraries // put the template in an inline namespace. @@ -27,7 +30,6 @@ namespace std { #include "cmFindCommon.h" -class cmCommand; class cmExecutionStatus; class cmSearchPath; @@ -65,7 +67,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmFindPackageCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmFindPathCommand.h b/Source/cmFindPathCommand.h index cb0db4c..89e2cef 100644 --- a/Source/cmFindPathCommand.h +++ b/Source/cmFindPathCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmFindBase.h" -class cmCommand; class cmExecutionStatus; /** \class cmFindPathCommand @@ -27,7 +29,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmFindPathCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmFindProgramCommand.h b/Source/cmFindProgramCommand.h index 147936c..40e455e 100644 --- a/Source/cmFindProgramCommand.h +++ b/Source/cmFindProgramCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmFindBase.h" -class cmCommand; class cmExecutionStatus; /** \class cmFindProgramCommand @@ -28,7 +30,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmFindProgramCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmForEachCommand.h b/Source/cmForEachCommand.h index 5131a4f..cd112b8 100644 --- a/Source/cmForEachCommand.h +++ b/Source/cmForEachCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmFunctionBlocker.h" #include "cmListFileCache.h" @@ -39,7 +41,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmForEachCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index 9067a5f..8e003ad 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -3,6 +3,9 @@ #include "cmFunctionCommand.h" #include +#include + +#include "cm_memory.hxx" #include "cmAlgorithms.h" #include "cmExecutionStatus.h" @@ -18,15 +21,15 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmFunctionHelperCommand* newC = new cmFunctionHelperCommand; + auto newC = cm::make_unique(); // we must copy when we clone newC->Args = this->Args; newC->Functions = this->Functions; newC->Policies = this->Policies; newC->FilePath = this->FilePath; - return newC; + return std::unique_ptr(std::move(newC)); } /** @@ -129,12 +132,12 @@ bool cmFunctionFunctionBlocker::IsFunctionBlocked( // if this is the endfunction for this function then execute if (!this->Depth) { // create a new command and add it to cmake - cmFunctionHelperCommand* f = new cmFunctionHelperCommand(); + auto f = cm::make_unique(); f->Args = this->Args; f->Functions = this->Functions; f->FilePath = this->GetStartingContext().FilePath; 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 mf.RemoveFunctionBlocker(this, lff); return true; diff --git a/Source/cmFunctionCommand.h b/Source/cmFunctionCommand.h index 8b37df0..449a180 100644 --- a/Source/cmFunctionCommand.h +++ b/Source/cmFunctionCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmFunctionBlocker.h" #include "cmListFileCache.h" @@ -34,7 +36,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmFunctionCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmGetCMakePropertyCommand.h b/Source/cmGetCMakePropertyCommand.h index 1f29c78..7790a6b 100644 --- a/Source/cmGetCMakePropertyCommand.h +++ b/Source/cmGetCMakePropertyCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmGetCMakePropertyCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmGetCMakePropertyCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmGetDirectoryPropertyCommand.h b/Source/cmGetDirectoryPropertyCommand.h index 02ea056..63a198a 100644 --- a/Source/cmGetDirectoryPropertyCommand.h +++ b/Source/cmGetDirectoryPropertyCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmGetDirectoryPropertyCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmGetDirectoryPropertyCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmGetFilenameComponentCommand.h b/Source/cmGetFilenameComponentCommand.h index 8c26655..1780b96 100644 --- a/Source/cmGetFilenameComponentCommand.h +++ b/Source/cmGetFilenameComponentCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmGetFilenameComponentCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmGetPropertyCommand.h b/Source/cmGetPropertyCommand.h index c3f653e..50e4014 100644 --- a/Source/cmGetPropertyCommand.h +++ b/Source/cmGetPropertyCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -17,7 +19,10 @@ class cmGetPropertyCommand : public cmCommand public: cmGetPropertyCommand(); - cmCommand* Clone() override { return new cmGetPropertyCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmGetSourceFilePropertyCommand.h b/Source/cmGetSourceFilePropertyCommand.h index 43bc330..387a7f4 100644 --- a/Source/cmGetSourceFilePropertyCommand.h +++ b/Source/cmGetSourceFilePropertyCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmGetSourceFilePropertyCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmGetSourceFilePropertyCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmGetTargetPropertyCommand.h b/Source/cmGetTargetPropertyCommand.h index 63ee5fd..1a53195 100644 --- a/Source/cmGetTargetPropertyCommand.h +++ b/Source/cmGetTargetPropertyCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmGetTargetPropertyCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmGetTargetPropertyCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmGetTestPropertyCommand.h b/Source/cmGetTestPropertyCommand.h index 4a74f59..a53a7f7 100644 --- a/Source/cmGetTestPropertyCommand.h +++ b/Source/cmGetTestPropertyCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmGetTestPropertyCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmGetTestPropertyCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 6f32861..c58ad06 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -11,8 +11,6 @@ #include "cmSystemTools.h" #include "cmake.h" -#include - static std::string cmIfCommandError( std::vector const& args) { diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index d34ed02..4a67760 100644 --- a/Source/cmIfCommand.h +++ b/Source/cmIfCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmFunctionBlocker.h" #include "cmListFileCache.h" @@ -38,7 +40,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmIfCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This overrides the default InvokeInitialPass implementation. diff --git a/Source/cmIncludeCommand.h b/Source/cmIncludeCommand.h index 3b843b2..94d3fbd 100644 --- a/Source/cmIncludeCommand.h +++ b/Source/cmIncludeCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmIncludeCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmIncludeDirectoryCommand.h b/Source/cmIncludeDirectoryCommand.h index 01d98db..4df94eb 100644 --- a/Source/cmIncludeDirectoryCommand.h +++ b/Source/cmIncludeDirectoryCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmIncludeDirectoryCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmIncludeExternalMSProjectCommand.h b/Source/cmIncludeExternalMSProjectCommand.h index 945acdc..9f76576 100644 --- a/Source/cmIncludeExternalMSProjectCommand.h +++ b/Source/cmIncludeExternalMSProjectCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmIncludeExternalMSProjectCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmIncludeGuardCommand.h b/Source/cmIncludeGuardCommand.h index eaad9b8..4306c4c 100644 --- a/Source/cmIncludeGuardCommand.h +++ b/Source/cmIncludeGuardCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmIncludeGuardCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmIncludeRegularExpressionCommand.h b/Source/cmIncludeRegularExpressionCommand.h index 8da991d..1723c8b 100644 --- a/Source/cmIncludeRegularExpressionCommand.h +++ b/Source/cmIncludeRegularExpressionCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmIncludeRegularExpressionCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmInstallCommand.h b/Source/cmInstallCommand.h index 202c438..28bf443 100644 --- a/Source/cmInstallCommand.h +++ b/Source/cmInstallCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmInstallCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmInstallFilesCommand.h b/Source/cmInstallFilesCommand.h index a52f45e..e068b0e 100644 --- a/Source/cmInstallFilesCommand.h +++ b/Source/cmInstallFilesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmInstallFilesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmInstallProgramsCommand.h b/Source/cmInstallProgramsCommand.h index 5c705eb..3242365 100644 --- a/Source/cmInstallProgramsCommand.h +++ b/Source/cmInstallProgramsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmInstallProgramsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmInstallTargetsCommand.h b/Source/cmInstallTargetsCommand.h index 9950fb7..55e69ba 100644 --- a/Source/cmInstallTargetsCommand.h +++ b/Source/cmInstallTargetsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmInstallTargetsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h index ae4fb7f..1a439de 100644 --- a/Source/cmLinkDirectoriesCommand.h +++ b/Source/cmLinkDirectoriesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -26,7 +28,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmLinkDirectoriesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmLinkLibrariesCommand.h b/Source/cmLinkLibrariesCommand.h index af25fba..484ab0a 100644 --- a/Source/cmLinkLibrariesCommand.h +++ b/Source/cmLinkLibrariesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmLinkLibrariesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmListCommand.h b/Source/cmListCommand.h index ea3d643..70c7f4e 100644 --- a/Source/cmListCommand.h +++ b/Source/cmListCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -22,7 +24,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmListCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmLoadCacheCommand.h b/Source/cmLoadCacheCommand.h index e0f6e4f..45e52f0 100644 --- a/Source/cmLoadCacheCommand.h +++ b/Source/cmLoadCacheCommand.h @@ -9,6 +9,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmLoadCacheCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx index 69751b6..235dcd4 100644 --- a/Source/cmLoadCommandCommand.cxx +++ b/Source/cmLoadCommandCommand.cxx @@ -3,10 +3,14 @@ #include "cmLoadCommandCommand.h" #include + #include #include #include #include +#include + +#include "cm_memory.hxx" #include "cmCPluginAPI.cxx" #include "cmCPluginAPI.h" @@ -39,12 +43,12 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmLoadedCommand* newC = new cmLoadedCommand; + auto newC = cm::make_unique(); // we must copy when we clone memcpy(&newC->info, &this->info, sizeof(info)); - return newC; + return std::unique_ptr(std::move(newC)); } /** @@ -237,9 +241,9 @@ bool cmLoadCommandCommand::InitialPass(std::vector const& args, // function blocker if (initFunction) { // create a function blocker and set it up - cmLoadedCommand* f = new cmLoadedCommand(); + auto f = cm::make_unique(); (*initFunction)(&f->info); - this->Makefile->GetState()->AddScriptedCommand(args[0], f); + this->Makefile->GetState()->AddScriptedCommand(args[0], std::move(f)); return true; } this->SetError("Attempt to load command failed. " diff --git a/Source/cmLoadCommandCommand.h b/Source/cmLoadCommandCommand.h index 021e6c7..d81cefb 100644 --- a/Source/cmLoadCommandCommand.h +++ b/Source/cmLoadCommandCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmLoadCommandCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmLoadCommandCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; }; diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index e9c6aea..3d553b7 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -6,6 +6,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -21,15 +23,15 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr Clone() override { - cmMacroHelperCommand* newC = new cmMacroHelperCommand; + auto newC = cm::make_unique(); // we must copy when we clone newC->Args = this->Args; newC->Functions = this->Functions; newC->FilePath = this->FilePath; newC->Policies = this->Policies; - return newC; + return std::unique_ptr(std::move(newC)); } /** @@ -164,12 +166,12 @@ bool cmMacroFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, if (!this->Depth) { mf.AppendProperty("MACROS", this->Args[0].c_str()); // create a new command and add it to cmake - cmMacroHelperCommand* f = new cmMacroHelperCommand(); + auto f = cm::make_unique(); f->Args = this->Args; f->Functions = this->Functions; f->FilePath = this->GetStartingContext().FilePath; 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 mf.RemoveFunctionBlocker(this, lff); return true; diff --git a/Source/cmMacroCommand.h b/Source/cmMacroCommand.h index b54ed66..3ebd959 100644 --- a/Source/cmMacroCommand.h +++ b/Source/cmMacroCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmFunctionBlocker.h" #include "cmListFileCache.h" @@ -34,7 +36,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmMacroCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmMakeDirectoryCommand.h b/Source/cmMakeDirectoryCommand.h index d2637f3..b1fb49b 100644 --- a/Source/cmMakeDirectoryCommand.h +++ b/Source/cmMakeDirectoryCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -27,7 +29,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmMakeDirectoryCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5f22a07..501ea69 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -118,7 +118,6 @@ cmMakefile::~cmMakefile() cmDeleteAll(this->SourceFiles); cmDeleteAll(this->Tests); cmDeleteAll(this->ImportedTargetsOwned); - cmDeleteAll(this->FinalPassCommands); cmDeleteAll(this->FunctionBlockers); cmDeleteAll(this->EvaluationFiles); } @@ -418,7 +417,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, } } else if (pcmd->HasFinalPass()) { // use the command - this->FinalPassCommands.push_back(pcmd.release()); + this->FinalPassCommands.push_back(std::move(pcmd)); } } } else { @@ -776,8 +775,8 @@ void cmMakefile::FinalPass() // give all the commands a chance to do something // 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. diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index d0b70d9..1b4ead7 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -937,7 +937,7 @@ protected: size_t ObjectLibrariesSourceGroupIndex; #endif - std::vector FinalPassCommands; + std::vector> FinalPassCommands; cmGlobalGenerator* GlobalGenerator; bool IsFunctionBlocked(const cmListFileFunction& lff, cmExecutionStatus& status); diff --git a/Source/cmMarkAsAdvancedCommand.h b/Source/cmMarkAsAdvancedCommand.h index 5dd198f..e367c46 100644 --- a/Source/cmMarkAsAdvancedCommand.h +++ b/Source/cmMarkAsAdvancedCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmMarkAsAdvancedCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmMathCommand.h b/Source/cmMathCommand.h index 0c6c76b..23633d3 100644 --- a/Source/cmMathCommand.h +++ b/Source/cmMathCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -19,7 +21,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmMathCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmMessageCommand.h b/Source/cmMessageCommand.h index 819ebda..ef89d59 100644 --- a/Source/cmMessageCommand.h +++ b/Source/cmMessageCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -22,7 +24,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmMessageCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmOptionCommand.h b/Source/cmOptionCommand.h index 34e0e6f..eddab03 100644 --- a/Source/cmOptionCommand.h +++ b/Source/cmOptionCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmOptionCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmOutputRequiredFilesCommand.h b/Source/cmOutputRequiredFilesCommand.h index 09e622b..faffabd 100644 --- a/Source/cmOutputRequiredFilesCommand.h +++ b/Source/cmOutputRequiredFilesCommand.h @@ -10,6 +10,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmDependInformation; @@ -18,7 +20,10 @@ class cmExecutionStatus; class cmOutputRequiredFilesCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmOutputRequiredFilesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; diff --git a/Source/cmParseArgumentsCommand.h b/Source/cmParseArgumentsCommand.h index b8ba61d..692ea64 100644 --- a/Source/cmParseArgumentsCommand.h +++ b/Source/cmParseArgumentsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -21,7 +23,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmParseArgumentsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmProjectCommand.h b/Source/cmProjectCommand.h index f1d03e7..8b9bcc8 100644 --- a/Source/cmProjectCommand.h +++ b/Source/cmProjectCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -26,7 +28,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmProjectCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmQTWrapCPPCommand.h b/Source/cmQTWrapCPPCommand.h index c1dcd54..88a2210 100644 --- a/Source/cmQTWrapCPPCommand.h +++ b/Source/cmQTWrapCPPCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmQTWrapCPPCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmQTWrapUICommand.h b/Source/cmQTWrapUICommand.h index 15cab40..6a346d4 100644 --- a/Source/cmQTWrapUICommand.h +++ b/Source/cmQTWrapUICommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmQTWrapUICommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmRemoveCommand.h b/Source/cmRemoveCommand.h index 7b11849..088d8ad 100644 --- a/Source/cmRemoveCommand.h +++ b/Source/cmRemoveCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmRemoveCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmRemoveDefinitionsCommand.h b/Source/cmRemoveDefinitionsCommand.h index a5cb204..85d01d4 100644 --- a/Source/cmRemoveDefinitionsCommand.h +++ b/Source/cmRemoveDefinitionsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmRemoveDefinitionsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmReturnCommand.h b/Source/cmReturnCommand.h index ef39614..e9264d2 100644 --- a/Source/cmReturnCommand.h +++ b/Source/cmReturnCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmReturnCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSeparateArgumentsCommand.h b/Source/cmSeparateArgumentsCommand.h index 988ad23..76e2002 100644 --- a/Source/cmSeparateArgumentsCommand.h +++ b/Source/cmSeparateArgumentsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmSeparateArgumentsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSetCommand.h b/Source/cmSetCommand.h index 76e3eae..1c5a435 100644 --- a/Source/cmSetCommand.h +++ b/Source/cmSetCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmSetCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSetDirectoryPropertiesCommand.h b/Source/cmSetDirectoryPropertiesCommand.h index 473347c..5416127 100644 --- a/Source/cmSetDirectoryPropertiesCommand.h +++ b/Source/cmSetDirectoryPropertiesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -16,7 +18,10 @@ class cmMakefile; class cmSetDirectoryPropertiesCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmSetDirectoryPropertiesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSetPropertyCommand.h b/Source/cmSetPropertyCommand.h index f1126bb..4051e48 100644 --- a/Source/cmSetPropertyCommand.h +++ b/Source/cmSetPropertyCommand.h @@ -9,6 +9,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -22,7 +24,10 @@ class cmSetPropertyCommand : public cmCommand public: cmSetPropertyCommand(); - cmCommand* Clone() override { return new cmSetPropertyCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSetSourceFilesPropertiesCommand.h b/Source/cmSetSourceFilesPropertiesCommand.h index afb19f6..6fd6c41 100644 --- a/Source/cmSetSourceFilesPropertiesCommand.h +++ b/Source/cmSetSourceFilesPropertiesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -16,7 +18,10 @@ class cmMakefile; class cmSetSourceFilesPropertiesCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmSetSourceFilesPropertiesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSetTargetPropertiesCommand.h b/Source/cmSetTargetPropertiesCommand.h index c9755da..7e4606e 100644 --- a/Source/cmSetTargetPropertiesCommand.h +++ b/Source/cmSetTargetPropertiesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -16,7 +18,10 @@ class cmMakefile; class cmSetTargetPropertiesCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmSetTargetPropertiesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSetTestsPropertiesCommand.h b/Source/cmSetTestsPropertiesCommand.h index 84b2645..d73e95a 100644 --- a/Source/cmSetTestsPropertiesCommand.h +++ b/Source/cmSetTestsPropertiesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -16,7 +18,10 @@ class cmMakefile; class cmSetTestsPropertiesCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmSetTestsPropertiesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSiteNameCommand.h b/Source/cmSiteNameCommand.h index 2d8dc17..0190abb 100644 --- a/Source/cmSiteNameCommand.h +++ b/Source/cmSiteNameCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmSiteNameCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSourceGroupCommand.h b/Source/cmSourceGroupCommand.h index ec5ad32..eec4ec0 100644 --- a/Source/cmSourceGroupCommand.h +++ b/Source/cmSourceGroupCommand.h @@ -9,6 +9,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmSourceGroupCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 878d5b6..9748cf5 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "cm_memory.hxx" @@ -29,11 +30,7 @@ cmState::cmState() this->GlobVerificationManager = cm::make_unique(); } -cmState::~cmState() -{ - cmDeleteAll(this->BuiltinCommands); - cmDeleteAll(this->ScriptedCommands); -} +cmState::~cmState() = default; const char* cmState::GetTargetTypeName(cmStateEnums::TargetType targetType) { @@ -421,50 +418,55 @@ void cmState::SetIsGeneratorMultiConfig(bool b) this->IsGeneratorMultiConfig = b; } -void cmState::AddBuiltinCommand(std::string const& name, cmCommand* command) +void cmState::AddBuiltinCommand(std::string const& name, + std::unique_ptr command) { assert(name == cmSystemTools::LowerCase(name)); assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end()); - this->BuiltinCommands.insert(std::make_pair(name, command)); + this->BuiltinCommands.insert( + std::map>::value_type( + name, std::move(command))); } -void cmState::AddDisallowedCommand(std::string const& name, cmCommand* command, +void cmState::AddDisallowedCommand(std::string const& name, + std::unique_ptr command, cmPolicies::PolicyID policy, const char* message) { - this->AddBuiltinCommand(name, - new cmDisallowedCommand(command, policy, message)); + this->AddBuiltinCommand( + name, + cm::make_unique(std::move(command), policy, message)); } void cmState::AddUnexpectedCommand(std::string const& name, const char* error) { - this->AddBuiltinCommand(name, new cmUnexpectedCommand(name, error)); + this->AddBuiltinCommand(name, + cm::make_unique(name, error)); } -void cmState::AddScriptedCommand(std::string const& name, cmCommand* command) +void cmState::AddScriptedCommand(std::string const& name, + std::unique_ptr command) { std::string sName = cmSystemTools::LowerCase(name); // if the command already exists, give a new name to the old command. if (cmCommand* oldCmd = this->GetCommand(sName)) { std::string const newName = "_" + sName; - std::map::iterator pos = - this->ScriptedCommands.find(newName); + auto pos = this->ScriptedCommands.find(newName); if (pos != this->ScriptedCommands.end()) { - delete pos->second; this->ScriptedCommands.erase(pos); } this->ScriptedCommands.insert(std::make_pair(newName, oldCmd->Clone())); } // if the command already exists, free the old one - std::map::iterator pos = - this->ScriptedCommands.find(sName); + auto pos = this->ScriptedCommands.find(sName); if (pos != this->ScriptedCommands.end()) { - delete pos->second; this->ScriptedCommands.erase(pos); } - this->ScriptedCommands.insert(std::make_pair(sName, command)); + this->ScriptedCommands.insert( + std::map>::value_type( + sName, std::move(command))); } cmCommand* cmState::GetCommand(std::string const& name) const @@ -474,14 +476,13 @@ cmCommand* cmState::GetCommand(std::string const& name) const cmCommand* cmState::GetCommandByExactName(std::string const& name) const { - std::map::const_iterator pos; - pos = this->ScriptedCommands.find(name); + auto pos = this->ScriptedCommands.find(name); if (pos != this->ScriptedCommands.end()) { - return pos->second; + return pos->second.get(); } pos = this->BuiltinCommands.find(name); if (pos != this->BuiltinCommands.end()) { - return pos->second; + return pos->second.get(); } return nullptr; } @@ -506,16 +507,13 @@ std::vector cmState::GetCommandNames() const void cmState::RemoveBuiltinCommand(std::string const& name) { assert(name == cmSystemTools::LowerCase(name)); - std::map::iterator i = - this->BuiltinCommands.find(name); + auto i = this->BuiltinCommands.find(name); assert(i != this->BuiltinCommands.end()); - delete i->second; this->BuiltinCommands.erase(i); } void cmState::RemoveUserDefinedCommands() { - cmDeleteAll(this->ScriptedCommands); this->ScriptedCommands.clear(); } diff --git a/Source/cmState.h b/Source/cmState.h index 0649ace..7e88030 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -146,11 +146,14 @@ public: // Returns a command from its name, or nullptr cmCommand* GetCommandByExactName(std::string const& name) const; - void AddBuiltinCommand(std::string const& name, cmCommand* command); - void AddDisallowedCommand(std::string const& name, cmCommand* command, + void AddBuiltinCommand(std::string const& name, + std::unique_ptr command); + void AddDisallowedCommand(std::string const& name, + std::unique_ptr command, cmPolicies::PolicyID policy, const char* message); void AddUnexpectedCommand(std::string const& name, const char* error); - void AddScriptedCommand(std::string const& name, cmCommand* command); + void AddScriptedCommand(std::string const& name, + std::unique_ptr command); void RemoveBuiltinCommand(std::string const& name); void RemoveUserDefinedCommands(); std::vector GetCommandNames() const; @@ -209,8 +212,8 @@ private: std::map PropertyDefinitions; std::vector EnabledLanguages; - std::map BuiltinCommands; - std::map ScriptedCommands; + std::map> BuiltinCommands; + std::map> ScriptedCommands; cmPropertyMap GlobalProperties; std::unique_ptr CacheManager; std::unique_ptr GlobVerificationManager; diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 10ccac0..4ad0870 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index acde605..f48ea17 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -9,6 +9,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmStringCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSubdirCommand.h b/Source/cmSubdirCommand.h index adab757..3499c46 100644 --- a/Source/cmSubdirCommand.h +++ b/Source/cmSubdirCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -25,7 +27,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmSubdirCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmSubdirDependsCommand.h b/Source/cmSubdirDependsCommand.h index 2db28c6..64c28b9 100644 --- a/Source/cmSubdirDependsCommand.h +++ b/Source/cmSubdirDependsCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmSubdirDependsCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmSubdirDependsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; }; diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h index d41483a..25af21d 100644 --- a/Source/cmTargetCompileDefinitionsCommand.h +++ b/Source/cmTargetCompileDefinitionsCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmTargetPropCommandBase.h" -class cmCommand; class cmExecutionStatus; class cmTarget; @@ -20,7 +22,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmTargetCompileDefinitionsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h index 45240a5..07948fa 100644 --- a/Source/cmTargetCompileFeaturesCommand.h +++ b/Source/cmTargetCompileFeaturesCommand.h @@ -8,15 +8,20 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmTargetPropCommandBase.h" -class cmCommand; class cmExecutionStatus; class cmTarget; class cmTargetCompileFeaturesCommand : public cmTargetPropCommandBase { - cmCommand* Clone() override { return new cmTargetCompileFeaturesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h index 6fb151a..a571cfb 100644 --- a/Source/cmTargetCompileOptionsCommand.h +++ b/Source/cmTargetCompileOptionsCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmTargetPropCommandBase.h" -class cmCommand; class cmExecutionStatus; class cmTarget; @@ -20,7 +22,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmTargetCompileOptionsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h index 57bf8fc..6defab2 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.h +++ b/Source/cmTargetIncludeDirectoriesCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmTargetPropCommandBase.h" -class cmCommand; class cmExecutionStatus; class cmTarget; @@ -20,7 +22,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmTargetIncludeDirectoriesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmTargetLinkDirectoriesCommand.h b/Source/cmTargetLinkDirectoriesCommand.h index 52c75a0..a2fcfa9 100644 --- a/Source/cmTargetLinkDirectoriesCommand.h +++ b/Source/cmTargetLinkDirectoriesCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmTargetPropCommandBase.h" -class cmCommand; class cmExecutionStatus; class cmTarget; @@ -20,7 +22,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmTargetLinkDirectoriesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h index 54f8cf4..6698ce0 100644 --- a/Source/cmTargetLinkLibrariesCommand.h +++ b/Source/cmTargetLinkLibrariesCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmTargetLinkLibraryType.h" @@ -30,7 +32,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmTargetLinkLibrariesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmTargetLinkOptionsCommand.h b/Source/cmTargetLinkOptionsCommand.h index a1fc9fc..3710739 100644 --- a/Source/cmTargetLinkOptionsCommand.h +++ b/Source/cmTargetLinkOptionsCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmTargetPropCommandBase.h" -class cmCommand; class cmExecutionStatus; class cmTarget; @@ -20,7 +22,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmTargetLinkOptionsCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h index b01e3ca..90fd45f 100644 --- a/Source/cmTargetSourcesCommand.h +++ b/Source/cmTargetSourcesCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmTargetPropCommandBase.h" -class cmCommand; class cmExecutionStatus; class cmTarget; @@ -20,7 +22,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmTargetSourcesCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmTryCompileCommand.h b/Source/cmTryCompileCommand.h index 8237878..ec9f8b8 100644 --- a/Source/cmTryCompileCommand.h +++ b/Source/cmTryCompileCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmCoreTryCompile.h" -class cmCommand; class cmExecutionStatus; /** \class cmTryCompileCommand @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmTryCompileCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmTryRunCommand.h b/Source/cmTryRunCommand.h index c54622c..bacfcdb 100644 --- a/Source/cmTryRunCommand.h +++ b/Source/cmTryRunCommand.h @@ -8,9 +8,11 @@ #include #include +#include "cm_memory.hxx" + +#include "cmCommand.h" #include "cmCoreTryCompile.h" -class cmCommand; class cmExecutionStatus; /** \class cmTryRunCommand @@ -24,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmTryRunCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmUVProcessChain.cxx b/Source/cmUVProcessChain.cxx index fbd5634..56d6c09 100644 --- a/Source/cmUVProcessChain.cxx +++ b/Source/cmUVProcessChain.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmUVProcessChain.h" -#include "cmAlgorithms.h" #include "cmGetPipes.h" #include "cmUVHandlePtr.h" #include "cmUVStreambuf.h" @@ -10,6 +9,7 @@ #include +#include // IWYU pragma: keep #include #include diff --git a/Source/cmUnexpectedCommand.h b/Source/cmUnexpectedCommand.h index 33d6bdc..6e4cee5 100644 --- a/Source/cmUnexpectedCommand.h +++ b/Source/cmUnexpectedCommand.h @@ -9,6 +9,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -22,9 +24,9 @@ public: { } - cmCommand* Clone() override + std::unique_ptr Clone() override { - return new cmUnexpectedCommand(this->Name, this->Error); + return cm::make_unique(this->Name, this->Error); } bool InitialPass(std::vector const& args, diff --git a/Source/cmUnsetCommand.h b/Source/cmUnsetCommand.h index 4e1208a..9b78d44 100644 --- a/Source/cmUnsetCommand.h +++ b/Source/cmUnsetCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmUnsetCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmUseMangledMesaCommand.h b/Source/cmUseMangledMesaCommand.h index e2f1d9b..1c01596 100644 --- a/Source/cmUseMangledMesaCommand.h +++ b/Source/cmUseMangledMesaCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmUseMangledMesaCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmUseMangledMesaCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; diff --git a/Source/cmUtilitySourceCommand.h b/Source/cmUtilitySourceCommand.h index 165ecef..cef7fed 100644 --- a/Source/cmUtilitySourceCommand.h +++ b/Source/cmUtilitySourceCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmUtilitySourceCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmUtilitySourceCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; }; diff --git a/Source/cmVariableRequiresCommand.h b/Source/cmVariableRequiresCommand.h index 94970c5..38e7490 100644 --- a/Source/cmVariableRequiresCommand.h +++ b/Source/cmVariableRequiresCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,7 +17,10 @@ class cmExecutionStatus; class cmVariableRequiresCommand : public cmCommand { public: - cmCommand* Clone() override { return new cmVariableRequiresCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } bool InitialPass(std::vector const& args, cmExecutionStatus& status) override; }; diff --git a/Source/cmVariableWatchCommand.h b/Source/cmVariableWatchCommand.h index 6a8115d..0dbb0cb 100644 --- a/Source/cmVariableWatchCommand.h +++ b/Source/cmVariableWatchCommand.h @@ -9,6 +9,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,7 +25,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmVariableWatchCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } //! Default constructor cmVariableWatchCommand(); diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx index 0d3bdf8..31a878d 100644 --- a/Source/cmWhileCommand.cxx +++ b/Source/cmWhileCommand.cxx @@ -9,8 +9,6 @@ #include "cmMessageType.h" #include "cmSystemTools.h" -#include - cmWhileFunctionBlocker::cmWhileFunctionBlocker(cmMakefile* mf) : Makefile(mf) , Depth(0) diff --git a/Source/cmWhileCommand.h b/Source/cmWhileCommand.h index 6f6d405..857d1c8 100644 --- a/Source/cmWhileCommand.h +++ b/Source/cmWhileCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmFunctionBlocker.h" #include "cmListFileCache.h" @@ -39,7 +41,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmWhileCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This overrides the default InvokeInitialPass implementation. diff --git a/Source/cmWriteFileCommand.h b/Source/cmWriteFileCommand.h index 9028f84..3961898 100644 --- a/Source/cmWriteFileCommand.h +++ b/Source/cmWriteFileCommand.h @@ -8,6 +8,8 @@ #include #include +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -22,7 +24,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmWriteFileCommand; } + std::unique_ptr Clone() override + { + return cm::make_unique(); + } /** * This is called when the command is first encountered in diff --git a/Tests/CMakeLib/testUVProcessChain.cxx b/Tests/CMakeLib/testUVProcessChain.cxx index 2c1202e..63c9943 100644 --- a/Tests/CMakeLib/testUVProcessChain.cxx +++ b/Tests/CMakeLib/testUVProcessChain.cxx @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include -- cgit v0.12