diff options
Diffstat (limited to 'Source')
260 files changed, 2023 insertions, 1195 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 300aab7..f0084cd 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 15) -set(CMake_VERSION_PATCH 20190709) +set(CMake_VERSION_PATCH 20190722) #set(CMake_VERSION_RC 1) diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index 045d93d..fa64d79 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -604,7 +604,7 @@ std::string cmCPackWIXGenerator::GetRootFolderId() const bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate() { - std::string wixTemplate = FindTemplate("WIX.template.in"); + std::string wixTemplate = FindTemplate("Internal/CPack/WIX.template.in"); if (GetOption("CPACK_WIX_TEMPLATE") != 0) { wixTemplate = GetOption("CPACK_WIX_TEMPLATE"); } diff --git a/Source/CPack/cmCPackExternalGenerator.cxx b/Source/CPack/cmCPackExternalGenerator.cxx index 9dc9853..b4c7a5a 100644 --- a/Source/CPack/cmCPackExternalGenerator.cxx +++ b/Source/CPack/cmCPackExternalGenerator.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackExternalGenerator.h" -#include "cmAlgorithms.h" #include "cmCPackComponentGroup.h" #include "cmCPackLog.h" #include "cmMakefile.h" @@ -17,6 +16,8 @@ #include <utility> #include <vector> +#include "cm_memory.hxx" + int cmCPackExternalGenerator::InitializeInternal() { this->SetOption("CPACK_EXTERNAL_KNOWN_VERSIONS", "1.0"); diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 540ce46..350ebed 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -7,7 +7,7 @@ #include "cmsys/RegularExpression.hxx" #include <algorithm> #include <cstring> -#include <memory> // IWYU pragma: keep +#include <memory> #include <utility> #include "cmCPackComponentGroup.h" diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index e2020c5..87c36fa 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -36,7 +36,8 @@ int cmCPackNSISGenerator::PackageFiles() { // TODO: Fix nsis to force out file name - std::string nsisInFileName = this->FindTemplate("NSIS.template.in"); + std::string nsisInFileName = + this->FindTemplate("Internal/CPack/NSIS.template.in"); if (nsisInFileName.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack error: Could not find NSIS installer template file." @@ -44,7 +45,7 @@ int cmCPackNSISGenerator::PackageFiles() return false; } std::string nsisInInstallOptions = - this->FindTemplate("NSIS.InstallOptions.ini.in"); + this->FindTemplate("Internal/CPack/NSIS.InstallOptions.ini.in"); if (nsisInInstallOptions.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack error: Could not find NSIS installer options file." diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx index 90e0afe..41470c9 100644 --- a/Source/CPack/cmCPackOSXX11Generator.cxx +++ b/Source/CPack/cmCPackOSXX11Generator.cxx @@ -245,7 +245,7 @@ bool cmCPackOSXX11Generator::CopyResourcePlistFile( const std::string& name, const std::string& dir, const char* outputFileName /* = 0 */, bool copyOnly /* = false */) { - std::string inFName = "CPack."; + std::string inFName = "Internal/CPack/CPack."; inFName += name; inFName += ".in"; std::string inFileName = this->FindTemplate(inFName.c_str()); diff --git a/Source/CPack/cmCPackPKGGenerator.cxx b/Source/CPack/cmCPackPKGGenerator.cxx index 8c22c65..d361921 100644 --- a/Source/CPack/cmCPackPKGGenerator.cxx +++ b/Source/CPack/cmCPackPKGGenerator.cxx @@ -48,7 +48,7 @@ std::string cmCPackPKGGenerator::GetPackageName( void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) { std::string distributionTemplate = - this->FindTemplate("CPack.distribution.dist.in"); + this->FindTemplate("Internal/CPack/CPack.distribution.dist.in"); if (distributionTemplate.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: " << distributionTemplate @@ -305,7 +305,7 @@ bool cmCPackPKGGenerator::CopyResourcePlistFile(const std::string& name, outName = name.c_str(); } - std::string inFName = "CPack."; + std::string inFName = "Internal/CPack/CPack."; inFName += name; inFName += ".in"; std::string inFileName = this->FindTemplate(inFName.c_str()); diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx index aba15d2..4666dc2 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/Source/CPack/cmCPackSTGZGenerator.cxx @@ -21,7 +21,8 @@ int cmCPackSTGZGenerator::InitializeInternal() { this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0"); - std::string inFile = this->FindTemplate("CPack.STGZ_Header.sh.in"); + std::string inFile = + this->FindTemplate("Internal/CPack/CPack.STGZ_Header.sh.in"); if (inFile.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find template file: " << inFile << std::endl); diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 58b9e70..c6018cf 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -5,7 +5,6 @@ #include "cmsys/Encoding.hxx" #include <iostream> #include <map> -#include <memory> // IWYU pragma: keep #include <sstream> #include <stddef.h> #include <string> @@ -29,19 +28,20 @@ #include "cmSystemTools.h" #include "cmake.h" -static const char* cmDocumentationName[][2] = { +namespace { +const char* cmDocumentationName[][2] = { { nullptr, " cpack - Packaging driver provided by CMake." }, { nullptr, nullptr } }; -static const char* cmDocumentationUsage[][2] = { +const char* cmDocumentationUsage[][2] = { // clang-format off { nullptr, " cpack [options]" }, { nullptr, nullptr } // clang-format on }; -static const char* cmDocumentationOptions[][2] = { +const char* cmDocumentationOptions[][2] = { { "-G <generators>", "Override/define CPACK_GENERATOR" }, { "-C <Configuration>", "Specify the project configuration" }, { "-D <var>=<value>", "Set a CPack variable." }, @@ -90,10 +90,11 @@ int cpackDefinitionArgument(const char* argument, const char* cValue, return 1; } -static void cpackProgressCallback(const std::string& message, float /*unused*/) +void cpackProgressCallback(const std::string& message, float /*unused*/) { std::cout << "-- " << message << std::endl; } +} // namespace // this is CPack. int main(int argc, char const* const* argv) diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index 9ad9669..3aea1f4 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -76,6 +76,11 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring, if (config) { args.push_back("-DCMAKE_BUILD_TYPE:STRING=" + std::string(config)); } + if (!this->BuildMakeProgram.empty() && + (this->BuildGenerator.find("Make") != std::string::npos || + this->BuildGenerator.find("Ninja") != std::string::npos)) { + args.push_back("-DCMAKE_MAKE_PROGRAM:FILEPATH=" + this->BuildMakeProgram); + } for (std::string const& opt : this->BuildOptions) { args.push_back(opt); 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 <string> +#include <utility> #include <vector> +#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<cmCommand> Clone() override { - cmCTestBuildCommand* ni = new cmCTestBuildCommand; + auto ni = cm::make_unique<cmCTestBuildCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(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 <string> +#include <utility> + +#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<cmCommand> Clone() override { - cmCTestConfigureCommand* ni = new cmCTestConfigureCommand; + auto ni = cm::make_unique<cmCTestConfigureCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(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 <set> #include <string> +#include <utility> + +#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<cmCommand> Clone() override { - cmCTestCoverageCommand* ni = new cmCTestCoverageCommand; + auto ni = cm::make_unique<cmCTestCoverageCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(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 <string> +#include <utility> #include <vector> -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<cmCommand> Clone() override { - cmCTestEmptyBinaryDirectoryCommand* ni = - new cmCTestEmptyBinaryDirectoryCommand; + auto ni = cm::make_unique<cmCTestEmptyBinaryDirectoryCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index a96513e..237ca82 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -6,7 +6,6 @@ #include "cmsys/Process.h" #include "cmsys/RegularExpression.hxx" #include <iostream> -#include <memory> // IWYU pragma: keep #include <stdlib.h> #include <string.h> 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 <utility> + +#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<cmCommand> Clone() override { - cmCTestMemCheckCommand* ni = new cmCTestMemCheckCommand; + auto ni = cm::make_unique<cmCTestMemCheckCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(std::move(ni)); } protected: diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index ef63073..42534f7 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -29,11 +29,13 @@ #include <iostream> #include <list> #include <math.h> +#include <memory> #include <sstream> #include <stack> #include <stdlib.h> #include <unordered_map> #include <utility> +#include <vector> namespace cmsys { class RegularExpression; @@ -821,6 +823,11 @@ static Json::Value DumpCTestProperties( "FAIL_REGULAR_EXPRESSION", DumpRegExToJsonArray(testProperties.ErrorRegularExpressions))); } + if (!testProperties.SkipRegularExpressions.empty()) { + properties.append(DumpCTestProperty( + "SKIP_REGULAR_EXPRESSION", + DumpRegExToJsonArray(testProperties.SkipRegularExpressions))); + } if (!testProperties.FixturesCleanup.empty()) { properties.append(DumpCTestProperty( "FIXTURES_CLEANUP", DumpToJsonArray(testProperties.FixturesCleanup))); 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 <string> +#include <utility> #include <vector> -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<cmCommand> Clone() override { - cmCTestReadCustomFilesCommand* ni = new cmCTestReadCustomFilesCommand; + auto ni = cm::make_unique<cmCTestReadCustomFilesCommand>(); ni->CTest = this->CTest; - return ni; + return std::unique_ptr<cmCommand>(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 <string> +#include <utility> #include <vector> -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<cmCommand> Clone() override { - cmCTestRunScriptCommand* ni = new cmCTestRunScriptCommand; + auto ni = cm::make_unique<cmCTestRunScriptCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 31976b9..65cf646 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -11,7 +11,6 @@ #include "cmsys/RegularExpression.hxx" #include <chrono> -#include <cmAlgorithms.h> #include <cstdint> #include <cstring> #include <iomanip> @@ -20,6 +19,8 @@ #include <stdio.h> #include <utility> +#include "cm_memory.hxx" + cmCTestRunTest::cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler) : MultiTestHandler(multiHandler) { @@ -76,6 +77,7 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) } std::int64_t retVal = this->TestProcess->GetExitValue(); bool forceFail = false; + bool forceSkip = false; bool skipped = false; bool outputTestErrorsToConsole = false; if (!this->TestProperties->RequiredRegularExpressions.empty() && @@ -85,43 +87,64 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) if (pass.first.find(this->ProcessOutput)) { found = true; reason = "Required regular expression found."; + reason += " Regex=["; + reason += pass.second; + reason += "]"; break; } } if (!found) { reason = "Required regular expression not found."; + reason += " Regex=["; + for (auto& pass : this->TestProperties->RequiredRegularExpressions) { + reason += pass.second; + reason += "\n"; + } + reason += "]"; forceFail = true; } - reason += "Regex=["; - for (auto& pass : this->TestProperties->RequiredRegularExpressions) { - reason += pass.second; - reason += "\n"; - } - reason += "]"; } if (!this->TestProperties->ErrorRegularExpressions.empty() && this->FailedDependencies.empty()) { - for (auto& pass : this->TestProperties->ErrorRegularExpressions) { - if (pass.first.find(this->ProcessOutput)) { + for (auto& fail : this->TestProperties->ErrorRegularExpressions) { + if (fail.first.find(this->ProcessOutput)) { reason = "Error regular expression found in output."; reason += " Regex=["; - reason += pass.second; + reason += fail.second; reason += "]"; forceFail = true; break; } } } + if (!this->TestProperties->SkipRegularExpressions.empty() && + this->FailedDependencies.empty()) { + for (auto& skip : this->TestProperties->SkipRegularExpressions) { + if (skip.first.find(this->ProcessOutput)) { + reason = "Skip regular expression found in output."; + reason += " Regex=["; + reason += skip.second; + reason += "]"; + forceSkip = true; + break; + } + } + } std::ostringstream outputStream; if (res == cmProcess::State::Exited) { bool success = !forceFail && (retVal == 0 || !this->TestProperties->RequiredRegularExpressions.empty()); - if (this->TestProperties->SkipReturnCode >= 0 && - this->TestProperties->SkipReturnCode == retVal) { + if ((this->TestProperties->SkipReturnCode >= 0 && + this->TestProperties->SkipReturnCode == retVal) || + forceSkip) { this->TestResult.Status = cmCTestTestHandler::NOT_RUN; std::ostringstream s; - s << "SKIP_RETURN_CODE=" << this->TestProperties->SkipReturnCode; + if (forceSkip) { + s << "SKIP_REGULAR_EXPRESSION_MATCHED"; + } else { + s << "SKIP_RETURN_CODE=" << this->TestProperties->SkipReturnCode; + } this->TestResult.CompletionStatus = s.str(); cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Skipped "); skipped = true; diff --git a/Source/CTest/cmCTestRunTest.h b/Source/CTest/cmCTestRunTest.h index 38cc417..43dfe8e 100644 --- a/Source/CTest/cmCTestRunTest.h +++ b/Source/CTest/cmCTestRunTest.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include <memory> #include <set> #include <stddef.h> #include <string> @@ -12,7 +13,7 @@ #include "cmCTestTestHandler.h" #include "cmDuration.h" -#include "cmProcess.h" // IWYU pragma: keep (for unique_ptr) +#include "cmProcess.h" class cmCTest; class cmCTestMultiProcessHandler; diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index a739f44..85040dd 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -4,13 +4,8 @@ #include "cmsys/Directory.hxx" #include "cmsys/Process.h" -#include <map> -#include <ratio> -#include <sstream> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <utility> + +#include "cm_memory.hxx" #include "cmCTest.h" #include "cmCTestBuildCommand.h" @@ -27,6 +22,7 @@ #include "cmCTestTestCommand.h" #include "cmCTestUpdateCommand.h" #include "cmCTestUploadCommand.h" +#include "cmCommand.h" #include "cmDuration.h" #include "cmFunctionBlocker.h" #include "cmGeneratedFileStream.h" @@ -38,6 +34,15 @@ #include "cmSystemTools.h" #include "cmake.h" +#include <map> +#include <memory> +#include <ratio> +#include <sstream> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <utility> + #ifdef _WIN32 # include <windows.h> #else @@ -167,12 +172,12 @@ void cmCTestScriptHandler::UpdateElapsedTime() } } -void cmCTestScriptHandler::AddCTestCommand(std::string const& name, - cmCTestCommand* command) +void cmCTestScriptHandler::AddCTestCommand( + std::string const& name, std::unique_ptr<cmCTestCommand> command) { command->CTest = this->CTest; command->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 +300,28 @@ void cmCTestScriptHandler::CreateCMake() } }); - this->AddCTestCommand("ctest_build", new cmCTestBuildCommand); - this->AddCTestCommand("ctest_configure", new cmCTestConfigureCommand); - this->AddCTestCommand("ctest_coverage", new cmCTestCoverageCommand); + this->AddCTestCommand("ctest_build", cm::make_unique<cmCTestBuildCommand>()); + this->AddCTestCommand("ctest_configure", + cm::make_unique<cmCTestConfigureCommand>()); + this->AddCTestCommand("ctest_coverage", + cm::make_unique<cmCTestCoverageCommand>()); this->AddCTestCommand("ctest_empty_binary_directory", - new cmCTestEmptyBinaryDirectoryCommand); - this->AddCTestCommand("ctest_memcheck", new cmCTestMemCheckCommand); + cm::make_unique<cmCTestEmptyBinaryDirectoryCommand>()); + this->AddCTestCommand("ctest_memcheck", + cm::make_unique<cmCTestMemCheckCommand>()); this->AddCTestCommand("ctest_read_custom_files", - new cmCTestReadCustomFilesCommand); - this->AddCTestCommand("ctest_run_script", new cmCTestRunScriptCommand); - this->AddCTestCommand("ctest_sleep", new cmCTestSleepCommand); - this->AddCTestCommand("ctest_start", new cmCTestStartCommand); - this->AddCTestCommand("ctest_submit", new cmCTestSubmitCommand); - this->AddCTestCommand("ctest_test", new cmCTestTestCommand); - this->AddCTestCommand("ctest_update", new cmCTestUpdateCommand); - this->AddCTestCommand("ctest_upload", new cmCTestUploadCommand); + cm::make_unique<cmCTestReadCustomFilesCommand>()); + this->AddCTestCommand("ctest_run_script", + cm::make_unique<cmCTestRunScriptCommand>()); + this->AddCTestCommand("ctest_sleep", cm::make_unique<cmCTestSleepCommand>()); + this->AddCTestCommand("ctest_start", cm::make_unique<cmCTestStartCommand>()); + this->AddCTestCommand("ctest_submit", + cm::make_unique<cmCTestSubmitCommand>()); + this->AddCTestCommand("ctest_test", cm::make_unique<cmCTestTestCommand>()); + this->AddCTestCommand("ctest_update", + cm::make_unique<cmCTestUpdateCommand>()); + this->AddCTestCommand("ctest_upload", + cm::make_unique<cmCTestUploadCommand>()); } // this sets up some variables for the script to use, creates the required @@ -362,9 +374,11 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) #endif // always add a function blocker to update the elapsed time - cmCTestScriptFunctionBlocker* f = new cmCTestScriptFunctionBlocker(); - f->CTestScriptHandler = this; - this->Makefile->AddFunctionBlocker(f); + { + auto fb = cm::make_unique<cmCTestScriptFunctionBlocker>(); + fb->CTestScriptHandler = this; + this->Makefile->AddFunctionBlocker(std::move(fb)); + } /* Execute CTestScriptMode.cmake, which loads CMakeDetermineSystem and CMakeSystemSpecificInformation, so 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 <chrono> +#include <memory> #include <string> #include <vector> @@ -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<cmCTestCommand> 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 <string> +#include <utility> #include <vector> -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<cmCommand> Clone() override { - cmCTestSleepCommand* ni = new cmCTestSleepCommand; + auto ni = cm::make_unique<cmCTestSleepCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(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 <iosfwd> #include <string> +#include <utility> #include <vector> -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<cmCommand> Clone() override { - cmCTestStartCommand* ni = new cmCTestStartCommand; + auto ni = cm::make_unique<cmCTestStartCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; ni->CreateNewTag = this->CreateNewTag; ni->Quiet = this->Quiet; - return ni; + return std::unique_ptr<cmCommand>(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 <sstream> +#include <utility> + +#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<cmCommand> cmCTestSubmitCommand::Clone() { - cmCTestSubmitCommand* ni = new cmCTestSubmitCommand; + auto ni = cm::make_unique<cmCTestSubmitCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(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 <memory> #include <set> #include <string> #include <vector> -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<cmCommand> Clone() override; bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 1fa7988..54c4bae 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -266,15 +266,6 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( } } - upload_as += "&MD5="; - - if (cmSystemTools::IsOn(this->GetOption("InternalTest"))) { - upload_as += "bad_md5sum"; - } else { - upload_as += - cmSystemTools::ComputeFileHash(local_file, cmCryptoHash::AlgoMD5); - } - // Generate Done.xml right before it is submitted. // The reason for this is two-fold: // 1) It must be generated after some other part has been submitted @@ -286,6 +277,15 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( this->CTest->GenerateDoneFile(); } + upload_as += "&MD5="; + + if (cmSystemTools::IsOn(this->GetOption("InternalTest"))) { + upload_as += "bad_md5sum"; + } else { + upload_as += + cmSystemTools::ComputeFileHash(local_file, cmCryptoHash::AlgoMD5); + } + if (!cmSystemTools::FileExists(local_file)) { cmCTestLog(this->CTest, ERROR_MESSAGE, " Cannot find file: " << local_file << std::endl); 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 <string> +#include <utility> + +#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<cmCommand> Clone() override { - cmCTestTestCommand* ni = new cmCTestTestCommand; + auto ni = cm::make_unique<cmCTestTestCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 0ed56c8..c2748e1 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -11,12 +11,14 @@ #include <functional> #include <iomanip> #include <iterator> -#include <memory> // IWYU pragma: keep #include <set> #include <sstream> #include <stdio.h> #include <stdlib.h> #include <time.h> +#include <utility> + +#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<cmCommand> Clone() override { - cmCTestSubdirCommand* c = new cmCTestSubdirCommand; + auto c = cm::make_unique<cmCTestSubdirCommand>(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr<cmCommand>(std::move(c)); } /** @@ -122,11 +124,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr<cmCommand> Clone() override { - cmCTestAddSubdirectoryCommand* c = new cmCTestAddSubdirectoryCommand; + auto c = cm::make_unique<cmCTestAddSubdirectoryCommand>(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr<cmCommand>(std::move(c)); } /** @@ -187,11 +189,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr<cmCommand> Clone() override { - cmCTestAddTestCommand* c = new cmCTestAddTestCommand; + auto c = cm::make_unique<cmCTestAddTestCommand>(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr<cmCommand>(std::move(c)); } /** @@ -220,11 +222,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr<cmCommand> Clone() override { - cmCTestSetTestsPropertiesCommand* c = new cmCTestSetTestsPropertiesCommand; + auto c = cm::make_unique<cmCTestSetTestsPropertiesCommand>(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr<cmCommand>(std::move(c)); } /** @@ -249,12 +251,11 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr<cmCommand> Clone() override { - cmCTestSetDirectoryPropertiesCommand* c = - new cmCTestSetDirectoryPropertiesCommand; + auto c = cm::make_unique<cmCTestSetDirectoryPropertiesCommand>(); c->TestHandler = this->TestHandler; - return c; + return std::unique_ptr<cmCommand>(std::move(c)); } /** @@ -525,7 +526,7 @@ int cmCTestTestHandler::ProcessHandler() std::vector<cmCTestTestHandler::cmCTestTestResult> disabledTests; for (cmCTestTestResult const& ft : resultsSet) { - if (cmHasLiteralPrefix(ft.CompletionStatus, "SKIP_RETURN_CODE=") || + if (cmHasLiteralPrefix(ft.CompletionStatus, "SKIP_") || ft.CompletionStatus == "Disabled") { disabledTests.push_back(ft); } @@ -598,7 +599,7 @@ int cmCTestTestHandler::ProcessHandler() for (cmCTestTestResult const& ft : resultsSet) { if (ft.Status != cmCTestTestHandler::COMPLETED && - !cmHasLiteralPrefix(ft.CompletionStatus, "SKIP_RETURN_CODE=") && + !cmHasLiteralPrefix(ft.CompletionStatus, "SKIP_") && ft.CompletionStatus != "Disabled") { ofs << ft.TestCount << ":" << ft.Name << std::endl; auto testColor = cmCTest::Color::RED; @@ -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<cmCTestAddTestCommand>(); 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<cmCTestSubdirCommand>(); 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<cmCTestAddSubdirectoryCommand>(); 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<cmCTestSetTestsPropertiesCommand>(); 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<cmCTestSetDirectoryPropertiesCommand>(); 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")) { @@ -2229,6 +2229,13 @@ bool cmCTestTestHandler::SetTestsProperties( rt.ErrorRegularExpressions.emplace_back(cr, cr); } } + if (key == "SKIP_REGULAR_EXPRESSION") { + std::vector<std::string> lval; + cmSystemTools::ExpandListArgument(val, lval); + for (std::string const& cr : lval) { + rt.SkipRegularExpressions.emplace_back(cr, cr); + } + } if (key == "PROCESSORS") { rt.Processors = atoi(val.c_str()); if (rt.Processors < 1) { diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 7f3f5e4..5bbc68e 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -118,6 +118,8 @@ public: std::vector<std::pair<cmsys::RegularExpression, std::string>> RequiredRegularExpressions; std::vector<std::pair<cmsys::RegularExpression, std::string>> + SkipRegularExpressions; + std::vector<std::pair<cmsys::RegularExpression, std::string>> TimeoutRegularExpressions; std::map<std::string, std::string> Measurements; bool IsInBasedOnREOptions; 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 <string> +#include <utility> + +#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<cmCommand> Clone() override { - cmCTestUpdateCommand* ni = new cmCTestUpdateCommand; + auto ni = cm::make_unique<cmCTestUpdateCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(std::move(ni)); } /** diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx index 5cfc4a7..d80b5a5 100644 --- a/Source/CTest/cmCTestUpdateHandler.cxx +++ b/Source/CTest/cmCTestUpdateHandler.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCTestUpdateHandler.h" -#include "cmAlgorithms.h" #include "cmCLocaleEnvironmentScope.h" #include "cmCTest.h" #include "cmCTestBZR.h" @@ -18,9 +17,10 @@ #include "cmXMLWriter.h" #include <chrono> -#include <memory> // IWYU pragma: keep #include <sstream> +#include "cm_memory.hxx" + static const char* cmCTestUpdateHandlerUpdateStrings[] = { "Unknown", "CVS", "SVN", "BZR", "GIT", "HG", "P4" }; 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 <set> #include <string> +#include <utility> + +#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<cmCommand> Clone() override { - cmCTestUploadCommand* ni = new cmCTestUploadCommand; + auto ni = cm::make_unique<cmCTestUploadCommand>(); ni->CTest = this->CTest; ni->CTestScriptHandler = this->CTestScriptHandler; - return ni; + return std::unique_ptr<cmCommand>(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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddCompileDefinitionsCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddCompileOptionsCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddCustomCommandCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddCustomTargetCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddDefinitionsCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddDependenciesCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddExecutableCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddLibraryCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddLinkOptionsCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddSubDirectoryCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAddTestCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index d1e32b0..d153076 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -11,7 +11,6 @@ #include <algorithm> #include <functional> #include <iterator> -#include <memory> #include <sstream> #include <string.h> #include <string> @@ -340,20 +339,6 @@ inline void cmStripSuffixIfExists(std::string& str, const std::string& suffix) namespace cm { -#if defined(CMake_HAVE_CXX_MAKE_UNIQUE) - -using std::make_unique; - -#else - -template <typename T, typename... Args> -std::unique_ptr<T> make_unique(Args&&... args) -{ - return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); -} - -#endif - #if __cplusplus >= 201703L || defined(_MSVC_LANG) && _MSVC_LANG >= 201703L using std::size; 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmAuxSourceDirectoryCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmBinUtilsLinuxELFLinker.cxx b/Source/cmBinUtilsLinuxELFLinker.cxx index 4fb15f2..86846cb 100644 --- a/Source/cmBinUtilsLinuxELFLinker.cxx +++ b/Source/cmBinUtilsLinuxELFLinker.cxx @@ -2,7 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmBinUtilsLinuxELFLinker.h" -#include "cmAlgorithms.h" + #include "cmBinUtilsLinuxELFObjdumpGetRuntimeDependenciesTool.h" #include "cmLDConfigLDConfigTool.h" #include "cmMakefile.h" @@ -12,9 +12,10 @@ #include <cmsys/RegularExpression.hxx> -#include <memory> #include <sstream> +#include "cm_memory.hxx" + static std::string ReplaceOrigin(const std::string& rpath, const std::string& origin) { diff --git a/Source/cmBinUtilsLinuxELFLinker.h b/Source/cmBinUtilsLinuxELFLinker.h index 348edc4..e209637 100644 --- a/Source/cmBinUtilsLinuxELFLinker.h +++ b/Source/cmBinUtilsLinuxELFLinker.h @@ -9,7 +9,7 @@ #include "cmLDConfigTool.h" #include "cmStateTypes.h" -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <vector> diff --git a/Source/cmBinUtilsMacOSMachOLinker.cxx b/Source/cmBinUtilsMacOSMachOLinker.cxx index e219847..ac93155 100644 --- a/Source/cmBinUtilsMacOSMachOLinker.cxx +++ b/Source/cmBinUtilsMacOSMachOLinker.cxx @@ -12,6 +12,8 @@ #include <string> #include <vector> +#include "cm_memory.hxx" + cmBinUtilsMacOSMachOLinker::cmBinUtilsMacOSMachOLinker( cmRuntimeDependencyArchive* archive) : cmBinUtilsLinker(archive) diff --git a/Source/cmBinUtilsMacOSMachOLinker.h b/Source/cmBinUtilsMacOSMachOLinker.h index 0350d1e..f4f309d 100644 --- a/Source/cmBinUtilsMacOSMachOLinker.h +++ b/Source/cmBinUtilsMacOSMachOLinker.h @@ -8,7 +8,7 @@ #include "cmBinUtilsMacOSMachOGetRuntimeDependenciesTool.h" #include "cmStateTypes.h" -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <vector> diff --git a/Source/cmBinUtilsWindowsPELinker.cxx b/Source/cmBinUtilsWindowsPELinker.cxx index 796e9ed..31602c4 100644 --- a/Source/cmBinUtilsWindowsPELinker.cxx +++ b/Source/cmBinUtilsWindowsPELinker.cxx @@ -2,16 +2,17 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmBinUtilsWindowsPELinker.h" -#include "cmAlgorithms.h" + #include "cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool.h" #include "cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.h" #include "cmRuntimeDependencyArchive.h" #include "cmSystemTools.h" -#include <memory> #include <sstream> #include <vector> +#include "cm_memory.hxx" + #ifdef _WIN32 # include <windows.h> #endif diff --git a/Source/cmBinUtilsWindowsPELinker.h b/Source/cmBinUtilsWindowsPELinker.h index d742195..8d2bf4b 100644 --- a/Source/cmBinUtilsWindowsPELinker.h +++ b/Source/cmBinUtilsWindowsPELinker.h @@ -8,7 +8,7 @@ #include "cmBinUtilsWindowsPEGetRuntimeDependenciesTool.h" #include "cmStateTypes.h" -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> class cmRuntimeDependencyArchive; 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmBreakCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmBuildCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmBuildNameCommand>(); + } bool InitialPass(std::vector<std::string> 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 <string> #include <vector> +#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<cmCommand> Clone() override { - return new cmCMakeHostSystemInformationCommand; + return cm::make_unique<cmCMakeHostSystemInformationCommand>(); } /** 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmCMakeMinimumRequired>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmCMakePolicyCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index d1226c3..83e3eff 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -15,7 +15,6 @@ #include <ctype.h> #include <iostream> #include <map> -#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -30,6 +29,8 @@ # include <unistd.h> // IWYU pragma: keep #endif +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmCTestBuildAndTestHandler.h" #include "cmCTestBuildHandler.h" @@ -1098,9 +1099,10 @@ int cmCTest::RunMakeCommand(const std::string& command, std::string& output, cmProcessOutput processOutput(encoding); std::string strdata; cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, - " Each . represents " << tick_len << " bytes of output" - << std::endl - << " " << std::flush); + " Each . represents " << tick_len + << " bytes of output\n" + " " + << std::flush); while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) { processOutput.DecodeText(data, length, strdata); for (char& cc : strdata) { @@ -1115,8 +1117,7 @@ int cmCTest::RunMakeCommand(const std::string& command, std::string& output, if (tick % tick_line_len == 0 && tick > 0) { cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Size: " << int((double(output.size()) / 1024.0) + 1) - << "K" << std::endl - << " " << std::flush); + << "K\n " << std::flush); } } cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, @@ -1324,18 +1325,14 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, if (output) { *output += outerr; } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, - outerr << std::endl - << std::flush); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl); } else if (result == cmsysProcess_State_Error) { std::string outerr = "\n*** ERROR executing: "; outerr += cmsysProcess_GetErrorString(cp); if (output) { *output += outerr; } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, - outerr << std::endl - << std::flush); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl); } cmsysProcess_Delete(cp); @@ -3077,11 +3074,11 @@ void cmCTest::Log(int logType, const char* file, int line, const char* msg, } else { *this->Impl->OutputLogFile << cmCTestStringLogType[logType]; } - *this->Impl->OutputLogFile << "] " << std::endl << std::flush; + *this->Impl->OutputLogFile << "] " << std::endl; } *this->Impl->OutputLogFile << msg << std::flush; if (logType != this->Impl->OutputLogFileLastTag) { - *this->Impl->OutputLogFile << std::endl << std::flush; + *this->Impl->OutputLogFile << std::endl; this->Impl->OutputLogFileLastTag = logType; } } @@ -3194,7 +3191,7 @@ void cmCTest::OutputTestErrors(std::vector<char> const& process_output) if (!process_output.empty()) { test_outputs.append(process_output.data(), process_output.size()); } - cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush); + cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl); } bool cmCTest::CompressString(std::string& str) diff --git a/Source/cmCTest.h b/Source/cmCTest.h index d300c33..7f66378 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -10,7 +10,7 @@ #include <chrono> #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <sstream> #include <string> #include <time.h> diff --git a/Source/cmCommand.h b/Source/cmCommand.h index 9ccd773..b210f27 100644 --- a/Source/cmCommand.h +++ b/Source/cmCommand.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include <memory> #include <string> #include <vector> @@ -60,22 +61,9 @@ public: cmExecutionStatus&) = 0; /** - * This is called at the end after all the information - * specified by the command is accumulated. Most commands do - * not implement this method. At this point, reading and - * writing to the cache can be done. - */ - virtual void FinalPass() {} - - /** - * Does this command have a final pass? Query after InitialPass. - */ - virtual bool HasFinalPass() const { return false; } - - /** * This is a virtual constructor for the command. */ - virtual cmCommand* Clone() = 0; + virtual std::unique_ptr<cmCommand> 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<cmBreakCommand>()); state->AddBuiltinCommand("cmake_minimum_required", - new cmCMakeMinimumRequired); - state->AddBuiltinCommand("cmake_policy", new cmCMakePolicyCommand); - state->AddBuiltinCommand("configure_file", new cmConfigureFileCommand); - state->AddBuiltinCommand("continue", new cmContinueCommand); - state->AddBuiltinCommand("exec_program", new cmExecProgramCommand); - state->AddBuiltinCommand("execute_process", new cmExecuteProcessCommand); - state->AddBuiltinCommand("file", new cmFileCommand); - state->AddBuiltinCommand("find_file", new cmFindFileCommand); - state->AddBuiltinCommand("find_library", new cmFindLibraryCommand); - state->AddBuiltinCommand("find_package", new cmFindPackageCommand); - state->AddBuiltinCommand("find_path", new cmFindPathCommand); - state->AddBuiltinCommand("find_program", new cmFindProgramCommand); - state->AddBuiltinCommand("foreach", new cmForEachCommand); - state->AddBuiltinCommand("function", new cmFunctionCommand); + cm::make_unique<cmCMakeMinimumRequired>()); + state->AddBuiltinCommand("cmake_policy", + cm::make_unique<cmCMakePolicyCommand>()); + state->AddBuiltinCommand("configure_file", + cm::make_unique<cmConfigureFileCommand>()); + state->AddBuiltinCommand("continue", cm::make_unique<cmContinueCommand>()); + state->AddBuiltinCommand("exec_program", + cm::make_unique<cmExecProgramCommand>()); + state->AddBuiltinCommand("execute_process", + cm::make_unique<cmExecuteProcessCommand>()); + state->AddBuiltinCommand("file", cm::make_unique<cmFileCommand>()); + state->AddBuiltinCommand("find_file", cm::make_unique<cmFindFileCommand>()); + state->AddBuiltinCommand("find_library", + cm::make_unique<cmFindLibraryCommand>()); + state->AddBuiltinCommand("find_package", + cm::make_unique<cmFindPackageCommand>()); + state->AddBuiltinCommand("find_path", cm::make_unique<cmFindPathCommand>()); + state->AddBuiltinCommand("find_program", + cm::make_unique<cmFindProgramCommand>()); + state->AddBuiltinCommand("foreach", cm::make_unique<cmForEachCommand>()); + state->AddBuiltinCommand("function", cm::make_unique<cmFunctionCommand>()); state->AddBuiltinCommand("get_cmake_property", - new cmGetCMakePropertyCommand); + cm::make_unique<cmGetCMakePropertyCommand>()); state->AddBuiltinCommand("get_directory_property", - new cmGetDirectoryPropertyCommand); + cm::make_unique<cmGetDirectoryPropertyCommand>()); state->AddBuiltinCommand("get_filename_component", - new cmGetFilenameComponentCommand); - state->AddBuiltinCommand("get_property", new cmGetPropertyCommand); - state->AddBuiltinCommand("if", new cmIfCommand); - state->AddBuiltinCommand("include", new cmIncludeCommand); - state->AddBuiltinCommand("include_guard", new cmIncludeGuardCommand); - state->AddBuiltinCommand("list", new cmListCommand); - state->AddBuiltinCommand("macro", new cmMacroCommand); - state->AddBuiltinCommand("make_directory", new cmMakeDirectoryCommand); - state->AddBuiltinCommand("mark_as_advanced", new cmMarkAsAdvancedCommand); - state->AddBuiltinCommand("math", new cmMathCommand); - state->AddBuiltinCommand("message", new cmMessageCommand); - state->AddBuiltinCommand("option", new cmOptionCommand); + cm::make_unique<cmGetFilenameComponentCommand>()); + state->AddBuiltinCommand("get_property", + cm::make_unique<cmGetPropertyCommand>()); + state->AddBuiltinCommand("if", cm::make_unique<cmIfCommand>()); + state->AddBuiltinCommand("include", cm::make_unique<cmIncludeCommand>()); + state->AddBuiltinCommand("include_guard", + cm::make_unique<cmIncludeGuardCommand>()); + state->AddBuiltinCommand("list", cm::make_unique<cmListCommand>()); + state->AddBuiltinCommand("macro", cm::make_unique<cmMacroCommand>()); + state->AddBuiltinCommand("make_directory", + cm::make_unique<cmMakeDirectoryCommand>()); + state->AddBuiltinCommand("mark_as_advanced", + cm::make_unique<cmMarkAsAdvancedCommand>()); + state->AddBuiltinCommand("math", cm::make_unique<cmMathCommand>()); + state->AddBuiltinCommand("message", cm::make_unique<cmMessageCommand>()); + state->AddBuiltinCommand("option", cm::make_unique<cmOptionCommand>()); state->AddBuiltinCommand("cmake_parse_arguments", - new cmParseArgumentsCommand); - state->AddBuiltinCommand("return", new cmReturnCommand); + cm::make_unique<cmParseArgumentsCommand>()); + state->AddBuiltinCommand("return", cm::make_unique<cmReturnCommand>()); state->AddBuiltinCommand("separate_arguments", - new cmSeparateArgumentsCommand); - state->AddBuiltinCommand("set", new cmSetCommand); + cm::make_unique<cmSeparateArgumentsCommand>()); + state->AddBuiltinCommand("set", cm::make_unique<cmSetCommand>()); state->AddBuiltinCommand("set_directory_properties", - new cmSetDirectoryPropertiesCommand); - state->AddBuiltinCommand("set_property", new cmSetPropertyCommand); - state->AddBuiltinCommand("site_name", new cmSiteNameCommand); - state->AddBuiltinCommand("string", new cmStringCommand); - state->AddBuiltinCommand("unset", new cmUnsetCommand); - state->AddBuiltinCommand("while", new cmWhileCommand); + cm::make_unique<cmSetDirectoryPropertiesCommand>()); + state->AddBuiltinCommand("set_property", + cm::make_unique<cmSetPropertyCommand>()); + state->AddBuiltinCommand("site_name", cm::make_unique<cmSiteNameCommand>()); + state->AddBuiltinCommand("string", cm::make_unique<cmStringCommand>()); + state->AddBuiltinCommand("unset", cm::make_unique<cmUnsetCommand>()); + state->AddBuiltinCommand("while", cm::make_unique<cmWhileCommand>()); state->AddUnexpectedCommand( "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<cmCMakeHostSystemInformationCommand>()); + state->AddBuiltinCommand("remove", cm::make_unique<cmRemoveCommand>()); + state->AddBuiltinCommand("variable_watch", + cm::make_unique<cmVariableWatchCommand>()); + state->AddBuiltinCommand("write_file", + cm::make_unique<cmWriteFileCommand>()); state->AddDisallowedCommand( - "build_name", new cmBuildNameCommand, cmPolicies::CMP0036, + "build_name", cm::make_unique<cmBuildNameCommand>(), 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<cmUseMangledMesaCommand>(), + 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<cmAddCustomCommandCommand>()); + state->AddBuiltinCommand("add_custom_target", + cm::make_unique<cmAddCustomTargetCommand>()); + state->AddBuiltinCommand("add_definitions", + cm::make_unique<cmAddDefinitionsCommand>()); + state->AddBuiltinCommand("add_dependencies", + cm::make_unique<cmAddDependenciesCommand>()); + state->AddBuiltinCommand("add_executable", + cm::make_unique<cmAddExecutableCommand>()); + state->AddBuiltinCommand("add_library", + cm::make_unique<cmAddLibraryCommand>()); + state->AddBuiltinCommand("add_subdirectory", + cm::make_unique<cmAddSubDirectoryCommand>()); + state->AddBuiltinCommand("add_test", cm::make_unique<cmAddTestCommand>()); + state->AddBuiltinCommand("build_command", cm::make_unique<cmBuildCommand>()); state->AddBuiltinCommand("create_test_sourcelist", - new cmCreateTestSourceList); - state->AddBuiltinCommand("define_property", new cmDefinePropertyCommand); - state->AddBuiltinCommand("enable_language", new cmEnableLanguageCommand); - state->AddBuiltinCommand("enable_testing", new cmEnableTestingCommand); + cm::make_unique<cmCreateTestSourceList>()); + state->AddBuiltinCommand("define_property", + cm::make_unique<cmDefinePropertyCommand>()); + state->AddBuiltinCommand("enable_language", + cm::make_unique<cmEnableLanguageCommand>()); + state->AddBuiltinCommand("enable_testing", + cm::make_unique<cmEnableTestingCommand>()); state->AddBuiltinCommand("get_source_file_property", - new cmGetSourceFilePropertyCommand); + cm::make_unique<cmGetSourceFilePropertyCommand>()); state->AddBuiltinCommand("get_target_property", - new cmGetTargetPropertyCommand); - state->AddBuiltinCommand("get_test_property", new cmGetTestPropertyCommand); + cm::make_unique<cmGetTargetPropertyCommand>()); + state->AddBuiltinCommand("get_test_property", + cm::make_unique<cmGetTestPropertyCommand>()); state->AddBuiltinCommand("include_directories", - new cmIncludeDirectoryCommand); - state->AddBuiltinCommand("include_regular_expression", - new cmIncludeRegularExpressionCommand); - state->AddBuiltinCommand("install", new cmInstallCommand); - state->AddBuiltinCommand("install_files", new cmInstallFilesCommand); - state->AddBuiltinCommand("install_targets", new cmInstallTargetsCommand); - state->AddBuiltinCommand("link_directories", new cmLinkDirectoriesCommand); - state->AddBuiltinCommand("project", new cmProjectCommand); - state->AddBuiltinCommand("set_source_files_properties", - new cmSetSourceFilesPropertiesCommand); + cm::make_unique<cmIncludeDirectoryCommand>()); + state->AddBuiltinCommand( + "include_regular_expression", + cm::make_unique<cmIncludeRegularExpressionCommand>()); + state->AddBuiltinCommand("install", cm::make_unique<cmInstallCommand>()); + state->AddBuiltinCommand("install_files", + cm::make_unique<cmInstallFilesCommand>()); + state->AddBuiltinCommand("install_targets", + cm::make_unique<cmInstallTargetsCommand>()); + state->AddBuiltinCommand("link_directories", + cm::make_unique<cmLinkDirectoriesCommand>()); + state->AddBuiltinCommand("project", cm::make_unique<cmProjectCommand>()); + state->AddBuiltinCommand( + "set_source_files_properties", + cm::make_unique<cmSetSourceFilesPropertiesCommand>()); state->AddBuiltinCommand("set_target_properties", - new cmSetTargetPropertiesCommand); + cm::make_unique<cmSetTargetPropertiesCommand>()); state->AddBuiltinCommand("set_tests_properties", - new cmSetTestsPropertiesCommand); - state->AddBuiltinCommand("subdirs", new cmSubdirCommand); - state->AddBuiltinCommand("target_compile_definitions", - new cmTargetCompileDefinitionsCommand); + cm::make_unique<cmSetTestsPropertiesCommand>()); + state->AddBuiltinCommand("subdirs", cm::make_unique<cmSubdirCommand>()); + state->AddBuiltinCommand( + "target_compile_definitions", + cm::make_unique<cmTargetCompileDefinitionsCommand>()); state->AddBuiltinCommand("target_compile_features", - new cmTargetCompileFeaturesCommand); + cm::make_unique<cmTargetCompileFeaturesCommand>()); state->AddBuiltinCommand("target_compile_options", - new cmTargetCompileOptionsCommand); - state->AddBuiltinCommand("target_include_directories", - new cmTargetIncludeDirectoriesCommand); + cm::make_unique<cmTargetCompileOptionsCommand>()); + state->AddBuiltinCommand( + "target_include_directories", + cm::make_unique<cmTargetIncludeDirectoriesCommand>()); state->AddBuiltinCommand("target_link_libraries", - new cmTargetLinkLibrariesCommand); - state->AddBuiltinCommand("target_sources", new cmTargetSourcesCommand); - state->AddBuiltinCommand("try_compile", new cmTryCompileCommand); - state->AddBuiltinCommand("try_run", new cmTryRunCommand); + cm::make_unique<cmTargetLinkLibrariesCommand>()); + state->AddBuiltinCommand("target_sources", + cm::make_unique<cmTargetSourcesCommand>()); + state->AddBuiltinCommand("try_compile", + cm::make_unique<cmTryCompileCommand>()); + state->AddBuiltinCommand("try_run", cm::make_unique<cmTryRunCommand>()); #if defined(CMAKE_BUILD_WITH_CMAKE) state->AddBuiltinCommand("add_compile_definitions", - new cmAddCompileDefinitionsCommand); + cm::make_unique<cmAddCompileDefinitionsCommand>()); state->AddBuiltinCommand("add_compile_options", - new cmAddCompileOptionsCommand); + cm::make_unique<cmAddCompileOptionsCommand>()); state->AddBuiltinCommand("aux_source_directory", - new cmAuxSourceDirectoryCommand); - state->AddBuiltinCommand("export", new cmExportCommand); - state->AddBuiltinCommand("fltk_wrap_ui", new cmFLTKWrapUICommand); - state->AddBuiltinCommand("include_external_msproject", - new cmIncludeExternalMSProjectCommand); - state->AddBuiltinCommand("install_programs", new cmInstallProgramsCommand); - state->AddBuiltinCommand("add_link_options", new cmAddLinkOptionsCommand); - state->AddBuiltinCommand("link_libraries", new cmLinkLibrariesCommand); + cm::make_unique<cmAuxSourceDirectoryCommand>()); + state->AddBuiltinCommand("export", cm::make_unique<cmExportCommand>()); + state->AddBuiltinCommand("fltk_wrap_ui", + cm::make_unique<cmFLTKWrapUICommand>()); + state->AddBuiltinCommand( + "include_external_msproject", + cm::make_unique<cmIncludeExternalMSProjectCommand>()); + state->AddBuiltinCommand("install_programs", + cm::make_unique<cmInstallProgramsCommand>()); + state->AddBuiltinCommand("add_link_options", + cm::make_unique<cmAddLinkOptionsCommand>()); + state->AddBuiltinCommand("link_libraries", + cm::make_unique<cmLinkLibrariesCommand>()); state->AddBuiltinCommand("target_link_options", - new cmTargetLinkOptionsCommand); + cm::make_unique<cmTargetLinkOptionsCommand>()); state->AddBuiltinCommand("target_link_directories", - new cmTargetLinkDirectoriesCommand); - state->AddBuiltinCommand("load_cache", new cmLoadCacheCommand); - state->AddBuiltinCommand("qt_wrap_cpp", new cmQTWrapCPPCommand); - state->AddBuiltinCommand("qt_wrap_ui", new cmQTWrapUICommand); + cm::make_unique<cmTargetLinkDirectoriesCommand>()); + state->AddBuiltinCommand("load_cache", + cm::make_unique<cmLoadCacheCommand>()); + state->AddBuiltinCommand("qt_wrap_cpp", + cm::make_unique<cmQTWrapCPPCommand>()); + state->AddBuiltinCommand("qt_wrap_ui", cm::make_unique<cmQTWrapUICommand>()); state->AddBuiltinCommand("remove_definitions", - new cmRemoveDefinitionsCommand); - state->AddBuiltinCommand("source_group", new cmSourceGroupCommand); + cm::make_unique<cmRemoveDefinitionsCommand>()); + state->AddBuiltinCommand("source_group", + cm::make_unique<cmSourceGroupCommand>()); state->AddDisallowedCommand( - "export_library_dependencies", new cmExportLibraryDependenciesCommand, - cmPolicies::CMP0033, + "export_library_dependencies", + cm::make_unique<cmExportLibraryDependenciesCommand>(), cmPolicies::CMP0033, "The export_library_dependencies command should not be called; " "see CMP0033."); state->AddDisallowedCommand( - "load_command", new cmLoadCommandCommand, cmPolicies::CMP0031, + "load_command", cm::make_unique<cmLoadCommandCommand>(), + cmPolicies::CMP0031, "The load_command command should not be called; see CMP0031."); state->AddDisallowedCommand( - "output_required_files", new cmOutputRequiredFilesCommand, + "output_required_files", cm::make_unique<cmOutputRequiredFilesCommand>(), 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<cmSubdirDependsCommand>(), + 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<cmUtilitySourceCommand>(), + 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<cmVariableRequiresCommand>(), + cmPolicies::CMP0035, "The variable_requires command should not be called; see CMP0035."); #endif } diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index a7618c7..54fc54c 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -23,6 +23,8 @@ #include <string.h> #include <utility> +#include "cm_memory.hxx" + /* This file computes an ordered list of link items to use when linking a diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index 0b1f00c..839c27a 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -10,6 +10,7 @@ #include "cmTargetLinkLibraryType.h" #include <map> +#include <memory> #include <queue> #include <set> #include <string> diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index b366ebb..f696f28 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -268,10 +268,6 @@ cmComputeLinkInformation::cmComputeLinkInformation( return; } - // Check whether we should use an import library for linking a target. - this->UseImportLibrary = - this->Makefile->IsDefinitionSet("CMAKE_IMPORT_LIBRARY_SUFFIX"); - // Check whether we should skip dependencies on shared library files. this->LinkDependsNoShared = this->Target->GetPropertyAsBool("LINK_DEPENDS_NO_SHARED"); @@ -280,7 +276,7 @@ cmComputeLinkInformation::cmComputeLinkInformation( // to use when creating a plugin (module) that obtains symbols from // the program that will load it. this->LoaderFlag = nullptr; - if (!this->UseImportLibrary && + if (!this->Target->IsDLLPlatform() && this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) { std::string loader_flag_var = "CMAKE_SHARED_MODULE_LOADER_"; loader_flag_var += this->LinkLanguage; @@ -493,9 +489,7 @@ bool cmComputeLinkInformation::Compute() std::set<cmGeneratorTarget const*> const& wrongItems = cld.GetOldWrongConfigItems(); for (cmGeneratorTarget const* tgt : wrongItems) { - bool implib = (this->UseImportLibrary && - (tgt->GetType() == cmStateEnums::SHARED_LIBRARY)); - cmStateEnums::ArtifactType artifact = implib + cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(this->Config) ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; this->OldLinkDirItems.push_back( @@ -578,7 +572,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item, // Compute the proper name to use to link this library. const std::string& config = this->Config; bool impexe = (tgt && tgt->IsExecutableWithExports()); - if (impexe && !this->UseImportLibrary && !this->LoaderFlag) { + if (impexe && !tgt->HasImportLibrary(config) && !this->LoaderFlag) { // Skip linking to executables on platforms with no import // libraries or loader flags. return; @@ -592,7 +586,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item, // platform. Add it now. std::string linkItem; linkItem = this->LoaderFlag; - cmStateEnums::ArtifactType artifact = this->UseImportLibrary + cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(config) ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; @@ -616,15 +610,21 @@ void cmComputeLinkInformation::AddItem(std::string const& item, // Its object-files should already have been extracted for linking. } else { // Decide whether to use an import library. - bool implib = - (this->UseImportLibrary && - (impexe || tgt->GetType() == cmStateEnums::SHARED_LIBRARY)); - cmStateEnums::ArtifactType artifact = implib + cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(config) ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; // Pass the full path to the target file. std::string lib = tgt->GetFullPath(config, artifact, true); + if (tgt->Target->IsAIX() && cmHasLiteralSuffix(lib, "-NOTFOUND") && + artifact == cmStateEnums::ImportLibraryArtifact) { + // This is an imported executable on AIX that has ENABLE_EXPORTS + // but not IMPORTED_IMPLIB. CMake used to produce and accept such + // imported executables on AIX before we taught it to use linker + // import files. For compatibility, simply skip linking to this + // executable as we did before. It works with runtime linking. + return; + } if (!this->LinkDependsNoShared || tgt->GetType() != cmStateEnums::SHARED_LIBRARY) { this->Depends.push_back(lib); @@ -694,7 +694,7 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item, // linked will be able to find it. std::string lib; if (tgt) { - cmStateEnums::ArtifactType artifact = this->UseImportLibrary + cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(this->Config) ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; lib = tgt->GetFullPath(this->Config, artifact); diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index 863639c..3be2c7f 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -179,7 +179,6 @@ private: bool OldLinkDirMode; bool OpenBSD; bool LinkDependsNoShared; - bool UseImportLibrary; bool RuntimeUseChrpath; bool NoSONameUsesPath; bool LinkWithRuntimePath; 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmConfigureFileCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmContinueCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmCreateTestSourceList>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx index d914eb1..5e919af 100644 --- a/Source/cmCryptoHash.cxx +++ b/Source/cmCryptoHash.cxx @@ -2,13 +2,13 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCryptoHash.h" -#include "cmAlgorithms.h" #include "cm_kwiml.h" #include "cm_rhash.h" #include "cmsys/FStream.hxx" + #include <string.h> -#include <memory> // IWYU pragma: keep +#include "cm_memory.hxx" static unsigned int const cmCryptoHashAlgoToId[] = { /* clang-format needs this comment to break after the opening brace */ diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h index b712f09..c7d3377 100644 --- a/Source/cmCryptoHash.h +++ b/Source/cmCryptoHash.h @@ -5,7 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include <memory> // IWYU pragma: keep +#include <memory> #include <stddef.h> #include <string> #include <vector> diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 89aaad0..5e8731a 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -12,7 +12,7 @@ #include "cmStateTypes.h" #include "cmSystemTools.h" -#include <memory> // IWYU pragma: keep +#include <memory> #include <stddef.h> #include <utility> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmDefinePropertyCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmDisallowedCommand.h b/Source/cmDisallowedCommand.h index d85c00f..e07f255 100644 --- a/Source/cmDisallowedCommand.h +++ b/Source/cmDisallowedCommand.h @@ -6,8 +6,11 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <string> +#include <utility> #include <vector> +#include "cm_memory.hxx" + #include "cmCommand.h" #include "cmPolicies.h" @@ -16,31 +19,27 @@ class cmExecutionStatus; class cmDisallowedCommand : public cmCommand { public: - cmDisallowedCommand(cmCommand* command, cmPolicies::PolicyID policy, - const char* message) - : Command(command) + cmDisallowedCommand(std::unique_ptr<cmCommand> command, + cmPolicies::PolicyID policy, const char* message) + : Command(std::move(command)) , Policy(policy) , Message(message) { } - ~cmDisallowedCommand() override { delete this->Command; } + ~cmDisallowedCommand() override = default; - cmCommand* Clone() override + std::unique_ptr<cmCommand> Clone() override { - return new cmDisallowedCommand(this->Command->Clone(), this->Policy, - this->Message); + return cm::make_unique<cmDisallowedCommand>(this->Command->Clone(), + this->Policy, this->Message); } bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; - void FinalPass() override { this->Command->FinalPass(); } - - bool HasFinalPass() const override { return this->Command->HasFinalPass(); } - private: - cmCommand* Command; + std::unique_ptr<cmCommand> Command; cmPolicies::PolicyID Policy; const char* Message; }; diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index 2226463..096016d 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -4,9 +4,10 @@ #include "cmAlgorithms.h" #include "cm_kwiml.h" +#include "cm_memory.hxx" #include "cmsys/FStream.hxx" #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <sstream> #include <stddef.h> #include <utility> @@ -109,10 +110,10 @@ public: }; // Construct and take ownership of the file stream object. - cmELFInternal(cmELF* external, std::unique_ptr<cmsys::ifstream>& fin, + cmELFInternal(cmELF* external, std::unique_ptr<std::istream> fin, ByteOrderType order) : External(external) - , Stream(*fin.release()) + , Stream(std::move(fin)) , ByteOrder(order) , ELFType(cmELF::FileTypeInvalid) { @@ -132,7 +133,7 @@ public: } // Destruct and delete the file stream object. - virtual ~cmELFInternal() { delete &this->Stream; } + virtual ~cmELFInternal() = default; // Forward to the per-class implementation. virtual unsigned int GetNumberOfSections() const = 0; @@ -171,7 +172,7 @@ protected: cmELF* External; // The stream from which to read. - std::istream& Stream; + std::unique_ptr<std::istream> Stream; // The byte order of the ELF file. ByteOrderType ByteOrder; @@ -233,7 +234,7 @@ public: typedef typename Types::tagtype tagtype; // Construct with a stream and byte swap indicator. - cmELFInternalImpl(cmELF* external, std::unique_ptr<cmsys::ifstream>& fin, + cmELFInternalImpl(cmELF* external, std::unique_ptr<std::istream> fin, ByteOrderType order); // Return the number of sections as specified by the ELF header. @@ -352,7 +353,7 @@ private: bool Read(ELF_Ehdr& x) { // Read the header from the file. - if (!this->Stream.read(reinterpret_cast<char*>(&x), sizeof(x))) { + if (!this->Stream->read(reinterpret_cast<char*>(&x), sizeof(x))) { return false; } @@ -382,26 +383,26 @@ private: } bool Read(ELF_Shdr& x) { - if (this->Stream.read(reinterpret_cast<char*>(&x), sizeof(x)) && + if (this->Stream->read(reinterpret_cast<char*>(&x), sizeof(x)) && this->NeedSwap) { ByteSwap(x); } - return !this->Stream.fail(); + return !this->Stream->fail(); } bool Read(ELF_Dyn& x) { - if (this->Stream.read(reinterpret_cast<char*>(&x), sizeof(x)) && + if (this->Stream->read(reinterpret_cast<char*>(&x), sizeof(x)) && this->NeedSwap) { ByteSwap(x); } - return !this->Stream.fail(); + return !this->Stream->fail(); } bool LoadSectionHeader(ELF_Half i) { // Read the section header from the file. - this->Stream.seekg(this->ELFHeader.e_shoff + - this->ELFHeader.e_shentsize * i); + this->Stream->seekg(this->ELFHeader.e_shoff + + this->ELFHeader.e_shentsize * i); if (!this->Read(this->SectionHeaders[i])) { return false; } @@ -426,9 +427,10 @@ private: }; template <class Types> -cmELFInternalImpl<Types>::cmELFInternalImpl( - cmELF* external, std::unique_ptr<cmsys::ifstream>& fin, ByteOrderType order) - : cmELFInternal(external, fin, order) +cmELFInternalImpl<Types>::cmELFInternalImpl(cmELF* external, + std::unique_ptr<std::istream> fin, + ByteOrderType order) + : cmELFInternal(external, std::move(fin), order) { // Read the main header. if (!this->Read(this->ELFHeader)) { @@ -510,7 +512,7 @@ bool cmELFInternalImpl<Types>::LoadDynamicSection() // Read each entry. for (int j = 0; j < n; ++j) { // Seek to the beginning of the section entry. - this->Stream.seekg(sec.sh_offset + sec.sh_entsize * j); + this->Stream->seekg(sec.sh_offset + sec.sh_entsize * j); ELF_Dyn& dyn = this->DynamicSectionEntries[j]; // Try reading the entry. @@ -630,7 +632,7 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString( unsigned long first = static_cast<unsigned long>(dyn.d_un.d_val); unsigned long last = first; unsigned long end = static_cast<unsigned long>(strtab.sh_size); - this->Stream.seekg(strtab.sh_offset + first); + this->Stream->seekg(strtab.sh_offset + first); // Read the string. It may be followed by more than one NULL // terminator. Count the total size of the region allocated to @@ -639,7 +641,7 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString( // assumption. bool terminated = false; char c; - while (last != end && this->Stream.get(c) && !(terminated && c)) { + while (last != end && this->Stream->get(c) && !(terminated && c)) { ++last; if (c) { se.Value += c; @@ -649,7 +651,7 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString( } // Make sure the whole value was read. - if (!this->Stream) { + if (!(*this->Stream)) { this->SetErrorMessage("Dynamic section specifies unreadable RPATH."); se.Value = ""; return nullptr; @@ -679,10 +681,9 @@ const long cmELF::TagMipsRldMapRel = 0; #endif cmELF::cmELF(const char* fname) - : Internal(nullptr) { // Try to open the file. - std::unique_ptr<cmsys::ifstream> fin(new cmsys::ifstream(fname)); + auto fin = cm::make_unique<cmsys::ifstream>(fname); // Quit now if the file could not be opened. if (!fin || !*fin) { @@ -725,12 +726,14 @@ cmELF::cmELF(const char* fname) // parser implementation. if (ident[EI_CLASS] == ELFCLASS32) { // 32-bit ELF - this->Internal = new cmELFInternalImpl<cmELFTypes32>(this, fin, order); + this->Internal = cm::make_unique<cmELFInternalImpl<cmELFTypes32>>( + this, std::move(fin), order); } #ifndef _SCO_DS else if (ident[EI_CLASS] == ELFCLASS64) { // 64-bit ELF - this->Internal = new cmELFInternalImpl<cmELFTypes64>(this, fin, order); + this->Internal = cm::make_unique<cmELFInternalImpl<cmELFTypes64>>( + this, std::move(fin), order); } #endif else { @@ -739,10 +742,7 @@ cmELF::cmELF(const char* fname) } } -cmELF::~cmELF() -{ - delete this->Internal; -} +cmELF::~cmELF() = default; bool cmELF::Valid() const { diff --git a/Source/cmELF.h b/Source/cmELF.h index 987f0c3..afef654 100644 --- a/Source/cmELF.h +++ b/Source/cmELF.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> +#include <memory> #include <string> #include <utility> #include <vector> @@ -108,7 +109,7 @@ public: private: friend class cmELFInternal; bool Valid() const; - cmELFInternal* Internal; + std::unique_ptr<cmELFInternal> Internal; std::string ErrorMessage; }; 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmEnableLanguageCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmEnableTestingCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmExecProgramCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 494afbb..689fc20 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -4,10 +4,12 @@ #include "cm_static_string_view.hxx" #include "cmsys/Process.h" + #include <algorithm> #include <ctype.h> /* isspace */ #include <iostream> #include <stdio.h> +#include <vector> #include "cmAlgorithms.h" #include "cmArgumentParser.h" 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmExecuteProcessCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx index ced27c9..e693155 100644 --- a/Source/cmExportBuildAndroidMKGenerator.cxx +++ b/Source/cmExportBuildAndroidMKGenerator.cxx @@ -3,7 +3,6 @@ #include "cmExportBuildAndroidMKGenerator.h" #include <algorithm> -#include <memory> // IWYU pragma: keep #include <sstream> #include <utility> diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 5800629..de3e0e2 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -236,14 +236,15 @@ void cmExportBuildFileGenerator::SetImportLocationProperty( } // Add the import library for windows DLLs. - if (target->HasImportLibrary(config) && - mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) { + if (target->HasImportLibrary(config)) { std::string prop = "IMPORTED_IMPLIB"; prop += suffix; std::string value = target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact); - target->GetImplibGNUtoMS(config, value, value, - "${CMAKE_IMPORT_LIBRARY_SUFFIX}"); + if (mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) { + target->GetImplibGNUtoMS(config, value, value, + "${CMAKE_IMPORT_LIBRARY_SUFFIX}"); + } properties[prop] = value; } } 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmExportCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index c366183..29afc9f 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -20,11 +20,12 @@ #include "cmsys/FStream.hxx" #include <assert.h> -#include <memory> // IWYU pragma: keep #include <sstream> #include <string.h> #include <utility> +#include "cm_memory.hxx" + static std::string cmExportFileGeneratorEscape(std::string const& str) { // Escape a property value for writing into a .cmake file. diff --git a/Source/cmExportLibraryDependenciesCommand.cxx b/Source/cmExportLibraryDependenciesCommand.cxx index b60a053..8f2fff5 100644 --- a/Source/cmExportLibraryDependenciesCommand.cxx +++ b/Source/cmExportLibraryDependenciesCommand.cxx @@ -4,10 +4,10 @@ #include "cmsys/FStream.hxx" #include <map> -#include <memory> // IWYU pragma: keep #include <utility> -#include "cmAlgorithms.h" +#include "cm_memory.hxx" + #include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" @@ -19,57 +19,31 @@ class cmExecutionStatus; -bool cmExportLibraryDependenciesCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) -{ - if (args.empty()) { - this->SetError("called with incorrect number of arguments"); - return false; - } - - // store the arguments for the final pass - this->Filename = args[0]; - this->Append = false; - if (args.size() > 1) { - if (args[1] == "APPEND") { - this->Append = true; - } - } - return true; -} - -void cmExportLibraryDependenciesCommand::FinalPass() -{ - // export_library_dependencies() shouldn't modify anything - // ensure this by calling a const method - this->ConstFinalPass(); -} - -void cmExportLibraryDependenciesCommand::ConstFinalPass() const +static void FinalAction(cmMakefile& makefile, std::string const& filename, + bool append) { // Use copy-if-different if not appending. std::unique_ptr<cmsys::ofstream> foutPtr; - if (this->Append) { + if (append) { const auto openmodeApp = std::ios::app; - foutPtr = - cm::make_unique<cmsys::ofstream>(this->Filename.c_str(), openmodeApp); + foutPtr = cm::make_unique<cmsys::ofstream>(filename.c_str(), openmodeApp); } else { std::unique_ptr<cmGeneratedFileStream> ap( - new cmGeneratedFileStream(this->Filename, true)); + new cmGeneratedFileStream(filename, true)); ap->SetCopyIfDifferent(true); foutPtr = std::move(ap); } std::ostream& fout = *foutPtr; if (!fout) { - cmSystemTools::Error("Error Writing " + this->Filename); + cmSystemTools::Error("Error Writing " + filename); cmSystemTools::ReportLastSystemError(""); return; } // Collect dependency information about all library targets built in // the project. - cmake* cm = this->Makefile->GetCMakeInstance(); + cmake* cm = makefile.GetCMakeInstance(); cmGlobalGenerator* global = cm->GetGlobalGenerator(); const std::vector<cmMakefile*>& locals = global->GetMakefiles(); std::map<std::string, std::string> libDepsOld; @@ -166,3 +140,20 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const } fout << "endif()\n"; } + +bool cmExportLibraryDependenciesCommand::InitialPass( + std::vector<std::string> const& args, cmExecutionStatus&) +{ + if (args.empty()) { + this->SetError("called with incorrect number of arguments"); + return false; + } + + std::string const& filename = args[0]; + bool const append = args.size() > 1 && args[1] == "APPEND"; + this->Makefile->AddFinalAction([filename, append](cmMakefile& makefile) { + FinalAction(makefile, filename, append); + }); + + return true; +} diff --git a/Source/cmExportLibraryDependenciesCommand.h b/Source/cmExportLibraryDependenciesCommand.h index 8414866..4817162 100644 --- a/Source/cmExportLibraryDependenciesCommand.h +++ b/Source/cmExportLibraryDependenciesCommand.h @@ -8,6 +8,8 @@ #include <string> #include <vector> +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -15,20 +17,12 @@ class cmExecutionStatus; class cmExportLibraryDependenciesCommand : public cmCommand { public: - cmCommand* Clone() override + std::unique_ptr<cmCommand> Clone() override { - return new cmExportLibraryDependenciesCommand; + return cm::make_unique<cmExportLibraryDependenciesCommand>(); } bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; - - void FinalPass() override; - bool HasFinalPass() const override { return true; } - -private: - std::string Filename; - bool Append = false; - void ConstFinalPass() const; }; #endif diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index c169032..a3c9802 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -13,7 +13,7 @@ #include "cmTarget.h" #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <utility> cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator( diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index aece3bc..06709f1 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -44,6 +44,8 @@ void AppendDictionary(cmXMLWriter& xml, const char* key, T const& value) cmExtraEclipseCDT4Generator::cmExtraEclipseCDT4Generator() { + this->IsOutOfSourceBuild = false; + this->GenerateSourceProject = false; this->SupportsVirtualFolders = true; this->GenerateLinkedResources = true; this->SupportsGmakeErrorParser = true; @@ -164,6 +166,29 @@ void cmExtraEclipseCDT4Generator::Generate() // create a .cproject file this->CreateCProjectFile(); + + // create resource settings + this->CreateSettingsResourcePrefsFile(); +} + +void cmExtraEclipseCDT4Generator::CreateSettingsResourcePrefsFile() +{ + cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0]; + cmMakefile* mf = lg->GetMakefile(); + + const std::string filename = + this->HomeOutputDirectory + "/.settings/org.eclipse.core.resources.prefs"; + + cmGeneratedFileStream fout(filename); + if (!fout) { + return; + } + + fout << "eclipse.preferences.version=1" << std::endl; + const char* encoding = mf->GetDefinition("CMAKE_ECLIPSE_RESOURCE_ENCODING"); + if (encoding) { + fout << "encoding/<project>=" << encoding << std::endl; + } } void cmExtraEclipseCDT4Generator::CreateSourceProjectFile() diff --git a/Source/cmExtraEclipseCDT4Generator.h b/Source/cmExtraEclipseCDT4Generator.h index 5136660..ef038d9 100644 --- a/Source/cmExtraEclipseCDT4Generator.h +++ b/Source/cmExtraEclipseCDT4Generator.h @@ -43,6 +43,9 @@ private: // create .project file in the source tree void CreateSourceProjectFile(); + // create .settings/org.eclipse.core.resources.prefs + void CreateSettingsResourcePrefsFile(); + // create .project file void CreateProjectFile(); diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index 89629c7..70800b4 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -13,6 +13,23 @@ class cmExecutionStatus; class cmTarget; +static void FinalAction(cmMakefile& makefile, std::string const& name) +{ + // people should add the srcs to the target themselves, but the old command + // didn't support that, so check and see if they added the files in and if + // they didn;t then print a warning and add then anyhow + cmTarget* target = makefile.FindLocalNonAliasTarget(name); + if (!target) { + std::string msg = + "FLTK_WRAP_UI was called with a target that was never created: "; + msg += name; + msg += ". The problem was found while processing the source directory: "; + msg += makefile.GetCurrentSourceDirectory(); + msg += ". This FLTK_WRAP_UI call will be ignored."; + cmSystemTools::Message(msg, "Warning"); + } +} + // cmFLTKWrapUICommand bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) @@ -27,8 +44,8 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, std::string const& fluid_exe = this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE"); - // get parameter for the command - this->Target = args[0]; // Target that will use the generated files + // Target that will use the generated files + std::string const& target = args[0]; // get the list of GUI files from which .cxx and .h will be generated std::string outputDirectory = this->Makefile->GetCurrentBinaryDirectory(); @@ -41,6 +58,9 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, this->Makefile->AddIncludeDirectories(outputDirectories); } + // List of produced files. + std::vector<cmSourceFile*> generatedSourcesClasses; + for (std::string const& arg : cmMakeRange(args).advance(1)) { cmSourceFile* curr = this->Makefile->GetSource(arg); // if we should use the source GUI @@ -84,40 +104,23 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, cmSourceFile* sf = this->Makefile->GetSource(cxxres); sf->AddDepend(hname); sf->AddDepend(origname); - this->GeneratedSourcesClasses.push_back(sf); + generatedSourcesClasses.push_back(sf); } } // create the variable with the list of sources in it - size_t lastHeadersClass = this->GeneratedSourcesClasses.size(); + size_t lastHeadersClass = generatedSourcesClasses.size(); std::string sourceListValue; for (size_t classNum = 0; classNum < lastHeadersClass; classNum++) { if (classNum) { sourceListValue += ";"; } - sourceListValue += this->GeneratedSourcesClasses[classNum]->GetFullPath(); + sourceListValue += generatedSourcesClasses[classNum]->GetFullPath(); } - std::string varName = this->Target; - varName += "_FLTK_UI_SRCS"; + std::string const varName = target + "_FLTK_UI_SRCS"; this->Makefile->AddDefinition(varName, sourceListValue.c_str()); + this->Makefile->AddFinalAction( + [target](cmMakefile& makefile) { FinalAction(makefile, target); }); return true; } - -void cmFLTKWrapUICommand::FinalPass() -{ - // people should add the srcs to the target themselves, but the old command - // didn't support that, so check and see if they added the files in and if - // they didn;t then print a warning and add then anyhow - cmTarget* target = this->Makefile->FindLocalNonAliasTarget(this->Target); - if (!target) { - std::string msg = - "FLTK_WRAP_UI was called with a target that was never created: "; - msg += this->Target; - msg += ". The problem was found while processing the source directory: "; - msg += this->Makefile->GetCurrentSourceDirectory(); - msg += ". This FLTK_WRAP_UI call will be ignored."; - cmSystemTools::Message(msg, "Warning"); - return; - } -} diff --git a/Source/cmFLTKWrapUICommand.h b/Source/cmFLTKWrapUICommand.h index 044755e..ea8d401 100644 --- a/Source/cmFLTKWrapUICommand.h +++ b/Source/cmFLTKWrapUICommand.h @@ -8,10 +8,11 @@ #include <string> #include <vector> +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; -class cmSourceFile; /** \class cmFLTKWrapUICommand * \brief Create .h and .cxx files rules for FLTK user interfaces files @@ -25,7 +26,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmFLTKWrapUICommand; } + std::unique_ptr<cmCommand> Clone() override + { + return cm::make_unique<cmFLTKWrapUICommand>(); + } /** * This is called when the command is first encountered in @@ -33,27 +37,6 @@ public: */ bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; - - /** - * This is called at the end after all the information - * specified by the command is accumulated. Most commands do - * not implement this method. At this point, reading and - * writing to the cache can be done. - */ - void FinalPass() override; - bool HasFinalPass() const override { return true; } - -private: - /** - * List of produced files. - */ - std::vector<cmSourceFile*> GeneratedSourcesClasses; - - /** - * List of Fluid files that provide the source - * generating .cxx and .h files - */ - std::string Target; }; #endif diff --git a/Source/cmFileAPI.h b/Source/cmFileAPI.h index 602efa8..aa5a42f 100644 --- a/Source/cmFileAPI.h +++ b/Source/cmFileAPI.h @@ -10,7 +10,7 @@ #include "cm_jsoncpp_writer.h" #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <unordered_set> #include <vector> diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 0fb166a..7b916cd 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -31,6 +31,7 @@ #include <algorithm> #include <cassert> #include <map> +#include <memory> #include <set> #include <string> #include <unordered_map> @@ -1075,17 +1076,16 @@ Json::Value Target::DumpArtifacts() } // Add Windows-specific artifacts produced by the linker. + if (this->GT->HasImportLibrary(this->Config)) { + Json::Value artifact = Json::objectValue; + artifact["path"] = + RelativeIfUnder(this->TopBuild, + this->GT->GetFullPath( + this->Config, cmStateEnums::ImportLibraryArtifact)); + artifacts.append(std::move(artifact)); // NOLINT(*) + } if (this->GT->IsDLLPlatform() && this->GT->GetType() != cmStateEnums::STATIC_LIBRARY) { - if (this->GT->GetType() == cmStateEnums::SHARED_LIBRARY || - this->GT->IsExecutableWithExports()) { - Json::Value artifact = Json::objectValue; - artifact["path"] = - RelativeIfUnder(this->TopBuild, - this->GT->GetFullPath( - this->Config, cmStateEnums::ImportLibraryArtifact)); - artifacts.append(std::move(artifact)); // NOLINT(*) - } cmGeneratorTarget::OutputInfo const* output = this->GT->GetOutputInfo(this->Config); if (output && !output->PdbDir.empty()) { diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 980ad21..9871f49 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -13,7 +13,6 @@ #include <cmath> #include <ctype.h> #include <map> -#include <memory> // IWYU pragma: keep #include <set> #include <sstream> #include <stdio.h> @@ -21,6 +20,8 @@ #include <utility> #include <vector> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmArgumentParser.h" #include "cmCryptoHash.h" 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmFileCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmFileTimes.cxx b/Source/cmFileTimes.cxx index fd4f679..3824e9b 100644 --- a/Source/cmFileTimes.cxx +++ b/Source/cmFileTimes.cxx @@ -2,11 +2,12 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmFileTimes.h" -#include "cmAlgorithms.h" #include "cm_sys_stat.h" #include <utility> +#include "cm_memory.hxx" + #if defined(_WIN32) # include "cmSystemTools.h" # include <windows.h> diff --git a/Source/cmFileTimes.h b/Source/cmFileTimes.h index cbf0fe2..191d89e 100644 --- a/Source/cmFileTimes.h +++ b/Source/cmFileTimes.h @@ -5,7 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> /** \class cmFileTimes diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index c6b9049..a5937a0 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -148,7 +148,7 @@ void cmFindCommon::SelectDefaultMacMode() void cmFindCommon::SelectDefaultSearchModes() { const std::array<std::pair<bool&, std::string>, 5> search_paths = { - { { this->NoPackageRootPath, "CMAKE_FIND_USE_PACAKGE_ROOT_PATH" }, + { { this->NoPackageRootPath, "CMAKE_FIND_USE_PACKAGE_ROOT_PATH" }, { this->NoCMakePath, "CMAKE_FIND_USE_CMAKE_PATH" }, { this->NoCMakeEnvironmentPath, "CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH" }, 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<cmCommand> Clone() override + { + return cm::make_unique<cmFindFileCommand>(); + } }; #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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmFindLibraryCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 557069b..c6d599e 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -13,12 +13,13 @@ #include <deque> #include <functional> #include <iterator> -#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <string.h> #include <utility> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -188,7 +189,12 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, } // Check if User Package Registry should be disabled - if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY")) { + // The `CMAKE_FIND_USE_PACKAGE_REGISTRY` has + // priority over the deprecated CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY + if (const char* def = + this->Makefile->GetDefinition("CMAKE_FIND_USE_PACKAGE_REGISTRY")) { + this->NoUserRegistry = !cmSystemTools::IsOn(def); + } else if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY")) { this->NoUserRegistry = true; } @@ -817,8 +823,9 @@ bool cmFindPackageCommand::HandlePackageMode( } } - if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG") && !found && - handlePackageModeType == HandlePackageModeType::Config) { + if (this->UseFindModules && !found && + handlePackageModeType == HandlePackageModeType::Config && + this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) { // Config mode failed. Allow Module case. result = false; } 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 <string> #include <vector> +#include "cm_memory.hxx" + // IWYU insists we should forward-declare instead of including <functional>, // 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<cmCommand> Clone() override + { + return cm::make_unique<cmFindPackageCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmFindPathCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmFindProgramCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx index 08003eb..a30ebe1 100644 --- a/Source/cmForEachCommand.cxx +++ b/Source/cmForEachCommand.cxx @@ -2,12 +2,13 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmForEachCommand.h" -#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> +#include <utility> + +#include "cm_memory.hxx" -#include "cmAlgorithms.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -121,7 +122,7 @@ bool cmForEachCommand::InitialPass(std::vector<std::string> const& args, } // create a function blocker - auto f = cm::make_unique<cmForEachFunctionBlocker>(this->Makefile); + auto fb = cm::make_unique<cmForEachFunctionBlocker>(this->Makefile); if (args.size() > 1) { if (args[1] == "RANGE") { int start = 0; @@ -168,23 +169,22 @@ bool cmForEachCommand::InitialPass(std::vector<std::string> const& args, break; } } - f->Args = range; + fb->Args = range; } else { - f->Args = args; + fb->Args = args; } } else { - f->Args = args; + fb->Args = args; } - this->Makefile->AddFunctionBlocker(f.release()); + this->Makefile->AddFunctionBlocker(std::move(fb)); return true; } bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args) { - std::unique_ptr<cmForEachFunctionBlocker> f( - new cmForEachFunctionBlocker(this->Makefile)); - f->Args.push_back(args[0]); + auto fb = cm::make_unique<cmForEachFunctionBlocker>(this->Makefile); + fb->Args.push_back(args[0]); enum Doing { @@ -195,7 +195,7 @@ bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args) Doing doing = DoingNone; for (unsigned int i = 2; i < args.size(); ++i) { if (doing == DoingItems) { - f->Args.push_back(args[i]); + fb->Args.push_back(args[i]); } else if (args[i] == "LISTS") { doing = DoingLists; } else if (args[i] == "ITEMS") { @@ -203,7 +203,7 @@ bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args) } else if (doing == DoingLists) { const char* value = this->Makefile->GetDefinition(args[i]); if (value && *value) { - cmSystemTools::ExpandListArgument(value, f->Args, true); + cmSystemTools::ExpandListArgument(value, fb->Args, true); } } else { std::ostringstream e; @@ -214,7 +214,7 @@ bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args) } } - this->Makefile->AddFunctionBlocker(f.release()); // TODO: pass unique_ptr + this->Makefile->AddFunctionBlocker(std::move(fb)); return true; } 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmForEachCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index 9067a5f..6d06531 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -3,6 +3,9 @@ #include "cmFunctionCommand.h" #include <sstream> +#include <utility> + +#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<cmCommand> Clone() override { - cmFunctionHelperCommand* newC = new cmFunctionHelperCommand; + auto newC = cm::make_unique<cmFunctionHelperCommand>(); // 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<cmCommand>(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<cmFunctionHelperCommand>(); 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; @@ -176,8 +179,10 @@ bool cmFunctionCommand::InitialPass(std::vector<std::string> const& args, } // create a function blocker - cmFunctionFunctionBlocker* f = new cmFunctionFunctionBlocker(); - cmAppend(f->Args, args); - this->Makefile->AddFunctionBlocker(f); + { + auto fb = cm::make_unique<cmFunctionFunctionBlocker>(); + cmAppend(fb->Args, args); + this->Makefile->AddFunctionBlocker(std::move(fb)); + } 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmFunctionCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 175a26d..4d3a005 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -3,7 +3,7 @@ #include "cmGeneratorExpression.h" #include "cmsys/RegularExpression.hxx" -#include <memory> // IWYU pragma: keep +#include <memory> #include <utility> #include "assert.h" diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index fd36c4b..ef76651 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -8,7 +8,7 @@ #include "cmListFileCache.h" #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <set> #include <string> #include <utility> diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index 326cb0e..11c2dcc 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -3,7 +3,7 @@ #include "cmGeneratorExpressionEvaluationFile.h" #include "cmsys/FStream.hxx" -#include <memory> // IWYU pragma: keep +#include <memory> #include <sstream> #include <utility> diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h index 89a2390..06ebeac 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.h +++ b/Source/cmGeneratorExpressionEvaluationFile.h @@ -6,7 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <vector> diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index a60c75c..d828dac 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -33,7 +33,7 @@ #include <errno.h> #include <iterator> #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <set> #include <sstream> #include <stdlib.h> diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 85a8dbb..d3e8248 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -7,7 +7,7 @@ #include <assert.h> #include <errno.h> #include <iterator> -#include <memory> // IWYU pragma: keep +#include <memory> #include <queue> #include <sstream> #include <stdio.h> @@ -259,9 +259,6 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) t->GetSourceBacktraces(), this->SourceEntries, true); - this->DLLPlatform = - !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); - this->PolicyMap = t->GetPolicyMap(); } @@ -468,7 +465,7 @@ std::string cmGeneratorTarget::GetFilePrefix( const std::string& config, cmStateEnums::ArtifactType artifact) const { if (this->IsImported()) { - const char* prefix = this->GetFilePrefixInternal(artifact); + const char* prefix = this->GetFilePrefixInternal(config, artifact); return prefix ? prefix : std::string(); } @@ -481,7 +478,7 @@ std::string cmGeneratorTarget::GetFileSuffix( const std::string& config, cmStateEnums::ArtifactType artifact) const { if (this->IsImported()) { - const char* suffix = this->GetFileSuffixInternal(artifact); + const char* suffix = this->GetFileSuffixInternal(config, artifact); return suffix ? suffix : std::string(); } @@ -508,7 +505,8 @@ std::string cmGeneratorTarget::GetFilePostfix(const std::string& config) const } const char* cmGeneratorTarget::GetFilePrefixInternal( - cmStateEnums::ArtifactType artifact, const std::string& language) const + std::string const& config, cmStateEnums::ArtifactType artifact, + const std::string& language) const { // no prefix for non-main target types. if (this->GetType() != cmStateEnums::STATIC_LIBRARY && @@ -523,8 +521,7 @@ const char* cmGeneratorTarget::GetFilePrefixInternal( // Return an empty prefix for the import library if this platform // does not support import libraries. - if (isImportedLibraryArtifact && - !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) { + if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) { return nullptr; } @@ -558,7 +555,8 @@ const char* cmGeneratorTarget::GetFilePrefixInternal( return targetPrefix; } const char* cmGeneratorTarget::GetFileSuffixInternal( - cmStateEnums::ArtifactType artifact, const std::string& language) const + std::string const& config, cmStateEnums::ArtifactType artifact, + const std::string& language) const { // no suffix for non-main target types. if (this->GetType() != cmStateEnums::STATIC_LIBRARY && @@ -573,8 +571,7 @@ const char* cmGeneratorTarget::GetFileSuffixInternal( // Return an empty suffix for the import library if this platform // does not support import libraries. - if (isImportedLibraryArtifact && - !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) { + if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) { return nullptr; } @@ -2357,7 +2354,7 @@ void cmGeneratorTarget::ComputeModuleDefinitionInfo( bool cmGeneratorTarget::IsDLLPlatform() const { - return this->DLLPlatform; + return this->Target->IsDLLPlatform(); } void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result, @@ -2757,6 +2754,13 @@ std::string cmGeneratorTarget::GetCreateRuleVariable( case cmStateEnums::MODULE_LIBRARY: return "CMAKE_" + lang + "_CREATE_SHARED_MODULE"; case cmStateEnums::EXECUTABLE: + if (this->IsExecutableWithExports()) { + std::string linkExeWithExports = + "CMAKE_" + lang + "_LINK_EXECUTABLE_WITH_EXPORTS"; + if (this->Makefile->IsDefinitionSet(linkExeWithExports)) { + return linkExeWithExports; + } + } return "CMAKE_" + lang + "_LINK_EXECUTABLE"; default: break; @@ -3924,8 +3928,7 @@ void cmGeneratorTarget::GetFullNameInternal( // Return an empty name for the import library if this platform // does not support import libraries. - if (isImportedLibraryArtifact && - !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) { + if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) { outPrefix.clear(); outBase.clear(); outSuffix.clear(); @@ -3934,8 +3937,8 @@ void cmGeneratorTarget::GetFullNameInternal( // retrieve prefix and suffix std::string ll = this->GetLinkerLanguage(config); - const char* targetPrefix = this->GetFilePrefixInternal(artifact, ll); - const char* targetSuffix = this->GetFileSuffixInternal(artifact, ll); + const char* targetPrefix = this->GetFilePrefixInternal(config, artifact, ll); + const char* targetSuffix = this->GetFileSuffixInternal(config, artifact, ll); // The implib option is only allowed for shared libraries, module // libraries, and executables. @@ -6360,7 +6363,18 @@ bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const this->IsExecutableWithExports()) && // Assemblies which have only managed code do not have // import libraries. - this->GetManagedType(config) != ManagedType::Managed); + this->GetManagedType(config) != ManagedType::Managed) || + (this->Target->IsAIX() && this->IsExecutableWithExports()); +} + +bool cmGeneratorTarget::NeedImportLibraryName(std::string const& config) const +{ + return this->HasImportLibrary(config) || + // On DLL platforms we always generate the import library name + // just in case the sources have export markup. + (this->IsDLLPlatform() && + (this->GetType() == cmStateEnums::EXECUTABLE || + this->GetType() == cmStateEnums::MODULE_LIBRARY)); } std::string cmGeneratorTarget::GetSupportDirectory() const diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 627a055..e86535d 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -743,9 +743,13 @@ private: mutable std::map<std::string, bool> DebugCompatiblePropertiesDone; - const char* GetFilePrefixInternal(cmStateEnums::ArtifactType artifact, + bool NeedImportLibraryName(std::string const& config) const; + + const char* GetFilePrefixInternal(std::string const& config, + cmStateEnums::ArtifactType artifact, const std::string& language = "") const; - const char* GetFileSuffixInternal(cmStateEnums::ArtifactType artifact, + const char* GetFileSuffixInternal(std::string const& config, + cmStateEnums::ArtifactType artifact, const std::string& language = "") const; std::string GetFullNameInternal(const std::string& config, @@ -909,7 +913,6 @@ private: mutable bool DebugSourcesDone; mutable bool LinkImplementationLanguageIsContextDependent; mutable bool UtilityItemsDone; - bool DLLPlatform; bool ComputePDBOutputDir(const std::string& kind, const std::string& config, std::string& out) const; 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmGetCMakePropertyCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmGetDirectoryPropertyCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmGetFilenameComponentCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmGetPropertyCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmGetSourceFilePropertyCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmGetTargetPropertyCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmGetTestPropertyCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index b80da72..997595b 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -22,9 +22,11 @@ #include "cmTarget.h" #include <algorithm> +#include <memory> #include <ostream> #include <set> #include <utility> +#include <vector> cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget* target) : GeneratorTarget(target) diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 7fd5433..e36825c 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -7,6 +7,7 @@ #include <iosfwd> #include <map> +#include <memory> #include <set> #include <string> #include <unordered_map> diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 2d52356..7e81a54 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -9,10 +9,11 @@ #include <algorithm> #include <ctype.h> #include <iterator> -#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmDocumentationEntry.h" #include "cmFortranParser.h" @@ -638,7 +639,9 @@ void cmGlobalNinjaGenerator::EnableLanguage( (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "GNU") || (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "GNU") || (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "Clang") || - (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "Clang")))) { + (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "Clang") || + (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "QCC") || + (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "QCC")))) { this->UsingGCCOnWindows = true; } #endif diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 15dd404..99afc1d 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -7,7 +7,7 @@ #include <iosfwd> #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <set> #include <string> #include <unordered_map> diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index aa584ad..35af0e1 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -7,6 +7,8 @@ #include <sstream> #include <utility> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmDocumentationEntry.h" #include "cmGeneratedFileStream.h" diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 7c2bcd3..d99a906 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -5,11 +5,12 @@ #include "cmsys/RegularExpression.hxx" #include <assert.h> #include <iomanip> -#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <string.h> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" #include "cmCustomCommand.h" diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index a75d8a9..9befb78 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -4,7 +4,7 @@ #include <cstddef> #include <iostream> -#include <memory> // IWYU pragma: keep +#include <memory> #include <sstream> #include <utility> diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index d1f8f58..625dd45 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmIfCommand.h" +#include "cm_memory.hxx" + #include "cmConditionEvaluator.h" #include "cmExecutionStatus.h" #include "cmExpandedCommandArgument.h" @@ -11,7 +13,7 @@ #include "cmSystemTools.h" #include "cmake.h" -#include <memory> // IWYU pragma: keep +#include <utility> static std::string cmIfCommandError( std::vector<cmExpandedCommandArgument> const& args) @@ -202,15 +204,17 @@ bool cmIfCommand::InvokeInitialPass( this->Makefile->IssueMessage(status, err); } - cmIfFunctionBlocker* f = new cmIfFunctionBlocker(); - // if is isn't true block the commands - f->ScopeDepth = 1; - f->IsBlocking = !isTrue; - if (isTrue) { - f->HasRun = true; + { + auto fb = cm::make_unique<cmIfFunctionBlocker>(); + // if is isn't true block the commands + fb->ScopeDepth = 1; + fb->IsBlocking = !isTrue; + if (isTrue) { + fb->HasRun = true; + } + fb->Args = args; + this->Makefile->AddFunctionBlocker(std::move(fb)); } - f->Args = args; - this->Makefile->AddFunctionBlocker(f); return true; } 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmIfCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmIncludeCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmIncludeDirectoryCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmIncludeExternalMSProjectCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmIncludeGuardCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmIncludeRegularExpressionCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index dba4bbb..3b0659c 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -389,10 +389,6 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) return true; } - // Check whether this is a DLL platform. - bool dll_platform = - !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); - for (std::string const& tgt : targetList) { if (this->Makefile->IsAlias(tgt)) { @@ -472,7 +468,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) // Shared libraries are handled differently on DLL and non-DLL // platforms. All windows platforms are DLL platforms including // cygwin. Currently no other platform is a DLL platform. - if (dll_platform) { + if (target.IsDLLPlatform()) { // When in namelink only mode skip all libraries on Windows. if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { continue; @@ -641,7 +637,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) // On DLL platforms an executable may also have an import // library. Install it to the archive destination if it // exists. - if (dll_platform && !archiveArgs.GetDestination().empty() && + if ((target.IsDLLPlatform() || target.IsAIX()) && + !archiveArgs.GetDestination().empty() && target.IsExecutableWithExports()) { // The import library uses the ARCHIVE properties. archiveGenerator = CreateInstallTargetGenerator( 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmInstallCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx index 14288f6..c8ebc8c 100644 --- a/Source/cmInstallDirectoryGenerator.cxx +++ b/Source/cmInstallDirectoryGenerator.cxx @@ -8,7 +8,7 @@ #include "cmMakefile.h" #include "cmSystemTools.h" -#include <memory> // IWYU pragma: keep +#include <memory> cmInstallDirectoryGenerator::cmInstallDirectoryGenerator( std::vector<std::string> const& dirs, const char* dest, diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx index efbcb67..4522669 100644 --- a/Source/cmInstallFilesCommand.cxx +++ b/Source/cmInstallFilesCommand.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallFilesCommand.h" -#include "cmAlgorithms.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmInstallFilesGenerator.h" @@ -13,7 +12,13 @@ class cmExecutionStatus; -// cmExecutableCommand +static std::string FindInstallSource(cmMakefile& makefile, const char* name); +static void CreateInstallGenerator(cmMakefile& makefile, + std::string const& dest, + std::vector<std::string> const& files); +static void FinalAction(cmMakefile& makefile, std::string const& dest, + std::vector<std::string> const& args); + bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) { @@ -25,18 +30,20 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args, // Enable the install target. this->Makefile->GetGlobalGenerator()->EnableInstallTarget(); - this->Destination = args[0]; + std::string const& dest = args[0]; if ((args.size() > 1) && (args[1] == "FILES")) { - this->IsFilesForm = true; + std::vector<std::string> files; for (std::string const& arg : cmMakeRange(args).advance(2)) { // Find the source location for each file listed. - this->Files.push_back(this->FindInstallSource(arg.c_str())); + files.push_back(FindInstallSource(*this->Makefile, arg.c_str())); } - this->CreateInstallGenerator(); + CreateInstallGenerator(*this->Makefile, dest, files); } else { - this->IsFilesForm = false; - cmAppend(this->FinalArgs, args.begin() + 1, args.end()); + std::vector<std::string> finalArgs(args.begin() + 1, args.end()); + this->Makefile->AddFinalAction([dest, finalArgs](cmMakefile& makefile) { + FinalAction(makefile, dest, finalArgs); + }); } this->Makefile->GetGlobalGenerator()->AddInstallComponent( @@ -45,23 +52,20 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args, return true; } -void cmInstallFilesCommand::FinalPass() +static void FinalAction(cmMakefile& makefile, std::string const& dest, + std::vector<std::string> const& args) { - // No final pass for "FILES" form of arguments. - if (this->IsFilesForm) { - return; - } - std::string testf; - std::string const& ext = this->FinalArgs[0]; + std::string const& ext = args[0]; + std::vector<std::string> installFiles; // two different options - if (this->FinalArgs.size() > 1) { + if (args.size() > 1) { // now put the files into the list - std::vector<std::string>::iterator s = this->FinalArgs.begin(); + std::vector<std::string>::const_iterator s = args.begin(); ++s; // for each argument, get the files - for (; s != this->FinalArgs.end(); ++s) { + for (; s != args.end(); ++s) { // replace any variables std::string const& temps = *s; if (!cmSystemTools::GetFilenamePath(temps).empty()) { @@ -72,30 +76,31 @@ void cmInstallFilesCommand::FinalPass() } // add to the result - this->Files.push_back(this->FindInstallSource(testf.c_str())); + installFiles.push_back(FindInstallSource(makefile, testf.c_str())); } } else // reg exp list { std::vector<std::string> files; - std::string const& regex = this->FinalArgs[0]; - cmSystemTools::Glob(this->Makefile->GetCurrentSourceDirectory(), regex, - files); + std::string const& regex = args[0]; + cmSystemTools::Glob(makefile.GetCurrentSourceDirectory(), regex, files); std::vector<std::string>::iterator s = files.begin(); // for each argument, get the files for (; s != files.end(); ++s) { - this->Files.push_back(this->FindInstallSource(s->c_str())); + installFiles.push_back(FindInstallSource(makefile, s->c_str())); } } - this->CreateInstallGenerator(); + CreateInstallGenerator(makefile, dest, installFiles); } -void cmInstallFilesCommand::CreateInstallGenerator() const +static void CreateInstallGenerator(cmMakefile& makefile, + std::string const& dest, + std::vector<std::string> const& files) { // Construct the destination. This command always installs under // the prefix. We skip the leading slash given by the user. - std::string destination = this->Destination.substr(1); + std::string destination = dest.substr(1); cmSystemTools::ConvertToUnixSlashes(destination); if (destination.empty()) { destination = "."; @@ -106,12 +111,12 @@ void cmInstallFilesCommand::CreateInstallGenerator() const const char* no_rename = ""; bool no_exclude_from_all = false; std::string no_component = - this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"); + makefile.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"); std::vector<std::string> no_configurations; cmInstallGenerator::MessageLevel message = - cmInstallGenerator::SelectMessageLevel(this->Makefile); - this->Makefile->AddInstallGenerator(new cmInstallFilesGenerator( - this->Files, destination.c_str(), false, no_permissions, no_configurations, + cmInstallGenerator::SelectMessageLevel(&makefile); + makefile.AddInstallGenerator(new cmInstallFilesGenerator( + files, destination.c_str(), false, no_permissions, no_configurations, no_component.c_str(), message, no_exclude_from_all, no_rename)); } @@ -121,7 +126,7 @@ void cmInstallFilesCommand::CreateInstallGenerator() const * present in the build tree. If a full path is given, it is just * returned. */ -std::string cmInstallFilesCommand::FindInstallSource(const char* name) const +static std::string FindInstallSource(cmMakefile& makefile, const char* name) { if (cmSystemTools::FileIsFullPath(name) || cmGeneratorExpression::Find(name) == 0) { @@ -130,10 +135,10 @@ std::string cmInstallFilesCommand::FindInstallSource(const char* name) const } // This is a relative path. - std::string tb = this->Makefile->GetCurrentBinaryDirectory(); + std::string tb = makefile.GetCurrentBinaryDirectory(); tb += "/"; tb += name; - std::string ts = this->Makefile->GetCurrentSourceDirectory(); + std::string ts = makefile.GetCurrentSourceDirectory(); ts += "/"; ts += name; diff --git a/Source/cmInstallFilesCommand.h b/Source/cmInstallFilesCommand.h index a52f45e..f9b84fd 100644 --- a/Source/cmInstallFilesCommand.h +++ b/Source/cmInstallFilesCommand.h @@ -8,6 +8,8 @@ #include <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmInstallFilesCommand>(); + } /** * This is called when the command is first encountered in @@ -32,25 +37,6 @@ public: */ bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; - - /** - * This is called at the end after all the information - * specified by the command is accumulated. Most commands do - * not implement this method. At this point, reading and - * writing to the cache can be done. - */ - void FinalPass() override; - bool HasFinalPass() const override { return !this->IsFilesForm; } - -protected: - void CreateInstallGenerator() const; - std::string FindInstallSource(const char* name) const; - -private: - std::vector<std::string> FinalArgs; - bool IsFilesForm = false; - std::string Destination; - std::vector<std::string> Files; }; #endif diff --git a/Source/cmInstallFilesGenerator.cxx b/Source/cmInstallFilesGenerator.cxx index 2ed9f73..e8e82cc 100644 --- a/Source/cmInstallFilesGenerator.cxx +++ b/Source/cmInstallFilesGenerator.cxx @@ -6,7 +6,7 @@ #include "cmInstallType.h" #include "cmSystemTools.h" -#include <memory> // IWYU pragma: keep +#include <memory> class cmLocalGenerator; diff --git a/Source/cmInstallProgramsCommand.cxx b/Source/cmInstallProgramsCommand.cxx index a58f875..6ec02e7 100644 --- a/Source/cmInstallProgramsCommand.cxx +++ b/Source/cmInstallProgramsCommand.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallProgramsCommand.h" -#include "cmAlgorithms.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmInstallFilesGenerator.h" @@ -12,6 +11,10 @@ class cmExecutionStatus; +static void FinalAction(cmMakefile& makefile, std::string const& dest, + std::vector<std::string> const& args); +static std::string FindInstallSource(cmMakefile& makefile, const char* name); + // cmExecutableCommand bool cmInstallProgramsCommand::InitialPass( std::vector<std::string> const& args, cmExecutionStatus&) @@ -24,51 +27,55 @@ bool cmInstallProgramsCommand::InitialPass( // Enable the install target. this->Makefile->GetGlobalGenerator()->EnableInstallTarget(); - this->Destination = args[0]; - - cmAppend(this->FinalArgs, args.begin() + 1, args.end()); - this->Makefile->GetGlobalGenerator()->AddInstallComponent( this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); + std::string const& dest = args[0]; + std::vector<std::string> const finalArgs(args.begin() + 1, args.end()); + this->Makefile->AddFinalAction([dest, finalArgs](cmMakefile& makefile) { + FinalAction(makefile, dest, finalArgs); + }); return true; } -void cmInstallProgramsCommand::FinalPass() +static void FinalAction(cmMakefile& makefile, std::string const& dest, + std::vector<std::string> const& args) { bool files_mode = false; - if (!this->FinalArgs.empty() && this->FinalArgs[0] == "FILES") { + if (!args.empty() && args[0] == "FILES") { files_mode = true; } + std::vector<std::string> files; + // two different options - if (this->FinalArgs.size() > 1 || files_mode) { + if (args.size() > 1 || files_mode) { // for each argument, get the programs - std::vector<std::string>::iterator s = this->FinalArgs.begin(); + std::vector<std::string>::const_iterator s = args.begin(); if (files_mode) { // Skip the FILES argument in files mode. ++s; } - for (; s != this->FinalArgs.end(); ++s) { + for (; s != args.end(); ++s) { // add to the result - this->Files.push_back(this->FindInstallSource(s->c_str())); + files.push_back(FindInstallSource(makefile, s->c_str())); } } else // reg exp list { std::vector<std::string> programs; - cmSystemTools::Glob(this->Makefile->GetCurrentSourceDirectory(), - this->FinalArgs[0], programs); + cmSystemTools::Glob(makefile.GetCurrentSourceDirectory(), args[0], + programs); std::vector<std::string>::iterator s = programs.begin(); // for each argument, get the programs for (; s != programs.end(); ++s) { - this->Files.push_back(this->FindInstallSource(s->c_str())); + files.push_back(FindInstallSource(makefile, s->c_str())); } } // Construct the destination. This command always installs under // the prefix. We skip the leading slash given by the user. - std::string destination = this->Destination.substr(1); + std::string destination = dest.substr(1); cmSystemTools::ConvertToUnixSlashes(destination); if (destination.empty()) { destination = "."; @@ -79,12 +86,12 @@ void cmInstallProgramsCommand::FinalPass() const char* no_rename = ""; bool no_exclude_from_all = false; std::string no_component = - this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"); + makefile.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"); std::vector<std::string> no_configurations; cmInstallGenerator::MessageLevel message = - cmInstallGenerator::SelectMessageLevel(this->Makefile); - this->Makefile->AddInstallGenerator(new cmInstallFilesGenerator( - this->Files, destination.c_str(), true, no_permissions, no_configurations, + cmInstallGenerator::SelectMessageLevel(&makefile); + makefile.AddInstallGenerator(new cmInstallFilesGenerator( + files, destination.c_str(), true, no_permissions, no_configurations, no_component.c_str(), message, no_exclude_from_all, no_rename)); } @@ -94,7 +101,7 @@ void cmInstallProgramsCommand::FinalPass() * present in the build tree. If a full path is given, it is just * returned. */ -std::string cmInstallProgramsCommand::FindInstallSource(const char* name) const +static std::string FindInstallSource(cmMakefile& makefile, const char* name) { if (cmSystemTools::FileIsFullPath(name) || cmGeneratorExpression::Find(name) == 0) { @@ -103,10 +110,10 @@ std::string cmInstallProgramsCommand::FindInstallSource(const char* name) const } // This is a relative path. - std::string tb = this->Makefile->GetCurrentBinaryDirectory(); + std::string tb = makefile.GetCurrentBinaryDirectory(); tb += "/"; tb += name; - std::string ts = this->Makefile->GetCurrentSourceDirectory(); + std::string ts = makefile.GetCurrentSourceDirectory(); ts += "/"; ts += name; diff --git a/Source/cmInstallProgramsCommand.h b/Source/cmInstallProgramsCommand.h index 5c705eb..ccd621d 100644 --- a/Source/cmInstallProgramsCommand.h +++ b/Source/cmInstallProgramsCommand.h @@ -8,6 +8,8 @@ #include <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmInstallProgramsCommand>(); + } /** * This is called when the command is first encountered in @@ -32,24 +37,6 @@ public: */ bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; - - /** - * This is called at the end after all the information - * specified by the command is accumulated. Most commands do - * not implement this method. At this point, reading and - * writing to the cache can be done. - */ - void FinalPass() override; - - bool HasFinalPass() const override { return true; } - -protected: - std::string FindInstallSource(const char* name) const; - -private: - std::vector<std::string> FinalArgs; - std::string Destination; - std::vector<std::string> Files; }; #endif diff --git a/Source/cmInstallScriptGenerator.cxx b/Source/cmInstallScriptGenerator.cxx index 5832d27..b7b7817 100644 --- a/Source/cmInstallScriptGenerator.cxx +++ b/Source/cmInstallScriptGenerator.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallScriptGenerator.h" +#include <memory> #include <ostream> #include <vector> diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index 0774436..d891ad8 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -4,6 +4,7 @@ #include <assert.h> #include <map> +#include <memory> #include <set> #include <sstream> #include <utility> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmInstallTargetsCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h index b7d602e..eb827be 100644 --- a/Source/cmInstalledFile.h +++ b/Source/cmInstalledFile.h @@ -8,7 +8,7 @@ #include "cmGeneratorExpression.h" #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <vector> diff --git a/Source/cmJsonObjects.cxx b/Source/cmJsonObjects.cxx index 8d065e1..2423faf 100644 --- a/Source/cmJsonObjects.cxx +++ b/Source/cmJsonObjects.cxx @@ -31,6 +31,7 @@ #include <functional> #include <limits> #include <map> +#include <memory> #include <set> #include <string> #include <unordered_map> @@ -515,9 +516,11 @@ static Json::Value DumpTarget(cmGeneratorTarget* target, Json::Value artifacts = Json::arrayValue; artifacts.append( target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact)); - if (target->IsDLLPlatform()) { + if (target->HasImportLibrary(config)) { artifacts.append( target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact)); + } + if (target->IsDLLPlatform()) { const cmGeneratorTarget::OutputInfo* output = target->GetOutputInfo(config); if (output && !output->PdbDir.empty()) { 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmLinkDirectoriesCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmLinkLibrariesCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmLinkLineComputer.cxx b/Source/cmLinkLineComputer.cxx index 469faca..8746b35 100644 --- a/Source/cmLinkLineComputer.cxx +++ b/Source/cmLinkLineComputer.cxx @@ -110,8 +110,7 @@ std::string cmLinkLineComputer::ComputeLinkPath( if (target->GetType() == cmStateEnums::STATIC_LIBRARY || target->GetType() == cmStateEnums::SHARED_LIBRARY) { cmStateEnums::ArtifactType type = cmStateEnums::RuntimeBinaryArtifact; - if (target->GetType() == cmStateEnums::SHARED_LIBRARY && - target->IsDLLPlatform()) { + if (target->HasImportLibrary(cli.GetConfig())) { type = cmStateEnums::ImportLibraryArtifact; } diff --git a/Source/cmLinkLineDeviceComputer.cxx b/Source/cmLinkLineDeviceComputer.cxx index d27da3e..8d2add6 100644 --- a/Source/cmLinkLineDeviceComputer.cxx +++ b/Source/cmLinkLineDeviceComputer.cxx @@ -90,12 +90,17 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries( } if (item.Target) { - bool skip = true; - if (item.Target->GetType() == cmStateEnums::STATIC_LIBRARY) { - if ((!item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS")) && - item.Target->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) { - skip = false; - } + bool skip = false; + switch (item.Target->GetType()) { + case cmStateEnums::MODULE_LIBRARY: + case cmStateEnums::INTERFACE_LIBRARY: + skip = true; + break; + case cmStateEnums::STATIC_LIBRARY: + skip = item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS"); + break; + default: + break; } if (skip) { continue; diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 1b01ea2..a2e665f 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -13,6 +13,9 @@ #include <stdio.h> #include <stdlib.h> // required for atoi #include <utility> +#include <vector> + +#include "cm_memory.hxx" #include "cmAlgorithms.h" #include "cmGeneratorExpression.h" 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmListCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 9457415..5de1a74 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -6,7 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> -#include <memory> // IWYU pragma: keep +#include <memory> #include <stddef.h> #include <string> #include <utility> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmLoadCacheCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx index 69751b6..f5da2ee 100644 --- a/Source/cmLoadCommandCommand.cxx +++ b/Source/cmLoadCommandCommand.cxx @@ -3,10 +3,14 @@ #include "cmLoadCommandCommand.h" #include <signal.h> + #include <sstream> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <utility> + +#include "cm_memory.hxx" #include "cmCPluginAPI.cxx" #include "cmCPluginAPI.h" @@ -21,30 +25,98 @@ class cmExecutionStatus; # include <malloc.h> /* for malloc/free on QNX */ #endif -extern "C" void TrapsForSignalsCFunction(int sig); +namespace { + +const char* LastName = nullptr; + +extern "C" void TrapsForSignals(int sig) +{ + fprintf(stderr, "CMake loaded command %s crashed with signal: %d.\n", + LastName, sig); +} + +struct SignalHandlerGuard +{ + explicit SignalHandlerGuard(const char* name) + { + LastName = name != nullptr ? name : "????"; + + signal(SIGSEGV, TrapsForSignals); +#ifdef SIGBUS + signal(SIGBUS, TrapsForSignals); +#endif + signal(SIGILL, TrapsForSignals); + } + + ~SignalHandlerGuard() + { + signal(SIGSEGV, nullptr); +#ifdef SIGBUS + signal(SIGBUS, nullptr); +#endif + signal(SIGILL, nullptr); + } + + SignalHandlerGuard(SignalHandlerGuard const&) = delete; + SignalHandlerGuard& operator=(SignalHandlerGuard const&) = delete; +}; + +struct LoadedCommandImpl : cmLoadedCommandInfo +{ + explicit LoadedCommandImpl(CM_INIT_FUNCTION init) + : cmLoadedCommandInfo{ 0, 0, &cmStaticCAPI, 0, + nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr } + { + init(this); + } + + ~LoadedCommandImpl() + { + if (this->Destructor) { + SignalHandlerGuard guard(this->Name); + this->Destructor(this); + } + if (this->Error != nullptr) { + free(this->Error); + } + } + + LoadedCommandImpl(LoadedCommandImpl const&) = delete; + LoadedCommandImpl& operator=(LoadedCommandImpl const&) = delete; + + int DoInitialPass(cmMakefile* mf, int argc, char* argv[]) + { + SignalHandlerGuard guard(this->Name); + return this->InitialPass(this, mf, argc, argv); + } + + void DoFinalPass(cmMakefile* mf) + { + SignalHandlerGuard guard(this->Name); + this->FinalPass(this, mf); + } +}; // a class for loadabple commands class cmLoadedCommand : public cmCommand { public: - cmLoadedCommand() + cmLoadedCommand() = default; + explicit cmLoadedCommand(CM_INIT_FUNCTION init) + : Impl(std::make_shared<LoadedCommandImpl>(init)) { - memset(&this->info, 0, sizeof(this->info)); - this->info.CAPI = &cmStaticCAPI; } - //! clean up any memory allocated by the plugin - ~cmLoadedCommand() override; - /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override + std::unique_ptr<cmCommand> Clone() override { - cmLoadedCommand* newC = new cmLoadedCommand; + auto newC = cm::make_unique<cmLoadedCommand>(); // we must copy when we clone - memcpy(&newC->info, &this->info, sizeof(info)); - return newC; + newC->Impl = this->Impl; + return std::unique_ptr<cmCommand>(std::move(newC)); } /** @@ -54,66 +126,20 @@ public: bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) override; - /** - * This is called at the end after all the information - * specified by the command is accumulated. Most commands do - * not implement this method. At this point, reading and - * writing to the cache can be done. - */ - void FinalPass() override; - bool HasFinalPass() const override - { - return this->info.FinalPass != nullptr; - } - - static const char* LastName; - static void TrapsForSignals(int sig) - { - fprintf(stderr, "CMake loaded command %s crashed with signal: %d.\n", - cmLoadedCommand::LastName, sig); - } - static void InstallSignalHandlers(const char* name, int remove = 0) - { - cmLoadedCommand::LastName = name; - if (!name) { - cmLoadedCommand::LastName = "????"; - } - - if (!remove) { - signal(SIGSEGV, TrapsForSignalsCFunction); -#ifdef SIGBUS - signal(SIGBUS, TrapsForSignalsCFunction); -#endif - signal(SIGILL, TrapsForSignalsCFunction); - } else { - signal(SIGSEGV, nullptr); -#ifdef SIGBUS - signal(SIGBUS, nullptr); -#endif - signal(SIGILL, nullptr); - } - } - - cmLoadedCommandInfo info; +private: + std::shared_ptr<LoadedCommandImpl> Impl; }; -extern "C" void TrapsForSignalsCFunction(int sig) -{ - cmLoadedCommand::TrapsForSignals(sig); -} - -const char* cmLoadedCommand::LastName = nullptr; - bool cmLoadedCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) { - if (!info.InitialPass) { + if (!this->Impl->InitialPass) { return true; } // clear the error string - if (this->info.Error) { - free(this->info.Error); + if (this->Impl->Error) { + free(this->Impl->Error); } // create argc and argv and then invoke the command @@ -126,42 +152,26 @@ bool cmLoadedCommand::InitialPass(std::vector<std::string> const& args, for (i = 0; i < argc; ++i) { argv[i] = strdup(args[i].c_str()); } - cmLoadedCommand::InstallSignalHandlers(info.Name); - int result = info.InitialPass(&info, this->Makefile, argc, argv); - cmLoadedCommand::InstallSignalHandlers(info.Name, 1); + int result = this->Impl->DoInitialPass(this->Makefile, argc, argv); cmFreeArguments(argc, argv); if (result) { + if (this->Impl->FinalPass) { + auto impl = this->Impl; + this->Makefile->AddFinalAction( + [impl](cmMakefile& makefile) { impl->DoFinalPass(&makefile); }); + } return true; } /* Initial Pass must have failed so set the error string */ - if (this->info.Error) { - this->SetError(this->info.Error); + if (this->Impl->Error) { + this->SetError(this->Impl->Error); } return false; } -void cmLoadedCommand::FinalPass() -{ - if (this->info.FinalPass) { - cmLoadedCommand::InstallSignalHandlers(info.Name); - this->info.FinalPass(&this->info, this->Makefile); - cmLoadedCommand::InstallSignalHandlers(info.Name, 1); - } -} - -cmLoadedCommand::~cmLoadedCommand() -{ - if (this->info.Destructor) { - cmLoadedCommand::InstallSignalHandlers(info.Name); - this->info.Destructor(&this->info); - cmLoadedCommand::InstallSignalHandlers(info.Name, 1); - } - if (this->info.Error) { - free(this->info.Error); - } -} +} // namespace // cmLoadCommandCommand bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& args, @@ -236,10 +246,8 @@ bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& args, // if the symbol is found call it to set the name on the // function blocker if (initFunction) { - // create a function blocker and set it up - cmLoadedCommand* f = new cmLoadedCommand(); - (*initFunction)(&f->info); - this->Makefile->GetState()->AddScriptedCommand(args[0], f); + this->Makefile->GetState()->AddScriptedCommand( + args[0], cm::make_unique<cmLoadedCommand>(initFunction)); 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmLoadCommandCommand>(); + } bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; }; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 801f0e8..4ffd6e0 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -26,22 +26,24 @@ #include "cmTestGenerator.h" #include "cmVersion.h" #include "cmake.h" +#include "cmsys/RegularExpression.hxx" #if defined(CMAKE_BUILD_WITH_CMAKE) # define CM_LG_ENCODE_OBJECT_NAMES # include "cmCryptoHash.h" #endif -#include "cmsys/RegularExpression.hxx" #include <algorithm> #include <assert.h> #include <initializer_list> #include <iterator> +#include <memory> #include <sstream> #include <stdio.h> #include <string.h> #include <unordered_set> #include <utility> +#include <vector> #if defined(__HAIKU__) # include <FindDirectory.h> @@ -1513,8 +1515,10 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065( } CM_FALLTHROUGH; case cmPolicies::OLD: - // OLD behavior is to always add the flags - add_shlib_flags = true; + // OLD behavior is to always add the flags, except on AIX where + // we compute symbol exports if ENABLE_EXPORTS is on. + add_shlib_flags = + !(tgt.Target->IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS")); break; case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: @@ -1523,8 +1527,10 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065( cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065)); CM_FALLTHROUGH; case cmPolicies::NEW: - // NEW behavior is to only add the flags if ENABLE_EXPORTS is on - add_shlib_flags = tgt.GetPropertyAsBool("ENABLE_EXPORTS"); + // NEW behavior is to only add the flags if ENABLE_EXPORTS is on, + // except on AIX where we compute symbol exports. + add_shlib_flags = + !tgt.Target->IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS"); break; } diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 81cafa3..248f4a6 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -5,7 +5,7 @@ #include <algorithm> #include <assert.h> #include <iterator> -#include <memory> // IWYU pragma: keep +#include <memory> #include <sstream> #include <stdio.h> #include <utility> diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index c392e97..1ec1fd9 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -5,11 +5,12 @@ #include "cmsys/FStream.hxx" #include "cmsys/Terminal.h" #include <algorithm> -#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <utility> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmCustomCommand.h" // IWYU pragma: keep #include "cmCustomCommandGenerator.h" diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 7ba3471..8154f3e 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -703,8 +703,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( } Options targetOptions(this, t, table, gg->ExtraFlagTable); targetOptions.FixExceptionHandlingDefault(); - std::string asmLocation = configName + "/"; - targetOptions.AddFlag("AssemblerListingLocation", asmLocation); + targetOptions.AddFlag("AssemblerListingLocation", "$(IntDir)\\"); targetOptions.Parse(flags); targetOptions.Parse(defineFlags); targetOptions.ParseFinish(); diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index 3fdafd2..585eb3c 100644 --- a/Source/cmLocalVisualStudioGenerator.h +++ b/Source/cmLocalVisualStudioGenerator.h @@ -6,7 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include "cmGlobalVisualStudioGenerator.h" diff --git a/Source/cmMachO.cxx b/Source/cmMachO.cxx index ac6dce9..bec3ad8 100644 --- a/Source/cmMachO.cxx +++ b/Source/cmMachO.cxx @@ -4,10 +4,13 @@ #include "cmAlgorithms.h" #include "cmsys/FStream.hxx" + #include <cstddef> #include <string> #include <vector> +#include "cm_memory.hxx" + // Include the Mach-O format information system header. #include <mach-o/fat.h> #include <mach-o/loader.h> diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index e9c6aea..6e65c6b 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -6,6 +6,8 @@ #include <stdio.h> #include <utility> +#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<cmCommand> Clone() override { - cmMacroHelperCommand* newC = new cmMacroHelperCommand; + auto newC = cm::make_unique<cmMacroHelperCommand>(); // 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<cmCommand>(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<cmMacroHelperCommand>(); 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; @@ -211,8 +213,10 @@ bool cmMacroCommand::InitialPass(std::vector<std::string> const& args, } // create a function blocker - cmMacroFunctionBlocker* f = new cmMacroFunctionBlocker(); - cmAppend(f->Args, args); - this->Makefile->AddFunctionBlocker(f); + { + auto fb = cm::make_unique<cmMacroFunctionBlocker>(); + cmAppend(fb->Args, args); + this->Makefile->AddFunctionBlocker(std::move(fb)); + } 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmMacroCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmMakeDirectoryCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index bd98f08..1723c5a 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -9,7 +9,7 @@ #include <cstring> #include <ctype.h> #include <iterator> -#include <memory> // IWYU pragma: keep +#include <memory> #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -118,8 +118,6 @@ cmMakefile::~cmMakefile() cmDeleteAll(this->SourceFiles); cmDeleteAll(this->Tests); cmDeleteAll(this->ImportedTargetsOwned); - cmDeleteAll(this->FinalPassCommands); - cmDeleteAll(this->FunctionBlockers); cmDeleteAll(this->EvaluationFiles); } @@ -416,9 +414,6 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, if (this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE) { cmSystemTools::SetFatalErrorOccured(); } - } else if (pcmd->HasFinalPass()) { - // use the command - this->FinalPassCommands.push_back(pcmd.release()); } } } else { @@ -769,6 +764,11 @@ struct file_not_persistent }; } +void cmMakefile::AddFinalAction(FinalAction action) +{ + this->FinalActions.push_back(std::move(action)); +} + void cmMakefile::FinalPass() { // do all the variable expansions here @@ -776,8 +776,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 (FinalAction& action : this->FinalActions) { + action(*this); } // go through all configured files and see which ones still exist. @@ -3077,13 +3077,13 @@ bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff, cmExecutionStatus& status) { // if there are no blockers get out of here - if (this->FunctionBlockers.begin() == this->FunctionBlockers.end()) { + if (this->FunctionBlockers.empty()) { return false; } // loop over all function blockers to see if any block this command // evaluate in reverse, this is critical for balanced IF statements etc - for (cmFunctionBlocker* pos : cmReverseRange(this->FunctionBlockers)) { + for (auto const& pos : cmReverseRange(this->FunctionBlockers)) { if (pos->IsFunctionBlocked(lff, *this, status)) { return true; } @@ -3103,7 +3103,8 @@ void cmMakefile::PopFunctionBlockerBarrier(bool reportError) FunctionBlockersType::size_type barrier = this->FunctionBlockerBarriers.back(); while (this->FunctionBlockers.size() > barrier) { - std::unique_ptr<cmFunctionBlocker> fb(this->FunctionBlockers.back()); + std::unique_ptr<cmFunctionBlocker> fb( + std::move(this->FunctionBlockers.back())); this->FunctionBlockers.pop_back(); if (reportError) { // Report the context in which the unclosed block was opened. @@ -3228,14 +3229,14 @@ bool cmMakefile::ExpandArguments( return !cmSystemTools::GetFatalErrorOccured(); } -void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb) +void cmMakefile::AddFunctionBlocker(std::unique_ptr<cmFunctionBlocker> fb) { if (!this->ExecutionStatusStack.empty()) { // Record the context in which the blocker is created. fb->SetStartingContext(this->GetExecutionContext()); } - this->FunctionBlockers.push_back(fb); + this->FunctionBlockers.push_back(std::move(fb)); } std::unique_ptr<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker( @@ -3251,9 +3252,8 @@ std::unique_ptr<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker( // Search for the function blocker whose scope this command ends. for (FunctionBlockersType::size_type i = this->FunctionBlockers.size(); i > barrier; --i) { - std::vector<cmFunctionBlocker*>::iterator pos = - this->FunctionBlockers.begin() + (i - 1); - if (*pos == fb) { + auto pos = this->FunctionBlockers.begin() + (i - 1); + if (pos->get() == fb) { // Warn if the arguments do not match, but always remove. if (!(*pos)->ShouldRemove(lff, *this)) { cmListFileContext const& lfc = fb->GetStartingContext(); @@ -3269,9 +3269,9 @@ std::unique_ptr<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker( /* clang-format on */ this->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } - cmFunctionBlocker* b = *pos; + std::unique_ptr<cmFunctionBlocker> b = std::move(*pos); this->FunctionBlockers.erase(pos); - return std::unique_ptr<cmFunctionBlocker>(b); + return b; } } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index d223347..1eca18c 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -7,8 +7,9 @@ #include "cmsys/RegularExpression.hxx" #include <deque> +#include <functional> #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <set> #include <stack> #include <stddef.h> @@ -17,6 +18,7 @@ #include <vector> #include "cmAlgorithms.h" +#include "cmFunctionBlocker.h" #include "cmListFileCache.h" #include "cmMessageType.h" #include "cmNewLineStyle.h" @@ -30,13 +32,11 @@ # include "cmSourceGroup.h" #endif -class cmCommand; class cmCompiledGeneratorExpression; class cmCustomCommandLines; class cmExecutionStatus; class cmExpandedCommandArgument; class cmExportBuildFileGenerator; -class cmFunctionBlocker; class cmGeneratorExpressionEvaluationFile; class cmGlobalGenerator; class cmInstallGenerator; @@ -95,7 +95,7 @@ public: /** * Add a function blocker to this makefile */ - void AddFunctionBlocker(cmFunctionBlocker* fb); + void AddFunctionBlocker(std::unique_ptr<cmFunctionBlocker> fb); /// @return whether we are processing the top CMakeLists.txt file. bool IsRootMakefile() const; @@ -125,6 +125,13 @@ public: bool EnforceUniqueName(std::string const& name, std::string& msg, bool isCustom = false) const; + using FinalAction = std::function<void(cmMakefile&)>; + + /** + * Register an action that is executed during FinalPass + */ + void AddFinalAction(FinalAction action); + /** * Perform FinalPass, Library dependency analysis etc before output of the * makefile. @@ -132,7 +139,7 @@ public: void ConfigureFinalPass(); /** - * run the final pass on all commands. + * run all FinalActions. */ void FinalPass(); @@ -937,7 +944,7 @@ protected: size_t ObjectLibrariesSourceGroupIndex; #endif - std::vector<cmCommand*> FinalPassCommands; + std::vector<FinalAction> FinalActions; cmGlobalGenerator* GlobalGenerator; bool IsFunctionBlocked(const cmListFileFunction& lff, cmExecutionStatus& status); @@ -955,7 +962,7 @@ private: bool EnforceUniqueDir(const std::string& srcPath, const std::string& binPath) const; - typedef std::vector<cmFunctionBlocker*> FunctionBlockersType; + typedef std::vector<std::unique_ptr<cmFunctionBlocker>> FunctionBlockersType; FunctionBlockersType FunctionBlockers; std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers; void PushFunctionBlockerBarrier(); diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 6b9b9c7..a7f2a97 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -2,13 +2,14 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmMakefileExecutableTargetGenerator.h" -#include <memory> // IWYU pragma: keep #include <set> #include <sstream> #include <string> #include <utility> #include <vector> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" @@ -482,9 +483,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) // Construct the main link rule. std::vector<std::string> real_link_commands; - std::string linkRuleVar = "CMAKE_"; - linkRuleVar += linkLanguage; - linkRuleVar += "_LINK_EXECUTABLE"; + std::string linkRuleVar = this->GeneratorTarget->GetCreateRuleVariable( + linkLanguage, this->ConfigName); std::string linkRule = this->GetLinkRule(linkRuleVar); std::vector<std::string> commands1; cmSystemTools::ExpandListArgument(linkRule, real_link_commands); diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index b9f7c6d..bdde4b8 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -2,13 +2,14 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmMakefileLibraryTargetGenerator.h" -#include <memory> // IWYU pragma: keep #include <set> #include <sstream> #include <stddef.h> #include <utility> #include <vector> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index b3bab4b..b5a6246 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -2,7 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmMakefileTargetGenerator.h" -#include <memory> // IWYU pragma: keep +#include <memory> #include <sstream> #include <stdio.h> #include <utility> diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index c570a7c..9eeeed0 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -7,6 +7,7 @@ #include <iosfwd> #include <map> +#include <memory> #include <set> #include <string> #include <vector> diff --git a/Source/cmMakefileUtilityTargetGenerator.cxx b/Source/cmMakefileUtilityTargetGenerator.cxx index 4236995..8ed6be5 100644 --- a/Source/cmMakefileUtilityTargetGenerator.cxx +++ b/Source/cmMakefileUtilityTargetGenerator.cxx @@ -7,7 +7,8 @@ #include <utility> #include <vector> -#include "cmAlgorithms.h" +#include "cm_memory.hxx" + #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalUnixMakefileGenerator3.h" 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmMarkAsAdvancedCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmMathCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 5320ec5..58f3b2f 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -25,7 +25,6 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, auto i = args.cbegin(); auto type = MessageType::MESSAGE; - auto status = false; auto fatal = false; auto level = cmake::LogLevel::LOG_UNDEFINED; if (*i == "SEND_ERROR") { @@ -55,19 +54,15 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, } ++i; } else if (*i == "STATUS") { - status = true; level = cmake::LogLevel::LOG_STATUS; ++i; } else if (*i == "VERBOSE") { - status = true; level = cmake::LogLevel::LOG_VERBOSE; ++i; } else if (*i == "DEBUG") { - status = true; level = cmake::LogLevel::LOG_DEBUG; ++i; } else if (*i == "TRACE") { - status = true; level = cmake::LogLevel::LOG_TRACE; ++i; } else if (*i == "DEPRECATION") { @@ -105,17 +100,46 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, auto message = cmJoin(cmMakeRange(i, args.cend()), ""); - if (type != MessageType::MESSAGE) { - // we've overridden the message type, above, so display it directly - cmMessenger* m = this->Makefile->GetMessenger(); - m->DisplayMessage(type, message, this->Makefile->GetBacktrace()); - } else { - if (status) { - this->Makefile->DisplayStatus(message, -1); - } else { + if (cmake::LogLevel::LOG_NOTICE <= level) { + // Check if any indentation has requested: + // `CMAKE_MESSAGE_INDENT` is a list of "padding" pieces + // to be joined and prepended to the message lines. + auto indent = + cmJoin(cmSystemTools::ExpandedListArgument( + this->Makefile->GetSafeDefinition("CMAKE_MESSAGE_INDENT")), + ""); + // Make every line of the `message` indented + // NOTE Can't reuse `cmDocumentationFormatter::PrintPreformatted` + // here cuz it appends `\n` to the EOM ;-( + cmSystemTools::ReplaceString(message, "\n", "\n" + indent); + message = indent + message; + } + + switch (level) { + case cmake::LogLevel::LOG_ERROR: + case cmake::LogLevel::LOG_WARNING: + // we've overridden the message type, above, so display it directly + this->Makefile->GetMessenger()->DisplayMessage( + type, message, this->Makefile->GetBacktrace()); + break; + + case cmake::LogLevel::LOG_NOTICE: cmSystemTools::Message(message); - } + break; + + case cmake::LogLevel::LOG_STATUS: + case cmake::LogLevel::LOG_VERBOSE: + case cmake::LogLevel::LOG_DEBUG: + case cmake::LogLevel::LOG_TRACE: + this->Makefile->DisplayStatus(message, -1); + break; + + default: + assert("Unexpected log level! Review the `cmMessageCommand.cxx`." && + false); + break; } + if (fatal) { cmSystemTools::SetFatalErrorOccured(); } 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmMessageCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx index 1d790e2..0d2b21f 100644 --- a/Source/cmMessenger.cxx +++ b/Source/cmMessenger.cxx @@ -100,8 +100,7 @@ void displayMessage(MessageType t, std::ostringstream& msg) "it."; } else if (t == MessageType::AUTHOR_ERROR) { msg << "This error is for project developers. Use -Wno-error=dev to " - "suppress " - "it."; + "suppress it."; } // Add a terminating blank line. diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index f65abc8..88040f8 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -6,11 +6,12 @@ #include <assert.h> #include <iterator> #include <map> -#include <memory> // IWYU pragma: keep #include <set> #include <sstream> #include <utility> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmCustomCommand.h" // IWYU pragma: keep #include "cmCustomCommandGenerator.h" diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 2139a45..de79817 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -8,10 +8,11 @@ #include <assert.h> #include <iterator> #include <map> -#include <memory> // IWYU pragma: keep #include <ostream> #include <utility> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" #include "cmCustomCommandGenerator.h" diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 3055e18..a99d8e7 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -13,7 +13,7 @@ #include "cmOSXBundleGenerator.h" #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <set> #include <string> #include <vector> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmOptionCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmOrderDirectories.cxx b/Source/cmOrderDirectories.cxx index 585db42..2d055ff 100644 --- a/Source/cmOrderDirectories.cxx +++ b/Source/cmOrderDirectories.cxx @@ -13,6 +13,7 @@ #include <assert.h> #include <functional> #include <sstream> +#include <vector> /* Directory ordering computation. 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmOutputRequiredFilesCommand>(); + } bool InitialPass(std::vector<std::string> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmParseArgumentsCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index c16a46f..e0f48de 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -283,7 +283,10 @@ class cmMakefile; SELECT(POLICY, CMP0095, \ "RPATH entries are properly escaped in the intermediary CMake " \ "install script.", \ - 3, 16, 0, cmPolicies::WARN) + 3, 16, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0096, \ + "project() preserves leading zeros in version components.", 3, 16, \ + 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index 8615ecc..e3d3bd8 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -3,9 +3,12 @@ #include "cmProjectCommand.h" #include "cmsys/RegularExpression.hxx" +#include <array> +#include <cstdio> #include <functional> +#include <limits> #include <sstream> -#include <stdio.h> +#include <utility> #include "cmAlgorithms.h" #include "cmMakefile.h" @@ -33,25 +36,19 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, this->Makefile->SetProjectName(projectName); - std::string bindir = projectName; - bindir += "_BINARY_DIR"; - std::string srcdir = projectName; - srcdir += "_SOURCE_DIR"; - this->Makefile->AddCacheDefinition( - bindir, this->Makefile->GetCurrentBinaryDirectory().c_str(), + projectName + "_BINARY_DIR", + this->Makefile->GetCurrentBinaryDirectory().c_str(), "Value Computed by CMake", cmStateEnums::STATIC); this->Makefile->AddCacheDefinition( - srcdir, this->Makefile->GetCurrentSourceDirectory().c_str(), + projectName + "_SOURCE_DIR", + this->Makefile->GetCurrentSourceDirectory().c_str(), "Value Computed by CMake", cmStateEnums::STATIC); - bindir = "PROJECT_BINARY_DIR"; - srcdir = "PROJECT_SOURCE_DIR"; - this->Makefile->AddDefinition( - bindir, this->Makefile->GetCurrentBinaryDirectory().c_str()); + "PROJECT_BINARY_DIR", this->Makefile->GetCurrentBinaryDirectory().c_str()); this->Makefile->AddDefinition( - srcdir, this->Makefile->GetCurrentSourceDirectory().c_str()); + "PROJECT_SOURCE_DIR", this->Makefile->GetCurrentSourceDirectory().c_str()); this->Makefile->AddDefinition("PROJECT_NAME", projectName.c_str()); @@ -205,7 +202,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, languages.emplace_back("NONE"); } - cmPolicies::PolicyStatus cmp0048 = + cmPolicies::PolicyStatus const cmp0048 = this->Makefile->GetPolicyStatus(cmPolicies::CMP0048); if (haveVersion) { // Set project VERSION variables to given values @@ -220,64 +217,87 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, cmsys::RegularExpression vx( R"(^([0-9]+(\.[0-9]+(\.[0-9]+(\.[0-9]+)?)?)?)?$)"); if (!vx.find(version)) { - std::string e = "VERSION \"" + version + "\" format invalid."; + std::string e = R"(VERSION ")" + version + R"(" format invalid.)"; this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e); cmSystemTools::SetFatalErrorOccured(); return true; } - std::string vs; - const char* sep = ""; - char vb[4][64]; - unsigned int v[4] = { 0, 0, 0, 0 }; - int vc = - sscanf(version.c_str(), "%u.%u.%u.%u", &v[0], &v[1], &v[2], &v[3]); - for (int i = 0; i < 4; ++i) { - if (i < vc) { - sprintf(vb[i], "%u", v[i]); - vs += sep; - vs += vb[i]; - sep = "."; - } else { - vb[i][0] = 0; + cmPolicies::PolicyStatus const cmp0096 = + this->Makefile->GetPolicyStatus(cmPolicies::CMP0096); + + constexpr std::size_t MAX_VERSION_COMPONENTS = 4u; + std::string version_string; + std::array<std::string, MAX_VERSION_COMPONENTS> version_components; + + if (cmp0096 == cmPolicies::OLD || cmp0096 == cmPolicies::WARN) { + char vb[MAX_VERSION_COMPONENTS][std::numeric_limits<unsigned>::digits10]; + unsigned v[MAX_VERSION_COMPONENTS] = { 0, 0, 0, 0 }; + const int vc = std::sscanf(version.c_str(), "%u.%u.%u.%u", &v[0], &v[1], + &v[2], &v[3]); + for (auto i = 0u; i < MAX_VERSION_COMPONENTS; ++i) { + if (int(i) < vc) { + std::sprintf(vb[i], "%u", v[i]); + version_string += &"."[std::size_t(i == 0)]; + version_string += vb[i]; + version_components[i] = vb[i]; + } else { + vb[i][0] = '\x00'; + } + } + } else { + // The regex above verified that we have a .-separated string of + // non-negative integer components. Keep the original string. + version_string = std::move(version); + // Split the integer components. + auto components = cmSystemTools::SplitString(version_string, '.'); + for (auto i = 0u; i < components.size(); ++i) { + version_components[i] = std::move(components[i]); } } std::string vv; vv = projectName + "_VERSION"; - this->Makefile->AddDefinition("PROJECT_VERSION", vs.c_str()); - this->Makefile->AddDefinition(vv, vs.c_str()); + this->Makefile->AddDefinition("PROJECT_VERSION", version_string.c_str()); + this->Makefile->AddDefinition(vv, version_string.c_str()); vv = projectName + "_VERSION_MAJOR"; - this->Makefile->AddDefinition("PROJECT_VERSION_MAJOR", vb[0]); - this->Makefile->AddDefinition(vv, vb[0]); + this->Makefile->AddDefinition("PROJECT_VERSION_MAJOR", + version_components[0].c_str()); + this->Makefile->AddDefinition(vv, version_components[0].c_str()); vv = projectName + "_VERSION_MINOR"; - this->Makefile->AddDefinition("PROJECT_VERSION_MINOR", vb[1]); - this->Makefile->AddDefinition(vv, vb[1]); + this->Makefile->AddDefinition("PROJECT_VERSION_MINOR", + version_components[1].c_str()); + this->Makefile->AddDefinition(vv, version_components[1].c_str()); vv = projectName + "_VERSION_PATCH"; - this->Makefile->AddDefinition("PROJECT_VERSION_PATCH", vb[2]); - this->Makefile->AddDefinition(vv, vb[2]); + this->Makefile->AddDefinition("PROJECT_VERSION_PATCH", + version_components[2].c_str()); + this->Makefile->AddDefinition(vv, version_components[2].c_str()); vv = projectName + "_VERSION_TWEAK"; - this->Makefile->AddDefinition("PROJECT_VERSION_TWEAK", vb[3]); - this->Makefile->AddDefinition(vv, vb[3]); + this->Makefile->AddDefinition("PROJECT_VERSION_TWEAK", + version_components[3].c_str()); + this->Makefile->AddDefinition(vv, version_components[3].c_str()); // Also, try set top level variables - TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION", vs.c_str()); - TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MAJOR", vb[0]); - TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MINOR", vb[1]); - TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_PATCH", vb[2]); - TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_TWEAK", vb[3]); + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION", version_string.c_str()); + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MAJOR", + version_components[0].c_str()); + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MINOR", + version_components[1].c_str()); + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_PATCH", + version_components[2].c_str()); + TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_TWEAK", + version_components[3].c_str()); } else if (cmp0048 != cmPolicies::OLD) { // Set project VERSION variables to empty - std::vector<std::string> vv; - vv.emplace_back("PROJECT_VERSION"); - vv.emplace_back("PROJECT_VERSION_MAJOR"); - vv.emplace_back("PROJECT_VERSION_MINOR"); - vv.emplace_back("PROJECT_VERSION_PATCH"); - vv.emplace_back("PROJECT_VERSION_TWEAK"); - vv.push_back(projectName + "_VERSION"); - vv.push_back(projectName + "_VERSION_MAJOR"); - vv.push_back(projectName + "_VERSION_MINOR"); - vv.push_back(projectName + "_VERSION_PATCH"); - vv.push_back(projectName + "_VERSION_TWEAK"); + std::vector<std::string> vv = { "PROJECT_VERSION", + "PROJECT_VERSION_MAJOR", + "PROJECT_VERSION_MINOR", + "PROJECT_VERSION_PATCH", + "PROJECT_VERSION_TWEAK", + projectName + "_VERSION", + projectName + "_VERSION_MAJOR", + projectName + "_VERSION_MINOR", + projectName + "_VERSION_PATCH", + projectName + "_VERSION_TWEAK" }; if (this->Makefile->IsRootMakefile()) { vv.emplace_back("CMAKE_PROJECT_VERSION"); vv.emplace_back("CMAKE_PROJECT_VERSION_MAJOR"); @@ -287,7 +307,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, } std::string vw; for (std::string const& i : vv) { - const char* v = this->Makefile->GetDefinition(i); + const char* const v = this->Makefile->GetDefinition(i); if (v && *v) { if (cmp0048 == cmPolicies::WARN) { if (!injectedProjectCommand) { @@ -319,8 +339,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, if (languages.empty()) { // if no language is specified do c and c++ - languages.emplace_back("C"); - languages.emplace_back("CXX"); + languages = { "C", "CXX" }; } this->Makefile->EnableLanguage(languages, false); @@ -337,7 +356,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, bool cmProjectCommand::IncludeByVariable(const std::string& variable) { - const char* include = this->Makefile->GetDefinition(variable); + const char* const include = this->Makefile->GetDefinition(variable); if (!include) { return true; } 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmProjectCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmQTWrapCPPCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmQTWrapUICommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h index 9c52129..619fff1 100644 --- a/Source/cmQtAutoGen.h +++ b/Source/cmQtAutoGen.h @@ -5,7 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <vector> diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index ef8a56b..f172b77 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -4,7 +4,6 @@ #include "cmQtAutoGen.h" #include "cmQtAutoGenInitializer.h" -#include "cmAlgorithms.h" #include "cmCustomCommandLines.h" #include "cmDuration.h" #include "cmGeneratorTarget.h" @@ -17,9 +16,10 @@ #include "cmSystemTools.h" #include "cmTarget.h" -#include <memory> #include <utility> +#include "cm_memory.hxx" + cmQtAutoGenGlobalInitializer::Keywords::Keywords() : AUTOMOC("AUTOMOC") , AUTOUIC("AUTOUIC") diff --git a/Source/cmQtAutoGenGlobalInitializer.h b/Source/cmQtAutoGenGlobalInitializer.h index d56153a..d7f4cc6 100644 --- a/Source/cmQtAutoGenGlobalInitializer.h +++ b/Source/cmQtAutoGenGlobalInitializer.h @@ -8,7 +8,7 @@ #include "cmQtAutoGen.h" #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <unordered_map> #include <vector> diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 83a1bc4..4b12419 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -38,6 +38,8 @@ #include <utility> #include <vector> +#include "cm_memory.hxx" + static std::size_t GetParallelCPUCount() { static std::size_t count = 0; diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h index aa073d1..eb0d35e 100644 --- a/Source/cmQtAutoGenInitializer.h +++ b/Source/cmQtAutoGenInitializer.h @@ -8,7 +8,7 @@ #include "cmQtAutoGen.h" #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <ostream> #include <set> #include <string> diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx index e1c435b..2516d84 100644 --- a/Source/cmQtAutoGenerator.cxx +++ b/Source/cmQtAutoGenerator.cxx @@ -5,7 +5,8 @@ #include "cmsys/FStream.hxx" -#include "cmAlgorithms.h" +#include "cm_memory.hxx" + #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmState.h" diff --git a/Source/cmQtAutoMocUic.cxx b/Source/cmQtAutoMocUic.cxx index 889f47d..44d2db0 100644 --- a/Source/cmQtAutoMocUic.cxx +++ b/Source/cmQtAutoMocUic.cxx @@ -5,11 +5,12 @@ #include <algorithm> #include <array> #include <list> -#include <memory> #include <set> #include <sstream> #include <utility> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmCryptoHash.h" #include "cmGeneratedFileStream.h" diff --git a/Source/cmQtAutoMocUic.h b/Source/cmQtAutoMocUic.h index 8061c13..dc18328 100644 --- a/Source/cmQtAutoMocUic.h +++ b/Source/cmQtAutoMocUic.h @@ -14,7 +14,7 @@ #include <atomic> #include <cstddef> #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <set> #include <string> #include <unordered_map> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmRemoveCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmRemoveDefinitionsCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmReturnCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmRuntimeDependencyArchive.cxx b/Source/cmRuntimeDependencyArchive.cxx index a1d1f95..45aff69 100644 --- a/Source/cmRuntimeDependencyArchive.cxx +++ b/Source/cmRuntimeDependencyArchive.cxx @@ -3,7 +3,6 @@ #include "cmRuntimeDependencyArchive.h" -#include "cmAlgorithms.h" #include "cmBinUtilsLinuxELFLinker.h" #include "cmBinUtilsMacOSMachOLinker.h" #include "cmBinUtilsWindowsPELinker.h" @@ -27,6 +26,8 @@ #include <utility> #include <vector> +#include "cm_memory.hxx" + #if defined(_WIN32) static void AddVisualStudioPath(std::vector<std::string>& paths, const std::string& prefix, diff --git a/Source/cmRuntimeDependencyArchive.h b/Source/cmRuntimeDependencyArchive.h index ec3ecd4..67efec7 100644 --- a/Source/cmRuntimeDependencyArchive.h +++ b/Source/cmRuntimeDependencyArchive.h @@ -9,7 +9,7 @@ #include "cmsys/RegularExpression.hxx" #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <set> #include <string> #include <vector> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSeparateArgumentsCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index 1903fd9..9df1883 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmServer.h" -#include "cmAlgorithms.h" #include "cmConnection.h" #include "cmFileMonitor.h" #include "cmJsonObjectDictionary.h" @@ -18,10 +17,11 @@ #include <cassert> #include <cstdint> #include <iostream> -#include <memory> #include <mutex> #include <utility> +#include "cm_memory.hxx" + void on_signal(uv_signal_t* signal, int signum) { auto conn = static_cast<cmServerBase*>(signal->data); diff --git a/Source/cmServer.h b/Source/cmServer.h index aba4924..ab2ad23 100644 --- a/Source/cmServer.h +++ b/Source/cmServer.h @@ -10,7 +10,7 @@ #include "cmUVHandlePtr.h" -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <vector> diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index 558391f..c5de742 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmServerProtocol.h" -#include "cmAlgorithms.h" #include "cmExternalMakefileProjectGenerator.h" #include "cmFileMonitor.h" #include "cmGlobalGenerator.h" @@ -19,11 +18,12 @@ #include <algorithm> #include <cassert> #include <functional> -#include <memory> #include <string> #include <utility> #include <vector> +#include "cm_memory.hxx" + // Get rid of some windows macros: #undef max 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSetCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSetDirectoryPropertiesCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSetPropertyCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSetSourceFilesPropertiesCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSetTargetPropertiesCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSetTestsPropertiesCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSiteNameCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSourceGroupCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 587cda5..9748cf5 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -6,8 +6,11 @@ #include <algorithm> #include <assert.h> #include <string.h> +#include <type_traits> #include <utility> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmCacheManager.h" #include "cmCommand.h" @@ -27,11 +30,7 @@ cmState::cmState() this->GlobVerificationManager = cm::make_unique<cmGlobVerificationManager>(); } -cmState::~cmState() -{ - cmDeleteAll(this->BuiltinCommands); - cmDeleteAll(this->ScriptedCommands); -} +cmState::~cmState() = default; const char* cmState::GetTargetTypeName(cmStateEnums::TargetType targetType) { @@ -419,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<cmCommand> 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<std::string, std::unique_ptr<cmCommand>>::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<cmCommand> command, cmPolicies::PolicyID policy, const char* message) { - this->AddBuiltinCommand(name, - new cmDisallowedCommand(command, policy, message)); + this->AddBuiltinCommand( + name, + cm::make_unique<cmDisallowedCommand>(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<cmUnexpectedCommand>(name, error)); } -void cmState::AddScriptedCommand(std::string const& name, cmCommand* command) +void cmState::AddScriptedCommand(std::string const& name, + std::unique_ptr<cmCommand> 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<std::string, cmCommand*>::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<std::string, cmCommand*>::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<std::string, std::unique_ptr<cmCommand>>::value_type( + sName, std::move(command))); } cmCommand* cmState::GetCommand(std::string const& name) const @@ -472,14 +476,13 @@ cmCommand* cmState::GetCommand(std::string const& name) const cmCommand* cmState::GetCommandByExactName(std::string const& name) const { - std::map<std::string, cmCommand*>::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; } @@ -504,16 +507,13 @@ std::vector<std::string> cmState::GetCommandNames() const void cmState::RemoveBuiltinCommand(std::string const& name) { assert(name == cmSystemTools::LowerCase(name)); - std::map<std::string, cmCommand*>::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 accd838..7e88030 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <map> +#include <memory> #include <set> #include <string> #include <vector> @@ -145,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<cmCommand> command); + void AddDisallowedCommand(std::string const& name, + std::unique_ptr<cmCommand> 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<cmCommand> command); void RemoveBuiltinCommand(std::string const& name); void RemoveUserDefinedCommands(); std::vector<std::string> GetCommandNames() const; @@ -208,8 +212,8 @@ private: std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions; std::vector<std::string> EnabledLanguages; - std::map<std::string, cmCommand*> BuiltinCommands; - std::map<std::string, cmCommand*> ScriptedCommands; + std::map<std::string, std::unique_ptr<cmCommand>> BuiltinCommands; + std::map<std::string, std::unique_ptr<cmCommand>> ScriptedCommands; cmPropertyMap GlobalProperties; std::unique_ptr<cmCacheManager> CacheManager; std::unique_ptr<cmGlobVerificationManager> GlobVerificationManager; diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 6ca1c9f..3f70ed3 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -6,6 +6,7 @@ #include <algorithm> #include <assert.h> #include <iterator> +#include <vector> #include "cmAlgorithms.h" #include "cmProperty.h" diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 998f904..4ad0870 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -8,7 +8,6 @@ #include <algorithm> #include <ctype.h> #include <iterator> -#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmStringCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSubdirCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmSubdirDependsCommand>(); + } bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; }; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index b10b30f..b1a0127 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -12,6 +12,8 @@ #include <string.h> #include <unordered_set> +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmCustomCommand.h" #include "cmGeneratorExpression.h" @@ -168,7 +170,8 @@ public: cmPropertyMap Properties; bool IsGeneratorProvided; bool HaveInstallRule; - bool DLLPlatform; + bool IsDLLPlatform; + bool IsAIX; bool IsAndroid; bool IsImportedTarget; bool ImportedGloballyVisible; @@ -216,7 +219,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, impl->Name = name; impl->IsGeneratorProvided = false; impl->HaveInstallRule = false; - impl->DLLPlatform = false; + impl->IsDLLPlatform = false; + impl->IsAIX = false; impl->IsAndroid = false; impl->IsImportedTarget = (vis == VisibilityImported || vis == VisibilityImportedGlobally); @@ -224,9 +228,13 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, impl->BuildInterfaceIncludesAppended = false; // Check whether this is a DLL platform. - impl->DLLPlatform = + impl->IsDLLPlatform = !impl->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); + // Check whether we are targeting AIX. + impl->IsAIX = + (impl->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "AIX"); + // Check whether we are targeting an Android platform. impl->IsAndroid = (impl->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android"); @@ -1657,6 +1665,16 @@ cmPropertyMap const& cmTarget::GetProperties() const return impl->Properties; } +bool cmTarget::IsDLLPlatform() const +{ + return impl->IsDLLPlatform; +} + +bool cmTarget::IsAIX() const +{ + return impl->IsAIX; +} + bool cmTarget::IsImported() const { return impl->IsImportedTarget; @@ -1698,7 +1716,8 @@ const char* cmTarget::GetSuffixVariableInternal( ? "CMAKE_SHARED_LIBRARY_SUFFIX" : "CMAKE_EXECUTABLE_SUFFIX"); case cmStateEnums::ImportLibraryArtifact: - return "CMAKE_IMPORT_LIBRARY_SUFFIX"; + return (impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_SUFFIX" + : "CMAKE_IMPORT_LIBRARY_SUFFIX"); } break; default: @@ -1738,7 +1757,8 @@ const char* cmTarget::GetPrefixVariableInternal( ? "CMAKE_SHARED_LIBRARY_PREFIX" : ""); case cmStateEnums::ImportLibraryArtifact: - return "CMAKE_IMPORT_LIBRARY_PREFIX"; + return (impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_PREFIX" + : "CMAKE_IMPORT_LIBRARY_PREFIX"); } break; default: @@ -1872,9 +1892,10 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config, // If we needed to find one of the mapped configurations but did not // On a DLL platform there may be only IMPORTED_IMPLIB for a shared // library or an executable with exports. - bool allowImp = (impl->DLLPlatform && + bool allowImp = (this->IsDLLPlatform() && (this->GetType() == cmStateEnums::SHARED_LIBRARY || - this->IsExecutableWithExports())); + this->IsExecutableWithExports())) || + (this->IsAIX() && this->IsExecutableWithExports()); // If a mapping was found, check its configurations. for (std::vector<std::string>::const_iterator mci = mappedConfigs.begin(); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index fdcca47..a808bb4 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -6,7 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> -#include <memory> // IWYU pragma: keep +#include <memory> #include <set> #include <string> #include <utility> @@ -177,6 +177,12 @@ public: //! Get all properties cmPropertyMap const& GetProperties() const; + //! Return whether or not the target is for a DLL platform. + bool IsDLLPlatform() const; + + //! Return whether or not we are targeting AIX. + bool IsAIX() const; + bool IsImported() const; bool IsImportedGloballyVisible() const; 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTargetCompileDefinitionsCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTargetCompileFeaturesCommand>(); + } bool InitialPass(std::vector<std::string> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTargetCompileOptionsCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTargetIncludeDirectoriesCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTargetLinkDirectoriesCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTargetLinkLibrariesCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTargetLinkOptionsCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTargetSourcesCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index 498953e..916784c 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -2,8 +2,10 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmTestGenerator.h" +#include <memory> #include <ostream> #include <utility> +#include <vector> #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTryCompileCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmTryRunCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cmUVProcessChain.cxx b/Source/cmUVProcessChain.cxx index 90ece0b..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,10 +9,12 @@ #include <assert.h> +#include <istream> // IWYU pragma: keep #include <iterator> -#include <memory> #include <utility> +#include "cm_memory.hxx" + struct cmUVProcessChain::InternalData { struct BasicStreamData diff --git a/Source/cmUVProcessChain.h b/Source/cmUVProcessChain.h index 2b33520..75f8f66 100644 --- a/Source/cmUVProcessChain.h +++ b/Source/cmUVProcessChain.h @@ -7,7 +7,7 @@ #include <array> #include <iosfwd> -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <vector> 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 <utility> #include <vector> +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -22,9 +24,9 @@ public: { } - cmCommand* Clone() override + std::unique_ptr<cmCommand> Clone() override { - return new cmUnexpectedCommand(this->Name, this->Error); + return cm::make_unique<cmUnexpectedCommand>(this->Name, this->Error); } bool InitialPass(std::vector<std::string> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmUnsetCommand>(); + } /** * 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmUseMangledMesaCommand>(); + } bool InitialPass(std::vector<std::string> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmUtilitySourceCommand>(); + } bool InitialPass(std::vector<std::string> 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmVariableRequiresCommand>(); + } bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; }; diff --git a/Source/cmVariableWatch.h b/Source/cmVariableWatch.h index 1230101..acac2c1 100644 --- a/Source/cmVariableWatch.h +++ b/Source/cmVariableWatch.h @@ -6,7 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <string> #include <vector> diff --git a/Source/cmVariableWatchCommand.cxx b/Source/cmVariableWatchCommand.cxx index 5fe55bd..afc0b76 100644 --- a/Source/cmVariableWatchCommand.cxx +++ b/Source/cmVariableWatchCommand.cxx @@ -3,6 +3,7 @@ #include "cmVariableWatchCommand.h" #include <sstream> +#include <utility> #include "cmExecutionStatus.h" #include "cmListFileCache.h" @@ -84,15 +85,39 @@ static void deleteVariableWatchCallbackData(void* client_data) delete data; } -cmVariableWatchCommand::cmVariableWatchCommand() = default; - -cmVariableWatchCommand::~cmVariableWatchCommand() +/** This command does not really have a final pass but it needs to + stay alive since it owns variable watch callback information. */ +class FinalAction { - for (std::string const& wv : this->WatchedVariables) { - this->Makefile->GetCMakeInstance()->GetVariableWatch()->RemoveWatch( - wv, cmVariableWatchCommandVariableAccessed); +public: + FinalAction(cmMakefile* makefile, std::string variable) + : Action(std::make_shared<Impl>(makefile, std::move(variable))) + { } -} + + void operator()(cmMakefile&) const {} + +private: + struct Impl + { + Impl(cmMakefile* makefile, std::string variable) + : Makefile(makefile) + , Variable(std::move(variable)) + { + } + + ~Impl() + { + this->Makefile->GetCMakeInstance()->GetVariableWatch()->RemoveWatch( + this->Variable, cmVariableWatchCommandVariableAccessed); + } + + cmMakefile* Makefile; + std::string Variable; + }; + + std::shared_ptr<Impl const> Action; +}; bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) @@ -118,7 +143,6 @@ bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args, data->InCallback = false; data->Command = command; - this->WatchedVariables.insert(variable); if (!this->Makefile->GetCMakeInstance()->GetVariableWatch()->AddWatch( variable, cmVariableWatchCommandVariableAccessed, data, deleteVariableWatchCallbackData)) { @@ -126,5 +150,6 @@ bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args, return false; } + this->Makefile->AddFinalAction(FinalAction(this->Makefile, variable)); return true; } diff --git a/Source/cmVariableWatchCommand.h b/Source/cmVariableWatchCommand.h index 6a8115d..221269f 100644 --- a/Source/cmVariableWatchCommand.h +++ b/Source/cmVariableWatchCommand.h @@ -5,10 +5,11 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include <set> #include <string> #include <vector> +#include "cm_memory.hxx" + #include "cmCommand.h" class cmExecutionStatus; @@ -23,13 +24,10 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() override { return new cmVariableWatchCommand; } - - //! Default constructor - cmVariableWatchCommand(); - - //! Destructor. - ~cmVariableWatchCommand() override; + std::unique_ptr<cmCommand> Clone() override + { + return cm::make_unique<cmVariableWatchCommand>(); + } /** * This is called when the command is first encountered in @@ -37,13 +35,6 @@ public: */ bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; - - /** This command does not really have a final pass but it needs to - stay alive since it owns variable watch callback information. */ - bool HasFinalPass() const override { return true; } - -protected: - std::set<std::string> WatchedVariables; }; #endif diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 0420881..4a151b3 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -19,9 +19,10 @@ #include "windows.h" #include <iterator> -#include <memory> // IWYU pragma: keep #include <set> +#include "cm_memory.hxx" + static void ConvertToWindowsSlash(std::string& s); static std::string cmVS10EscapeXML(std::string arg) @@ -1218,7 +1219,7 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues( this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) { e1.Element("CharacterSet", "Unicode"); } else if (this->GeneratorTarget->GetType() <= - cmStateEnums::MODULE_LIBRARY && + cmStateEnums::OBJECT_LIBRARY && this->ClOptions[config]->UsingSBCS()) { e1.Element("CharacterSet", "NotSet"); } else { @@ -2648,8 +2649,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( clOptions.AddFlag("UseFullPaths", "false"); } clOptions.AddFlag("PrecompiledHeader", "NotUsing"); - std::string asmLocation = configName + "/"; - clOptions.AddFlag("AssemblerListingLocation", asmLocation); + clOptions.AddFlag("AssemblerListingLocation", "$(IntDir)"); } } diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx index a01fa6f..a902964 100644 --- a/Source/cmWhileCommand.cxx +++ b/Source/cmWhileCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmWhileCommand.h" +#include "cm_memory.hxx" + #include "cmConditionEvaluator.h" #include "cmExecutionStatus.h" #include "cmExpandedCommandArgument.h" @@ -9,7 +11,7 @@ #include "cmMessageType.h" #include "cmSystemTools.h" -#include <memory> // IWYU pragma: keep +#include <utility> cmWhileFunctionBlocker::cmWhileFunctionBlocker(cmMakefile* mf) : Makefile(mf) @@ -136,9 +138,10 @@ bool cmWhileCommand::InvokeInitialPass( } // create a function blocker - cmWhileFunctionBlocker* f = new cmWhileFunctionBlocker(this->Makefile); - f->Args = args; - this->Makefile->AddFunctionBlocker(f); - + { + auto fb = cm::make_unique<cmWhileFunctionBlocker>(this->Makefile); + fb->Args = args; + this->Makefile->AddFunctionBlocker(std::move(fb)); + } return true; } 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmWhileCommand>(); + } /** * This overrides the default InvokeInitialPass implementation. diff --git a/Source/cmWorkerPool.cxx b/Source/cmWorkerPool.cxx index cbf070e..974100b 100644 --- a/Source/cmWorkerPool.cxx +++ b/Source/cmWorkerPool.cxx @@ -16,6 +16,8 @@ #include <stddef.h> #include <thread> +#include "cm_memory.hxx" + /** * @brief libuv pipe buffer class */ diff --git a/Source/cmWorkerPool.h b/Source/cmWorkerPool.h index f08bb4f..d708118 100644 --- a/Source/cmWorkerPool.h +++ b/Source/cmWorkerPool.h @@ -5,14 +5,13 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include "cmAlgorithms.h" // IWYU pragma: keep - -#include <memory> // IWYU pragma: keep #include <stdint.h> #include <string> #include <utility> #include <vector> +#include "cm_memory.hxx" + // -- Types class cmWorkerPoolInternal; 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 <string> #include <vector> +#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<cmCommand> Clone() override + { + return cm::make_unique<cmWriteFileCommand>(); + } /** * This is called when the command is first encountered in diff --git a/Source/cm_memory.hxx b/Source/cm_memory.hxx new file mode 100644 index 0000000..9f5e678 --- /dev/null +++ b/Source/cm_memory.hxx @@ -0,0 +1,31 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cm_memory_hxx +#define cm_memory_hxx + +#include "cmConfigure.h" // IWYU pragma: keep + +#include <memory> // IWYU pragma: export +#if !defined(CMake_HAVE_CXX_MAKE_UNIQUE) +# include <utility> +#endif + +namespace cm { + +#if defined(CMake_HAVE_CXX_MAKE_UNIQUE) + +using std::make_unique; + +#else + +template <typename T, typename... Args> +std::unique_ptr<T> make_unique(Args&&... args) +{ + return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); +} + +#endif + +} // namespace cm + +#endif diff --git a/Source/cmake.cxx b/Source/cmake.cxx index ca3b405..7250e51 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmake.h" +#include "cm_memory.hxx" + #include "cmAlgorithms.h" #include "cmCommands.h" #include "cmDocumentation.h" @@ -104,7 +106,6 @@ #include <cstring> #include <initializer_list> #include <iostream> -#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> diff --git a/Source/cmake.h b/Source/cmake.h index c03872b..6aa00e1 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -7,7 +7,7 @@ #include <functional> #include <map> -#include <memory> // IWYU pragma: keep +#include <memory> #include <set> #include <string> #include <unordered_set> diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index a6348b3..cfb3cee 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -31,13 +31,14 @@ #include <string> #include <vector> +namespace { #ifdef CMAKE_BUILD_WITH_CMAKE -static const char* cmDocumentationName[][2] = { +const char* cmDocumentationName[][2] = { { nullptr, " cmake - Cross-Platform Makefile Generator." }, { nullptr, nullptr } }; -static const char* cmDocumentationUsage[][2] = { +const char* cmDocumentationUsage[][2] = { { nullptr, " cmake [options] <path-to-source>\n" " cmake [options] <path-to-existing-build>\n" @@ -49,40 +50,12 @@ static const char* cmDocumentationUsage[][2] = { { nullptr, nullptr } }; -static const char* cmDocumentationUsageNote[][2] = { +const char* cmDocumentationUsageNote[][2] = { { nullptr, "Run 'cmake --help' for more information." }, { nullptr, nullptr } }; -# define CMAKE_BUILD_OPTIONS \ - " <dir> = Project binary directory to be built.\n" \ - " --parallel [<jobs>], -j [<jobs>]\n" \ - " = Build in parallel using the given number of jobs. \n" \ - " If <jobs> is omitted the native build tool's \n" \ - " default number is used.\n" \ - " The CMAKE_BUILD_PARALLEL_LEVEL environment " \ - "variable\n" \ - " specifies a default parallel level when this " \ - "option\n" \ - " is not given.\n" \ - " --target <tgt>..., -t <tgt>... \n" \ - " = Build <tgt> instead of default targets.\n" \ - " --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \ - " --clean-first = Build target 'clean' first, then build.\n" \ - " (To clean only, use --target 'clean'.)\n" \ - " --verbose, -v = Enable verbose output - if supported - including\n" \ - " the build commands to be executed. \n" \ - " -- = Pass remaining options to the native tool.\n" - -# define CMAKE_INSTALL_OPTIONS \ - " <dir> = Project binary directory to install.\n" \ - " --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \ - " --component <comp> = Component-based install. Only install <comp>.\n" \ - " --prefix <prefix> = The installation prefix CMAKE_INSTALL_PREFIX.\n" \ - " --strip = Performing install/strip.\n" \ - " -v --verbose = Enable verbose output.\n" - -static const char* cmDocumentationOptions[][2] = { +const char* cmDocumentationOptions[][2] = { CMAKE_STANDARD_OPTIONS_TABLE, { "-E", "CMake command mode." }, { "-L[A][H]", "List non-advanced cached variables." }, @@ -117,7 +90,7 @@ static const char* cmDocumentationOptions[][2] = { #endif -static int do_command(int ac, char const* const* av) +int do_command(int ac, char const* const* av) { std::vector<std::string> args; args.reserve(ac - 1); @@ -126,12 +99,7 @@ static int do_command(int ac, char const* const* av) return cmcmd::ExecuteCMakeCommand(args); } -int do_cmake(int ac, char const* const* av); -static int do_build(int ac, char const* const* av); -static int do_install(int ac, char const* const* av); -static int do_open(int ac, char const* const* av); - -static cmMakefile* cmakemainGetMakefile(cmake* cm) +cmMakefile* cmakemainGetMakefile(cmake* cm) { if (cm && cm->GetDebugOutput()) { cmGlobalGenerator* gg = cm->GetGlobalGenerator(); @@ -142,7 +110,7 @@ static cmMakefile* cmakemainGetMakefile(cmake* cm) return nullptr; } -static std::string cmakemainGetStack(cmake* cm) +std::string cmakemainGetStack(cmake* cm) { std::string msg; cmMakefile* mf = cmakemainGetMakefile(cm); @@ -156,14 +124,13 @@ static std::string cmakemainGetStack(cmake* cm) return msg; } -static void cmakemainMessageCallback(const std::string& m, - const char* /*unused*/, cmake* cm) +void cmakemainMessageCallback(const std::string& m, const char* /*unused*/, + cmake* cm) { - std::cerr << m << cmakemainGetStack(cm) << std::endl << std::flush; + std::cerr << m << cmakemainGetStack(cm) << std::endl; } -static void cmakemainProgressCallback(const std::string& m, float prog, - cmake* cm) +void cmakemainProgressCallback(const std::string& m, float prog, cmake* cm) { cmMakefile* mf = cmakemainGetMakefile(cm); std::string dir; @@ -178,48 +145,6 @@ static void cmakemainProgressCallback(const std::string& m, float prog, if ((prog < 0) || (!dir.empty())) { std::cout << "-- " << m << dir << cmakemainGetStack(cm) << std::endl; } - - std::cout.flush(); -} - -int main(int ac, char const* const* av) -{ - cmSystemTools::EnsureStdPipes(); -#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) - // Replace streambuf so we can output Unicode to console - cmsys::ConsoleBuf::Manager consoleOut(std::cout); - consoleOut.SetUTF8Pipes(); - cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true); - consoleErr.SetUTF8Pipes(); -#endif - cmsys::Encoding::CommandLineArguments args = - cmsys::Encoding::CommandLineArguments::Main(ac, av); - ac = args.argc(); - av = args.argv(); - - cmSystemTools::EnableMSVCDebugHook(); - cmSystemTools::InitializeLibUV(); - cmSystemTools::FindCMakeResources(av[0]); - if (ac > 1) { - if (strcmp(av[1], "--build") == 0) { - return do_build(ac, av); - } - if (strcmp(av[1], "--install") == 0) { - return do_install(ac, av); - } - if (strcmp(av[1], "--open") == 0) { - return do_open(ac, av); - } - if (strcmp(av[1], "-E") == 0) { - return do_command(ac, av); - } - } - int ret = do_cmake(ac, av); -#ifdef CMAKE_BUILD_WITH_CMAKE - cmDynamicLoader::FlushCache(); -#endif - uv_loop_close(uv_default_loop()); - return ret; } int do_cmake(int ac, char const* const* av) @@ -381,7 +306,6 @@ int do_cmake(int ac, char const* const* av) return 0; } -namespace { int extract_job_number(int& index, char const* current, char const* next, int len_of_flag) { @@ -411,9 +335,8 @@ int extract_job_number(int& index, char const* current, char const* next, } return jobs; } -} -static int do_build(int ac, char const* const* av) +int do_build(int ac, char const* const* av) { #ifndef CMAKE_BUILD_WITH_CMAKE std::cerr << "This cmake does not support --build\n"; @@ -541,7 +464,24 @@ static int do_build(int ac, char const* const* av) std::cerr << "Usage: cmake --build <dir> [options] [-- [native-options]]\n" "Options:\n" - CMAKE_BUILD_OPTIONS + " <dir> = Project binary directory to be built.\n" + " --parallel [<jobs>], -j [<jobs>]\n" + " = Build in parallel using the given number of jobs. \n" + " If <jobs> is omitted the native build tool's \n" + " default number is used.\n" + " The CMAKE_BUILD_PARALLEL_LEVEL environment " + "variable\n" + " specifies a default parallel level when this " + "option\n" + " is not given.\n" + " --target <tgt>..., -t <tgt>... \n" + " = Build <tgt> instead of default targets.\n" + " --config <cfg> = For multi-configuration tools, choose <cfg>.\n" + " --clean-first = Build target 'clean' first, then build.\n" + " (To clean only, use --target 'clean'.)\n" + " --verbose, -v = Enable verbose output - if supported - including\n" + " the build commands to be executed. \n" + " -- = Pass remaining options to the native tool.\n" ; /* clang-format on */ return 1; @@ -560,7 +500,7 @@ static int do_build(int ac, char const* const* av) #endif } -static int do_install(int ac, char const* const* av) +int do_install(int ac, char const* const* av) { #ifndef CMAKE_BUILD_WITH_CMAKE std::cerr << "This cmake does not support --install\n"; @@ -627,8 +567,18 @@ static int do_install(int ac, char const* const* av) } if (dir.empty()) { - std::cerr << "Usage: cmake --install <dir> " - "[options]\nOptions:\n" CMAKE_INSTALL_OPTIONS; + /* clang-format off */ + std::cerr << + "Usage: cmake --install <dir> [options]\n" + "Options:\n" + " <dir> = Project binary directory to install.\n" + " --config <cfg> = For multi-configuration tools, choose <cfg>.\n" + " --component <comp> = Component-based install. Only install <comp>.\n" + " --prefix <prefix> = The installation prefix CMAKE_INSTALL_PREFIX.\n" + " --strip = Performing install/strip.\n" + " -v --verbose = Enable verbose output.\n" + ; + /* clang-format on */ return 1; } @@ -671,7 +621,7 @@ static int do_install(int ac, char const* const* av) #endif } -static int do_open(int ac, char const* const* av) +int do_open(int ac, char const* const* av) { #ifndef CMAKE_BUILD_WITH_CMAKE std::cerr << "This cmake does not support --open\n"; @@ -713,3 +663,44 @@ static int do_open(int ac, char const* const* av) return cm.Open(dir, false) ? 0 : 1; #endif } +} // namespace + +int main(int ac, char const* const* av) +{ + cmSystemTools::EnsureStdPipes(); +#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) + // Replace streambuf so we can output Unicode to console + cmsys::ConsoleBuf::Manager consoleOut(std::cout); + consoleOut.SetUTF8Pipes(); + cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true); + consoleErr.SetUTF8Pipes(); +#endif + cmsys::Encoding::CommandLineArguments args = + cmsys::Encoding::CommandLineArguments::Main(ac, av); + ac = args.argc(); + av = args.argv(); + + cmSystemTools::EnableMSVCDebugHook(); + cmSystemTools::InitializeLibUV(); + cmSystemTools::FindCMakeResources(av[0]); + if (ac > 1) { + if (strcmp(av[1], "--build") == 0) { + return do_build(ac, av); + } + if (strcmp(av[1], "--install") == 0) { + return do_install(ac, av); + } + if (strcmp(av[1], "--open") == 0) { + return do_open(ac, av); + } + if (strcmp(av[1], "-E") == 0) { + return do_command(ac, av); + } + } + int ret = do_cmake(ac, av); +#ifdef CMAKE_BUILD_WITH_CMAKE + cmDynamicLoader::FlushCache(); +#endif + uv_loop_close(uv_default_loop()); + return ret; +} diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 86082e5..503dce1 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -41,7 +41,7 @@ #include <array> #include <iostream> #include <iterator> -#include <memory> // IWYU pragma: keep +#include <memory> #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -114,6 +114,8 @@ void CMakeCommandUsage(const char* program) << " touch <file>... - touch a <file>.\n" << " touch_nocreate <file>... - touch a <file> but do not create it.\n" << " create_symlink old new - create a symbolic link new -> old\n" + << " true - do nothing with an exit code of 0\n" + << " false - do nothing with an exit code of 1\n" #if defined(_WIN32) && !defined(__CYGWIN__) << "Available on Windows only:\n" << " delete_regv key - delete registry value\n" @@ -891,6 +893,16 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args) return 0; } + // Command to do nothing with an exit code of 0. + if (args[1] == "true") { + return 0; + } + + // Command to do nothing with an exit code of 1. + if (args[1] == "false") { + return 1; + } + // Internal CMake shared library support. if (args[1] == "cmake_symlink_library" && args.size() == 5) { return cmcmd::SymlinkLibrary(args); |