diff options
172 files changed, 1677 insertions, 2035 deletions
diff --git a/.clang-tidy b/.clang-tidy index cfca64e..a240e9c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,16 +7,11 @@ bugprone-*,\ -bugprone-too-small-loop-variable,\ google-readability-casting,\ misc-*,\ --misc-incorrect-roundings,\ --misc-macro-parentheses,\ --misc-misplaced-widening-cast,\ -misc-non-private-member-variables-in-classes,\ -misc-static-assert,\ modernize-*,\ -modernize-avoid-c-arrays,\ -modernize-deprecated-headers,\ --modernize-return-braced-init-list,\ --modernize-use-auto,\ -modernize-use-nodiscard,\ -modernize-use-noexcept,\ -modernize-use-transparent-functors,\ @@ -24,7 +19,6 @@ performance-*,\ readability-*,\ -readability-function-size,\ -readability-identifier-naming,\ --readability-implicit-bool-cast,\ -readability-implicit-bool-conversion,\ -readability-inconsistent-declaration-parameter-name,\ -readability-magic-numbers,\ @@ -38,4 +32,6 @@ CheckOptions: value: '1' - key: modernize-use-equals-default.IgnoreMacros value: '0' + - key: modernize-use-auto.MinTypeNameLength + value: '80' ... diff --git a/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst index ed321fc..ab2a023 100644 --- a/Help/command/add_custom_command.rst +++ b/Help/command/add_custom_command.rst @@ -68,9 +68,6 @@ The options are: order-only dependencies to ensure the byproducts will be available before their dependents build. - The ``BYPRODUCTS`` option is ignored on non-Ninja generators - except to mark byproducts ``GENERATED``. - ``COMMAND`` Specify the command-line(s) to execute at build time. If more than one ``COMMAND`` is specified they will be executed in order, @@ -111,6 +108,9 @@ The options are: an ``OUTPUT`` of another custom command in the same directory (``CMakeLists.txt`` file) CMake automatically brings the other custom command into the target in which this command is built. + A target-level dependency is added if any dependency is listed as + ``BYPRODUCTS`` of a target or any of its build events in the same + directory to ensure the byproducts will be available. If ``DEPENDS`` is not specified the command will run whenever the ``OUTPUT`` is missing; if the command does not actually create the ``OUTPUT`` then the rule will always run. diff --git a/Help/command/add_custom_target.rst b/Help/command/add_custom_target.rst index 08b9516..e74960c 100644 --- a/Help/command/add_custom_target.rst +++ b/Help/command/add_custom_target.rst @@ -49,9 +49,6 @@ The options are: order-only dependencies to ensure the byproducts will be available before their dependents build. - The ``BYPRODUCTS`` option is ignored on non-Ninja generators - except to mark byproducts ``GENERATED``. - ``COMMAND`` Specify the command-line(s) to execute at build time. If more than one ``COMMAND`` is specified they will be executed in order, @@ -86,6 +83,9 @@ The options are: :command:`add_custom_command` command calls in the same directory (``CMakeLists.txt`` file). They will be brought up to date when the target is built. + A target-level dependency is added if any dependency is a byproduct + of a target or any of its build events in the same directory to ensure + the byproducts will be available before this target is built. Use the :command:`add_dependencies` command to add dependencies on other targets. diff --git a/Help/cpack_gen/wix.rst b/Help/cpack_gen/wix.rst index dde4943..7fb5a12 100644 --- a/Help/cpack_gen/wix.rst +++ b/Help/cpack_gen/wix.rst @@ -95,6 +95,10 @@ Windows using WiX. If this variable is not set, it will be initialized with CPACK_PACKAGE_NAME + If this variable is set to ``.``, then application shortcuts will be + created directly in the start menu and the uninstaller shortcut will be + omitted. + .. variable:: CPACK_WIX_CULTURES Language(s) of the installer diff --git a/Help/release/dev/windows-auto-export-incremental-build.rst b/Help/release/dev/windows-auto-export-incremental-build.rst new file mode 100644 index 0000000..3126329 --- /dev/null +++ b/Help/release/dev/windows-auto-export-incremental-build.rst @@ -0,0 +1,6 @@ +windows-auto-export-incremental-build +------------------------------------- + +* On Windows, existing auto generated exports are now only updated if the + modified time stamp of the exports is not newer than any modified time stamp + of the input files. diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 857e5f1..2aef888 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 15) -set(CMake_VERSION_PATCH 20190909) +set(CMake_VERSION_PATCH 20190916) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index d1ffcef..94530c1 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -77,8 +77,7 @@ int cmCPackIFWGenerator::PackageFiles() if (!this->OnlineOnly && !this->DownloadedPackages.empty()) { ifwCmd.emplace_back("-i"); - std::set<cmCPackIFWPackage*>::iterator it = - this->DownloadedPackages.begin(); + auto it = this->DownloadedPackages.begin(); ifwArg = (*it)->Name; ++it; while (it != this->DownloadedPackages.end()) { @@ -137,8 +136,7 @@ int cmCPackIFWGenerator::PackageFiles() if (!this->Installer.Resources.empty()) { ifwCmd.emplace_back("-r"); - std::vector<std::string>::iterator it = - this->Installer.Resources.begin(); + auto it = this->Installer.Resources.begin(); std::string path = this->toplevel + "/resources/"; ifwArg = path + *it; ++it; @@ -180,8 +178,7 @@ int cmCPackIFWGenerator::PackageFiles() } else if (!this->DownloadedPackages.empty() && !this->Installer.RemoteRepositories.empty()) { ifwCmd.emplace_back("-e"); - std::set<cmCPackIFWPackage*>::iterator it = - this->DownloadedPackages.begin(); + auto it = this->DownloadedPackages.begin(); ifwArg = (*it)->Name; ++it; while (it != this->DownloadedPackages.end()) { @@ -193,14 +190,13 @@ int cmCPackIFWGenerator::PackageFiles() ifwCmd.emplace_back("-i"); ifwArg.clear(); // Binary - std::set<cmCPackIFWPackage*>::iterator bit = - this->BinaryPackages.begin(); + auto bit = this->BinaryPackages.begin(); while (bit != this->BinaryPackages.end()) { ifwArg += (*bit)->Name + ","; ++bit; } // Depend - DependenceMap::iterator it = this->DependentPackages.begin(); + auto it = this->DependentPackages.begin(); ifwArg += it->second.Name; ++it; while (it != this->DependentPackages.end()) { @@ -410,7 +406,7 @@ std::string cmCPackIFWGenerator::GetComponentInstallDirNameSuffix( cmCPackComponent* cmCPackIFWGenerator::GetComponent( const std::string& projectName, const std::string& componentName) { - ComponentsMap::iterator cit = this->Components.find(componentName); + auto cit = this->Components.find(componentName); if (cit != this->Components.end()) { return &(cit->second); } @@ -422,7 +418,7 @@ cmCPackComponent* cmCPackIFWGenerator::GetComponent( } std::string name = this->GetComponentPackageName(component); - PackagesMap::iterator pit = this->Packages.find(name); + auto pit = this->Packages.find(name); if (pit != this->Packages.end()) { return component; } @@ -462,7 +458,7 @@ cmCPackComponentGroup* cmCPackIFWGenerator::GetComponentGroup( } std::string name = this->GetGroupPackageName(group); - PackagesMap::iterator pit = this->Packages.find(name); + auto pit = this->Packages.find(name); if (pit != this->Packages.end()) { return group; } @@ -593,23 +589,21 @@ std::string cmCPackIFWGenerator::GetComponentPackageName( cmCPackIFWPackage* cmCPackIFWGenerator::GetGroupPackage( cmCPackComponentGroup* group) const { - std::map<cmCPackComponentGroup*, cmCPackIFWPackage*>::const_iterator pit = - this->GroupPackages.find(group); + auto pit = this->GroupPackages.find(group); return pit != this->GroupPackages.end() ? pit->second : nullptr; } cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage( cmCPackComponent* component) const { - std::map<cmCPackComponent*, cmCPackIFWPackage*>::const_iterator pit = - this->ComponentPackages.find(component); + auto pit = this->ComponentPackages.find(component); return pit != this->ComponentPackages.end() ? pit->second : nullptr; } cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository( const std::string& repositoryName) { - RepositoriesMap::iterator rit = this->Repositories.find(repositoryName); + auto rit = this->Repositories.find(repositoryName); if (rit != this->Repositories.end()) { return &(rit->second); } diff --git a/Source/CPack/IFW/cmCPackIFWPackage.cxx b/Source/CPack/IFW/cmCPackIFWPackage.cxx index fb75145..5fa8cce 100644 --- a/Source/CPack/IFW/cmCPackIFWPackage.cxx +++ b/Source/CPack/IFW/cmCPackIFWPackage.cxx @@ -620,7 +620,7 @@ void cmCPackIFWPackage::GeneratePackageFile() // Write dependencies if (!compDepSet.empty()) { std::ostringstream dependencies; - std::set<DependenceStruct>::iterator it = compDepSet.begin(); + auto it = compDepSet.begin(); dependencies << it->NameWithCompare(); ++it; while (it != compDepSet.end()) { @@ -638,7 +638,7 @@ void cmCPackIFWPackage::GeneratePackageFile() // Write automatic dependency on if (!compAutoDepSet.empty()) { std::ostringstream dependencies; - std::set<DependenceStruct>::iterator it = compAutoDepSet.begin(); + auto it = compAutoDepSet.begin(); dependencies << it->NameWithCompare(); ++it; while (it != compAutoDepSet.end()) { @@ -674,7 +674,7 @@ void cmCPackIFWPackage::GeneratePackageFile() // Replaces if (!this->Replaces.empty()) { std::ostringstream replaces; - std::vector<std::string>::iterator it = this->Replaces.begin(); + auto it = this->Replaces.begin(); replaces << *it; ++it; while (it != this->Replaces.end()) { diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index b0b2df2..f784832 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -537,9 +537,16 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() } } - bool emitUninstallShortcut = - emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) != - emittedShortcutTypes.end(); + bool emitUninstallShortcut = true; + const char* cpackWixProgramMenuFolder = + GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); + if (cpackWixProgramMenuFolder && + cm::string_view(cpackWixProgramMenuFolder) == ".") { + emitUninstallShortcut = false; + } else if (emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) == + emittedShortcutTypes.end()) { + emitUninstallShortcut = false; + } if (!CreateShortcuts(std::string(), "ProductFeature", globalShortcuts, emitUninstallShortcut, fileDefinitions, @@ -733,9 +740,16 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( { std::string directoryId; switch (type) { - case cmWIXShortcuts::START_MENU: - directoryId = "PROGRAM_MENU_FOLDER"; - break; + case cmWIXShortcuts::START_MENU: { + const char* cpackWixProgramMenuFolder = + GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); + if (cpackWixProgramMenuFolder && + cm::string_view(cpackWixProgramMenuFolder) == ".") { + directoryId = "ProgramMenuFolder"; + } else { + directoryId = "PROGRAM_MENU_FOLDER"; + } + } break; case cmWIXShortcuts::DESKTOP: directoryId = "DesktopFolder"; break; @@ -789,8 +803,13 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( fileDefinitions); if (type == cmWIXShortcuts::START_MENU) { - fileDefinitions.EmitRemoveFolder("CM_REMOVE_PROGRAM_MENU_FOLDER" + - idSuffix); + const char* cpackWixProgramMenuFolder = + GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); + if (cpackWixProgramMenuFolder && + cm::string_view(cpackWixProgramMenuFolder) != ".") { + fileDefinitions.EmitRemoveFolder("CM_REMOVE_PROGRAM_MENU_FOLDER" + + idSuffix); + } } if (emitUninstallShortcut) { diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx index 975dffb..0a83ca2 100644 --- a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx @@ -14,10 +14,12 @@ void cmWIXDirectoriesSourceWriter::EmitStartMenuFolder( BeginElement("Directory"); AddAttribute("Id", "ProgramMenuFolder"); - BeginElement("Directory"); - AddAttribute("Id", "PROGRAM_MENU_FOLDER"); - AddAttribute("Name", startMenuFolder); - EndElement("Directory"); + if (startMenuFolder != ".") { + BeginElement("Directory"); + AddAttribute("Id", "PROGRAM_MENU_FOLDER"); + AddAttribute("Name", startMenuFolder); + EndElement("Directory"); + } EndElement("Directory"); } diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx index 4d41049..a564eb1 100644 --- a/Source/CPack/cmCPackGeneratorFactory.cxx +++ b/Source/CPack/cmCPackGeneratorFactory.cxx @@ -158,8 +158,7 @@ cmCPackGenerator* cmCPackGeneratorFactory::NewGenerator( cmCPackGenerator* cmCPackGeneratorFactory::NewGeneratorInternal( const std::string& name) { - cmCPackGeneratorFactory::t_GeneratorCreatorsMap::iterator it = - this->GeneratorCreators.find(name); + auto it = this->GeneratorCreators.find(name); if (it == this->GeneratorCreators.end()) { return nullptr; } diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx index 0f621cc..e8728a3 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -184,8 +184,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) // The default behavior is to have one package by component group // unless CPACK_COMPONENTS_IGNORE_GROUP is specified. if (!ignoreGroup) { - std::map<std::string, cmCPackComponentGroup>::iterator mainCompGIt = - this->ComponentGroups.end(); + auto mainCompGIt = this->ComponentGroups.end(); std::map<std::string, cmCPackComponentGroup>::iterator compGIt; for (compGIt = this->ComponentGroups.begin(); @@ -206,8 +205,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) retval &= PackageOnePack(initialTopLevel, compGIt->first); } // Handle Orphan components (components not belonging to any groups) - std::map<std::string, cmCPackComponent>::iterator mainCompIt = - this->Components.end(); + auto mainCompIt = this->Components.end(); std::map<std::string, cmCPackComponent>::iterator compIt; for (compIt = this->Components.begin(); compIt != this->Components.end(); ++compIt) { @@ -251,8 +249,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) // CPACK_COMPONENTS_IGNORE_GROUPS is set // We build 1 package per component else { - std::map<std::string, cmCPackComponent>::iterator mainCompIt = - this->Components.end(); + auto mainCompIt = this->Components.end(); std::map<std::string, cmCPackComponent>::iterator compIt; for (compIt = this->Components.begin(); compIt != this->Components.end(); diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 772fa47..d9dd931 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -1830,9 +1830,8 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch( return 0; } std::map<std::string, std::string> fileMap; - std::vector<std::string>::iterator fp = filesFullPath.begin(); - for (std::vector<std::string>::iterator f = files.begin(); f != files.end(); - ++f, ++fp) { + auto fp = filesFullPath.begin(); + for (auto f = files.begin(); f != files.end(); ++f, ++fp) { fileMap[*f] = *fp; } @@ -1870,7 +1869,7 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch( this->StartCoverageLogXML(covLogXML); count++; // move on one } - std::map<std::string, std::string>::iterator i = fileMap.find(file); + auto i = fileMap.find(file); // if the file should be covered write out the header for that file if (i != fileMap.end()) { // we have a new file so count it in the output @@ -2202,7 +2201,7 @@ bool cmCTestCoverageHandler::ParseBullsEyeCovsrcLine( int cmCTestCoverageHandler::GetLabelId(std::string const& label) { - LabelIdMapType::iterator i = this->LabelIdMap.find(label); + auto i = this->LabelIdMap.find(label); if (i == this->LabelIdMap.end()) { int n = int(this->Labels.size()); this->Labels.push_back(label); @@ -2273,7 +2272,7 @@ void cmCTestCoverageHandler::LoadLabels(const char* dir) void cmCTestCoverageHandler::WriteXMLLabels(cmXMLWriter& xml, std::string const& source) { - LabelMapType::const_iterator li = this->SourceLabels.find(source); + auto li = this->SourceLabels.find(source); if (li != this->SourceLabels.end() && !li->second.empty()) { xml.StartElement("Labels"); for (auto const& ls : li->second) { @@ -2316,7 +2315,7 @@ bool cmCTestCoverageHandler::IsFilteredOut(std::string const& source) // The source is filtered out if it does not have any labels in // common with the filter set. std::string shortSrc = this->CTest->GetShortPathToFile(source.c_str()); - LabelMapType::const_iterator li = this->SourceLabels.find(shortSrc); + auto li = this->SourceLabels.find(shortSrc); if (li != this->SourceLabels.end()) { return !this->IntersectsFilter(li->second); } diff --git a/Source/CTest/cmCTestGenericHandler.cxx b/Source/CTest/cmCTestGenericHandler.cxx index d3020b5..cc0b4ed 100644 --- a/Source/CTest/cmCTestGenericHandler.cxx +++ b/Source/CTest/cmCTestGenericHandler.cxx @@ -23,8 +23,7 @@ cmCTestGenericHandler::~cmCTestGenericHandler() = default; void cmCTestGenericHandler::SetOption(const std::string& op, const char* value) { if (!value) { - cmCTestGenericHandler::t_StringToString::iterator remit = - this->Options.find(op); + auto remit = this->Options.find(op); if (remit != this->Options.end()) { this->Options.erase(remit); } @@ -39,8 +38,7 @@ void cmCTestGenericHandler::SetPersistentOption(const std::string& op, { this->SetOption(op, value); if (!value) { - cmCTestGenericHandler::t_StringToString::iterator remit = - this->PersistentOptions.find(op); + auto remit = this->PersistentOptions.find(op); if (remit != this->PersistentOptions.end()) { this->PersistentOptions.erase(remit); } @@ -62,8 +60,7 @@ void cmCTestGenericHandler::Initialize() const char* cmCTestGenericHandler::GetOption(const std::string& op) { - cmCTestGenericHandler::t_StringToString::iterator remit = - this->Options.find(op); + auto remit = this->Options.find(op); if (remit == this->Options.end()) { return nullptr; } diff --git a/Source/CTest/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx index 9bca7cb..08c850d 100644 --- a/Source/CTest/cmCTestP4.cxx +++ b/Source/CTest/cmCTestP4.cxx @@ -146,8 +146,7 @@ private: cmCTestP4::User cmCTestP4::GetUserData(const std::string& username) { - std::map<std::string, cmCTestP4::User>::const_iterator it = - Users.find(username); + auto it = Users.find(username); if (it == Users.end()) { std::vector<char const*> p4_users; diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 23c6b0d..c5bb826 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -571,8 +571,7 @@ bool cmCTestRunTest::StartTest(size_t completed, size_t total) void cmCTestRunTest::ComputeArguments() { this->Arguments.clear(); // reset because this might be a rerun - std::vector<std::string>::const_iterator j = - this->TestProperties->Args.begin(); + auto j = this->TestProperties->Args.begin(); ++j; // skip test name // find the test executable if (this->TestHandler->MemCheck) { diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index 6d8077f..a945111 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -169,7 +169,7 @@ void cmCTestSVN::GuessBase(SVNInfo& svninfo, slash = svninfo.URL.find('/', slash + 1)) { // If the URL suffix is a prefix of at least one path then it is the base. std::string base = cmCTest::DecodeURL(svninfo.URL.substr(slash)); - for (std::vector<Change>::const_iterator ci = changes.begin(); + for (auto ci = changes.begin(); svninfo.Base.empty() && ci != changes.end(); ++ci) { if (cmCTestSVNPathStarts(ci->Path, base)) { svninfo.Base = base; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index f67b11a..f0c5939 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -7,8 +7,8 @@ #include "cmAlgorithms.h" #include "cmCTest.h" #include "cmCTestMultiProcessHandler.h" -#include "cmCommand.h" #include "cmDuration.h" +#include "cmExecutionStatus.h" #include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" @@ -40,36 +40,42 @@ #include <time.h> #include <utility> -class cmExecutionStatus; +namespace { -class cmCTestSubdirCommand : public cmCommand +class cmCTestCommand { public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override + cmCTestCommand(cmCTestTestHandler* testHandler) + : TestHandler(testHandler) { - auto c = cm::make_unique<cmCTestSubdirCommand>(); - c->TestHandler = this->TestHandler; - return std::unique_ptr<cmCommand>(std::move(c)); } - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& /*unused*/) override; + virtual ~cmCTestCommand() = default; + + bool operator()(std::vector<cmListFileArgument> const& args, + cmExecutionStatus& status) + { + cmMakefile& mf = status.GetMakefile(); + std::vector<std::string> expandedArguments; + if (!mf.ExpandArguments(args, expandedArguments)) { + // There was an error expanding arguments. It was already + // reported, so we can skip this command without error. + return true; + } + return this->InitialPass(expandedArguments, status); + } + + virtual bool InitialPass(std::vector<std::string> const& args, + cmExecutionStatus& status) = 0; cmCTestTestHandler* TestHandler; }; -bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& /*unused*/) +bool cmCTestSubdirCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); @@ -90,8 +96,8 @@ bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args, { cmWorkingDirectory workdir(fname); if (workdir.Failed()) { - this->SetError("Failed to change directory to " + fname + " : " + - std::strerror(workdir.GetLastResult())); + status.SetError("Failed to change directory to " + fname + " : " + + std::strerror(workdir.GetLastResult())); return false; } const char* testFilename; @@ -107,45 +113,21 @@ bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args, } fname += "/"; fname += testFilename; - readit = this->Makefile->ReadDependentFile(fname); + readit = status.GetMakefile().ReadDependentFile(fname); } if (!readit) { - std::string m = cmStrCat("Could not find include file: ", fname); - this->SetError(m); + status.SetError(cmStrCat("Could not find include file: ", fname)); return false; } } return true; } -class cmCTestAddSubdirectoryCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - auto c = cm::make_unique<cmCTestAddSubdirectoryCommand>(); - c->TestHandler = this->TestHandler; - return std::unique_ptr<cmCommand>(std::move(c)); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& /*unused*/) override; - - cmCTestTestHandler* TestHandler; -}; - -bool cmCTestAddSubdirectoryCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus& /*unused*/) +bool cmCTestAddSubdirectoryCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } @@ -171,28 +153,19 @@ bool cmCTestAddSubdirectoryCommand::InitialPass( } fname += "/"; fname += testFilename; - readit = this->Makefile->ReadDependentFile(fname); + readit = status.GetMakefile().ReadDependentFile(fname); } if (!readit) { - std::string m = cmStrCat("Could not find include file: ", fname); - this->SetError(m); + status.SetError(cmStrCat("Could not find include file: ", fname)); return false; } return true; } -class cmCTestAddTestCommand : public cmCommand +class cmCTestAddTestCommand : public cmCTestCommand { public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - auto c = cm::make_unique<cmCTestAddTestCommand>(); - c->TestHandler = this->TestHandler; - return std::unique_ptr<cmCommand>(std::move(c)); - } + using cmCTestCommand::cmCTestCommand; /** * This is called when the command is first encountered in @@ -200,32 +173,22 @@ public: */ bool InitialPass(std::vector<std::string> const& /*args*/, cmExecutionStatus& /*unused*/) override; - - cmCTestTestHandler* TestHandler; }; bool cmCTestAddTestCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& /*unused*/) + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } return this->TestHandler->AddTest(args); } -class cmCTestSetTestsPropertiesCommand : public cmCommand +class cmCTestSetTestsPropertiesCommand : public cmCTestCommand { public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - auto c = cm::make_unique<cmCTestSetTestsPropertiesCommand>(); - c->TestHandler = this->TestHandler; - return std::unique_ptr<cmCommand>(std::move(c)); - } + using cmCTestCommand::cmCTestCommand; /** * This is called when the command is first encountered in @@ -233,8 +196,6 @@ public: */ bool InitialPass(std::vector<std::string> const& /*args*/, cmExecutionStatus& /*unused*/) override; - - cmCTestTestHandler* TestHandler; }; bool cmCTestSetTestsPropertiesCommand::InitialPass( @@ -243,18 +204,10 @@ bool cmCTestSetTestsPropertiesCommand::InitialPass( return this->TestHandler->SetTestsProperties(args); } -class cmCTestSetDirectoryPropertiesCommand : public cmCommand +class cmCTestSetDirectoryPropertiesCommand : public cmCTestCommand { public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - auto c = cm::make_unique<cmCTestSetDirectoryPropertiesCommand>(); - c->TestHandler = this->TestHandler; - return std::unique_ptr<cmCommand>(std::move(c)); - } + using cmCTestCommand::cmCTestCommand; /** * This is called when the command is first encountered in @@ -262,8 +215,6 @@ public: */ bool InitialPass(std::vector<std::string> const& /*unused*/, cmExecutionStatus& /*unused*/) override; - - cmCTestTestHandler* TestHandler; }; bool cmCTestSetDirectoryPropertiesCommand::InitialPass( @@ -324,6 +275,8 @@ inline int GetNextRealNumber(std::string const& in, double& val, return 0; } +} // namespace + cmCTestTestHandler::cmCTestTestHandler() { this->UseUnion = false; @@ -690,8 +643,7 @@ void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject) for (std::string const& l : p.Labels) { // first check to see if the current label is a subproject label bool isSubprojectLabel = false; - std::vector<std::string>::iterator subproject = - std::find(subprojects.begin(), subprojects.end(), l); + auto subproject = std::find(subprojects.begin(), subprojects.end(), l); if (subproject != subprojects.end()) { isSubprojectLabel = true; } @@ -945,8 +897,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const FixtureDependencies fixtureSetups; FixtureDependencies fixtureCleanups; - for (ListOfTests::const_iterator it = this->TestList.begin(); - it != this->TestList.end(); ++it) { + for (auto it = this->TestList.begin(); it != this->TestList.end(); ++it) { const cmCTestTestProperties& p = *it; for (std::string const& deps : p.FixturesSetup) { @@ -1007,8 +958,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const // cleanup tests depend on this test case later. std::pair<FixtureDepsIterator, FixtureDepsIterator> setupRange = fixtureSetups.equal_range(requiredFixtureName); - for (FixtureDepsIterator sIt = setupRange.first; - sIt != setupRange.second; ++sIt) { + for (auto sIt = setupRange.first; sIt != setupRange.second; ++sIt) { const std::string& setupTestName = sIt->second->Name; tests[i].RequireSuccessDepends.insert(setupTestName); if (!cmContains(tests[i].Depends, setupTestName)) { @@ -1031,8 +981,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const !excludeSetupRegex.find(requiredFixtureName)) { std::pair<FixtureDepsIterator, FixtureDepsIterator> fixtureRange = fixtureSetups.equal_range(requiredFixtureName); - for (FixtureDepsIterator it = fixtureRange.first; - it != fixtureRange.second; ++it) { + for (auto it = fixtureRange.first; it != fixtureRange.second; ++it) { ListOfTests::const_iterator lotIt = it->second; const cmCTestTestProperties& p = *lotIt; @@ -1063,8 +1012,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const !excludeCleanupRegex.find(requiredFixtureName)) { std::pair<FixtureDepsIterator, FixtureDepsIterator> fixtureRange = fixtureCleanups.equal_range(requiredFixtureName); - for (FixtureDepsIterator it = fixtureRange.first; - it != fixtureRange.second; ++it) { + for (auto it = fixtureRange.first; it != fixtureRange.second; ++it) { ListOfTests::const_iterator lotIt = it->second; const cmCTestTestProperties& p = *lotIt; @@ -1112,8 +1060,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const // This cleanup test could be part of the original test list that was // passed in. It is then possible that no other test requires the // fIt fixture, so we have to check for this. - std::map<std::string, std::vector<size_t>>::const_iterator cIt = - fixtureRequirements.find(fixture); + auto cIt = fixtureRequirements.find(fixture); if (cIt != fixtureRequirements.end()) { const std::vector<size_t>& indices = cIt->second; for (size_t index : indices) { @@ -1688,31 +1635,23 @@ void cmCTestTestHandler::GetListOfTests() mf.AddDefinition("CTEST_CONFIGURATION_TYPE", this->CTest->GetConfigType()); // Add handler for ADD_TEST - auto newCom1 = cm::make_unique<cmCTestAddTestCommand>(); - newCom1->TestHandler = this; - cm.GetState()->AddBuiltinCommand("add_test", std::move(newCom1)); + cm.GetState()->AddBuiltinCommand("add_test", cmCTestAddTestCommand(this)); // Add handler for SUBDIRS - auto newCom2 = cm::make_unique<cmCTestSubdirCommand>(); - newCom2->TestHandler = this; - cm.GetState()->AddBuiltinCommand("subdirs", std::move(newCom2)); + cm.GetState()->AddBuiltinCommand("subdirs", cmCTestSubdirCommand); // Add handler for ADD_SUBDIRECTORY - auto newCom3 = cm::make_unique<cmCTestAddSubdirectoryCommand>(); - newCom3->TestHandler = this; - cm.GetState()->AddBuiltinCommand("add_subdirectory", std::move(newCom3)); + cm.GetState()->AddBuiltinCommand("add_subdirectory", + cmCTestAddSubdirectoryCommand); // Add handler for SET_TESTS_PROPERTIES - auto newCom4 = cm::make_unique<cmCTestSetTestsPropertiesCommand>(); - newCom4->TestHandler = this; - cm.GetState()->AddBuiltinCommand("set_tests_properties", std::move(newCom4)); + cm.GetState()->AddBuiltinCommand("set_tests_properties", + cmCTestSetTestsPropertiesCommand(this)); // Add handler for SET_DIRECTORY_PROPERTIES cm.GetState()->RemoveBuiltinCommand("set_directory_properties"); - auto newCom5 = cm::make_unique<cmCTestSetDirectoryPropertiesCommand>(); - newCom5->TestHandler = this; cm.GetState()->AddBuiltinCommand("set_directory_properties", - std::move(newCom5)); + cmCTestSetDirectoryPropertiesCommand(this)); const char* testFilename; if (cmSystemTools::FileExists("CTestTestfile.cmake")) { @@ -1819,8 +1758,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests) std::sort(this->TestsToRun.begin(), this->TestsToRun.end(), std::less<int>()); // remove duplicates - std::vector<int>::iterator new_end = - std::unique(this->TestsToRun.begin(), this->TestsToRun.end()); + auto new_end = std::unique(this->TestsToRun.begin(), this->TestsToRun.end()); this->TestsToRun.erase(new_end, this->TestsToRun.end()); } @@ -2257,8 +2195,7 @@ bool cmCTestTestHandler::SetTestsProperties( // sort the array std::sort(rt.Labels.begin(), rt.Labels.end()); // remove duplicates - std::vector<std::string>::iterator new_end = - std::unique(rt.Labels.begin(), rt.Labels.end()); + auto new_end = std::unique(rt.Labels.begin(), rt.Labels.end()); rt.Labels.erase(new_end, rt.Labels.end()); } if (key == "MEASUREMENT") { @@ -2337,8 +2274,7 @@ bool cmCTestTestHandler::SetDirectoryProperties( // sort the array std::sort(rt.Labels.begin(), rt.Labels.end()); // remove duplicates - std::vector<std::string>::iterator new_end = - std::unique(rt.Labels.begin(), rt.Labels.end()); + auto new_end = std::unique(rt.Labels.begin(), rt.Labels.end()); rt.Labels.erase(new_end, rt.Labels.end()); } } diff --git a/Source/CTest/cmParseCacheCoverage.cxx b/Source/CTest/cmParseCacheCoverage.cxx index cd2bb1a..b3ef7d3 100644 --- a/Source/CTest/cmParseCacheCoverage.cxx +++ b/Source/CTest/cmParseCacheCoverage.cxx @@ -47,8 +47,7 @@ void cmParseCacheCoverage::RemoveUnCoveredFiles() { // loop over the coverage data computed and remove all files // that only have -1 or 0 for the lines. - cmCTestCoverageHandlerContainer::TotalCoverageMap::iterator ci = - this->Coverage.TotalCoverage.begin(); + auto ci = this->Coverage.TotalCoverage.begin(); while (ci != this->Coverage.TotalCoverage.end()) { cmCTestCoverageHandlerContainer::SingleFileCoverageVector& v = ci->second; bool nothing = true; diff --git a/Source/CTest/cmParseMumpsCoverage.cxx b/Source/CTest/cmParseMumpsCoverage.cxx index afd7dc3..596b72e 100644 --- a/Source/CTest/cmParseMumpsCoverage.cxx +++ b/Source/CTest/cmParseMumpsCoverage.cxx @@ -123,8 +123,7 @@ bool cmParseMumpsCoverage::LoadPackages(const char* d) bool cmParseMumpsCoverage::FindMumpsFile(std::string const& routine, std::string& filepath) { - std::map<std::string, std::string>::iterator i = - this->RoutineToDirectory.find(routine); + auto i = this->RoutineToDirectory.find(routine); if (i != this->RoutineToDirectory.end()) { filepath = i->second; return true; diff --git a/Source/QtDialog/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx index d9a8aff..0f09d7c 100644 --- a/Source/QtDialog/FirstConfigure.cxx +++ b/Source/QtDialog/FirstConfigure.cxx @@ -107,8 +107,7 @@ void StartCompilerSetup::setGenerators( ->GeneratorDefaultPlatform[QString::fromLocal8Bit(gen.name.c_str())] = QString::fromLocal8Bit(gen.defaultPlatform.c_str()); - std::vector<std::string>::const_iterator platformIt = - gen.supportedPlatforms.cbegin(); + auto platformIt = gen.supportedPlatforms.cbegin(); while (platformIt != gen.supportedPlatforms.cend()) { this->GeneratorSupportedPlatforms.insert( diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index f1264d5..1a87028 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -20,7 +20,7 @@ bool cmAddExecutableCommand(std::vector<std::string> const& args, } cmMakefile& mf = status.GetMakefile(); - std::vector<std::string>::const_iterator s = args.begin(); + auto s = args.begin(); std::string const& exename = *s; diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index c067aea..dc8937a 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -34,7 +34,7 @@ bool cmAddLibraryCommand(std::vector<std::string> const& args, bool importTarget = false; bool importGlobal = false; - std::vector<std::string>::const_iterator s = args.begin(); + auto s = args.begin(); std::string const& libName = *s; diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 6775f9d..60b746c 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -165,14 +165,14 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem) { typename InputRange::const_iterator remIt = rem.begin(); typename InputRange::const_iterator remEnd = rem.end(); - const typename Range::iterator rangeEnd = r.end(); + const auto rangeEnd = r.end(); if (remIt == remEnd) { return rangeEnd; } - typename Range::iterator writer = r.begin(); + auto writer = r.begin(); std::advance(writer, *remIt); - typename Range::iterator pivot = writer; + auto pivot = writer; typename InputRange::value_type prevRem = *remIt; ++remIt; size_t count = 1; diff --git a/Source/cmBuildCommand.cxx b/Source/cmBuildCommand.cxx index e9e1d49..49c9439 100644 --- a/Source/cmBuildCommand.cxx +++ b/Source/cmBuildCommand.cxx @@ -2,32 +2,21 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmBuildCommand.h" -#include <sstream> - +#include "cmExecutionStatus.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmStateTypes.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; - -bool cmBuildCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) -{ - // Support the legacy signature of the command: - // - if (2 == args.size()) { - return this->TwoArgsSignature(args); - } - - return this->MainSignature(args); -} +namespace { -bool cmBuildCommand::MainSignature(std::vector<std::string> const& args) +bool MainSignature(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("requires at least one argument naming a CMake variable"); + status.SetError("requires at least one argument naming a CMake variable"); return false; } @@ -63,9 +52,7 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args) doing = DoingNone; target = args[i]; } else { - std::ostringstream e; - e << "unknown argument \"" << args[i] << "\""; - this->SetError(e.str()); + status.SetError(cmStrCat("unknown argument \"", args[i], "\"")); return false; } } @@ -82,30 +69,32 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args) configuration = "Release"; } + cmMakefile& mf = status.GetMakefile(); if (!project_name.empty()) { - this->Makefile->IssueMessage( - MessageType::AUTHOR_WARNING, - "Ignoring PROJECT_NAME option because it has no effect."); + mf.IssueMessage(MessageType::AUTHOR_WARNING, + "Ignoring PROJECT_NAME option because it has no effect."); } - std::string makecommand = - this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand( - target, configuration, "", this->Makefile->IgnoreErrorsCMP0061()); + std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand( + target, configuration, "", mf.IgnoreErrorsCMP0061()); - this->Makefile->AddDefinition(variable, makecommand); + mf.AddDefinition(variable, makecommand); return true; } -bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args) +bool TwoArgsSignature(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with less than two arguments"); + status.SetError("called with less than two arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + std::string const& define = args[0]; - const char* cacheValue = this->Makefile->GetDefinition(define); + const char* cacheValue = mf.GetDefinition(define); std::string configType; if (!cmSystemTools::GetEnv("CMAKE_CONFIG_TYPE", configType) || @@ -113,16 +102,28 @@ bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args) configType = "Release"; } - std::string makecommand = - this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand( - "", configType, "", this->Makefile->IgnoreErrorsCMP0061()); + std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand( + "", configType, "", mf.IgnoreErrorsCMP0061()); if (cacheValue) { return true; } - this->Makefile->AddCacheDefinition(define, makecommand.c_str(), - "Command used to build entire project " - "from the command line.", - cmStateEnums::STRING); + mf.AddCacheDefinition(define, makecommand.c_str(), + "Command used to build entire project " + "from the command line.", + cmStateEnums::STRING); return true; } + +} // namespace + +bool cmBuildCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + // Support the legacy signature of the command: + if (args.size() == 2) { + return TwoArgsSignature(args, status); + } + + return MainSignature(args, status); +} diff --git a/Source/cmBuildCommand.h b/Source/cmBuildCommand.h index d373103..45aa71d 100644 --- a/Source/cmBuildCommand.h +++ b/Source/cmBuildCommand.h @@ -8,47 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmBuildCommand - * \brief build_command command - * - * cmBuildCommand implements the build_command CMake command - */ -class cmBuildCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmBuildCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - - /** - * The primary command signature with optional, KEYWORD-based args. - */ - virtual bool MainSignature(std::vector<std::string> const& args); - - /** - * Legacy "exactly 2 args required" signature. - */ - virtual bool TwoArgsSignature(std::vector<std::string> const& args); - -private: - bool IgnoreErrors() const; -}; +bool cmBuildCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index e814d67..f19d99b 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -531,7 +531,7 @@ void CCONV* cmGetSource(void* arg, const char* name) cmMakefile* mf = static_cast<cmMakefile*>(arg); if (cmSourceFile* rsf = mf->GetSource(name)) { // Lookup the proxy source file object for this source. - cmCPluginAPISourceFileMap::iterator i = cmCPluginAPISourceFiles.find(rsf); + auto i = cmCPluginAPISourceFiles.find(rsf); if (i == cmCPluginAPISourceFiles.end()) { // Create a proxy source file object for this source. cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile; diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index f51ed0b..cd54770 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1483,8 +1483,7 @@ std::vector<std::string> cmCTest::GetLabelsForSubprojects() // sort the array std::sort(subprojects.begin(), subprojects.end()); // remove duplicates - std::vector<std::string>::iterator new_end = - std::unique(subprojects.begin(), subprojects.end()); + auto new_end = std::unique(subprojects.begin(), subprojects.end()); subprojects.erase(new_end, subprojects.end()); return subprojects; diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index cf28cdb..e28107f 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -480,7 +480,7 @@ void cmCacheManager::OutputNewlineTruncationWarning(std::ostream& fout, void cmCacheManager::RemoveCacheEntry(const std::string& key) { - CacheEntryMap::iterator i = this->Cache.find(key); + auto i = this->Cache.find(key); if (i != this->Cache.end()) { this->Cache.erase(i); } @@ -489,7 +489,7 @@ void cmCacheManager::RemoveCacheEntry(const std::string& key) cmCacheManager::CacheEntry* cmCacheManager::GetCacheEntry( const std::string& key) { - CacheEntryMap::iterator i = this->Cache.find(key); + auto i = this->Cache.find(key); if (i != this->Cache.end()) { return &i->second; } @@ -498,13 +498,13 @@ cmCacheManager::CacheEntry* cmCacheManager::GetCacheEntry( cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char* key) { - return CacheIterator(*this, key); + return { *this, key }; } const std::string* cmCacheManager::GetInitializedCacheValue( const std::string& key) const { - CacheEntryMap::const_iterator i = this->Cache.find(key); + auto i = this->Cache.find(key); if (i != this->Cache.end() && i->second.Initialized) { return &i->second.Value; } diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index a988bd8..faa60c5 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -94,7 +94,7 @@ public: }; //! return an iterator to iterate through the cache map - cmCacheManager::CacheIterator NewIterator() { return CacheIterator(*this); } + cmCacheManager::CacheIterator NewIterator() { return { *this }; } //! Load a cache for given makefile. Loads from path/CMakeCache.txt. bool LoadCache(const std::string& path, bool internal, diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 702b743..38fcf5b 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -125,14 +125,11 @@ void GetScriptingCommands(cmState* state) state->AddBuiltinCommand("exec_program", cmExecProgramCommand); state->AddBuiltinCommand("execute_process", cmExecuteProcessCommand); state->AddBuiltinCommand("file", 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("find_file", cmFindFile); + state->AddBuiltinCommand("find_library", cmFindLibrary); + state->AddBuiltinCommand("find_package", cmFindPackage); + state->AddBuiltinCommand("find_path", cmFindPath); + state->AddBuiltinCommand("find_program", cmFindProgram); state->AddBuiltinCommand("foreach", cmForEachCommand); state->AddBuiltinCommand("function", cmFunctionCommand); state->AddBuiltinCommand("get_cmake_property", cmGetCMakePropertyCommand); @@ -225,41 +222,32 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("add_library", cmAddLibraryCommand); state->AddBuiltinCommand("add_subdirectory", cmAddSubDirectoryCommand); state->AddBuiltinCommand("add_test", cmAddTestCommand); - state->AddBuiltinCommand("build_command", cm::make_unique<cmBuildCommand>()); - state->AddBuiltinCommand("create_test_sourcelist", - cm::make_unique<cmCreateTestSourceList>()); - state->AddBuiltinCommand("define_property", - cm::make_unique<cmDefinePropertyCommand>()); - state->AddBuiltinCommand("enable_language", - cm::make_unique<cmEnableLanguageCommand>()); + state->AddBuiltinCommand("build_command", cmBuildCommand); + state->AddBuiltinCommand("create_test_sourcelist", cmCreateTestSourceList); + state->AddBuiltinCommand("define_property", cmDefinePropertyCommand); + state->AddBuiltinCommand("enable_language", cmEnableLanguageCommand); state->AddBuiltinCommand("enable_testing", cmEnableTestingCommand); state->AddBuiltinCommand("get_source_file_property", - cm::make_unique<cmGetSourceFilePropertyCommand>()); - state->AddBuiltinCommand("get_target_property", - cm::make_unique<cmGetTargetPropertyCommand>()); - state->AddBuiltinCommand("get_test_property", - cm::make_unique<cmGetTestPropertyCommand>()); + cmGetSourceFilePropertyCommand); + state->AddBuiltinCommand("get_target_property", cmGetTargetPropertyCommand); + state->AddBuiltinCommand("get_test_property", cmGetTestPropertyCommand); state->AddBuiltinCommand("include_directories", cm::make_unique<cmIncludeDirectoryCommand>()); - state->AddBuiltinCommand( - "include_regular_expression", - cm::make_unique<cmIncludeRegularExpressionCommand>()); + state->AddBuiltinCommand("include_regular_expression", + 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("install_files", cmInstallFilesCommand); + state->AddBuiltinCommand("install_targets", 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_source_files_properties", + cmSetSourceFilesPropertiesCommand); state->AddBuiltinCommand("set_target_properties", cm::make_unique<cmSetTargetPropertiesCommand>()); state->AddBuiltinCommand("set_tests_properties", - cm::make_unique<cmSetTestsPropertiesCommand>()); - state->AddBuiltinCommand("subdirs", cm::make_unique<cmSubdirCommand>()); + cmSetTestsPropertiesCommand); + state->AddBuiltinCommand("subdirs", cmSubdirCommand); state->AddBuiltinCommand( "target_compile_definitions", cm::make_unique<cmTargetCompileDefinitionsCommand>()); @@ -288,27 +276,21 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("aux_source_directory", 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("fltk_wrap_ui", cmFLTKWrapUICommand); + state->AddBuiltinCommand("include_external_msproject", + cmIncludeExternalMSProjectCommand); + state->AddBuiltinCommand("install_programs", cmInstallProgramsCommand); state->AddBuiltinCommand("add_link_options", cmAddLinkOptionsCommand); - state->AddBuiltinCommand("link_libraries", - cm::make_unique<cmLinkLibrariesCommand>()); + state->AddBuiltinCommand("link_libraries", cmLinkLibrariesCommand); state->AddBuiltinCommand("target_link_options", cm::make_unique<cmTargetLinkOptionsCommand>()); state->AddBuiltinCommand("target_link_directories", 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", - cm::make_unique<cmRemoveDefinitionsCommand>()); + state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand); + state->AddBuiltinCommand("qt_wrap_ui", cmQTWrapUICommand); + state->AddBuiltinCommand("remove_definitions", cmRemoveDefinitionsCommand); state->AddBuiltinCommand("source_group", cm::make_unique<cmSourceGroupCommand>()); diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index 54443f2..33286ad 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -96,7 +96,7 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags( std::string cmCommonTargetGenerator::GetFlags(const std::string& l) { - ByLanguageMap::iterator i = this->FlagsByLanguage.find(l); + auto i = this->FlagsByLanguage.find(l); if (i == this->FlagsByLanguage.end()) { std::string flags; @@ -111,7 +111,7 @@ std::string cmCommonTargetGenerator::GetFlags(const std::string& l) std::string cmCommonTargetGenerator::GetDefines(const std::string& l) { - ByLanguageMap::iterator i = this->DefinesByLanguage.find(l); + auto i = this->DefinesByLanguage.find(l); if (i == this->DefinesByLanguage.end()) { std::set<std::string> defines; this->LocalCommonGenerator->GetTargetDefines(this->GeneratorTarget, @@ -128,7 +128,7 @@ std::string cmCommonTargetGenerator::GetDefines(const std::string& l) std::string cmCommonTargetGenerator::GetIncludes(std::string const& l) { - ByLanguageMap::iterator i = this->IncludesByLanguage.find(l); + auto i = this->IncludesByLanguage.find(l); if (i == this->IncludesByLanguage.end()) { std::string includes; this->AddIncludeFlags(includes, l); diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index a39425c..15b0087 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -283,8 +283,7 @@ std::map<cmLinkItem, int>::iterator cmComputeLinkDepends::AllocateLinkEntry( { std::map<cmLinkItem, int>::value_type index_entry( item, static_cast<int>(this->EntryList.size())); - std::map<cmLinkItem, int>::iterator lei = - this->LinkEntryIndex.insert(index_entry).first; + auto lei = this->LinkEntryIndex.insert(index_entry).first; this->EntryList.emplace_back(); this->InferredDependSets.push_back(nullptr); this->EntryConstraintGraph.emplace_back(); @@ -294,7 +293,7 @@ std::map<cmLinkItem, int>::iterator cmComputeLinkDepends::AllocateLinkEntry( int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item) { // Check if the item entry has already been added. - std::map<cmLinkItem, int>::iterator lei = this->LinkEntryIndex.find(item); + auto lei = this->LinkEntryIndex.find(item); if (lei != this->LinkEntryIndex.end()) { // Yes. We do not need to follow the item's dependencies again. return lei->second; @@ -394,8 +393,7 @@ void cmComputeLinkDepends::QueueSharedDependencies( void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep) { // Check if the target already has an entry. - std::map<cmLinkItem, int>::iterator lei = - this->LinkEntryIndex.find(dep.Item); + auto lei = this->LinkEntryIndex.find(dep.Item); if (lei == this->LinkEntryIndex.end()) { // Allocate a spot for the item entry. lei = this->AllocateLinkEntry(dep.Item); @@ -719,8 +717,7 @@ void cmComputeLinkDepends::VisitEntry(int index) // This entry has now been seen. Update its component. bool completed = false; int component = this->CCG->GetComponentMap()[index]; - std::map<int, PendingComponent>::iterator mi = - this->PendingComponents.find(this->ComponentOrder[component]); + auto mi = this->PendingComponents.find(this->ComponentOrder[component]); if (mi != this->PendingComponents.end()) { // The entry is in an already pending component. PendingComponent& pc = mi->second; diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index dd8d246..ade0f87 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1332,8 +1332,7 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item, std::string const& file) { // Do not depend on things that do not exist. - std::vector<std::string>::iterator i = - std::find(this->Depends.begin(), this->Depends.end(), item); + auto i = std::find(this->Depends.begin(), this->Depends.end(), item); if (i != this->Depends.end()) { this->Depends.erase(i); } diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index 6bf2f2d..de82782 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -140,8 +140,7 @@ void cmComputeTargetDepends::GetTargetDirectDepends(cmGeneratorTarget const* t, { // Lookup the index for this target. All targets should be known by // this point. - std::map<cmGeneratorTarget const*, int>::const_iterator tii = - this->TargetIndex.find(t); + auto tii = this->TargetIndex.find(t); assert(tii != this->TargetIndex.end()); int i = tii->second; @@ -149,7 +148,7 @@ void cmComputeTargetDepends::GetTargetDirectDepends(cmGeneratorTarget const* t, EdgeList const& nl = this->FinalGraph[i]; for (cmGraphEdge const& ni : nl) { cmGeneratorTarget const* dep = this->Targets[ni]; - cmTargetDependSet::iterator di = deps.insert(dep).first; + auto di = deps.insert(dep).first; di->SetType(ni.IsStrong()); di->SetBacktrace(ni.GetBacktrace()); } @@ -368,8 +367,7 @@ void cmComputeTargetDepends::AddTargetDepend( } else { // Lookup the index for this target. All targets should be known by // this point. - std::map<cmGeneratorTarget const*, int>::const_iterator tii = - this->TargetIndex.find(dependee); + auto tii = this->TargetIndex.find(dependee); assert(tii != this->TargetIndex.end()); int dependee_index = tii->second; diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 21df278..97469be 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -367,7 +367,7 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs, int reducible; do { reducible = 0; - cmArgumentList::iterator arg = newArgs.begin(); + auto arg = newArgs.begin(); while (arg != newArgs.end()) { if (IsKeyword(keyParenL, *arg)) { // search for the closing paren for this opening one @@ -393,7 +393,7 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs, std::vector<cmExpandedCommandArgument> newArgs2; // copy to the list structure - cmArgumentList::iterator argP1 = arg; + auto argP1 = arg; argP1++; cmAppend(newArgs2, argP1, argClose); newArgs2.pop_back(); @@ -424,7 +424,7 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&, int reducible; do { reducible = 0; - cmArgumentList::iterator arg = newArgs.begin(); + auto arg = newArgs.begin(); cmArgumentList::iterator argP1; cmArgumentList::iterator argP2; while (arg != newArgs.end()) { @@ -524,7 +524,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, const char* def2; do { reducible = 0; - cmArgumentList::iterator arg = newArgs.begin(); + auto arg = newArgs.begin(); cmArgumentList::iterator argP1; cmArgumentList::iterator argP2; while (arg != newArgs.end()) { @@ -700,7 +700,7 @@ bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs, int reducible; do { reducible = 0; - cmArgumentList::iterator arg = newArgs.begin(); + auto arg = newArgs.begin(); cmArgumentList::iterator argP1; cmArgumentList::iterator argP2; while (arg != newArgs.end()) { @@ -728,7 +728,7 @@ bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs, bool rhs; do { reducible = 0; - cmArgumentList::iterator arg = newArgs.begin(); + auto arg = newArgs.begin(); cmArgumentList::iterator argP1; cmArgumentList::iterator argP2; while (arg != newArgs.end()) { diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx index 4a1825f..9d492ba 100644 --- a/Source/cmCreateTestSourceList.cxx +++ b/Source/cmCreateTestSourceList.cxx @@ -4,23 +4,21 @@ #include <algorithm> +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; - -// cmCreateTestSourceList -bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmCreateTestSourceList(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 3) { - this->SetError("called with wrong number of arguments."); + status.SetError("called with wrong number of arguments."); return false; } - std::vector<std::string>::const_iterator i = args.begin(); + auto i = args.begin(); std::string extraInclude; std::string function; std::vector<std::string> tests; @@ -29,14 +27,14 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, if (*i == "EXTRA_INCLUDE") { ++i; if (i == args.end()) { - this->SetError("incorrect arguments to EXTRA_INCLUDE"); + status.SetError("incorrect arguments to EXTRA_INCLUDE"); return false; } extraInclude = cmStrCat("#include \"", *i, "\"\n"); } else if (*i == "FUNCTION") { ++i; if (i == args.end()) { - this->SetError("incorrect arguments to FUNCTION"); + status.SetError("incorrect arguments to FUNCTION"); return false; } function = cmStrCat(*i, "(&ac, &av);\n"); @@ -54,12 +52,12 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, // Name of the test driver // make sure they specified an extension if (cmSystemTools::GetFilenameExtension(*i).size() < 2) { - this->SetError( + status.SetError( "You must specify a file extension for the test driver file."); return false; } - std::string driver = - cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', *i); + cmMakefile& mf = status.GetMakefile(); + std::string driver = cmStrCat(mf.GetCurrentBinaryDirectory(), '/', *i); ++i; std::string configFile = cmSystemTools::GetCMakeRoot(); @@ -67,7 +65,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, configFile += "/Templates/TestDriver.cxx.in"; // Create the test driver file - std::vector<std::string>::const_iterator testsBegin = i; + auto testsBegin = i; std::vector<std::string> tests_func_name; // The rest of the arguments consist of a list of test source files. @@ -121,35 +119,32 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, numTests++; } if (!extraInclude.empty()) { - this->Makefile->AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES", - extraInclude); + mf.AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES", extraInclude); } if (!function.empty()) { - this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION", function); + mf.AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION", function); } - this->Makefile->AddDefinition("CMAKE_FORWARD_DECLARE_TESTS", - forwardDeclareCode); - this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES", - functionMapCode); + mf.AddDefinition("CMAKE_FORWARD_DECLARE_TESTS", forwardDeclareCode); + mf.AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES", functionMapCode); bool res = true; - if (!this->Makefile->ConfigureFile(configFile, driver, false, true, false)) { + if (!mf.ConfigureFile(configFile, driver, false, true, false)) { res = false; } // Construct the source list. std::string sourceListValue; { - cmSourceFile* sf = this->Makefile->GetOrCreateSource(driver); + cmSourceFile* sf = mf.GetOrCreateSource(driver); sf->SetProperty("ABSTRACT", "0"); sourceListValue = args[1]; } for (i = testsBegin; i != tests.end(); ++i) { - cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i); + cmSourceFile* sf = mf.GetOrCreateSource(*i); sf->SetProperty("ABSTRACT", "0"); sourceListValue += ";"; sourceListValue += *i; } - this->Makefile->AddDefinition(sourceList, sourceListValue); + mf.AddDefinition(sourceList, sourceListValue); return res; } diff --git a/Source/cmCreateTestSourceList.h b/Source/cmCreateTestSourceList.h index 5aa6af4..19503f4 100644 --- a/Source/cmCreateTestSourceList.h +++ b/Source/cmCreateTestSourceList.h @@ -8,34 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmCreateTestSourceList - * \brief Test driver generation command - * - */ - -class cmCreateTestSourceList : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmCreateTestSourceList>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmCreateTestSourceList(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmDefinePropertyCommand.cxx b/Source/cmDefinePropertyCommand.cxx index 86a83da..f4e4fda 100644 --- a/Source/cmDefinePropertyCommand.cxx +++ b/Source/cmDefinePropertyCommand.cxx @@ -2,19 +2,17 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmDefinePropertyCommand.h" -#include <sstream> - +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmProperty.h" #include "cmState.h" +#include "cmStringAlgorithms.h" -class cmExecutionStatus; - -bool cmDefinePropertyCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmDefinePropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } @@ -37,17 +35,17 @@ bool cmDefinePropertyCommand::InitialPass(std::vector<std::string> const& args, } else if (scope_arg == "CACHED_VARIABLE") { scope = cmProperty::CACHED_VARIABLE; } else { - std::ostringstream e; - e << "given invalid scope " << scope_arg << ". " - << "Valid scopes are " - << "GLOBAL, DIRECTORY, TARGET, SOURCE, " - << "TEST, VARIABLE, CACHED_VARIABLE."; - this->SetError(e.str()); + status.SetError(cmStrCat("given invalid scope ", scope_arg, + ". Valid scopes are GLOBAL, DIRECTORY, TARGET, " + "SOURCE, TEST, VARIABLE, CACHED_VARIABLE.")); return false; } // Parse remaining arguments. bool inherited = false; + std::string PropertyName; + std::string BriefDocs; + std::string FullDocs; enum Doing { DoingNone, @@ -68,39 +66,36 @@ bool cmDefinePropertyCommand::InitialPass(std::vector<std::string> const& args, inherited = true; } else if (doing == DoingProperty) { doing = DoingNone; - this->PropertyName = args[i]; + PropertyName = args[i]; } else if (doing == DoingBrief) { - this->BriefDocs += args[i]; + BriefDocs += args[i]; } else if (doing == DoingFull) { - this->FullDocs += args[i]; + FullDocs += args[i]; } else { - std::ostringstream e; - e << "given invalid argument \"" << args[i] << "\"."; - this->SetError(e.str()); + status.SetError(cmStrCat("given invalid argument \"", args[i], "\".")); return false; } } // Make sure a property name was found. - if (this->PropertyName.empty()) { - this->SetError("not given a PROPERTY <name> argument."); + if (PropertyName.empty()) { + status.SetError("not given a PROPERTY <name> argument."); return false; } // Make sure documentation was given. - if (this->BriefDocs.empty()) { - this->SetError("not given a BRIEF_DOCS <brief-doc> argument."); + if (BriefDocs.empty()) { + status.SetError("not given a BRIEF_DOCS <brief-doc> argument."); return false; } - if (this->FullDocs.empty()) { - this->SetError("not given a FULL_DOCS <full-doc> argument."); + if (FullDocs.empty()) { + status.SetError("not given a FULL_DOCS <full-doc> argument."); return false; } // Actually define the property. - this->Makefile->GetState()->DefineProperty( - this->PropertyName, scope, this->BriefDocs.c_str(), this->FullDocs.c_str(), - inherited); + status.GetMakefile().GetState()->DefineProperty( + PropertyName, scope, BriefDocs.c_str(), FullDocs.c_str(), inherited); return true; } diff --git a/Source/cmDefinePropertyCommand.h b/Source/cmDefinePropertyCommand.h index 36f97df..60dd76a 100644 --- a/Source/cmDefinePropertyCommand.h +++ b/Source/cmDefinePropertyCommand.h @@ -8,31 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmDefinePropertyCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmDefinePropertyCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -private: - std::string PropertyName; - std::string BriefDocs; - std::string FullDocs; -}; +bool cmDefinePropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index 06a442b..e8f6faf 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -33,8 +33,7 @@ bool cmDepends::Write(std::ostream& makeDepends, std::ostream& internalDepends) cmMakefile* mf = this->LocalGenerator->GetMakefile(); cmExpandList(mf->GetSafeDefinition(srcLang), pairs); } - for (std::vector<std::string>::iterator si = pairs.begin(); - si != pairs.end();) { + for (auto si = pairs.begin(); si != pairs.end();) { // Get the source and object file. std::string const& src = *si++; if (si == pairs.end()) { diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx index 0f9f166..a380b41 100644 --- a/Source/cmDependsC.cxx +++ b/Source/cmDependsC.cxx @@ -438,8 +438,7 @@ void cmDependsC::TransformLine(std::string& line) if (!this->IncludeRegexTransform.find(line)) { return; } - TransformRulesType::const_iterator tri = - this->TransformRules.find(this->IncludeRegexTransform.match(3)); + auto tri = this->TransformRules.find(this->IncludeRegexTransform.match(3)); if (tri == this->TransformRules.end()) { return; } diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index c30e0bf..b657ff7 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -56,8 +56,7 @@ public: cmFortranSourceInfo& CreateObjectInfo(const std::string& obj, const std::string& src) { - std::map<std::string, cmFortranSourceInfo>::iterator i = - this->ObjectInfo.find(obj); + auto i = this->ObjectInfo.find(obj); if (i == this->ObjectInfo.end()) { std::map<std::string, cmFortranSourceInfo>::value_type entry( obj, cmFortranSourceInfo()); @@ -303,9 +302,7 @@ void cmDependsFortran::ConsiderModule(const std::string& name, const std::string& stampDir) { // Locate each required module. - using TargetRequiresMap = cmDependsFortranInternals::TargetRequiresMap; - TargetRequiresMap::iterator required = - this->Internal->TargetRequires.find(name); + auto required = this->Internal->TargetRequires.find(name); if (required != this->Internal->TargetRequires.end() && required->second.empty()) { // The module is provided by a CMake target. It will have a stamp file. @@ -321,8 +318,6 @@ bool cmDependsFortran::WriteDependenciesReal(std::string const& obj, std::ostream& makeDepends, std::ostream& internalDepends) { - using TargetRequiresMap = cmDependsFortranInternals::TargetRequiresMap; - // Get the source file for this object. std::string const& src = info.Source; @@ -350,8 +345,7 @@ bool cmDependsFortran::WriteDependenciesReal(std::string const& obj, // The object file should depend on timestamped files for the // modules it uses. - TargetRequiresMap::const_iterator required = - this->Internal->TargetRequires.find(i); + auto required = this->Internal->TargetRequires.find(i); if (required == this->Internal->TargetRequires.end()) { abort(); } diff --git a/Source/cmDynamicLoader.cxx b/Source/cmDynamicLoader.cxx index 0549cf9..0b72a94 100644 --- a/Source/cmDynamicLoader.cxx +++ b/Source/cmDynamicLoader.cxx @@ -39,8 +39,7 @@ void cmDynamicLoaderCache::CacheFile(const char* path, bool cmDynamicLoaderCache::GetCacheFile(const char* path, cmsys::DynamicLoader::LibraryHandle& p) { - std::map<std::string, cmsys::DynamicLoader::LibraryHandle>::iterator it = - this->CacheMap.find(path); + auto it = this->CacheMap.find(path); if (it != this->CacheMap.end()) { p = it->second; return true; @@ -50,8 +49,7 @@ bool cmDynamicLoaderCache::GetCacheFile(const char* path, bool cmDynamicLoaderCache::FlushCache(const char* path) { - std::map<std::string, cmsys::DynamicLoader::LibraryHandle>::iterator it = - this->CacheMap.find(path); + auto it = this->CacheMap.find(path); bool ret = false; if (it != this->CacheMap.end()) { cmsys::DynamicLoader::CloseLibrary(it->second); diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index 648a900..90250b6 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -585,8 +585,7 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString( unsigned int tag) { // Short-circuit if already checked. - std::map<unsigned int, StringEntry>::iterator dssi = - this->DynamicSectionStrings.find(tag); + auto dssi = this->DynamicSectionStrings.find(tag); if (dssi != this->DynamicSectionStrings.end()) { if (dssi->second.Position > 0) { return &dssi->second; @@ -614,8 +613,7 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString( ELF_Shdr const& strtab = this->SectionHeaders[sec.sh_link]; // Look for the requested entry. - for (typename std::vector<ELF_Dyn>::iterator di = - this->DynamicSectionEntries.begin(); + for (auto di = this->DynamicSectionEntries.begin(); di != this->DynamicSectionEntries.end(); ++di) { ELF_Dyn& dyn = *di; if (static_cast<tagtype>(dyn.d_tag) == static_cast<tagtype>(tag)) { diff --git a/Source/cmEnableLanguageCommand.cxx b/Source/cmEnableLanguageCommand.cxx index ddd26de..59522c0 100644 --- a/Source/cmEnableLanguageCommand.cxx +++ b/Source/cmEnableLanguageCommand.cxx @@ -2,20 +2,19 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmEnableLanguageCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" -class cmExecutionStatus; - -// cmEnableLanguageCommand -bool cmEnableLanguageCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmEnableLanguageCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { - bool optional = false; - std::vector<std::string> languages; if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + + bool optional = false; + std::vector<std::string> languages; for (std::string const& it : args) { if (it == "OPTIONAL") { optional = true; @@ -24,6 +23,6 @@ bool cmEnableLanguageCommand::InitialPass(std::vector<std::string> const& args, } } - this->Makefile->EnableLanguage(languages, optional); + status.GetMakefile().EnableLanguage(languages, optional); return true; } diff --git a/Source/cmEnableLanguageCommand.h b/Source/cmEnableLanguageCommand.h index dc43e34..1f8c4ce 100644 --- a/Source/cmEnableLanguageCommand.h +++ b/Source/cmEnableLanguageCommand.h @@ -8,37 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmEnableLanguageCommand - * \brief Specify the name for this build project. - * - * cmEnableLanguageCommand is used to specify a name for this build project. - * It is defined once per set of CMakeList.txt files (including - * all subdirectories). Currently it just sets the name of the workspace - * file for Microsoft Visual C++ - */ -class cmEnableLanguageCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmEnableLanguageCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmEnableLanguageCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 9f0396b..e9d2412 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -311,7 +311,7 @@ cmExportBuildFileGenerator::FindBuildExportInfo(cmGlobalGenerator* gg, } } - return std::make_pair(exportFiles, ns); + return { exportFiles, ns }; } void cmExportBuildFileGenerator::ComplainAboutMissingTarget( diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 70f98bf..9545814 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -1185,7 +1185,7 @@ void cmExportFileGenerator::GenerateImportedFileChecksCode( << targetName << " "; for (std::string const& li : importedLocations) { - ImportPropertyMap::const_iterator pi = properties.find(li); + auto pi = properties.find(li); if (pi != properties.end()) { os << cmExportFileGeneratorEscape(pi->second) << " "; } diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index e7f301e..4e3db09 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -496,7 +496,7 @@ cmExportInstallFileGenerator::FindNamespaces(cmGlobalGenerator* gg, } } - return std::make_pair(exportFiles, ns); + return { exportFiles, ns }; } void cmExportInstallFileGenerator::ComplainAboutMissingTarget( diff --git a/Source/cmExportSetMap.cxx b/Source/cmExportSetMap.cxx index 293e80c..5c3f84f 100644 --- a/Source/cmExportSetMap.cxx +++ b/Source/cmExportSetMap.cxx @@ -9,7 +9,7 @@ cmExportSet* cmExportSetMap::operator[](const std::string& name) { - std::map<std::string, cmExportSet*>::iterator it = this->find(name); + auto it = this->find(name); if (it == this->end()) // Export set not found { it = this->insert(std::make_pair(name, new cmExportSet(name))).first; diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 5a9c54c..5a5d959 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -573,8 +573,7 @@ void cmExtraCodeBlocksGenerator::AppendTarget( cmAppend(allIncludeDirs, cmExpandedList(systemIncludeDirs)); } - std::vector<std::string>::const_iterator end = - cmRemoveDuplicates(allIncludeDirs); + auto end = cmRemoveDuplicates(allIncludeDirs); for (std::string const& str : cmMakeRange(allIncludeDirs.cbegin(), end)) { xml.StartElement("Add"); diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index 0956729..5a01eb2 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -307,7 +307,7 @@ void cmExtraCodeLiteGenerator::FindMatchingHeaderfiles( for (std::string const& ext : headerExts) { std::string hname = cmStrCat(headerBasename, '.', ext); // if it's already in the set, don't check if it exists on disk - std::set<std::string>::const_iterator headerIt = otherFiles.find(hname); + auto headerIt = otherFiles.find(hname); if (headerIt != otherFiles.end()) { break; } diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 43f1e12..d398018 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -800,7 +800,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const // the list must contain only definition-value pairs: if ((defs.size() % 2) == 0) { - std::vector<std::string>::const_iterator di = defs.begin(); + auto di = defs.begin(); while (di != defs.end()) { std::string def = *di; ++di; @@ -832,7 +832,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const // the list must contain only definition-value pairs: if ((defs.size() % 2) == 0) { - std::vector<std::string>::const_iterator di = defs.begin(); + auto di = defs.begin(); while (di != defs.end()) { std::string def = *di; ++di; diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 52ba968..6ad8609 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -242,7 +242,7 @@ void cmExtraSublimeTextGenerator::AppendTarget( target->GetSourceFiles(sourceFiles, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); for (cmSourceFile* sourceFile : sourceFiles) { - MapSourceFileFlags::iterator sourceFileFlagsIter = + auto sourceFileFlagsIter = sourceFileFlags.find(sourceFile->ResolveFullPath()); if (sourceFileFlagsIter == sourceFileFlags.end()) { sourceFileFlagsIter = diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index ea9e672..5094c3c 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -5,13 +5,13 @@ #include <stddef.h> #include "cmCustomCommandLines.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; class cmTarget; static void FinalAction(cmMakefile& makefile, std::string const& name) @@ -30,39 +30,40 @@ static void FinalAction(cmMakefile& makefile, std::string const& name) } } -// cmFLTKWrapUICommand -bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmFLTKWrapUICommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // what is the current source dir - std::string cdir = this->Makefile->GetCurrentSourceDirectory(); + std::string cdir = mf.GetCurrentSourceDirectory(); std::string const& fluid_exe = - this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE"); + mf.GetRequiredDefinition("FLTK_FLUID_EXECUTABLE"); // 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(); + std::string outputDirectory = mf.GetCurrentBinaryDirectory(); { // Some of the generated files are *.h so the directory "GUI" // where they are created have to be added to the include path std::vector<std::string> outputDirectories; outputDirectories.push_back(outputDirectory); - this->Makefile->AddIncludeDirectories(outputDirectories); + mf.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); + cmSourceFile* curr = mf.GetSource(arg); // if we should use the source GUI // to generate .cxx and .h files if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE")) { @@ -91,14 +92,12 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, std::string no_main_dependency; const char* no_comment = nullptr; const char* no_working_dir = nullptr; - this->Makefile->AddCustomCommandToOutput( - cxxres, depends, no_main_dependency, commandLines, no_comment, - no_working_dir); - this->Makefile->AddCustomCommandToOutput( - hname, depends, no_main_dependency, commandLines, no_comment, - no_working_dir); - - cmSourceFile* sf = this->Makefile->GetSource(cxxres); + mf.AddCustomCommandToOutput(cxxres, depends, no_main_dependency, + commandLines, no_comment, no_working_dir); + mf.AddCustomCommandToOutput(hname, depends, no_main_dependency, + commandLines, no_comment, no_working_dir); + + cmSourceFile* sf = mf.GetSource(cxxres); sf->AddDepend(hname); sf->AddDepend(origname); generatedSourcesClasses.push_back(sf); @@ -116,9 +115,9 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, } std::string const varName = target + "_FLTK_UI_SRCS"; - this->Makefile->AddDefinition(varName, sourceListValue); + mf.AddDefinition(varName, sourceListValue); - this->Makefile->AddFinalAction( + mf.AddFinalAction( [target](cmMakefile& makefile) { FinalAction(makefile, target); }); return true; } diff --git a/Source/cmFLTKWrapUICommand.h b/Source/cmFLTKWrapUICommand.h index ea8d401..bb56dbd 100644 --- a/Source/cmFLTKWrapUICommand.h +++ b/Source/cmFLTKWrapUICommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmFLTKWrapUICommand - * \brief Create .h and .cxx files rules for FLTK user interfaces files - * - * cmFLTKWrapUICommand is used to create wrappers for FLTK classes into - * normal C++ - */ -class cmFLTKWrapUICommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmFLTKWrapUICommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmFLTKWrapUICommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 3ac769c..e33ba2d 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -802,9 +802,13 @@ void Target::ProcessLanguage(std::string const& lang) { // FIXME: Add flags from end section of ExpandRuleVariable, // which may need to be factored out. - std::string flags; - lg->GetTargetCompileFlags(this->GT, this->Config, lang, flags); - cd.Flags.emplace_back(std::move(flags), JBTIndex()); + std::vector<BT<std::string>> flags = + lg->GetTargetCompileFlags(this->GT, this->Config, lang); + + cd.Flags.reserve(flags.size()); + for (const BT<std::string>& f : flags) { + cd.Flags.emplace_back(this->ToJBT(f)); + } } std::set<BT<std::string>> defines = lg->GetTargetDefines(this->GT, this->Config, lang); @@ -823,8 +827,7 @@ void Target::ProcessLanguage(std::string const& lang) Json::ArrayIndex Target::AddSourceGroup(cmSourceGroup* sg, Json::ArrayIndex si) { - std::unordered_map<cmSourceGroup const*, Json::ArrayIndex>::iterator i = - this->SourceGroupsMap.find(sg); + auto i = this->SourceGroupsMap.find(sg); if (i == this->SourceGroupsMap.end()) { auto sgIndex = static_cast<Json::ArrayIndex>(this->SourceGroups.size()); i = this->SourceGroupsMap.emplace(sg, sgIndex).first; @@ -1264,7 +1267,7 @@ Json::Value Target::DumpLinkCommandFragments() Json::Value linkFragments = Json::arrayValue; std::string linkLanguageFlags; - std::string linkFlags; + std::vector<BT<std::string>> linkFlags; std::string frameworkPath; std::string linkPath; std::string linkLibs; @@ -1275,7 +1278,6 @@ Json::Value Target::DumpLinkCommandFragments() linkLanguageFlags, linkFlags, frameworkPath, linkPath, this->GT); linkLanguageFlags = cmTrimWhitespace(linkLanguageFlags); - linkFlags = cmTrimWhitespace(linkFlags); frameworkPath = cmTrimWhitespace(frameworkPath); linkPath = cmTrimWhitespace(linkPath); linkLibs = cmTrimWhitespace(linkLibs); @@ -1286,8 +1288,11 @@ Json::Value Target::DumpLinkCommandFragments() } if (!linkFlags.empty()) { - linkFragments.append( - this->DumpCommandFragment(std::move(linkFlags), "flags")); + for (BT<std::string> frag : linkFlags) { + frag.Value = cmTrimWhitespace(frag.Value); + linkFragments.append( + this->DumpCommandFragment(this->ToJBT(frag), "flags")); + } } if (!frameworkPath.empty()) { diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 36a7dc3..e8a7810 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -91,7 +91,7 @@ std::string fix_file_url_windows(const std::string& url) bool HandleWriteImpl(std::vector<std::string> const& args, bool append, cmExecutionStatus& status) { - std::vector<std::string>::const_iterator i = args.begin(); + auto i = args.begin(); i++; // Get rid of subcommand @@ -663,7 +663,7 @@ bool HandleGlobImpl(std::vector<std::string> const& args, bool recurse, // File commands has at least one argument assert(args.size() > 1); - std::vector<std::string>::const_iterator i = args.begin(); + auto i = args.begin(); i++; // Get rid of subcommand @@ -1585,7 +1585,7 @@ bool HandleDownloadCommand(std::vector<std::string> const& args, cmExecutionStatus& status) { #if !defined(CMAKE_BOOTSTRAP) - std::vector<std::string>::const_iterator i = args.begin(); + auto i = args.begin(); if (args.size() < 3) { status.SetError("DOWNLOAD must be called with at least three arguments."); return false; @@ -1955,7 +1955,7 @@ bool HandleUploadCommand(std::vector<std::string> const& args, status.SetError("UPLOAD must be called with at least three arguments."); return false; } - std::vector<std::string>::const_iterator i = args.begin(); + auto i = args.begin(); ++i; std::string filename = *i; ++i; diff --git a/Source/cmFileLockResult.cxx b/Source/cmFileLockResult.cxx index 9ca5d8a..c4779f0 100644 --- a/Source/cmFileLockResult.cxx +++ b/Source/cmFileLockResult.cxx @@ -8,7 +8,7 @@ #define WINMSG_BUF_LEN (1024) cmFileLockResult cmFileLockResult::MakeOk() { - return cmFileLockResult(OK, 0); + return { OK, 0 }; } cmFileLockResult cmFileLockResult::MakeSystem() @@ -18,27 +18,27 @@ cmFileLockResult cmFileLockResult::MakeSystem() #else const Error lastError = errno; #endif - return cmFileLockResult(SYSTEM, lastError); + return { SYSTEM, lastError }; } cmFileLockResult cmFileLockResult::MakeTimeout() { - return cmFileLockResult(TIMEOUT, 0); + return { TIMEOUT, 0 }; } cmFileLockResult cmFileLockResult::MakeAlreadyLocked() { - return cmFileLockResult(ALREADY_LOCKED, 0); + return { ALREADY_LOCKED, 0 }; } cmFileLockResult cmFileLockResult::MakeInternal() { - return cmFileLockResult(INTERNAL, 0); + return { INTERNAL, 0 }; } cmFileLockResult cmFileLockResult::MakeNoFunction() { - return cmFileLockResult(NO_FUNCTION, 0); + return { NO_FUNCTION, 0 }; } bool cmFileLockResult::IsOk() const diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index cdc5f63..e0daa4f 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -16,7 +16,10 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -cmFindBase::cmFindBase() +class cmExecutionStatus; + +cmFindBase::cmFindBase(cmExecutionStatus& status) + : cmFindCommon(status) { this->AlreadyInCache = false; this->AlreadyInCacheWithoutMetaInfo = false; diff --git a/Source/cmFindBase.h b/Source/cmFindBase.h index 88b5b6c..f75db5f 100644 --- a/Source/cmFindBase.h +++ b/Source/cmFindBase.h @@ -10,6 +10,8 @@ #include "cmFindCommon.h" +class cmExecutionStatus; + /** \class cmFindBase * \brief Base class for most FIND_XXX commands. * @@ -19,7 +21,9 @@ class cmFindBase : public cmFindCommon { public: - cmFindBase(); + cmFindBase(cmExecutionStatus& status); + virtual ~cmFindBase() = default; + /** * This is called when the command is first encountered in * the CMakeLists.txt file. diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index 9425f99..5606838 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -8,6 +8,7 @@ #include <utility> #include "cmAlgorithms.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -24,7 +25,9 @@ cmFindCommon::PathLabel cmFindCommon::PathLabel::SystemEnvironment( cmFindCommon::PathLabel cmFindCommon::PathLabel::CMakeSystem("CMAKE_SYSTEM"); cmFindCommon::PathLabel cmFindCommon::PathLabel::Guess("GUESS"); -cmFindCommon::cmFindCommon() +cmFindCommon::cmFindCommon(cmExecutionStatus& status) + : Makefile(&status.GetMakefile()) + , Status(status) { this->FindRootPathMode = RootPathModeBoth; this->NoDefaultPath = false; @@ -51,7 +54,10 @@ cmFindCommon::cmFindCommon() this->InitializeSearchPathGroups(); } -cmFindCommon::~cmFindCommon() = default; +void cmFindCommon::SetError(std::string const& e) +{ + this->Status.SetError(e); +} void cmFindCommon::InitializeSearchPathGroups() { diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h index d95eeb1..8177eac 100644 --- a/Source/cmFindCommon.h +++ b/Source/cmFindCommon.h @@ -10,10 +10,12 @@ #include <string> #include <vector> -#include "cmCommand.h" #include "cmPathLabel.h" #include "cmSearchPath.h" +class cmExecutionStatus; +class cmMakefile; + /** \class cmFindCommon * \brief Base class for FIND_XXX implementations. * @@ -21,11 +23,12 @@ * cmFindProgramCommand, cmFindPathCommand, cmFindLibraryCommand, * cmFindFileCommand, and cmFindPackageCommand. */ -class cmFindCommon : public cmCommand +class cmFindCommon { public: - cmFindCommon(); - ~cmFindCommon() override; + cmFindCommon(cmExecutionStatus& status); + + void SetError(std::string const& e); protected: friend class cmSearchPath; @@ -127,6 +130,9 @@ protected: bool SearchAppBundleFirst; bool SearchAppBundleOnly; bool SearchAppBundleLast; + + cmMakefile* Makefile; + cmExecutionStatus& Status; }; #endif diff --git a/Source/cmFindFileCommand.cxx b/Source/cmFindFileCommand.cxx index 9840c4f..29a2bc4 100644 --- a/Source/cmFindFileCommand.cxx +++ b/Source/cmFindFileCommand.cxx @@ -2,7 +2,16 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmFindFileCommand.h" -cmFindFileCommand::cmFindFileCommand() +class cmExecutionStatus; + +cmFindFileCommand::cmFindFileCommand(cmExecutionStatus& status) + : cmFindPathCommand(status) { this->IncludeFileInPath = true; } + +bool cmFindFile(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return cmFindFileCommand(status).InitialPass(args); +} diff --git a/Source/cmFindFileCommand.h b/Source/cmFindFileCommand.h index 152b505..7dc6e55 100644 --- a/Source/cmFindFileCommand.h +++ b/Source/cmFindFileCommand.h @@ -5,11 +5,13 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include "cm_memory.hxx" +#include <string> +#include <vector> -#include "cmCommand.h" #include "cmFindPathCommand.h" +class cmExecutionStatus; + /** \class cmFindFileCommand * \brief Define a command to search for an executable program. * @@ -21,14 +23,10 @@ class cmFindFileCommand : public cmFindPathCommand { public: - cmFindFileCommand(); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmFindFileCommand>(); - } + cmFindFileCommand(cmExecutionStatus& status); }; +bool cmFindFile(std::vector<std::string> const& args, + cmExecutionStatus& status); + #endif diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 92c64c8..529e5c8 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -18,15 +18,15 @@ class cmExecutionStatus; -cmFindLibraryCommand::cmFindLibraryCommand() +cmFindLibraryCommand::cmFindLibraryCommand(cmExecutionStatus& status) + : cmFindBase(status) { this->EnvironmentPath = "LIB"; this->NamesPerDirAllowed = true; } // cmFindLibraryCommand -bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn, - cmExecutionStatus&) +bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn) { this->VariableDocumentation = "Path to a library."; this->CMakePathName = "LIBRARY"; @@ -490,3 +490,9 @@ std::string cmFindLibraryCommand::FindFrameworkLibraryDirsPerName() // No framework found. return ""; } + +bool cmFindLibrary(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return cmFindLibraryCommand(status).InitialPass(args); +} diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h index af17d60..b2f71b3 100644 --- a/Source/cmFindLibraryCommand.h +++ b/Source/cmFindLibraryCommand.h @@ -8,9 +8,6 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" #include "cmFindBase.h" class cmExecutionStatus; @@ -25,21 +22,9 @@ class cmExecutionStatus; class cmFindLibraryCommand : public cmFindBase { public: - cmFindLibraryCommand(); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmFindLibraryCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; + cmFindLibraryCommand(cmExecutionStatus& status); + + bool InitialPass(std::vector<std::string> const& args); protected: void AddArchitecturePaths(const char* suffix); @@ -57,4 +42,7 @@ private: std::string FindFrameworkLibraryDirsPerName(); }; +bool cmFindLibrary(std::vector<std::string> const& args, + cmExecutionStatus& status); + #endif diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 9132760..8f76030 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -85,7 +85,8 @@ void cmFindPackageCommand::Sort(std::vector<std::string>::iterator begin, // else do not sort } -cmFindPackageCommand::cmFindPackageCommand() +cmFindPackageCommand::cmFindPackageCommand(cmExecutionStatus& status) + : cmFindCommon(status) { this->CMakePathName = "PACKAGE"; this->Quiet = false; @@ -143,8 +144,7 @@ void cmFindPackageCommand::AppendSearchPathGroups() std::make_pair(PathLabel::SystemRegistry, cmSearchPath(this))); } -bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args) { if (args.empty()) { this->SetError("called with incorrect number of arguments"); @@ -847,8 +847,7 @@ bool cmFindPackageCommand::HandlePackageMode( // If there are files in ConsideredConfigs, it means that FooConfig.cmake // have been found, but they didn't have appropriate versions. else if (!this->ConsideredConfigs.empty()) { - std::vector<ConfigFileInfo>::const_iterator duplicate_end = - cmRemoveDuplicates(this->ConsideredConfigs); + auto duplicate_end = cmRemoveDuplicates(this->ConsideredConfigs); e << "Could not find a configuration file for package \"" << this->Name << "\" that " << (this->VersionExact ? "exactly matches" : "is compatible with") @@ -1080,7 +1079,7 @@ void cmFindPackageCommand::AppendToFoundProperty(bool found) std::string tmp = foundProp; cmExpandList(tmp, foundContents, false); - std::vector<std::string>::iterator nameIt = + auto nameIt = std::find(foundContents.begin(), foundContents.end(), this->Name); if (nameIt != foundContents.end()) { foundContents.erase(nameIt); @@ -1094,7 +1093,7 @@ void cmFindPackageCommand::AppendToFoundProperty(bool found) std::string tmp = notFoundProp; cmExpandList(tmp, notFoundContents, false); - std::vector<std::string>::iterator nameIt = + auto nameIt = std::find(notFoundContents.begin(), notFoundContents.end(), this->Name); if (nameIt != notFoundContents.end()) { notFoundContents.erase(nameIt); @@ -1199,8 +1198,7 @@ void cmFindPackageCommand::FillPrefixesPackageRoot() cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRoot]; // Add the PACKAGE_ROOT_PATH from each enclosing find_package call. - for (std::deque<std::vector<std::string>>::const_reverse_iterator pkgPaths = - this->Makefile->FindPackageRootPathStack.rbegin(); + for (auto pkgPaths = this->Makefile->FindPackageRootPathStack.rbegin(); pkgPaths != this->Makefile->FindPackageRootPathStack.rend(); ++pkgPaths) { for (std::string const& path : *pkgPaths) { @@ -2282,3 +2280,9 @@ bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in) } // TODO: Debug cmsys::Glob double slash problem. + +bool cmFindPackage(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return cmFindPackageCommand(status).InitialPass(args); +} diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index d57b38a..78b4985 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -3,9 +3,7 @@ #ifndef cmFindPackageCommand_h #define cmFindPackageCommand_h -#include "cmCommand.h" #include "cmConfigure.h" // IWYU pragma: keep -#include "cmPolicies.h" #include "cm_kwiml.h" #include <cstddef> @@ -15,7 +13,8 @@ #include <string> #include <vector> -#include "cm_memory.hxx" +#include "cmFindCommon.h" +#include "cmPolicies.h" // IWYU insists we should forward-declare instead of including <functional>, // but we cannot forward-declare reliably because some C++ standard libraries @@ -28,8 +27,6 @@ namespace std { /* clang-format on */ #endif -#include "cmFindCommon.h" - class cmExecutionStatus; class cmSearchPath; @@ -62,22 +59,9 @@ public: std::vector<std::string>::iterator end, SortOrderType order, SortDirectionType dir); - cmFindPackageCommand(); + cmFindPackageCommand(cmExecutionStatus& status); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmFindPackageCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; + bool InitialPass(std::vector<std::string> const& args); private: class PathLabel : public cmFindCommon::PathLabel @@ -246,4 +230,7 @@ struct hash<cmFindPackageCommand::ConfigFileInfo> }; } +bool cmFindPackage(std::vector<std::string> const& args, + cmExecutionStatus& status); + #endif diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx index 41f5e51..f5e2631 100644 --- a/Source/cmFindPathCommand.cxx +++ b/Source/cmFindPathCommand.cxx @@ -11,15 +11,15 @@ class cmExecutionStatus; -cmFindPathCommand::cmFindPathCommand() +cmFindPathCommand::cmFindPathCommand(cmExecutionStatus& status) + : cmFindBase(status) { this->EnvironmentPath = "INCLUDE"; this->IncludeFileInPath = false; } // cmFindPathCommand -bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn, - cmExecutionStatus&) +bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn) { this->VariableDocumentation = "Path to a file."; this->CMakePathName = "INCLUDE"; @@ -145,3 +145,9 @@ std::string cmFindPathCommand::FindFrameworkHeader() } return ""; } + +bool cmFindPath(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return cmFindPathCommand(status).InitialPass(args); +} diff --git a/Source/cmFindPathCommand.h b/Source/cmFindPathCommand.h index 89e2cef..8d1ea8b 100644 --- a/Source/cmFindPathCommand.h +++ b/Source/cmFindPathCommand.h @@ -8,9 +8,6 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" #include "cmFindBase.h" class cmExecutionStatus; @@ -25,21 +22,9 @@ class cmExecutionStatus; class cmFindPathCommand : public cmFindBase { public: - cmFindPathCommand(); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmFindPathCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; + cmFindPathCommand(cmExecutionStatus& status); + + bool InitialPass(std::vector<std::string> const& args); bool IncludeFileInPath; @@ -51,4 +36,7 @@ private: std::string FindFrameworkHeader(); }; +bool cmFindPath(std::vector<std::string> const& args, + cmExecutionStatus& status); + #endif diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index a2db65c..e0a3fbf 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -88,14 +88,14 @@ struct cmFindProgramHelper } }; -cmFindProgramCommand::cmFindProgramCommand() +cmFindProgramCommand::cmFindProgramCommand(cmExecutionStatus& status) + : cmFindBase(status) { this->NamesPerDirAllowed = true; } // cmFindProgramCommand -bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn, - cmExecutionStatus&) +bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn) { this->VariableDocumentation = "Path to a program."; this->CMakePathName = "PROGRAM"; @@ -270,3 +270,9 @@ std::string cmFindProgramCommand::GetBundleExecutable( return executable; } + +bool cmFindProgram(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return cmFindProgramCommand(status).InitialPass(args); +} diff --git a/Source/cmFindProgramCommand.h b/Source/cmFindProgramCommand.h index 40e455e..043b43c 100644 --- a/Source/cmFindProgramCommand.h +++ b/Source/cmFindProgramCommand.h @@ -8,9 +8,6 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" #include "cmFindBase.h" class cmExecutionStatus; @@ -26,21 +23,9 @@ class cmExecutionStatus; class cmFindProgramCommand : public cmFindBase { public: - cmFindProgramCommand(); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmFindProgramCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; + cmFindProgramCommand(cmExecutionStatus& status); + + bool InitialPass(std::vector<std::string> const& args); private: std::string FindProgram(); @@ -51,4 +36,7 @@ private: std::string GetBundleExecutable(std::string const& bundlePath); }; +bool cmFindProgram(std::vector<std::string> const& args, + cmExecutionStatus& status); + #endif diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index 9420541..fdc5e50 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -80,8 +80,7 @@ bool cmFunctionHelperCommand::operator()( // define ARGV and ARGN std::string argvDef = cmJoin(expandedArgs, ";"); - std::vector<std::string>::const_iterator eit = - expandedArgs.begin() + (this->Args.size() - 1); + auto eit = expandedArgs.begin() + (this->Args.size() - 1); std::string argnDef = cmJoin(cmMakeRange(eit, expandedArgs.end()), ";"); makefile.AddDefinition("ARGV", argvDef); makefile.MarkVariableAsUsed("ARGV"); diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 7475e9f..491d96f 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -4,6 +4,7 @@ #include <stdio.h> +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" #if !defined(CMAKE_BOOTSTRAP) @@ -149,7 +150,7 @@ bool cmGeneratedFileStreamBase::Close() // The destination is to be replaced. Rename the temporary to the // destination atomically. if (this->Compress) { - std::string gzname = this->TempName + ".temp.gz"; + std::string gzname = cmStrCat(this->TempName, ".temp.gz"); if (this->CompressFile(this->TempName, gzname)) { this->RenameFile(gzname, resname); } diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 32eb3cd..7bb6a63 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -370,9 +370,7 @@ bool cmGeneratorExpression::IsValidTargetName(const std::string& input) void cmCompiledGeneratorExpression::GetMaxLanguageStandard( const cmGeneratorTarget* tgt, std::map<std::string, std::string>& mapping) { - using MapType = - std::map<cmGeneratorTarget const*, std::map<std::string, std::string>>; - MapType::const_iterator it = this->MaxLanguageStandard.find(tgt); + auto it = this->MaxLanguageStandard.find(tgt); if (it != this->MaxLanguageStandard.end()) { mapping = it->second; } diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index df2227f..dda0abc 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -59,8 +59,7 @@ void cmGeneratorExpressionDAGChecker::Initialize() TEST_TRANSITIVE_PROPERTY_METHOD) false)) // NOLINT(*) #undef TEST_TRANSITIVE_PROPERTY_METHOD { - std::map<cmGeneratorTarget const*, std::set<std::string>>::const_iterator - it = top->Seen.find(this->Target); + auto it = top->Seen.find(this->Target); if (it != top->Seen.end()) { const std::set<std::string>& propSet = it->second; if (propSet.find(this->Property) != propSet.end()) { diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index 11c2dcc..eb43270 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -64,8 +64,7 @@ void cmGeneratorExpressionEvaluationFile::Generate( outputFileName = this->FixRelativePath(outputFileName, PathForOutput, lg); } - std::map<std::string, std::string>::iterator it = - outputFiles.find(outputFileName); + auto it = outputFiles.find(outputFileName); if (it != outputFiles.end()) { if (it->second == outputContent) { diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 7442018..c1343b2 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -30,9 +30,7 @@ std::string GeneratorExpressionContent::ProcessArbitraryContent( { std::string result; - const std::vector< - std::vector<cmGeneratorExpressionEvaluator*>>::const_iterator pend = - this->ParamChildren.end(); + const auto pend = this->ParamChildren.end(); for (; pit != pend; ++pit) { for (cmGeneratorExpressionEvaluator* pExprEval : *pit) { if (node->RequiresLiteralInput()) { @@ -116,11 +114,8 @@ std::string GeneratorExpressionContent::EvaluateParameters( { const int numExpected = node->NumExpectedParameters(); { - std::vector<std::vector<cmGeneratorExpressionEvaluator*>>::const_iterator - pit = this->ParamChildren.begin(); - const std::vector< - std::vector<cmGeneratorExpressionEvaluator*>>::const_iterator pend = - this->ParamChildren.end(); + auto pit = this->ParamChildren.begin(); + const auto pend = this->ParamChildren.end(); const bool acceptsArbitraryContent = node->AcceptsArbitraryContentParameter(); int counter = 1; diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx index e7effca..ba00b94 100644 --- a/Source/cmGeneratorExpressionParser.cxx +++ b/Source/cmGeneratorExpressionParser.cxx @@ -66,8 +66,7 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( unsigned int nestedLevel = this->NestingLevel; ++this->NestingLevel; - std::vector<cmGeneratorExpressionToken>::const_iterator startToken = - this->it - 1; + auto startToken = this->it - 1; std::vector<cmGeneratorExpressionEvaluator*> identifier; while (this->it->TokenType != cmGeneratorExpressionToken::EndExpression && @@ -174,13 +173,9 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( if (!parameters.empty()) { extendText(result, colonToken); - using EvaluatorVector = std::vector<cmGeneratorExpressionEvaluator*>; - using TokenVector = std::vector<cmGeneratorExpressionToken>; - std::vector<EvaluatorVector>::const_iterator pit = parameters.begin(); - const std::vector<EvaluatorVector>::const_iterator pend = - parameters.end(); - std::vector<TokenVector::const_iterator>::const_iterator commaIt = - commaTokens.begin(); + auto pit = parameters.begin(); + const auto pend = parameters.end(); + auto commaIt = commaTokens.begin(); assert(parameters.size() > commaTokens.size()); for (; pit != pend; ++pit, ++commaIt) { if (!pit->empty() && !emptyParamTermination) { diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index b4706a3..b019e0b 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -204,9 +204,8 @@ void CreatePropertyGeneratorExpressions( std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items, bool evaluateForBuildsystem = false) { - std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin(); - for (std::vector<std::string>::const_iterator it = entries.begin(); - it != entries.end(); ++it, ++btIt) { + auto btIt = backtraces.begin(); + for (auto it = entries.begin(); it != entries.end(); ++it, ++btIt) { items.push_back( CreateTargetPropertyEntry(*it, *btIt, evaluateForBuildsystem)); } @@ -471,8 +470,7 @@ std::string cmGeneratorTarget::GetOutputName( { // Lookup/compute/cache the output name for this configuration. OutputNameKey key(config, artifact); - cmGeneratorTarget::OutputNameMapType::iterator i = - this->OutputNameMap.find(key); + auto i = this->OutputNameMap.find(key); if (i == this->OutputNameMap.end()) { // Add empty name in map to detect potential recursion. OutputNameMapType::value_type entry(key, ""); @@ -716,7 +714,7 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src, std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends( cmSourceFile const* sf) const { - SourceEntriesType::const_iterator i = this->SourceDepends.find(sf); + auto i = this->SourceDepends.find(sf); if (i != this->SourceDepends.end()) { return &i->second.Depends; } @@ -925,8 +923,7 @@ void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf) bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const { const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping(); - std::set<cmSourceFile const*>::const_iterator it = - this->ExplicitObjectName.find(file); + auto it = this->ExplicitObjectName.find(file); return it != this->ExplicitObjectName.end(); } @@ -1108,8 +1105,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory( } using IncludeCacheType = std::map<std::string, std::vector<std::string>>; - IncludeCacheType::const_iterator iter = - this->SystemIncludesCache.find(config_upper); + auto iter = this->SystemIncludesCache.find(config_upper); if (iter == this->SystemIncludesCache.end()) { cmGeneratorExpressionDAGChecker dagChecker( @@ -1548,7 +1544,7 @@ cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources( // Lookup any existing link implementation for this configuration. std::string const key = cmSystemTools::UpperCase(config); - KindedSourcesMapType::iterator it = this->KindedSourcesMap.find(key); + auto it = this->KindedSourcesMap.find(key); if (it != this->KindedSourcesMap.end()) { if (!it->second.Initialized) { std::ostringstream e; @@ -1680,8 +1676,7 @@ void cmGeneratorTarget::ComputeAllConfigSources() const for (size_t ci = 0; ci < configs.size(); ++ci) { KindedSources const& sources = this->GetKindedSources(configs[ci]); for (SourceAndKind const& src : sources.Sources) { - std::map<cmSourceFile const*, size_t>::iterator mi = - index.find(src.Source.Value); + auto mi = index.find(src.Source.Value); if (mi == index.end()) { AllConfigSource acs; acs.Source = src.Source.Value; @@ -2292,7 +2287,7 @@ cmGeneratorTarget::LinkClosure const* cmGeneratorTarget::GetLinkClosure( const std::string& config) const { std::string key(cmSystemTools::UpperCase(config)); - LinkClosureMapType::iterator i = this->LinkClosureMap.find(key); + auto i = this->LinkClosureMap.find(key); if (i == this->LinkClosureMap.end()) { LinkClosure lc; this->ComputeLinkClosure(config, lc); @@ -2474,8 +2469,7 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo( if (!config.empty()) { config_upper = cmSystemTools::UpperCase(config); } - CompileInfoMapType::const_iterator i = - this->CompileInfoMap.find(config_upper); + auto i = this->CompileInfoMap.find(config_upper); if (i == this->CompileInfoMap.end()) { CompileInfo info; this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir); @@ -2500,8 +2494,7 @@ cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const if (!config.empty()) { config_upper = cmSystemTools::UpperCase(config); } - ModuleDefinitionInfoMapType::const_iterator i = - this->ModuleDefinitionInfoMap.find(config_upper); + auto i = this->ModuleDefinitionInfoMap.find(config_upper); if (i == this->ModuleDefinitionInfoMap.end()) { ModuleDefinitionInfo info; this->ComputeModuleDefinitionInfo(config, info); @@ -2606,7 +2599,7 @@ private: SourceEntry* CurrentEntry; std::queue<cmSourceFile*> SourceQueue; std::set<cmSourceFile*> SourcesQueued; - using NameMapType = std::map<std::string, cmSourceFile*>; + using NameMapType = std::map<std::string, cmSourcesWithOutput>; NameMapType NameMap; std::vector<std::string> NewSources; @@ -2712,19 +2705,30 @@ void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf) void cmTargetTraceDependencies::FollowName(std::string const& name) { - NameMapType::iterator i = this->NameMap.find(name); - if (i == this->NameMap.end()) { + // Use lower bound with key comparison to not repeat the search for the + // insert position if the name could not be found (which is the common case). + auto i = this->NameMap.lower_bound(name); + if (i == this->NameMap.end() || i->first != name) { // Check if we know how to generate this file. - cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name); - NameMapType::value_type entry(name, sf); - i = this->NameMap.insert(entry).first; - } - if (cmSourceFile* sf = i->second) { - // Record the dependency we just followed. - if (this->CurrentEntry) { - this->CurrentEntry->Depends.push_back(sf); + cmSourcesWithOutput sources = this->Makefile->GetSourcesWithOutput(name); + i = this->NameMap.emplace_hint(i, name, sources); + } + if (cmTarget* t = i->second.Target) { + // The name is a byproduct of a utility target or a PRE_BUILD, PRE_LINK, or + // POST_BUILD command. + this->GeneratorTarget->Target->AddUtility(t->GetName()); + } + if (cmSourceFile* sf = i->second.Source) { + // For now only follow the dependency if the source file is not a + // byproduct. Semantics of byproducts in a non-Ninja context will have to + // be defined first. + if (!i->second.SourceIsByproduct) { + // Record the dependency we just followed. + if (this->CurrentEntry) { + this->CurrentEntry->Depends.push_back(sf); + } + this->QueueSource(sf); } - this->QueueSource(sf); } } @@ -3417,8 +3421,7 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config, file << pchEpilogue << "\n"; } } - cmSystemTools::CopyFileIfDifferent(filename_tmp, filename); - cmSystemTools::RemoveFile(filename_tmp); + cmSystemTools::MoveFileIfDifferent(filename_tmp, filename); } return inserted.first->second; } @@ -3451,8 +3454,7 @@ std::string cmGeneratorTarget::GetPchSource(const std::string& config, cmGeneratedFileStream file(filename_tmp); file << "/* generated by CMake */\n"; } - cmSystemTools::CopyFileIfDifferent(filename_tmp, filename); - cmSystemTools::RemoveFile(filename_tmp); + cmSystemTools::MoveFileIfDifferent(filename_tmp, filename); } return inserted.first->second; } @@ -4260,8 +4262,7 @@ void cmGeneratorTarget::GetTargetObjectNames( for (cmSourceFile const* src : objectSources) { // Find the object file name corresponding to this source file. - std::map<cmSourceFile const*, std::string>::const_iterator map_it = - mapping.find(src); + auto map_it = mapping.find(src); // It must exist because we populated the mapping just above. assert(!map_it->second.empty()); objects.push_back(map_it->second); @@ -4285,8 +4286,7 @@ cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const { struct SourceFileFlags flags; this->ConstructSourceFileFlags(); - std::map<cmSourceFile const*, SourceFileFlags>::iterator si = - this->SourceFlagsMap.find(sf); + auto si = this->SourceFlagsMap.find(sf); if (si != this->SourceFlagsMap.end()) { flags = si->second; } else { @@ -4620,7 +4620,7 @@ void cmGeneratorTarget::CheckPropertyCompatibility( if (!prop.empty()) { // Use a sorted std::vector to keep the error message sorted. std::vector<std::string> props; - std::set<std::string>::const_iterator i = emittedBools.find(prop); + auto i = emittedBools.find(prop); if (i != emittedBools.end()) { props.push_back(strBool); } @@ -4778,21 +4778,21 @@ template <> std::pair<bool, bool> consistentProperty(bool lhs, bool rhs, CompatibleType /*unused*/) { - return std::make_pair(lhs == rhs, lhs); + return { lhs == rhs, lhs }; } std::pair<bool, const char*> consistentStringProperty(const char* lhs, const char* rhs) { const bool b = strcmp(lhs, rhs) == 0; - return std::make_pair(b, b ? lhs : nullptr); + return { b, b ? lhs : nullptr }; } std::pair<bool, std::string> consistentStringProperty(const std::string& lhs, const std::string& rhs) { const bool b = lhs == rhs; - return std::make_pair(b, b ? lhs : valueAsString(nullptr)); + return { b, b ? lhs : valueAsString(nullptr) }; } std::pair<bool, const char*> consistentNumberProperty(const char* lhs, @@ -4801,22 +4801,21 @@ std::pair<bool, const char*> consistentNumberProperty(const char* lhs, { char* pEnd; - const char* const null_ptr = nullptr; - long lnum = strtol(lhs, &pEnd, 0); if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) { - return std::pair<bool, const char*>(false, null_ptr); + return { false, nullptr }; } long rnum = strtol(rhs, &pEnd, 0); if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) { - return std::pair<bool, const char*>(false, null_ptr); + return { false, nullptr }; } if (t == NumberMaxType) { - return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs); + return { true, std::max(lnum, rnum) == lnum ? lhs : rhs }; } - return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs); + + return { true, std::min(lnum, rnum) == lnum ? lhs : rhs }; } template <> @@ -4825,21 +4824,19 @@ std::pair<bool, const char*> consistentProperty(const char* lhs, CompatibleType t) { if (!lhs && !rhs) { - return std::make_pair(true, lhs); + return { true, lhs }; } if (!lhs) { - return std::make_pair(true, rhs); + return { true, rhs }; } if (!rhs) { - return std::make_pair(true, lhs); + return { true, lhs }; } - const char* const null_ptr = nullptr; - switch (t) { case BoolType: { bool same = cmIsOn(lhs) == cmIsOn(rhs); - return std::make_pair(same, same ? lhs : nullptr); + return { same, same ? lhs : nullptr }; } case StringType: return consistentStringProperty(lhs, rhs); @@ -4848,7 +4845,7 @@ std::pair<bool, const char*> consistentProperty(const char* lhs, return consistentNumberProperty(lhs, rhs, t); } assert(false && "Unreachable!"); - return std::pair<bool, const char*>(false, null_ptr); + return { false, nullptr }; } std::pair<bool, std::string> consistentProperty(const std::string& lhs, @@ -4858,31 +4855,31 @@ std::pair<bool, std::string> consistentProperty(const std::string& lhs, const std::string null_ptr = valueAsString(nullptr); if (lhs == null_ptr && rhs == null_ptr) { - return std::make_pair(true, lhs); + return { true, lhs }; } if (lhs == null_ptr) { - return std::make_pair(true, rhs); + return { true, rhs }; } if (rhs == null_ptr) { - return std::make_pair(true, lhs); + return { true, lhs }; } switch (t) { case BoolType: { bool same = cmIsOn(lhs) == cmIsOn(rhs); - return std::make_pair(same, same ? lhs : null_ptr); + return { same, same ? lhs : null_ptr }; } case StringType: return consistentStringProperty(lhs, rhs); case NumberMinType: case NumberMaxType: { auto value = consistentNumberProperty(lhs.c_str(), rhs.c_str(), t); - return std::make_pair( - value.first, value.first ? std::string(value.second) : null_ptr); + return { value.first, + value.first ? std::string(value.second) : null_ptr }; } } assert(false && "Unreachable!"); - return std::pair<bool, std::string>(false, null_ptr); + return { false, null_ptr }; } template <typename PropertyType> @@ -5068,7 +5065,7 @@ cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation( { // Lookup any existing information for this configuration. std::string key(cmSystemTools::UpperCase(config)); - cmTargetLinkInformationMap::iterator i = this->LinkInformation.find(key); + auto i = this->LinkInformation.find(key); if (i == this->LinkInformation.end()) { // Compute information for this configuration. cmComputeLinkInformation* info = @@ -5469,7 +5466,7 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo( if (!config.empty()) { config_upper = cmSystemTools::UpperCase(config); } - OutputInfoMapType::iterator i = this->OutputInfoMap.find(config_upper); + auto i = this->OutputInfoMap.find(config_upper); if (i == this->OutputInfoMap.end()) { // Add empty info in map to detect potential recursion. OutputInfo info; @@ -5868,7 +5865,7 @@ cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo( config_upper = "NOCONFIG"; } - ImportInfoMapType::const_iterator i = this->ImportInfoMap.find(config_upper); + auto i = this->ImportInfoMap.find(config_upper); if (i == this->ImportInfoMap.end()) { ImportInfo info; this->ComputeImportInfo(config_upper, info); @@ -6072,7 +6069,7 @@ bool cmGeneratorTarget::GetConfigCommonSourceFiles( std::vector<std::string> const& configs = this->Makefile->GetGeneratorConfigs(); - std::vector<std::string>::const_iterator it = configs.begin(); + auto it = configs.begin(); const std::string& firstConfig = *it; this->GetSourceFilesWithoutObjectLibraries(files, firstConfig); diff --git a/Source/cmGetDirectoryPropertyCommand.cxx b/Source/cmGetDirectoryPropertyCommand.cxx index d078a7a..64438d5 100644 --- a/Source/cmGetDirectoryPropertyCommand.cxx +++ b/Source/cmGetDirectoryPropertyCommand.cxx @@ -24,7 +24,7 @@ bool cmGetDirectoryPropertyCommand(std::vector<std::string> const& args, return false; } - std::vector<std::string>::const_iterator i = args.begin(); + auto i = args.begin(); std::string const& variable = *i; ++i; diff --git a/Source/cmGetSourceFilePropertyCommand.cxx b/Source/cmGetSourceFilePropertyCommand.cxx index 5c1c8a5..eefdc6c 100644 --- a/Source/cmGetSourceFilePropertyCommand.cxx +++ b/Source/cmGetSourceFilePropertyCommand.cxx @@ -2,26 +2,25 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGetSourceFilePropertyCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmSourceFile.h" -class cmExecutionStatus; - -// cmSetSourceFilePropertyCommand -bool cmGetSourceFilePropertyCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmGetSourceFilePropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() != 3) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } std::string const& var = args[0]; std::string const& file = args[1]; - cmSourceFile* sf = this->Makefile->GetSource(file); + cmMakefile& mf = status.GetMakefile(); + cmSourceFile* sf = mf.GetSource(file); // for the location we must create a source file first if (!sf && args[2] == "LOCATION") { - sf = this->Makefile->CreateSource(file); + sf = mf.CreateSource(file); } if (sf) { const char* prop = nullptr; @@ -29,11 +28,11 @@ bool cmGetSourceFilePropertyCommand::InitialPass( prop = sf->GetPropertyForUser(args[2]); } if (prop) { - this->Makefile->AddDefinition(var, prop); + mf.AddDefinition(var, prop); return true; } } - this->Makefile->AddDefinition(var, "NOTFOUND"); + mf.AddDefinition(var, "NOTFOUND"); return true; } diff --git a/Source/cmGetSourceFilePropertyCommand.h b/Source/cmGetSourceFilePropertyCommand.h index 387a7f4..f0c319b 100644 --- a/Source/cmGetSourceFilePropertyCommand.h +++ b/Source/cmGetSourceFilePropertyCommand.h @@ -8,26 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmGetSourceFilePropertyCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmGetSourceFilePropertyCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmGetSourceFilePropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx index 07aaf02..7f5df9c 100644 --- a/Source/cmGetTargetPropertyCommand.cxx +++ b/Source/cmGetTargetPropertyCommand.cxx @@ -4,6 +4,7 @@ #include <sstream> +#include "cmExecutionStatus.h" #include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -11,32 +12,31 @@ #include "cmTarget.h" #include "cmTargetPropertyComputer.h" -class cmExecutionStatus; class cmMessenger; -// cmSetTargetPropertyCommand -bool cmGetTargetPropertyCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmGetTargetPropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() != 3) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } std::string const& var = args[0]; std::string const& targetName = args[1]; std::string prop; bool prop_exists = false; + cmMakefile& mf = status.GetMakefile(); - if (cmTarget* tgt = this->Makefile->FindTargetToUse(targetName)) { + if (cmTarget* tgt = mf.FindTargetToUse(targetName)) { if (args[2] == "ALIASED_TARGET") { - if (this->Makefile->IsAlias(targetName)) { + if (mf.IsAlias(targetName)) { prop = tgt->GetName(); prop_exists = true; } } else if (!args[2].empty()) { const char* prop_cstr = nullptr; - cmListFileBacktrace bt = this->Makefile->GetBacktrace(); - cmMessenger* messenger = this->Makefile->GetMessenger(); + cmListFileBacktrace bt = mf.GetBacktrace(); + cmMessenger* messenger = mf.GetMessenger(); if (cmTargetPropertyComputer::PassesWhitelist(tgt->GetType(), args[2], messenger, bt)) { prop_cstr = tgt->GetComputedProperty(args[2], messenger, bt); @@ -53,7 +53,7 @@ bool cmGetTargetPropertyCommand::InitialPass( bool issueMessage = false; std::ostringstream e; MessageType messageType = MessageType::AUTHOR_WARNING; - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0045)) { + switch (mf.GetPolicyStatus(cmPolicies::CMP0045)) { case cmPolicies::WARN: issueMessage = true; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0045) << "\n"; @@ -68,16 +68,16 @@ bool cmGetTargetPropertyCommand::InitialPass( if (issueMessage) { e << "get_target_property() called with non-existent target \"" << targetName << "\"."; - this->Makefile->IssueMessage(messageType, e.str()); + mf.IssueMessage(messageType, e.str()); if (messageType == MessageType::FATAL_ERROR) { return false; } } } if (prop_exists) { - this->Makefile->AddDefinition(var, prop); + mf.AddDefinition(var, prop); return true; } - this->Makefile->AddDefinition(var, var + "-NOTFOUND"); + mf.AddDefinition(var, var + "-NOTFOUND"); return true; } diff --git a/Source/cmGetTargetPropertyCommand.h b/Source/cmGetTargetPropertyCommand.h index 1a53195..c13078f 100644 --- a/Source/cmGetTargetPropertyCommand.h +++ b/Source/cmGetTargetPropertyCommand.h @@ -8,26 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmGetTargetPropertyCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmGetTargetPropertyCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmGetTargetPropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmGetTestPropertyCommand.cxx b/Source/cmGetTestPropertyCommand.cxx index 0b0d6eb..cf8c1d5 100644 --- a/Source/cmGetTestPropertyCommand.cxx +++ b/Source/cmGetTestPropertyCommand.cxx @@ -2,33 +2,32 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGetTestPropertyCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmTest.h" -class cmExecutionStatus; - -// cmGetTestPropertyCommand -bool cmGetTestPropertyCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmGetTestPropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 3) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } std::string const& testName = args[0]; std::string const& var = args[2]; - cmTest* test = this->Makefile->GetTest(testName); + cmMakefile& mf = status.GetMakefile(); + cmTest* test = mf.GetTest(testName); if (test) { const char* prop = nullptr; if (!args[1].empty()) { prop = test->GetProperty(args[1]); } if (prop) { - this->Makefile->AddDefinition(var, prop); + mf.AddDefinition(var, prop); return true; } } - this->Makefile->AddDefinition(var, "NOTFOUND"); + mf.AddDefinition(var, "NOTFOUND"); return true; } diff --git a/Source/cmGetTestPropertyCommand.h b/Source/cmGetTestPropertyCommand.h index a53a7f7..30beb8f 100644 --- a/Source/cmGetTestPropertyCommand.h +++ b/Source/cmGetTestPropertyCommand.h @@ -8,26 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmGetTestPropertyCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmGetTestPropertyCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmGetTestPropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 658f65d..09ed76d 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -177,8 +177,7 @@ void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout, void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config, const std::string& language) { - std::map<std::string, std::string>::iterator i = - this->FlagsByLanguage.find(language); + auto i = this->FlagsByLanguage.find(language); if (i == this->FlagsByLanguage.end()) { std::string flags; const char* lang = language.c_str(); @@ -209,8 +208,7 @@ void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config, std::string cmGhsMultiTargetGenerator::GetDefines(const std::string& language, std::string const& config) { - std::map<std::string, std::string>::iterator i = - this->DefinesByLanguage.find(language); + auto i = this->DefinesByLanguage.find(language); if (i == this->DefinesByLanguage.end()) { std::set<std::string> defines; const char* lang = language.c_str(); @@ -232,8 +230,7 @@ void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::ostream& fout, std::string const&, const std::string& language) { - std::map<std::string, std::string>::iterator flagsByLangI = - this->FlagsByLanguage.find(language); + auto flagsByLangI = this->FlagsByLanguage.find(language); if (flagsByLangI != this->FlagsByLanguage.end()) { if (!flagsByLangI->second.empty()) { std::vector<std::string> ghsCompFlags = diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index f6d5998..7aa231e 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -228,7 +228,7 @@ public: return this->GG->ConvertToNinjaPath(path); } }; - MapToNinjaPathImpl MapToNinjaPath() { return MapToNinjaPathImpl(this); } + MapToNinjaPathImpl MapToNinjaPath() { return { this }; } // -- Additional clean files void AddAdditionalCleanFile(std::string fileName); diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 22c304e..c7a0330 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -291,8 +291,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() // Sort the list and remove duplicates. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>()); #if !defined(__VMS) // The Compaq STL on VMS crashes, so accept duplicates. - std::vector<std::string>::iterator new_end = - std::unique(lfiles.begin(), lfiles.end()); + auto new_end = std::unique(lfiles.begin(), lfiles.end()); lfiles.erase(new_end, lfiles.end()); #endif diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 10f822f..af5d279 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -582,10 +582,8 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile( } // sort the array - std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>()); - std::vector<std::string>::iterator new_end = - std::unique(lfiles.begin(), lfiles.end()); - lfiles.erase(new_end, lfiles.end()); + std::sort(lfiles.begin(), lfiles.end()); + lfiles.erase(std::unique(lfiles.begin(), lfiles.end()), lfiles.end()); cmake* cm = this->GetCMakeInstance(); if (cm->DoWriteGlobVerifyTarget()) { @@ -1254,7 +1252,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget( bundleFiles[tsFlags.MacFolder].push_back(sourceFile); } } - for (auto keySources : bundleFiles) { + for (auto const& keySources : bundleFiles) { cmXCodeObject* copyFilesBuildPhase = this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase); copyFilesBuildPhase->SetComment("Copy files"); @@ -1302,7 +1300,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget( bundleFiles[tsFlags.MacFolder].push_back(sourceFile); } } - for (auto keySources : bundleFiles) { + for (auto const& keySources : bundleFiles) { cmXCodeObject* copyFilesBuildPhase = this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase); copyFilesBuildPhase->SetComment("Copy files"); @@ -1433,7 +1431,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateBuildPhase( void cmGlobalXCodeGenerator::CreateCustomCommands( cmXCodeObject* buildPhases, cmXCodeObject* sourceBuildPhase, cmXCodeObject* headerBuildPhase, cmXCodeObject* resourceBuildPhase, - std::vector<cmXCodeObject*> contentBuildPhases, + std::vector<cmXCodeObject*> const& contentBuildPhases, cmXCodeObject* frameworkBuildPhase, cmGeneratorTarget* gtgt) { std::vector<cmCustomCommand> const& prebuild = gtgt->GetPreBuildCommands(); @@ -2629,8 +2627,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget( return nullptr; } - std::map<cmGeneratorTarget const*, cmXCodeObject*>::const_iterator const i = - this->XCodeObjectMap.find(t); + auto const i = this->XCodeObjectMap.find(t); if (i == this->XCodeObjectMap.end()) { return nullptr; } @@ -2910,8 +2907,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup( } target += gtgt->GetName(); s = cmStrCat(target, '/', sg->GetFullName()); - std::map<std::string, cmXCodeObject*>::iterator it = - this->GroupNameMap.find(s); + auto it = this->GroupNameMap.find(s); if (it != this->GroupNameMap.end()) { return it->second; } @@ -2956,8 +2952,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup( std::string curr_folder = cmStrCat(target, '/'); for (auto const& folder : cmTokenize(sg->GetFullName(), "\\")) { curr_folder += folder; - std::map<std::string, cmXCodeObject*>::iterator i_folder = - this->GroupNameMap.find(curr_folder); + auto const i_folder = this->GroupNameMap.find(curr_folder); // Create new folder if (i_folder == this->GroupNameMap.end()) { cmXCodeObject* group = this->CreatePBXGroup(tgroup, folder); @@ -3269,8 +3264,7 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( std::string trel = this->ConvertToRelativeForMake(tfull); // Add this target to the post-build phases of its dependencies. - std::map<std::string, cmXCodeObject::StringVec>::const_iterator y = - target->GetDependTargets().find(configName); + auto const y = target->GetDependTargets().find(configName); if (y != target->GetDependTargets().end()) { for (auto const& deptgt : y->second) { makefileStream << this->PostBuildMakeTarget(deptgt, configName) @@ -3290,8 +3284,7 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( makefileStream << trel << ":"; // List dependencies if any exist. - std::map<std::string, cmXCodeObject::StringVec>::const_iterator x = - target->GetDependLibraries().find(configName); + auto const x = target->GetDependLibraries().find(configName); if (x != target->GetDependLibraries().end()) { for (auto const& deplib : x->second) { std::string file = this->ConvertToRelativeForMake(deplib); diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 71446f9..af905d0 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -122,13 +122,11 @@ private: std::string RelativeToSource(const std::string& p); std::string RelativeToBinary(const std::string& p); std::string ConvertToRelativeForMake(std::string const& p); - void CreateCustomCommands(cmXCodeObject* buildPhases, - cmXCodeObject* sourceBuildPhase, - cmXCodeObject* headerBuildPhase, - cmXCodeObject* resourceBuildPhase, - std::vector<cmXCodeObject*> contentBuildPhases, - cmXCodeObject* frameworkBuildPhase, - cmGeneratorTarget* gtgt); + void CreateCustomCommands( + cmXCodeObject* buildPhases, cmXCodeObject* sourceBuildPhase, + cmXCodeObject* headerBuildPhase, cmXCodeObject* resourceBuildPhase, + std::vector<cmXCodeObject*> const& contentBuildPhases, + cmXCodeObject* frameworkBuildPhase, cmGeneratorTarget* gtgt); std::string ComputeInfoPListLocation(cmGeneratorTarget* target); diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 9b58f61..e0d545d 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -368,8 +368,7 @@ void cmGraphVizWriter::WriteConnections( const std::string& targetName, std::set<std::string>& insertedNodes, std::set<std::string>& insertedConnections, cmGeneratedFileStream& str) const { - std::map<std::string, const cmGeneratorTarget*>::const_iterator targetPtrIt = - this->TargetPtrs.find(targetName); + auto targetPtrIt = this->TargetPtrs.find(targetName); if (targetPtrIt == this->TargetPtrs.end()) // not found at all { @@ -390,8 +389,7 @@ void cmGraphVizWriter::WriteConnections( for (auto const& llit : ll) { const std::string& libName = llit.first; - std::map<std::string, std::string>::const_iterator libNameIt = - this->TargetNamesNodes.find(libName); + auto libNameIt = this->TargetNamesNodes.find(libName); // can happen e.g. if GRAPHVIZ_TARGET_IGNORE_REGEX is used if (libNameIt == this->TargetNamesNodes.end()) { @@ -419,8 +417,7 @@ void cmGraphVizWriter::WriteDependerConnections( const std::string& targetName, std::set<std::string>& insertedNodes, std::set<std::string>& insertedConnections, cmGeneratedFileStream& str) const { - std::map<std::string, const cmGeneratorTarget*>::const_iterator targetPtrIt = - this->TargetPtrs.find(targetName); + auto targetPtrIt = this->TargetPtrs.find(targetName); if (targetPtrIt == this->TargetPtrs.end()) // not found at all { @@ -454,8 +451,7 @@ void cmGraphVizWriter::WriteDependerConnections( for (auto const& llit : ll) { if (llit.first == targetName) { // So this target links against targetName. - std::map<std::string, std::string>::const_iterator dependerNodeNameIt = - this->TargetNamesNodes.find(tptr.first); + auto dependerNodeNameIt = this->TargetNamesNodes.find(tptr.first); if (dependerNodeNameIt != this->TargetNamesNodes.end()) { std::string connectionName = @@ -487,8 +483,7 @@ void cmGraphVizWriter::WriteNode(const std::string& targetName, { if (insertedNodes.find(targetName) == insertedNodes.end()) { insertedNodes.insert(targetName); - std::map<std::string, std::string>::const_iterator nameIt = - this->TargetNamesNodes.find(targetName); + auto nameIt = this->TargetNamesNodes.find(targetName); str << " \"" << nameIt->second << "\" [ label=\"" << targetName << "\" shape=\"" << getShapeForTarget(target) << "\"];" << std::endl; @@ -556,8 +551,7 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt) } } - std::map<std::string, const cmGeneratorTarget*>::const_iterator tarIt = - this->TargetPtrs.find(libName); + auto tarIt = this->TargetPtrs.find(libName); if (tarIt == this->TargetPtrs.end()) { std::ostringstream ostr; ostr << this->GraphNodePrefix << cnt++; diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index 876bd95..a4d0a0d 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -22,7 +22,7 @@ bool cmIncludeDirectoryCommand::InitialPass( return true; } - std::vector<std::string>::const_iterator i = args.begin(); + auto i = args.begin(); bool before = this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE"); bool system = false; diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx index 93134ad..fa1e8bc 100644 --- a/Source/cmIncludeExternalMSProjectCommand.cxx +++ b/Source/cmIncludeExternalMSProjectCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmIncludeExternalMSProjectCommand.h" +#include "cmExecutionStatus.h" + #ifdef _WIN32 # include "cmGlobalGenerator.h" # include "cmMakefile.h" @@ -11,22 +13,20 @@ # include "cmake.h" #endif -class cmExecutionStatus; - -// cmIncludeExternalMSProjectCommand -bool cmIncludeExternalMSProjectCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmIncludeExternalMSProjectCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect " - "number of arguments"); + status.SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect " + "number of arguments"); return false; } + // only compile this for win32 to avoid coverage errors #ifdef _WIN32 - if (this->Makefile->GetDefinition("WIN32") || - this->Makefile->GetGlobalGenerator() - ->IsIncludeExternalMSProjectSupported()) { + cmMakefile& mf = status.GetMakefile(); + if (mf.GetDefinition("WIN32") || + mf.GetGlobalGenerator()->IsIncludeExternalMSProjectSupported()) { enum Doing { DoingNone, @@ -77,15 +77,15 @@ bool cmIncludeExternalMSProjectCommand::InitialPass( if (!customGuid.empty()) { std::string guidVariable = utility_name + "_GUID_CMAKE"; - this->Makefile->GetCMakeInstance()->AddCacheEntry( - guidVariable.c_str(), customGuid.c_str(), "Stored GUID", - cmStateEnums::INTERNAL); + mf.GetCMakeInstance()->AddCacheEntry(guidVariable.c_str(), + customGuid.c_str(), "Stored GUID", + cmStateEnums::INTERNAL); } // Create a target instance for this utility. - cmTarget* target = this->Makefile->AddNewTarget(cmStateEnums::UTILITY, - utility_name.c_str()); - if (this->Makefile->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { + cmTarget* target = + mf.AddNewTarget(cmStateEnums::UTILITY, utility_name.c_str()); + if (mf.GetPropertyAsBool("EXCLUDE_FROM_ALL")) { target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } diff --git a/Source/cmIncludeExternalMSProjectCommand.h b/Source/cmIncludeExternalMSProjectCommand.h index 9f76576..1013c44 100644 --- a/Source/cmIncludeExternalMSProjectCommand.h +++ b/Source/cmIncludeExternalMSProjectCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmIncludeExternalMSProjectCommand - * \brief Specify an external MS project file for inclusion in the workspace. - * - * cmIncludeExternalMSProjectCommand is used to specify an externally - * generated Microsoft project file for inclusion in the default workspace - * generated by CMake. - */ -class cmIncludeExternalMSProjectCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmIncludeExternalMSProjectCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmIncludeExternalMSProjectCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmIncludeRegularExpressionCommand.cxx b/Source/cmIncludeRegularExpressionCommand.cxx index 073c95f..655ebd6 100644 --- a/Source/cmIncludeRegularExpressionCommand.cxx +++ b/Source/cmIncludeRegularExpressionCommand.cxx @@ -2,22 +2,22 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmIncludeRegularExpressionCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" -class cmExecutionStatus; - -// cmIncludeRegularExpressionCommand -bool cmIncludeRegularExpressionCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmIncludeRegularExpressionCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { - if ((args.empty()) || (args.size() > 2)) { - this->SetError("called with incorrect number of arguments"); + if (args.empty() || args.size() > 2) { + status.SetError("called with incorrect number of arguments"); return false; } - this->Makefile->SetIncludeRegularExpression(args[0].c_str()); + + cmMakefile& mf = status.GetMakefile(); + mf.SetIncludeRegularExpression(args[0].c_str()); if (args.size() > 1) { - this->Makefile->SetComplainRegularExpression(args[1]); + mf.SetComplainRegularExpression(args[1]); } return true; diff --git a/Source/cmIncludeRegularExpressionCommand.h b/Source/cmIncludeRegularExpressionCommand.h index 1723c8b..ca152b0 100644 --- a/Source/cmIncludeRegularExpressionCommand.h +++ b/Source/cmIncludeRegularExpressionCommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmIncludeRegularExpressionCommand - * \brief Set the regular expression for following #includes. - * - * cmIncludeRegularExpressionCommand is used to specify the regular expression - * that determines whether to follow a #include file in dependency checking. - */ -class cmIncludeRegularExpressionCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmIncludeRegularExpressionCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmIncludeRegularExpressionCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmInstallExportAndroidMKGenerator.cxx b/Source/cmInstallExportAndroidMKGenerator.cxx deleted file mode 100644 index e8de029..0000000 --- a/Source/cmInstallExportAndroidMKGenerator.cxx +++ /dev/null @@ -1,134 +0,0 @@ - -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmInstallExportAndroidMKGenerator.h" - -#include <stdio.h> - -#include "cmExportInstallFileGenerator.h" -#include "cmExportSet.h" -#include "cmGeneratedFileStream.h" -#include "cmGlobalGenerator.h" -#include "cmInstallFilesGenerator.h" -#include "cmInstallTargetGenerator.h" -#include "cmLocalGenerator.h" -#include "cmMakefile.h" -#include "cmMessageType.h" - -cmInstallExportAndroidMKGenerator::cmInstallExportAndroidMKGenerator( - cmExportSet* exportSet, const char* destination, - const char* file_permissions, std::vector<std::string> const& configurations, - const char* component, MessageLevel message, bool exclude_from_all, - const char* filename, const char* name_space, bool exportOld) - : cmInstallExportGenerator(exportSet, destination, file_permissions, - configurations, component, message, - exclude_from_all, filename, name_space, exportOld) -{ -} - -cmInstallExportAndroidMKGenerator::~cmInstallExportAndroidMKGenerator() -{ -} - -bool cmInstallExportAndroidMKGenerator::Compute(cmLocalGenerator* lg) -{ - this->LocalGenerator = lg; - this->ExportSet->Compute(lg); - return true; -} - -void cmInstallExportAndroidMKGenerator::GenerateScript(std::ostream& os) -{ - // Skip empty sets. - if (ExportSet->GetTargetExports()->empty()) { - std::ostringstream e; - e << "INSTALL(EXPORT) given unknown export \"" << ExportSet->GetName() - << "\""; - cmSystemTools::Error(e.str()); - return; - } - - // Create the temporary directory in which to store the files. - this->ComputeTempDir(); - cmSystemTools::MakeDirectory(this->TempDir.c_str()); - - // Construct a temporary location for the file. - this->MainImportFile = cmStrCat(this->TempDir, '/', this->FileName); - - // Generate the import file for this export set. - this->EFGen->SetExportFile(this->MainImportFile.c_str()); - this->EFGen->SetNamespace(this->Namespace); - this->EFGen->SetExportOld(this->ExportOld); - if (this->ConfigurationTypes->empty()) { - if (!this->ConfigurationName.empty()) { - this->EFGen->AddConfiguration(this->ConfigurationName); - } else { - this->EFGen->AddConfiguration(""); - } - } else { - for (std::string const& config : this->ConfigurationTypes) { - this->EFGen->AddConfiguration(config); - } - } - this->EFGen->GenerateImportFile(); - - // Perform the main install script generation. - this->cmInstallGenerator::GenerateScript(os); -} - -void cmInstallExportAndroidMKGenerator::GenerateScriptConfigs( - std::ostream& os, Indent const& indent) -{ - // Create the main install rules first. - this->cmInstallGenerator::GenerateScriptConfigs(os, indent); - - // Now create a configuration-specific install rule for the import - // file of each configuration. - std::vector<std::string> files; - for (auto const& pair : this->EFGen->GetConfigImportFiles()) { - files.push_back(pair.second); - std::string config_test = this->CreateConfigTest(pair.first); - os << indent << "if(" << config_test << ")\n"; - this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files, - false, this->FilePermissions.c_str(), nullptr, - nullptr, nullptr, indent.Next()); - os << indent << "endif()\n"; - files.clear(); - } -} - -void cmInstallExportAndroidMKGenerator::GenerateScriptActions( - std::ostream& os, Indent const& indent) -{ - // Remove old per-configuration export files if the main changes. - std::string installedDir = - cmStrCat("$ENV{DESTDIR}", - this->ConvertToAbsoluteDestination(this->Destination), '/'); - std::string installedFile = cmStrCat(installedDir, this->FileName); - os << indent << "if(EXISTS \"" << installedFile << "\")\n"; - Indent indentN = indent.Next(); - Indent indentNN = indentN.Next(); - Indent indentNNN = indentNN.Next(); - /* clang-format off */ - os << indentN << "file(DIFFERENT EXPORT_FILE_CHANGED FILES\n" - << indentN << " \"" << installedFile << "\"\n" - << indentN << " \"" << this->MainImportFile << "\")\n"; - os << indentN << "if(EXPORT_FILE_CHANGED)\n"; - os << indentNN << "file(GLOB OLD_CONFIG_FILES \"" << installedDir - << this->EFGen->GetConfigImportFileGlob() << "\")\n"; - os << indentNN << "if(OLD_CONFIG_FILES)\n"; - os << indentNNN << "message(STATUS \"Old export file \\\"" << installedFile - << "\\\" will be replaced. Removing files [${OLD_CONFIG_FILES}].\")\n"; - os << indentNNN << "file(REMOVE ${OLD_CONFIG_FILES})\n"; - os << indentNN << "endif()\n"; - os << indentN << "endif()\n"; - os << indent << "endif()\n"; - /* clang-format on */ - - // Install the main export file. - std::vector<std::string> files; - files.push_back(this->MainImportFile); - this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files, - false, this->FilePermissions.c_str(), nullptr, nullptr, - nullptr, indent); -} diff --git a/Source/cmInstallExportAndroidMKGenerator.h b/Source/cmInstallExportAndroidMKGenerator.h deleted file mode 100644 index a92ff27..0000000 --- a/Source/cmInstallExportAndroidMKGenerator.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef cmInstallExportAndroidMKGenerator_h -#define cmInstallExportAndroidMKGenerator_h - -#include "cmInstallExportGenerator.h" - -class cmExportInstallFileGenerator; -class cmInstallFilesGenerator; -class cmInstallTargetGenerator; -class cmExportSet; -class cmMakefile; - -/** \class cmInstallExportAndroidMKGenerator - * \brief Generate rules for creating an export files. - */ -class cmInstallExportAndroidMKGenerator : public cmInstallExportGenerator -{ -public: - cmInstallExportAndroidMKGenerator( - cmExportSet* exportSet, const char* dest, const char* file_permissions, - const std::vector<std::string>& configurations, const char* component, - MessageLevel message, bool exclude_from_all, const char* filename, - const char* name_space, bool exportOld); - ~cmInstallExportAndroidMKGenerator(); - - bool Compute(cmLocalGenerator* lg) override; - -protected: - virtual void GenerateScript(std::ostream& os); - virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent); - virtual void GenerateScriptActions(std::ostream& os, Indent const& indent); - void GenerateImportFile(cmExportSet const* exportSet); - void GenerateImportFile(const char* config, cmExportSet const* exportSet); -}; - -#endif diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx index 11687a8..d623943 100644 --- a/Source/cmInstallFilesCommand.cxx +++ b/Source/cmInstallFilesCommand.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallFilesCommand.h" +#include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmInstallFilesGenerator.h" @@ -11,8 +12,6 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; - static std::string FindInstallSource(cmMakefile& makefile, const char* name); static void CreateInstallGenerator(cmMakefile& makefile, std::string const& dest, @@ -20,16 +19,18 @@ static void CreateInstallGenerator(cmMakefile& makefile, 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&) +bool cmInstallFilesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Enable the install target. - this->Makefile->GetGlobalGenerator()->EnableInstallTarget(); + mf.GetGlobalGenerator()->EnableInstallTarget(); std::string const& dest = args[0]; @@ -37,18 +38,18 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args, std::vector<std::string> files; for (std::string const& arg : cmMakeRange(args).advance(2)) { // Find the source location for each file listed. - files.push_back(FindInstallSource(*this->Makefile, arg.c_str())); + files.push_back(FindInstallSource(mf, arg.c_str())); } - CreateInstallGenerator(*this->Makefile, dest, files); + CreateInstallGenerator(mf, dest, files); } else { std::vector<std::string> finalArgs(args.begin() + 1, args.end()); - this->Makefile->AddFinalAction([dest, finalArgs](cmMakefile& makefile) { + mf.AddFinalAction([dest, finalArgs](cmMakefile& makefile) { FinalAction(makefile, dest, finalArgs); }); } - this->Makefile->GetGlobalGenerator()->AddInstallComponent( - this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); + mf.GetGlobalGenerator()->AddInstallComponent( + mf.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); return true; } @@ -63,7 +64,7 @@ static void FinalAction(cmMakefile& makefile, std::string const& dest, // two different options if (args.size() > 1) { // now put the files into the list - std::vector<std::string>::const_iterator s = args.begin(); + auto s = args.begin(); ++s; // for each argument, get the files for (; s != args.end(); ++s) { @@ -85,7 +86,7 @@ static void FinalAction(cmMakefile& makefile, std::string const& dest, std::string const& regex = args[0]; cmSystemTools::Glob(makefile.GetCurrentSourceDirectory(), regex, files); - std::vector<std::string>::iterator s = files.begin(); + auto s = files.begin(); // for each argument, get the files for (; s != files.end(); ++s) { installFiles.push_back(FindInstallSource(makefile, s->c_str())); diff --git a/Source/cmInstallFilesCommand.h b/Source/cmInstallFilesCommand.h index f9b84fd..f4ebbde 100644 --- a/Source/cmInstallFilesCommand.h +++ b/Source/cmInstallFilesCommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmInstallFilesCommand - * \brief Specifies where to install some files - * - * cmInstallFilesCommand specifies the relative path where a list of - * files should be installed. - */ -class cmInstallFilesCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmInstallFilesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmInstallFilesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmInstallProgramsCommand.cxx b/Source/cmInstallProgramsCommand.cxx index 3eca0e0..6bb4409 100644 --- a/Source/cmInstallProgramsCommand.cxx +++ b/Source/cmInstallProgramsCommand.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallProgramsCommand.h" +#include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmInstallFilesGenerator.h" @@ -10,30 +11,29 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -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&) +bool cmInstallProgramsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Enable the install target. - this->Makefile->GetGlobalGenerator()->EnableInstallTarget(); + mf.GetGlobalGenerator()->EnableInstallTarget(); - this->Makefile->GetGlobalGenerator()->AddInstallComponent( - this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); + mf.GetGlobalGenerator()->AddInstallComponent( + mf.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) { + mf.AddFinalAction([dest, finalArgs](cmMakefile& makefile) { FinalAction(makefile, dest, finalArgs); }); return true; @@ -52,7 +52,7 @@ static void FinalAction(cmMakefile& makefile, std::string const& dest, // two different options if (args.size() > 1 || files_mode) { // for each argument, get the programs - std::vector<std::string>::const_iterator s = args.begin(); + auto s = args.begin(); if (files_mode) { // Skip the FILES argument in files mode. ++s; @@ -67,7 +67,7 @@ static void FinalAction(cmMakefile& makefile, std::string const& dest, cmSystemTools::Glob(makefile.GetCurrentSourceDirectory(), args[0], programs); - std::vector<std::string>::iterator s = programs.begin(); + auto s = programs.begin(); // for each argument, get the programs for (; s != programs.end(); ++s) { files.push_back(FindInstallSource(makefile, s->c_str())); diff --git a/Source/cmInstallProgramsCommand.h b/Source/cmInstallProgramsCommand.h index ccd621d..c567f3b 100644 --- a/Source/cmInstallProgramsCommand.h +++ b/Source/cmInstallProgramsCommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmInstallProgramsCommand - * \brief Specifies where to install some programs - * - * cmInstallProgramsCommand specifies the relative path where a list of - * programs should be installed. - */ -class cmInstallProgramsCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmInstallProgramsCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmInstallProgramsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmInstallTargetsCommand.cxx b/Source/cmInstallTargetsCommand.cxx index ef07e2c..44f23a5 100644 --- a/Source/cmInstallTargetsCommand.cxx +++ b/Source/cmInstallTargetsCommand.cxx @@ -5,54 +5,54 @@ #include <unordered_map> #include <utility> +#include "cmExecutionStatus.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmTarget.h" -class cmExecutionStatus; - -// cmExecutableCommand -bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmInstallTargetsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Enable the install target. - this->Makefile->GetGlobalGenerator()->EnableInstallTarget(); + mf.GetGlobalGenerator()->EnableInstallTarget(); - cmMakefile::cmTargetMap& tgts = this->Makefile->GetTargets(); - std::vector<std::string>::const_iterator s = args.begin(); + cmMakefile::cmTargetMap& tgts = mf.GetTargets(); + auto s = args.begin(); ++s; std::string runtime_dir = "/bin"; for (; s != args.end(); ++s) { if (*s == "RUNTIME_DIRECTORY") { ++s; if (s == args.end()) { - this->SetError("called with RUNTIME_DIRECTORY but no actual " - "directory"); + status.SetError("called with RUNTIME_DIRECTORY but no actual " + "directory"); return false; } runtime_dir = *s; } else { - cmMakefile::cmTargetMap::iterator ti = tgts.find(*s); + auto ti = tgts.find(*s); if (ti != tgts.end()) { ti->second.SetInstallPath(args[0]); ti->second.SetRuntimeInstallPath(runtime_dir); ti->second.SetHaveInstallRule(true); } else { std::string str = "Cannot find target: \"" + *s + "\" to install."; - this->SetError(str); + status.SetError(str); return false; } } } - this->Makefile->GetGlobalGenerator()->AddInstallComponent( - this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); + mf.GetGlobalGenerator()->AddInstallComponent( + mf.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); return true; } diff --git a/Source/cmInstallTargetsCommand.h b/Source/cmInstallTargetsCommand.h index 55e69ba..0c5850c 100644 --- a/Source/cmInstallTargetsCommand.h +++ b/Source/cmInstallTargetsCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmInstallTargetsCommand - * \brief Specifies where to install some targets - * - * cmInstallTargetsCommand specifies the relative path where a list of - * targets should be installed. The targets can be executables or - * libraries. - */ -class cmInstallTargetsCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmInstallTargetsCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmInstallTargetsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmInstalledFile.cxx b/Source/cmInstalledFile.cxx index 11f6efb..7d98b90 100644 --- a/Source/cmInstalledFile.cxx +++ b/Source/cmInstalledFile.cxx @@ -74,7 +74,7 @@ bool cmInstalledFile::HasProperty(const std::string& prop) const bool cmInstalledFile::GetProperty(const std::string& prop, std::string& value) const { - PropertyMapType::const_iterator i = this->Properties.find(prop); + auto i = this->Properties.find(prop); if (i == this->Properties.end()) { return false; } diff --git a/Source/cmLinkLibrariesCommand.cxx b/Source/cmLinkLibrariesCommand.cxx index 13f6bae..cb63ceb 100644 --- a/Source/cmLinkLibrariesCommand.cxx +++ b/Source/cmLinkLibrariesCommand.cxx @@ -2,39 +2,37 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmLinkLibrariesCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" -class cmExecutionStatus; - -// cmLinkLibrariesCommand -bool cmLinkLibrariesCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmLinkLibrariesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { return true; } + cmMakefile& mf = status.GetMakefile(); // add libraries, note that there is an optional prefix // of debug and optimized than can be used - for (std::vector<std::string>::const_iterator i = args.begin(); - i != args.end(); ++i) { + for (auto i = args.begin(); i != args.end(); ++i) { if (*i == "debug") { ++i; if (i == args.end()) { - this->SetError("The \"debug\" argument must be followed by " - "a library"); + status.SetError("The \"debug\" argument must be followed by " + "a library"); return false; } - this->Makefile->AppendProperty("LINK_LIBRARIES", "debug"); + mf.AppendProperty("LINK_LIBRARIES", "debug"); } else if (*i == "optimized") { ++i; if (i == args.end()) { - this->SetError("The \"optimized\" argument must be followed by " - "a library"); + status.SetError("The \"optimized\" argument must be followed by " + "a library"); return false; } - this->Makefile->AppendProperty("LINK_LIBRARIES", "optimized"); + mf.AppendProperty("LINK_LIBRARIES", "optimized"); } - this->Makefile->AppendProperty("LINK_LIBRARIES", i->c_str()); + mf.AppendProperty("LINK_LIBRARIES", i->c_str()); } return true; diff --git a/Source/cmLinkLibrariesCommand.h b/Source/cmLinkLibrariesCommand.h index 484ab0a..3412251 100644 --- a/Source/cmLinkLibrariesCommand.h +++ b/Source/cmLinkLibrariesCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmLinkLibrariesCommand - * \brief Specify a list of libraries to link into executables. - * - * cmLinkLibrariesCommand is used to specify a list of libraries to link - * into executable(s) or shared objects. The names of the libraries - * should be those defined by the LIBRARY(library) command(s). - */ -class cmLinkLibrariesCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmLinkLibrariesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmLinkLibrariesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 57eeedb..b35dc6f 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -338,8 +338,7 @@ bool HandleFindCommand(std::vector<std::string> const& args, return true; } - std::vector<std::string>::iterator it = - std::find(varArgsExpanded.begin(), varArgsExpanded.end(), args[2]); + auto it = std::find(varArgsExpanded.begin(), varArgsExpanded.end(), args[2]); if (it != varArgsExpanded.end()) { status.GetMakefile().AddDefinition( variableName, @@ -441,13 +440,12 @@ bool HandleRemoveItemCommand(std::vector<std::string> const& args, std::vector<std::string> remove(args.begin() + 2, args.end()); std::sort(remove.begin(), remove.end()); - std::vector<std::string>::const_iterator remEnd = - std::unique(remove.begin(), remove.end()); - std::vector<std::string>::const_iterator remBegin = remove.begin(); + auto remEnd = std::unique(remove.begin(), remove.end()); + auto remBegin = remove.begin(); - std::vector<std::string>::const_iterator argsEnd = + auto argsEnd = cmRemoveMatching(varArgsExpanded, cmMakeRange(remBegin, remEnd)); - std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin(); + auto argsBegin = varArgsExpanded.cbegin(); std::string value = cmJoin(cmMakeRange(argsBegin, argsEnd), ";"); status.GetMakefile().AddDefinition(listName, value); return true; @@ -491,9 +489,8 @@ bool HandleRemoveDuplicatesCommand(std::vector<std::string> const& args, return true; } - std::vector<std::string>::const_iterator argsEnd = - cmRemoveDuplicates(varArgsExpanded); - std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin(); + auto argsEnd = cmRemoveDuplicates(varArgsExpanded); + auto argsBegin = varArgsExpanded.cbegin(); std::string value = cmJoin(cmMakeRange(argsBegin, argsEnd), ";"); status.GetMakefile().AddDefinition(listName, value); @@ -1357,13 +1354,12 @@ bool HandleRemoveAtCommand(std::vector<std::string> const& args, } std::sort(removed.begin(), removed.end()); - std::vector<size_t>::const_iterator remEnd = - std::unique(removed.begin(), removed.end()); - std::vector<size_t>::const_iterator remBegin = removed.begin(); + auto remEnd = std::unique(removed.begin(), removed.end()); + auto remBegin = removed.begin(); - std::vector<std::string>::const_iterator argsEnd = + auto argsEnd = cmRemoveIndices(varArgsExpanded, cmMakeRange(remBegin, remEnd)); - std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin(); + auto argsBegin = varArgsExpanded.cbegin(); std::string value = cmJoin(cmMakeRange(argsBegin, argsEnd), ";"); status.GetMakefile().AddDefinition(listName, value); @@ -1456,9 +1452,9 @@ bool FilterRegex(std::vector<std::string> const& args, bool includeMatches, return false; } - std::vector<std::string>::iterator argsBegin = varArgsExpanded.begin(); - std::vector<std::string>::iterator argsEnd = varArgsExpanded.end(); - std::vector<std::string>::iterator newArgsEnd = + auto argsBegin = varArgsExpanded.begin(); + auto argsEnd = varArgsExpanded.end(); + auto newArgsEnd = std::remove_if(argsBegin, argsEnd, MatchesRegex(regex, includeMatches)); std::string value = cmJoin(cmMakeRange(argsBegin, newArgsEnd), ";"); diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index ff3ecd9..349d5e9 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -326,6 +326,7 @@ cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& snapshot) { } +/* NOLINTNEXTLINE(performance-unnecessary-value-param) */ cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr<Entry const> parent, cmListFileContext const& lfc) : TopEntry(std::make_shared<Entry const>(std::move(parent), lfc)) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 25e4d01..51eb78c 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -649,8 +649,7 @@ void cmLocalGenerator::AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt) cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget( const std::string& name) const { - GeneratorTargetMap::const_iterator ti = - this->GeneratorTargetSearchIndex.find(name); + auto ti = this->GeneratorTargetSearchIndex.find(name); if (ti != this->GeneratorTargetSearchIndex.end()) { return ti->second; } @@ -833,29 +832,50 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, const std::string& lang, const std::string& config) { + std::vector<BT<std::string>> tmpFlags; + this->AddCompileOptions(tmpFlags, target, lang, config); + this->AppendFlags(flags, tmpFlags); +} + +void cmLocalGenerator::AddCompileOptions(std::vector<BT<std::string>>& flags, + cmGeneratorTarget* target, + const std::string& lang, + const std::string& config) +{ std::string langFlagRegexVar = std::string("CMAKE_") + lang + "_FLAG_REGEX"; if (const char* langFlagRegexStr = this->Makefile->GetDefinition(langFlagRegexVar)) { // Filter flags acceptable to this language. - std::vector<std::string> opts; if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) { + std::vector<std::string> opts; cmSystemTools::ParseWindowsCommandLine(targetFlags, opts); + // Re-escape these flags since COMPILE_FLAGS were already parsed + // as a command line above. + std::string compileOpts; + this->AppendCompileOptions(compileOpts, opts, langFlagRegexStr); + if (!compileOpts.empty()) { + flags.emplace_back(std::move(compileOpts)); + } } - target->GetCompileOptions(opts, config, lang); - // (Re-)Escape these flags. COMPILE_FLAGS were already parsed - // as a command line above, and COMPILE_OPTIONS are escaped. - this->AppendCompileOptions(flags, opts, langFlagRegexStr); + std::vector<BT<std::string>> targetCompileOpts = + target->GetCompileOptions(config, lang); + // COMPILE_OPTIONS are escaped. + this->AppendCompileOptions(flags, targetCompileOpts, langFlagRegexStr); } else { // Use all flags. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) { // COMPILE_FLAGS are not escaped for historical reasons. - this->AppendFlags(flags, targetFlags); + std::string compileFlags; + this->AppendFlags(compileFlags, targetFlags); + if (!compileFlags.empty()) { + flags.emplace_back(std::move(compileFlags)); + } } - std::vector<std::string> opts; - target->GetCompileOptions(opts, config, lang); + std::vector<BT<std::string>> targetCompileOpts = + target->GetCompileOptions(config, lang); // COMPILE_OPTIONS are escaped. - this->AppendCompileOptions(flags, opts); + this->AppendCompileOptions(flags, targetCompileOpts); } for (auto const& it : target->GetMaxLanguageStandards()) { @@ -882,7 +902,12 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, return; } } - this->AddCompilerRequirementFlag(flags, target, lang); + + std::string compReqFlag; + this->AddCompilerRequirementFlag(compReqFlag, target, lang); + if (!compReqFlag.empty()) { + flags.emplace_back(std::move(compReqFlag)); + } // Add compile flag for the MSVC compiler only. cmMakefile* mf = this->GetMakefile(); @@ -903,7 +928,11 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, std::string isJMCEnabled = cge->Evaluate(this, config); if (cmIsOn(isJMCEnabled)) { std::vector<std::string> optVec = cmExpandedList(jmc); - this->AppendCompileOptions(flags, optVec); + std::string jmcFlags; + this->AppendCompileOptions(jmcFlags, optVec); + if (!jmcFlags.empty()) { + flags.emplace_back(std::move(jmcFlags)); + } } } } @@ -1118,24 +1147,49 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags, std::string const& linkLanguage, cmGeneratorTarget* target) { + std::vector<BT<std::string>> tmpFlags = + this->GetStaticLibraryFlags(config, linkLanguage, target); + this->AppendFlags(flags, tmpFlags); +} + +std::vector<BT<std::string>> cmLocalGenerator::GetStaticLibraryFlags( + std::string const& config, std::string const& linkLanguage, + cmGeneratorTarget* target) +{ + std::vector<BT<std::string>> flags; if (linkLanguage != "Swift") { + std::string staticLibFlags; this->AppendFlags( - flags, this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS")); + staticLibFlags, + this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS")); if (!config.empty()) { std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config; - this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name)); + this->AppendFlags(staticLibFlags, + this->Makefile->GetSafeDefinition(name)); + } + if (!staticLibFlags.empty()) { + flags.emplace_back(std::move(staticLibFlags)); } } - this->AppendFlags(flags, target->GetSafeProperty("STATIC_LIBRARY_FLAGS")); + + std::string staticLibFlags; + this->AppendFlags(staticLibFlags, + target->GetSafeProperty("STATIC_LIBRARY_FLAGS")); if (!config.empty()) { std::string name = "STATIC_LIBRARY_FLAGS_" + config; - this->AppendFlags(flags, target->GetSafeProperty(name)); + this->AppendFlags(staticLibFlags, target->GetSafeProperty(name)); + } + + if (!staticLibFlags.empty()) { + flags.emplace_back(std::move(staticLibFlags)); } - std::vector<std::string> options; - target->GetStaticLibraryLinkOptions(options, config, linkLanguage); + std::vector<BT<std::string>> staticLibOpts = + target->GetStaticLibraryLinkOptions(config, linkLanguage); // STATIC_LIBRARY_OPTIONS are escaped. - this->AppendCompileOptions(flags, options); + this->AppendCompileOptions(flags, staticLibOpts); + + return flags; } void cmLocalGenerator::GetTargetFlags( @@ -1143,6 +1197,18 @@ void cmLocalGenerator::GetTargetFlags( std::string& linkLibs, std::string& flags, std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target) { + std::vector<BT<std::string>> tmpLinkFlags; + this->GetTargetFlags(linkLineComputer, config, linkLibs, flags, tmpLinkFlags, + frameworkPath, linkPath, target); + this->AppendFlags(linkFlags, tmpLinkFlags); +} + +void cmLocalGenerator::GetTargetFlags( + cmLinkLineComputer* linkLineComputer, const std::string& config, + std::string& linkLibs, std::string& flags, + std::vector<BT<std::string>>& linkFlags, std::string& frameworkPath, + std::string& linkPath, cmGeneratorTarget* target) +{ const std::string buildType = cmSystemTools::UpperCase(config); cmComputeLinkInformation* pcli = target->GetLinkInformation(config); const char* libraryLinkVariable = @@ -1153,7 +1219,7 @@ void cmLocalGenerator::GetTargetFlags( switch (target->GetType()) { case cmStateEnums::STATIC_LIBRARY: - this->GetStaticLibraryFlags(linkFlags, buildType, linkLanguage, target); + linkFlags = this->GetStaticLibraryFlags(buildType, linkLanguage, target); if (pcli && dynamic_cast<cmLinkLineDeviceComputer*>(linkLineComputer)) { // Compute the required cuda device link libraries when // resolving cuda device symbols @@ -1165,13 +1231,14 @@ void cmLocalGenerator::GetTargetFlags( libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS"; CM_FALLTHROUGH; case cmStateEnums::SHARED_LIBRARY: { + std::string sharedLibFlags; if (linkLanguage != "Swift") { - linkFlags = cmStrCat( + sharedLibFlags = cmStrCat( this->Makefile->GetSafeDefinition(libraryLinkVariable), ' '); if (!buildType.empty()) { std::string build = cmStrCat(libraryLinkVariable, '_', buildType); - linkFlags += this->Makefile->GetSafeDefinition(build); - linkFlags += " "; + sharedLibFlags += this->Makefile->GetSafeDefinition(build); + sharedLibFlags += " "; } if (this->Makefile->IsOn("WIN32") && !(this->Makefile->IsOn("CYGWIN") || @@ -1182,10 +1249,10 @@ void cmLocalGenerator::GetTargetFlags( this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG"); for (cmSourceFile* sf : sources) { if (sf->GetExtension() == "def") { - linkFlags += defFlag; - linkFlags += this->ConvertToOutputFormat( + sharedLibFlags += defFlag; + sharedLibFlags += this->ConvertToOutputFormat( cmSystemTools::CollapseFullPath(sf->ResolveFullPath()), SHELL); - linkFlags += " "; + sharedLibFlags += " "; } } } @@ -1193,36 +1260,40 @@ void cmLocalGenerator::GetTargetFlags( const char* targetLinkFlags = target->GetProperty("LINK_FLAGS"); if (targetLinkFlags) { - linkFlags += targetLinkFlags; - linkFlags += " "; + sharedLibFlags += targetLinkFlags; + sharedLibFlags += " "; } if (!buildType.empty()) { targetLinkFlags = target->GetProperty(cmStrCat("LINK_FLAGS_", buildType)); if (targetLinkFlags) { - linkFlags += targetLinkFlags; - linkFlags += " "; + sharedLibFlags += targetLinkFlags; + sharedLibFlags += " "; } } - std::vector<std::string> opts; - target->GetLinkOptions(opts, config, linkLanguage); + if (!sharedLibFlags.empty()) { + linkFlags.emplace_back(std::move(sharedLibFlags)); + } + + std::vector<BT<std::string>> linkOpts = + target->GetLinkOptions(config, linkLanguage); // LINK_OPTIONS are escaped. - this->AppendCompileOptions(linkFlags, opts); + this->AppendCompileOptions(linkFlags, linkOpts); if (pcli) { this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, frameworkPath, linkPath); } } break; case cmStateEnums::EXECUTABLE: { + std::string exeFlags; if (linkLanguage != "Swift") { - linkFlags += - this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); - linkFlags += " "; + exeFlags = this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); + exeFlags += " "; if (!buildType.empty()) { - linkFlags += this->Makefile->GetSafeDefinition( + exeFlags += this->Makefile->GetSafeDefinition( cmStrCat("CMAKE_EXE_LINKER_FLAGS_", buildType)); - linkFlags += " "; + exeFlags += " "; } if (linkLanguage.empty()) { cmSystemTools::Error( @@ -1232,19 +1303,19 @@ void cmLocalGenerator::GetTargetFlags( } if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) { - linkFlags += + exeFlags += this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE"); - linkFlags += " "; + exeFlags += " "; } else { - linkFlags += + exeFlags += this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE"); - linkFlags += " "; + exeFlags += " "; } if (target->IsExecutableWithExports()) { - linkFlags += this->Makefile->GetSafeDefinition( + exeFlags += this->Makefile->GetSafeDefinition( cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG")); - linkFlags += " "; + exeFlags += " "; } } @@ -1257,43 +1328,52 @@ void cmLocalGenerator::GetTargetFlags( if (cmIsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) { std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") + linkLanguage + std::string("_FLAGS"); - linkFlags += this->Makefile->GetSafeDefinition(sFlagVar); - linkFlags += " "; + exeFlags += this->Makefile->GetSafeDefinition(sFlagVar); + exeFlags += " "; } std::string cmp0065Flags = this->GetLinkLibsCMP0065(linkLanguage, *target); if (!cmp0065Flags.empty()) { - linkFlags += cmp0065Flags; - linkFlags += " "; + exeFlags += cmp0065Flags; + exeFlags += " "; } const char* targetLinkFlags = target->GetProperty("LINK_FLAGS"); if (targetLinkFlags) { - linkFlags += targetLinkFlags; - linkFlags += " "; + exeFlags += targetLinkFlags; + exeFlags += " "; } if (!buildType.empty()) { targetLinkFlags = target->GetProperty(cmStrCat("LINK_FLAGS_", buildType)); if (targetLinkFlags) { - linkFlags += targetLinkFlags; - linkFlags += " "; + exeFlags += targetLinkFlags; + exeFlags += " "; } } - std::vector<std::string> opts; - target->GetLinkOptions(opts, config, linkLanguage); + if (!exeFlags.empty()) { + linkFlags.emplace_back(std::move(exeFlags)); + } + + std::vector<BT<std::string>> linkOpts = + target->GetLinkOptions(config, linkLanguage); // LINK_OPTIONS are escaped. - this->AppendCompileOptions(linkFlags, opts); + this->AppendCompileOptions(linkFlags, linkOpts); } break; default: break; } - this->AppendPositionIndependentLinkerFlags(linkFlags, target, config, + std::string extraLinkFlags; + this->AppendPositionIndependentLinkerFlags(extraLinkFlags, target, config, linkLanguage); - this->AppendIPOLinkerFlags(linkFlags, target, config, linkLanguage); + this->AppendIPOLinkerFlags(extraLinkFlags, target, config, linkLanguage); + + if (!extraLinkFlags.empty()) { + linkFlags.emplace_back(std::move(extraLinkFlags)); + } } void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target, @@ -1301,26 +1381,45 @@ void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target, std::string const& lang, std::string& flags) { + std::vector<BT<std::string>> tmpFlags = + this->GetTargetCompileFlags(target, config, lang); + this->AppendFlags(flags, tmpFlags); +} + +std::vector<BT<std::string>> cmLocalGenerator::GetTargetCompileFlags( + cmGeneratorTarget* target, std::string const& config, + std::string const& lang) +{ + std::vector<BT<std::string>> flags; + std::string compileFlags; + cmMakefile* mf = this->GetMakefile(); // Add language-specific flags. - this->AddLanguageFlags(flags, target, lang, config); + this->AddLanguageFlags(compileFlags, target, lang, config); if (target->IsIPOEnabled(lang, config)) { - this->AppendFeatureOptions(flags, lang, "IPO"); + this->AppendFeatureOptions(compileFlags, lang, "IPO"); } - this->AddArchitectureFlags(flags, target, lang, config); + this->AddArchitectureFlags(compileFlags, target, lang, config); if (lang == "Fortran") { - this->AppendFlags(flags, this->GetTargetFortranFlags(target, config)); + this->AppendFlags(compileFlags, + this->GetTargetFortranFlags(target, config)); } - this->AddCMP0018Flags(flags, target, lang, config); - this->AddVisibilityPresetFlags(flags, target, lang); - this->AppendFlags(flags, mf->GetDefineFlags()); - this->AppendFlags(flags, this->GetFrameworkFlags(lang, config, target)); + this->AddCMP0018Flags(compileFlags, target, lang, config); + this->AddVisibilityPresetFlags(compileFlags, target, lang); + this->AppendFlags(compileFlags, mf->GetDefineFlags()); + this->AppendFlags(compileFlags, + this->GetFrameworkFlags(lang, config, target)); + + if (!compileFlags.empty()) { + flags.emplace_back(std::move(compileFlags)); + } this->AddCompileOptions(flags, target, lang, config); + return flags; } static std::string GetFrameworkFlags(const std::string& lang, @@ -1641,8 +1740,7 @@ void cmLocalGenerator::AddLanguageFlagsForLinking( cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse( const std::string& name) const { - GeneratorTargetMap::const_iterator imported = - this->ImportedGeneratorTargets.find(name); + auto imported = this->ImportedGeneratorTargets.find(name); if (imported != this->ImportedGeneratorTargets.end()) { return imported->second; } @@ -1843,8 +1941,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag( std::vector<std::string>& stds = langStdMap[lang]; - std::vector<std::string>::const_iterator stdIt = - std::find(stds.begin(), stds.end(), standard); + auto stdIt = std::find(stds.begin(), stds.end(), standard); if (stdIt == stds.end()) { std::string e = lang + "_STANDARD is set to invalid value '" + standard + "'"; @@ -1853,8 +1950,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag( return; } - std::vector<std::string>::const_iterator defaultStdIt = - std::find(stds.begin(), stds.end(), defaultStd); + auto defaultStdIt = std::find(stds.begin(), stds.end(), defaultStd); if (defaultStdIt == stds.end()) { std::string e = "CMAKE_" + lang + "_STANDARD_DEFAULT is set to invalid value '" + std::string(defaultStd) + @@ -2096,12 +2192,11 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags, const std::string& config) { // Add the flags from the variable itself. - std::string flagsVar = var; - this->AppendFlags(flags, this->Makefile->GetSafeDefinition(flagsVar)); + this->AppendFlags(flags, this->Makefile->GetSafeDefinition(var)); // Add the flags from the build-type specific variable. if (!config.empty()) { - flagsVar += "_"; - flagsVar += cmSystemTools::UpperCase(config); + const std::string flagsVar = + cmStrCat(var, '_', cmSystemTools::UpperCase(config)); this->AppendFlags(flags, this->Makefile->GetSafeDefinition(flagsVar)); } } @@ -2117,6 +2212,14 @@ void cmLocalGenerator::AppendFlags(std::string& flags, } } +void cmLocalGenerator::AppendFlags( + std::string& flags, const std::vector<BT<std::string>>& newFlags) const +{ + for (BT<std::string> const& flag : newFlags) { + this->AppendFlags(flags, flag.Value); + } +} + void cmLocalGenerator::AppendFlagEscape(std::string& flags, const std::string& rawFlag) const { @@ -2282,8 +2385,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target, } } } - cmSystemTools::CopyFileIfDifferent(filename_tmp, filename); - cmSystemTools::RemoveFile(filename_tmp); + cmSystemTools::MoveFileIfDifferent(filename_tmp, filename); target->AddSource(filename, true); @@ -2393,6 +2495,30 @@ void cmLocalGenerator::AppendCompileOptions( } } +void cmLocalGenerator::AppendCompileOptions( + std::vector<BT<std::string>>& options, + const std::vector<BT<std::string>>& options_vec, const char* regex) const +{ + if (regex != nullptr) { + // Filter flags upon specified regular expressions. + cmsys::RegularExpression r(regex); + + for (BT<std::string> const& opt : options_vec) { + if (r.find(opt.Value)) { + std::string flag; + this->AppendFlagEscape(flag, opt.Value); + options.emplace_back(std::move(flag), opt.Backtrace); + } + } + } else { + for (BT<std::string> const& opt : options_vec) { + std::string flag; + this->AppendFlagEscape(flag, opt.Value); + options.emplace_back(std::move(flag), opt.Backtrace); + } + } +} + void cmLocalGenerator::AppendIncludeDirectories( std::vector<std::string>& includes, const char* includes_list, const cmSourceFile& sourceFile) const @@ -2721,8 +2847,7 @@ std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName( const std::string& sin, std::string const& dir_max) { // Look for an existing mapped name for this object file. - std::map<std::string, std::string>::iterator it = - this->UniqueObjectNamesMap.find(sin); + auto it = this->UniqueObjectNamesMap.find(sin); // If no entry exists create one. if (it == this->UniqueObjectNamesMap.end()) { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index e6ba333..34f58bd 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -121,6 +121,8 @@ public: //! Append flags to a string. virtual void AppendFlags(std::string& flags, const std::string& newFlags) const; + virtual void AppendFlags(std::string& flags, + const std::vector<BT<std::string>>& newFlags) const; virtual void AppendFlagEscape(std::string& flags, const std::string& rawFlag) const; void AddPchDependencies(cmGeneratorTarget* target, @@ -197,6 +199,9 @@ public: void AppendCompileOptions(std::string& options, const std::vector<std::string>& options_vec, const char* regex = nullptr) const; + void AppendCompileOptions(std::vector<BT<std::string>>& options, + const std::vector<BT<std::string>>& options_vec, + const char* regex = nullptr) const; /** * Join a set of defines into a definesString with a space separator. @@ -283,6 +288,9 @@ public: void AddCompileOptions(std::string& flags, cmGeneratorTarget* target, const std::string& lang, const std::string& config); + void AddCompileOptions(std::vector<BT<std::string>>& flags, + cmGeneratorTarget* target, const std::string& lang, + const std::string& config); std::string GetProjectName() const; @@ -363,6 +371,9 @@ public: void GetStaticLibraryFlags(std::string& flags, std::string const& config, std::string const& linkLanguage, cmGeneratorTarget* target); + std::vector<BT<std::string>> GetStaticLibraryFlags( + std::string const& config, std::string const& linkLanguage, + cmGeneratorTarget* target); /** Fill out these strings for the given target. Libraries to link, * flags, and linkflags. */ @@ -371,6 +382,12 @@ public: std::string& flags, std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target); + void GetTargetFlags(cmLinkLineComputer* linkLineComputer, + const std::string& config, std::string& linkLibs, + std::string& flags, + std::vector<BT<std::string>>& linkFlags, + std::string& frameworkPath, std::string& linkPath, + cmGeneratorTarget* target); void GetTargetDefines(cmGeneratorTarget const* target, std::string const& config, std::string const& lang, std::set<std::string>& defines) const; @@ -380,6 +397,9 @@ public: void GetTargetCompileFlags(cmGeneratorTarget* target, std::string const& config, std::string const& lang, std::string& flags); + std::vector<BT<std::string>> GetTargetCompileFlags(cmGeneratorTarget* target, + std::string const& config, + std::string const& lang); std::string GetFrameworkFlags(std::string const& l, std::string const& config, diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index e28b876..1284d4d 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -386,8 +386,7 @@ std::string cmLocalNinjaGenerator::BuildCommandLine( } std::ostringstream cmd; - for (std::vector<std::string>::const_iterator li = cmdLines.begin(); - li != cmdLines.end(); ++li) + for (auto li = cmdLines.begin(); li != cmdLines.end(); ++li) #ifdef _WIN32 { if (li != cmdLines.begin()) { @@ -531,8 +530,7 @@ void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc, void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements() { for (cmCustomCommand const* customCommand : this->CustomCommands) { - CustomCommandTargetMap::iterator i = - this->CustomCommandTargets.find(customCommand); + auto i = this->CustomCommandTargets.find(customCommand); assert(i != this->CustomCommandTargets.end()); // A custom command may appear on multiple targets. However, some build @@ -544,7 +542,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements() // // FIXME: This won't work in certain obscure scenarios involving indirect // dependencies. - std::set<cmGeneratorTarget*>::iterator j = i->second.begin(); + auto j = i->second.begin(); assert(j != i->second.end()); std::vector<std::string> ccTargetDeps; this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j, diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 320a58b..8248608 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1225,8 +1225,7 @@ std::string cmLocalUnixMakefileGenerator3::CreateMakeVariable( // see if the variable has been defined before and return // the modified version of the variable - std::map<std::string, std::string>::iterator i = - this->MakeVariableMap.find(unmodified); + auto i = this->MakeVariableMap.find(unmodified); if (i != this->MakeVariableMap.end()) { return i->second; } @@ -1495,8 +1494,7 @@ void cmLocalUnixMakefileGenerator3::CheckMultipleOutputs(bool verbose) // Convert the string to a list and preserve empty entries. std::vector<std::string> pairs = cmExpandedList(pairs_string, true); - for (std::vector<std::string>::const_iterator i = pairs.begin(); - i != pairs.end() && (i + 1) != pairs.end();) { + for (auto i = pairs.begin(); i != pairs.end() && (i + 1) != pairs.end();) { const std::string& depender = *i++; const std::string& dependee = *i++; @@ -2019,10 +2017,9 @@ std::string cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath( if (components.size() > 1) { // Now add the rest of the components separated by the proper slash // direction for this platform. - std::vector<std::string>::const_iterator compEnd = std::remove( - components.begin() + 1, components.end() - 1, std::string()); - std::vector<std::string>::const_iterator compStart = - components.begin() + 1; + auto compEnd = std::remove(components.begin() + 1, components.end() - 1, + std::string()); + auto compStart = components.begin() + 1; result += cmJoin(cmMakeRange(compStart, compEnd), slash); // Only the last component can be empty to avoid double slashes. result += slash; diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 745e251..c02c0dc 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -90,6 +90,7 @@ public: // append flags to a string void AppendFlags(std::string& flags, const std::string& newFlags) const override; + using cmLocalCommonGenerator::AppendFlags; // append an echo command enum EchoColor diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 201cc13..ef6a705 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -65,8 +65,7 @@ bool cmMacroHelperCommand::operator()( // set the value of argc std::string argcDef = std::to_string(expandedArgs.size()); - std::vector<std::string>::const_iterator eit = - expandedArgs.begin() + (this->Args.size() - 1); + auto eit = expandedArgs.begin() + (this->Args.size() - 1); std::string expandedArgn = cmJoin(cmMakeRange(eit, expandedArgs.end()), ";"); std::string expandedArgv = cmJoin(expandedArgs, ";"); std::vector<std::string> variables; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 411add3..9e64f97 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -751,9 +751,8 @@ cmMakefile::GetExportBuildFileGenerators() const void cmMakefile::RemoveExportBuildFileGeneratorCMP0024( cmExportBuildFileGenerator* gen) { - std::vector<cmExportBuildFileGenerator*>::iterator it = - std::find(this->ExportBuildFileGenerators.begin(), - this->ExportBuildFileGenerators.end(), gen); + auto it = std::find(this->ExportBuildFileGenerators.begin(), + this->ExportBuildFileGenerators.end(), gen); if (it != this->ExportBuildFileGenerators.end()) { this->ExportBuildFileGenerators.erase(it); } @@ -829,7 +828,7 @@ void cmMakefile::AddCustomCommandToTarget( bool command_expand_lists, ObjectLibraryCommands objLibraryCommands) { // Find the target to which to add the custom command. - cmTargetMap::iterator ti = this->Targets.find(target); + auto ti = this->Targets.find(target); if (ti == this->Targets.end()) { MessageType messageType = MessageType::AUTHOR_WARNING; @@ -860,7 +859,7 @@ void cmMakefile::AddCustomCommandToTarget( e << "No TARGET '" << target << "' has been created in this directory."; } - IssueMessage(messageType, e.str()); + this->IssueMessage(messageType, e.str()); } return; @@ -886,11 +885,7 @@ void cmMakefile::AddCustomCommandToTarget( } // Always create the byproduct sources and mark them generated. - for (std::string const& o : byproducts) { - if (cmSourceFile* out = this->GetOrCreateSource(o, true)) { - out->SetProperty("GENERATED", "1"); - } - } + this->CreateGeneratedSources(byproducts); // Add the command to the appropriate build step for the target. std::vector<std::string> no_output; @@ -913,6 +908,37 @@ void cmMakefile::AddCustomCommandToTarget( t.AddPostBuildCommand(cc); break; } + this->UpdateOutputToSourceMap(byproducts, &t); +} + +void cmMakefile::UpdateOutputToSourceMap( + std::vector<std::string> const& byproducts, cmTarget* target) +{ + for (std::string const& o : byproducts) { + this->UpdateOutputToSourceMap(o, target); + } +} + +void cmMakefile::UpdateOutputToSourceMap(std::string const& byproduct, + cmTarget* target) +{ + SourceEntry entry; + entry.Sources.Target = target; + + auto pr = this->OutputToSource.emplace(byproduct, entry); + if (!pr.second) { + SourceEntry& current = pr.first->second; + // Has the target already been set? + if (!current.Sources.Target) { + current.Sources.Target = target; + } else { + // Multiple custom commands/targets produce the same output (source file + // or target). See also comment in other UpdateOutputToSourceMap + // overload. + // + // TODO: Warn the user about this case. + } + } } cmSourceFile* cmMakefile::AddCustomCommandToOutput( @@ -940,6 +966,10 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( } } + // Always create the output sources and mark them generated. + this->CreateGeneratedSources(outputs, cmSourceFileLocationKind::Known); + this->CreateGeneratedSources(byproducts, cmSourceFileLocationKind::Known); + // Choose a source file on which to store the custom command. cmSourceFile* file = nullptr; if (!commandLines.empty() && !main_dependency.empty()) { @@ -987,20 +1017,6 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( file->SetProperty("__CMAKE_RULE", "1"); } - // Always create the output sources and mark them generated. - for (std::string const& o : outputs) { - if (cmSourceFile* out = - this->GetOrCreateSource(o, true, cmSourceFileLocationKind::Known)) { - out->SetProperty("GENERATED", "1"); - } - } - for (std::string const& o : byproducts) { - if (cmSourceFile* out = - this->GetOrCreateSource(o, true, cmSourceFileLocationKind::Known)) { - out->SetProperty("GENERATED", "1"); - } - } - // Attach the custom command to the file. if (file) { // Construct a complete list of dependencies. @@ -1018,35 +1034,47 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( cc->SetDepfile(depfile); cc->SetJobPool(job_pool); file->SetCustomCommand(cc); - this->UpdateOutputToSourceMap(outputs, file); + this->UpdateOutputToSourceMap(outputs, file, false); + this->UpdateOutputToSourceMap(byproducts, file, true); } return file; } void cmMakefile::UpdateOutputToSourceMap( - std::vector<std::string> const& outputs, cmSourceFile* source) + std::vector<std::string> const& outputs, cmSourceFile* source, + bool byproduct) { for (std::string const& o : outputs) { - this->UpdateOutputToSourceMap(o, source); + this->UpdateOutputToSourceMap(o, source, byproduct); } } void cmMakefile::UpdateOutputToSourceMap(std::string const& output, - cmSourceFile* source) -{ - OutputToSourceMap::iterator i = this->OutputToSource.find(output); - if (i != this->OutputToSource.end()) { - // Multiple custom commands produce the same output but may - // be attached to a different source file (MAIN_DEPENDENCY). - // LinearGetSourceFileWithOutput would return the first one, - // so keep the mapping for the first one. - // - // TODO: Warn the user about this case. However, the VS 8 generator - // triggers it for separate generate.stamp rules in ZERO_CHECK and - // individual targets. - return; + cmSourceFile* source, bool byproduct) +{ + SourceEntry entry; + entry.Sources.Source = source; + entry.Sources.SourceIsByproduct = byproduct; + + auto pr = this->OutputToSource.emplace(output, entry); + if (!pr.second) { + SourceEntry& current = pr.first->second; + // Outputs take precedence over byproducts + if (!current.Sources.Source || + (current.Sources.SourceIsByproduct && !byproduct)) { + current.Sources.Source = source; + current.Sources.SourceIsByproduct = false; + } else { + // Multiple custom commands produce the same output but may + // be attached to a different source file (MAIN_DEPENDENCY). + // LinearGetSourceFileWithOutput would return the first one, + // so keep the mapping for the first one. + // + // TODO: Warn the user about this case. However, the VS 8 generator + // triggers it for separate generate.stamp rules in ZERO_CHECK and + // individual targets. + } } - this->OutputToSource[output] = source; } cmSourceFile* cmMakefile::AddCustomCommandToOutput( @@ -1110,7 +1138,7 @@ void cmMakefile::AddCustomCommandOldStyle( // then add the source to the target to make sure the rule is // included. if (sf && !sf->GetPropertyAsBool("__CMAKE_RULE")) { - cmTargetMap::iterator ti = this->Targets.find(target); + auto ti = this->Targets.find(target); if (ti != this->Targets.end()) { ti->second.AddSource(sf->ResolveFullPath()); } else { @@ -1180,6 +1208,7 @@ cmTarget* cmMakefile::AddUtilityCommand( if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } + if (!comment) { // Use an empty comment to avoid generation of default comment. comment = ""; @@ -1187,6 +1216,9 @@ cmTarget* cmMakefile::AddUtilityCommand( // Store the custom command in the target. if (!commandLines.empty() || !depends.empty()) { + // Always create the byproduct sources and mark them generated. + this->CreateGeneratedSources(byproducts, cmSourceFileLocationKind::Known); + std::string force = cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/", utilityName); std::vector<std::string> forced; @@ -1206,13 +1238,7 @@ cmTarget* cmMakefile::AddUtilityCommand( cmSystemTools::Error("Could not get source file entry for " + force); } - // Always create the byproduct sources and mark them generated. - for (std::string const& byproduct : byproducts) { - if (cmSourceFile* out = this->GetOrCreateSource( - byproduct, true, cmSourceFileLocationKind::Known)) { - out->SetProperty("GENERATED", "1"); - } - } + this->UpdateOutputToSourceMap(byproducts, target); } return target; } @@ -1355,9 +1381,8 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) std::vector<std::string> defs = cmExpandedList(cdefs); // Recompose the list without the definition. - std::vector<std::string>::const_iterator defEnd = - std::remove(defs.begin(), defs.end(), define); - std::vector<std::string>::const_iterator defBegin = defs.begin(); + auto defEnd = std::remove(defs.begin(), defs.end(), define); + auto defBegin = defs.begin(); std::string ndefs = cmJoin(cmMakeRange(defBegin, defEnd), ";"); // Store the new list. @@ -1640,7 +1665,7 @@ void cmMakefile::Configure() std::vector<cmMakefile*> subdirs = this->UnConfiguredDirectories; // for each subdir recurse - std::vector<cmMakefile*>::iterator sdi = subdirs.begin(); + auto sdi = subdirs.begin(); for (; sdi != subdirs.end(); ++sdi) { (*sdi)->StateSnapshot.InitializeFromParent_ForSubdirsCommand(); this->ConfigureSubDirectory(*sdi); @@ -1954,8 +1979,7 @@ void cmMakefile::AddGlobalLinkInformation(cmTarget& target) if (const char* linkLibsProp = this->GetProperty("LINK_LIBRARIES")) { std::vector<std::string> linkLibs = cmExpandedList(linkLibsProp); - for (std::vector<std::string>::iterator j = linkLibs.begin(); - j != linkLibs.end(); ++j) { + for (auto j = linkLibs.begin(); j != linkLibs.end(); ++j) { std::string libraryName = *j; cmTargetLinkLibraryType libType = GENERAL_LibraryType; if (libraryName == "optimized") { @@ -2024,56 +2048,130 @@ cmTarget* cmMakefile::AddExecutable(const std::string& exeName, cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type, const std::string& name) { - cmTargetMap::iterator it = + auto it = this->Targets .emplace(name, cmTarget(name, type, cmTarget::VisibilityNormal, this)) .first; + this->OrderedTargets.push_back(&it->second); this->GetGlobalGenerator()->IndexTarget(&it->second); this->GetStateSnapshot().GetDirectory().AddNormalTargetName(name); return &it->second; } +namespace { +bool AnyOutputMatches(const std::string& name, + const std::vector<std::string>& outputs) +{ + for (std::string const& output : outputs) { + std::string::size_type pos = output.rfind(name); + // If the output matches exactly + if (pos != std::string::npos && pos == output.size() - name.size() && + (pos == 0 || output[pos - 1] == '/')) { + return true; + } + } + return false; +} + +bool AnyTargetCommandOutputMatches( + const std::string& name, const std::vector<cmCustomCommand>& commands) +{ + for (cmCustomCommand const& command : commands) { + if (AnyOutputMatches(name, command.GetByproducts())) { + return true; + } + } + return false; +} +} + +cmTarget* cmMakefile::LinearGetTargetWithOutput(const std::string& name) const +{ + // We go through the ordered vector of targets to get reproducible results + // should multiple names match. + for (cmTarget* t : this->OrderedTargets) { + // Does the output of any command match the source file name? + if (AnyTargetCommandOutputMatches(name, t->GetPreBuildCommands())) { + return t; + } + if (AnyTargetCommandOutputMatches(name, t->GetPreLinkCommands())) { + return t; + } + if (AnyTargetCommandOutputMatches(name, t->GetPostBuildCommands())) { + return t; + } + } + return nullptr; +} + cmSourceFile* cmMakefile::LinearGetSourceFileWithOutput( - const std::string& name) const + const std::string& name, cmSourceOutputKind kind, bool& byproduct) const { - std::string out; + // Outputs take precedence over byproducts. + byproduct = false; + cmSourceFile* fallback = nullptr; - // look through all the source files that have custom commands - // and see if the custom command has the passed source file as an output + // Look through all the source files that have custom commands and see if the + // custom command has the passed source file as an output. for (cmSourceFile* src : this->SourceFiles) { - // does this source file have a custom command? + // Does this source file have a custom command? if (src->GetCustomCommand()) { // Does the output of the custom command match the source file name? - const std::vector<std::string>& outputs = - src->GetCustomCommand()->GetOutputs(); - for (std::string const& output : outputs) { - out = output; - std::string::size_type pos = out.rfind(name); - // If the output matches exactly - if (pos != std::string::npos && pos == out.size() - name.size() && - (pos == 0 || out[pos - 1] == '/')) { - return src; + if (AnyOutputMatches(name, src->GetCustomCommand()->GetOutputs())) { + // Return the first matching output. + return src; + } + if (kind == cmSourceOutputKind::OutputOrByproduct) { + if (AnyOutputMatches(name, src->GetCustomCommand()->GetByproducts())) { + // Do not return the source yet as there might be a matching output. + fallback = src; } } } } - // otherwise return NULL - return nullptr; + // Did we find a byproduct? + byproduct = fallback != nullptr; + return fallback; } -cmSourceFile* cmMakefile::GetSourceFileWithOutput( +cmSourcesWithOutput cmMakefile::GetSourcesWithOutput( const std::string& name) const { + // Linear search? Also see GetSourceFileWithOutput for detail. + if (!cmSystemTools::FileIsFullPath(name)) { + cmSourcesWithOutput sources; + sources.Target = this->LinearGetTargetWithOutput(name); + sources.Source = this->LinearGetSourceFileWithOutput( + name, cmSourceOutputKind::OutputOrByproduct, sources.SourceIsByproduct); + return sources; + } + // Otherwise we use an efficient lookup map. + auto o = this->OutputToSource.find(name); + if (o != this->OutputToSource.end()) { + return o->second.Sources; + } + return {}; +} + +cmSourceFile* cmMakefile::GetSourceFileWithOutput( + const std::string& name, cmSourceOutputKind kind) const +{ // If the queried path is not absolute we use the backward compatible // linear-time search for an output with a matching suffix. if (!cmSystemTools::FileIsFullPath(name)) { - return this->LinearGetSourceFileWithOutput(name); + bool byproduct = false; + return this->LinearGetSourceFileWithOutput(name, kind, byproduct); } // Otherwise we use an efficient lookup map. - OutputToSourceMap::const_iterator o = this->OutputToSource.find(name); - if (o != this->OutputToSource.end()) { - return (*o).second; + auto o = this->OutputToSource.find(name); + if (o != this->OutputToSource.end() && + (!o->second.Sources.SourceIsByproduct || + kind == cmSourceOutputKind::OutputOrByproduct)) { + // Source file could also be null pointer for example if we found the + // byproduct of a utility target or a PRE_BUILD, PRE_LINK, or POST_BUILD + // command of a target. + return o->second.Sources.Source; } return nullptr; } @@ -2188,8 +2286,7 @@ cmSourceGroup* cmMakefile::FindSourceGroup( const std::string& source, std::vector<cmSourceGroup>& groups) const { // First search for a group that lists the file explicitly. - for (std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin(); - sg != groups.rend(); ++sg) { + for (auto sg = groups.rbegin(); sg != groups.rend(); ++sg) { cmSourceGroup* result = sg->MatchChildrenFiles(source); if (result) { return result; @@ -2197,8 +2294,7 @@ cmSourceGroup* cmMakefile::FindSourceGroup( } // Now search for a group whose regex matches the file. - for (std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin(); - sg != groups.rend(); ++sg) { + for (auto sg = groups.rbegin(); sg != groups.rend(); ++sg) { cmSourceGroup* result = sg->MatchChildrenRegex(source); if (result) { return result; @@ -2281,8 +2377,7 @@ void cmMakefile::ExpandVariablesCMP0019() if (const char* linkLibsProp = this->GetProperty("LINK_LIBRARIES")) { std::vector<std::string> linkLibs = cmExpandedList(linkLibsProp); - for (std::vector<std::string>::iterator l = linkLibs.begin(); - l != linkLibs.end(); ++l) { + for (auto l = linkLibs.begin(); l != linkLibs.end(); ++l) { std::string libName = *l; if (libName == "optimized") { ++l; @@ -3325,6 +3420,16 @@ cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName, return this->CreateSource(sourceName, generated, kind); } +void cmMakefile::CreateGeneratedSources( + const std::vector<std::string>& outputs, cmSourceFileLocationKind kind) +{ + for (std::string const& output : outputs) { + if (cmSourceFile* out = this->GetOrCreateSource(output, true, kind)) { + out->SetProperty("GENERATED", "1"); + } + } +} + void cmMakefile::AddTargetObject(std::string const& tgtName, std::string const& objFile) { @@ -3841,7 +3946,7 @@ std::vector<std::string> cmMakefile::GetPropertyKeys() const cmTarget* cmMakefile::FindLocalNonAliasTarget(const std::string& name) const { - cmTargetMap::iterator i = this->Targets.find(name); + auto i = this->Targets.find(name); if (i != this->Targets.end()) { return &i->second; } @@ -3862,8 +3967,7 @@ cmTest* cmMakefile::CreateTest(const std::string& testName) cmTest* cmMakefile::GetTest(const std::string& testName) const { - std::map<std::string, cmTest*>::const_iterator mi = - this->Tests.find(testName); + auto mi = this->Tests.find(testName); if (mi != this->Tests.end()) { return mi->second; } @@ -3908,7 +4012,7 @@ std::string cmMakefile::FormatListFileStack() const std::ostringstream tmp; size_t depth = listFiles.size(); if (depth > 0) { - std::vector<std::string>::const_iterator it = listFiles.end(); + auto it = listFiles.end(); do { if (depth != listFiles.size()) { tmp << "\n "; @@ -3995,7 +4099,7 @@ cmTarget* cmMakefile::FindTargetToUse(const std::string& name, { // Look for an imported target. These take priority because they // are more local in scope and do not have to be globally unique. - TargetMap::const_iterator imported = this->ImportedTargets.find(name); + auto imported = this->ImportedTargets.find(name); if (imported != this->ImportedTargets.end()) { return imported->second; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 09f53c9..dc9318b 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -51,6 +51,24 @@ class cmTestGenerator; class cmVariableWatch; class cmake; +/** Flag if byproducts shall also be considered. */ +enum class cmSourceOutputKind +{ + OutputOnly, + OutputOrByproduct +}; + +/** Target and source file which have a specific output. */ +struct cmSourcesWithOutput +{ + /** Target with byproduct. */ + cmTarget* Target = nullptr; + + /** Source file with output or byproduct. */ + cmSourceFile* Source = nullptr; + bool SourceIsByproduct = false; +}; + /** A type-safe wrapper for a string representing a directory id. */ class cmDirectoryId { @@ -687,10 +705,19 @@ public: } /** - * Is there a source file that has the provided source file as an output? - * if so then return it + * Return the target if the provided source name is a byproduct of a utility + * target or a PRE_BUILD, PRE_LINK, or POST_BUILD command. + * Return the source file which has the provided source name as output. */ - cmSourceFile* GetSourceFileWithOutput(const std::string& outName) const; + cmSourcesWithOutput GetSourcesWithOutput(const std::string& name) const; + + /** + * Is there a source file that has the provided source name as an output? + * If so then return it. + */ + cmSourceFile* GetSourceFileWithOutput( + const std::string& name, + cmSourceOutputKind kind = cmSourceOutputKind::OutputOnly) const; //! Add a new cmTest to the list of tests for this makefile. cmTest* CreateTest(const std::string& testName); @@ -914,6 +941,9 @@ protected: mutable cmTargetMap Targets; std::map<std::string, std::string> AliasTargets; + using TargetsVec = std::vector<cmTarget*>; + TargetsVec OrderedTargets; + using SourceFileVec = std::vector<cmSourceFile*>; SourceFileVec SourceFiles; @@ -1030,22 +1060,43 @@ private: bool escapeQuotes, bool noEscapes, bool atOnly, const char* filename, long line, bool replaceAt) const; + + void CreateGeneratedSources( + const std::vector<std::string>& outputs, + cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); + /** - * Old version of GetSourceFileWithOutput(const std::string&) kept for - * backward-compatibility. It implements a linear search and support - * relative file paths. It is used as a fall back by - * GetSourceFileWithOutput(const std::string&). + * See LinearGetSourceFileWithOutput for background information */ - cmSourceFile* LinearGetSourceFileWithOutput(const std::string& cname) const; + cmTarget* LinearGetTargetWithOutput(const std::string& name) const; + + /** + * Generalized old version of GetSourceFileWithOutput kept for + * backward-compatibility. It implements a linear search and supports + * relative file paths. It is used as a fall back by GetSourceFileWithOutput + * and GetSourcesWithOutput. + */ + cmSourceFile* LinearGetSourceFileWithOutput(const std::string& name, + cmSourceOutputKind kind, + bool& byproduct) const; + + struct SourceEntry + { + cmSourcesWithOutput Sources; + }; // A map for fast output to input look up. - using OutputToSourceMap = std::unordered_map<std::string, cmSourceFile*>; + using OutputToSourceMap = std::unordered_map<std::string, SourceEntry>; OutputToSourceMap OutputToSource; + void UpdateOutputToSourceMap(std::vector<std::string> const& byproducts, + cmTarget* target); + void UpdateOutputToSourceMap(std::string const& byproduct, cmTarget* target); + void UpdateOutputToSourceMap(std::vector<std::string> const& outputs, - cmSourceFile* source); - void UpdateOutputToSourceMap(std::string const& output, - cmSourceFile* source); + cmSourceFile* source, bool byproduct); + void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source, + bool byproduct); bool AddRequiredTargetCFeature(cmTarget* target, const std::string& feature, std::string* error = nullptr) const; diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 36f6809..6d71a6d 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -837,7 +837,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( } // Create the archive with the first set of objects. - std::vector<std::string>::iterator osi = object_strings.begin(); + auto osi = object_strings.begin(); { vars.Objects = osi->c_str(); for (std::string const& acc : archiveCreateCommands) { diff --git a/Source/cmOrderDirectories.cxx b/Source/cmOrderDirectories.cxx index 35ec33e..c8cac3b 100644 --- a/Source/cmOrderDirectories.cxx +++ b/Source/cmOrderDirectories.cxx @@ -128,7 +128,7 @@ bool cmOrderDirectoriesConstraint::FileMayConflict(std::string const& dir, // Check if the file will be built by cmake. std::set<std::string> const& files = (this->GlobalGenerator->GetDirectoryContent(dir, false)); - std::set<std::string>::const_iterator fi = files.find(name); + auto fi = files.find(name); return fi != files.end(); } @@ -186,9 +186,9 @@ bool cmOrderDirectoriesConstraintSOName::FindConflict(std::string const& dir) // know the soname just look at all files that start with the // file name. Usually the soname starts with the library name. std::string base = this->FileName; - std::set<std::string>::const_iterator first = files.lower_bound(base); + auto first = files.lower_bound(base); ++base.back(); - std::set<std::string>::const_iterator last = files.upper_bound(base); + auto last = files.upper_bound(base); if (first != last) { return true; } @@ -380,7 +380,7 @@ void cmOrderDirectories::CollectOriginalDirectories() int cmOrderDirectories::AddOriginalDirectory(std::string const& dir) { // Add the runtime directory with a unique index. - std::map<std::string, int>::iterator i = this->DirectoryIndex.find(dir); + auto i = this->DirectoryIndex.find(dir); if (i == this->DirectoryIndex.end()) { std::map<std::string, int>::value_type entry( dir, static_cast<int>(this->OriginalDirectories.size())); @@ -441,8 +441,7 @@ void cmOrderDirectories::FindConflicts() std::sort(cl.begin(), cl.end()); // Make the edge list unique so cycle detection will be reliable. - ConflictList::iterator last = - std::unique(cl.begin(), cl.end(), cmOrderDirectoriesCompare()); + auto last = std::unique(cl.begin(), cl.end(), cmOrderDirectoriesCompare()); cl.erase(last, cl.end()); } @@ -553,8 +552,7 @@ bool cmOrderDirectories::IsSameDirectory(std::string const& l, std::string const& cmOrderDirectories::GetRealPath(std::string const& dir) { - std::map<std::string, std::string>::iterator i = - this->RealPaths.lower_bound(dir); + auto i = this->RealPaths.lower_bound(dir); if (i == this->RealPaths.end() || this->RealPaths.key_comp()(dir, i->first)) { using value_type = std::map<std::string, std::string>::value_type; diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx index c034fdd..2f4e003 100644 --- a/Source/cmOutputRequiredFilesCommand.cxx +++ b/Source/cmOutputRequiredFilesCommand.cxx @@ -367,8 +367,7 @@ protected: std::string fullPath = this->FullPath(file, extraPath); // Try to find the file's instance of cmDependInformation. - DependInformationMapType::const_iterator result = - this->DependInformationMap.find(fullPath); + auto result = this->DependInformationMap.find(fullPath); if (result != this->DependInformationMap.end()) { // Found an instance, return it. return result->second; @@ -398,7 +397,7 @@ protected: if (m != this->DirectoryToFileToPathMap.end()) { FileToPathMapType& map = m->second; - FileToPathMapType::iterator p = map.find(fname); + auto p = map.find(fname); if (p != map.end()) { return p->second; } diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx index a4dd70d..0b320b6 100644 --- a/Source/cmParseArgumentsCommand.cxx +++ b/Source/cmParseArgumentsCommand.cxx @@ -116,8 +116,8 @@ bool cmParseArgumentsCommand(std::vector<std::string> const& args, return false; } - std::vector<std::string>::const_iterator argIter = args.begin(); - std::vector<std::string>::const_iterator argEnd = args.end(); + auto argIter = args.begin(); + auto argEnd = args.end(); bool parseFromArgV = false; unsigned long argvStart = 0; if (*argIter == "PARSE_ARGV") { diff --git a/Source/cmPropertyDefinitionMap.cxx b/Source/cmPropertyDefinitionMap.cxx index 5daaf9b..f752ed7 100644 --- a/Source/cmPropertyDefinitionMap.cxx +++ b/Source/cmPropertyDefinitionMap.cxx @@ -10,7 +10,7 @@ void cmPropertyDefinitionMap::DefineProperty(const std::string& name, const char* FullDescription, bool chain) { - cmPropertyDefinitionMap::iterator it = this->find(name); + auto it = this->find(name); cmPropertyDefinition* prop; if (it == this->end()) { prop = &(*this)[name]; @@ -26,7 +26,7 @@ bool cmPropertyDefinitionMap::IsPropertyDefined(const std::string& name) const bool cmPropertyDefinitionMap::IsPropertyChained(const std::string& name) const { - cmPropertyDefinitionMap::const_iterator it = this->find(name); + auto it = this->find(name); if (it == this->end()) { return false; } diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index ba82813..1a5602b 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -2,45 +2,44 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmQTWrapCPPCommand.h" +#include <utility> + #include "cmCustomCommandLines.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -#include <utility> - -class cmExecutionStatus; - -// cmQTWrapCPPCommand -bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmQTWrapCPPCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 3) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Get the moc executable to run in the custom command. - std::string const& moc_exe = - this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE"); + std::string const& moc_exe = mf.GetRequiredDefinition("QT_MOC_EXECUTABLE"); // Get the variable holding the list of sources. std::string const& sourceList = args[1]; - std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList); + std::string sourceListValue = mf.GetSafeDefinition(sourceList); // Create a rule for all sources listed. for (std::string const& arg : cmMakeRange(args).advance(2)) { - cmSourceFile* curr = this->Makefile->GetSource(arg); + cmSourceFile* curr = mf.GetSource(arg); // if we should wrap the class if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) { // Compute the name of the file to generate. std::string srcName = cmSystemTools::GetFilenameWithoutLastExtension(arg); - std::string newName = cmStrCat( - this->Makefile->GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); - cmSourceFile* sf = this->Makefile->GetOrCreateSource(newName, true); + std::string newName = + cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); + cmSourceFile* sf = mf.GetOrCreateSource(newName, true); if (curr) { sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT")); } @@ -51,9 +50,9 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, hname = arg; } else { if (curr && curr->GetIsGenerated()) { - hname = this->Makefile->GetCurrentBinaryDirectory(); + hname = mf.GetCurrentBinaryDirectory(); } else { - hname = this->Makefile->GetCurrentSourceDirectory(); + hname = mf.GetCurrentSourceDirectory(); } hname += "/"; hname += arg; @@ -81,13 +80,13 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, std::string no_main_dependency; const char* no_working_dir = nullptr; - this->Makefile->AddCustomCommandToOutput( - newName, depends, no_main_dependency, commandLines, "Qt Wrapped File", - no_working_dir); + mf.AddCustomCommandToOutput(newName, depends, no_main_dependency, + commandLines, "Qt Wrapped File", + no_working_dir); } } // Store the final list of source files. - this->Makefile->AddDefinition(sourceList, sourceListValue); + mf.AddDefinition(sourceList, sourceListValue); return true; } diff --git a/Source/cmQTWrapCPPCommand.h b/Source/cmQTWrapCPPCommand.h index 88a2210..75fa180 100644 --- a/Source/cmQTWrapCPPCommand.h +++ b/Source/cmQTWrapCPPCommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmQTWrapCPPCommand - * \brief Create moc file rules for Qt classes - * - * cmQTWrapCPPCommand is used to create wrappers for Qt classes into - * normal C++ - */ -class cmQTWrapCPPCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmQTWrapCPPCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmQTWrapCPPCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index 8bc914f..b7b5efa 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -2,52 +2,50 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmQTWrapUICommand.h" +#include <utility> + #include "cmCustomCommandLines.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -#include <utility> - -class cmExecutionStatus; - -// cmQTWrapUICommand -bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmQTWrapUICommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 4) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Get the uic and moc executables to run in the custom commands. - std::string const& uic_exe = - this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE"); - std::string const& moc_exe = - this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE"); + std::string const& uic_exe = mf.GetRequiredDefinition("QT_UIC_EXECUTABLE"); + std::string const& moc_exe = mf.GetRequiredDefinition("QT_MOC_EXECUTABLE"); // Get the variable holding the list of sources. std::string const& headerList = args[1]; std::string const& sourceList = args[2]; - std::string headerListValue = this->Makefile->GetSafeDefinition(headerList); - std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList); + std::string headerListValue = mf.GetSafeDefinition(headerList); + std::string sourceListValue = mf.GetSafeDefinition(sourceList); // Create rules for all sources listed. for (std::string const& arg : cmMakeRange(args).advance(3)) { - cmSourceFile* curr = this->Makefile->GetSource(arg); + cmSourceFile* curr = mf.GetSource(arg); // if we should wrap the class if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) { // Compute the name of the files to generate. std::string srcName = cmSystemTools::GetFilenameWithoutLastExtension(arg); - std::string hName = cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), - '/', srcName, ".h"); - std::string cxxName = cmStrCat( - this->Makefile->GetCurrentBinaryDirectory(), '/', srcName, ".cxx"); - std::string mocName = cmStrCat( - this->Makefile->GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); + std::string hName = + cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".h"); + std::string cxxName = + cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".cxx"); + std::string mocName = + cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); // Compute the name of the ui file from which to generate others. std::string uiName; @@ -55,9 +53,9 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, uiName = arg; } else { if (curr && curr->GetIsGenerated()) { - uiName = this->Makefile->GetCurrentBinaryDirectory(); + uiName = mf.GetCurrentBinaryDirectory(); } else { - uiName = this->Makefile->GetCurrentSourceDirectory(); + uiName = mf.GetCurrentSourceDirectory(); } uiName += "/"; uiName += arg; @@ -109,25 +107,22 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, std::string no_main_dependency; const char* no_comment = nullptr; const char* no_working_dir = nullptr; - this->Makefile->AddCustomCommandToOutput( - hName, depends, no_main_dependency, hCommandLines, no_comment, - no_working_dir); + mf.AddCustomCommandToOutput(hName, depends, no_main_dependency, + hCommandLines, no_comment, no_working_dir); depends.push_back(hName); - this->Makefile->AddCustomCommandToOutput( - cxxName, depends, no_main_dependency, cxxCommandLines, no_comment, - no_working_dir); + mf.AddCustomCommandToOutput(cxxName, depends, no_main_dependency, + cxxCommandLines, no_comment, no_working_dir); depends.clear(); depends.push_back(hName); - this->Makefile->AddCustomCommandToOutput( - mocName, depends, no_main_dependency, mocCommandLines, no_comment, - no_working_dir); + mf.AddCustomCommandToOutput(mocName, depends, no_main_dependency, + mocCommandLines, no_comment, no_working_dir); } } // Store the final list of source files and headers. - this->Makefile->AddDefinition(sourceList, sourceListValue); - this->Makefile->AddDefinition(headerList, headerListValue); + mf.AddDefinition(sourceList, sourceListValue); + mf.AddDefinition(headerList, headerListValue); return true; } diff --git a/Source/cmQTWrapUICommand.h b/Source/cmQTWrapUICommand.h index 6a346d4..a17ef54 100644 --- a/Source/cmQTWrapUICommand.h +++ b/Source/cmQTWrapUICommand.h @@ -8,34 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmQTWrapUICommand - * \brief Create .h and .cxx files rules for Qt user interfaces files - * - * cmQTWrapUICommand is used to create wrappers for Qt classes into normal C++ - */ -class cmQTWrapUICommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmQTWrapUICommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmQTWrapUICommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx index 83df335..f3c78d3 100644 --- a/Source/cmQtAutoGen.cxx +++ b/Source/cmQtAutoGen.cxx @@ -24,8 +24,6 @@ void MergeOptions(std::vector<std::string>& baseOpts, std::vector<std::string> const& newOpts, std::initializer_list<cm::string_view> valueOpts, bool isQt5) { - using Iter = std::vector<std::string>::iterator; - using CIter = std::vector<std::string>::const_iterator; if (newOpts.empty()) { return; } @@ -35,10 +33,10 @@ void MergeOptions(std::vector<std::string>& baseOpts, } std::vector<std::string> extraOpts; - for (CIter fit = newOpts.begin(), fitEnd = newOpts.end(); fit != fitEnd; + for (auto fit = newOpts.begin(), fitEnd = newOpts.end(); fit != fitEnd; ++fit) { std::string const& newOpt = *fit; - Iter existIt = std::find(baseOpts.begin(), baseOpts.end(), newOpt); + auto existIt = std::find(baseOpts.begin(), baseOpts.end(), newOpt); if (existIt != baseOpts.end()) { if (newOpt.size() >= 2) { // Acquire the option name @@ -55,8 +53,8 @@ void MergeOptions(std::vector<std::string>& baseOpts, } // Test if this is a value option and change the existing value if (!optName.empty() && cmContains(valueOpts, optName)) { - const Iter existItNext(existIt + 1); - const CIter fitNext(fit + 1); + const auto existItNext(existIt + 1); + const auto fitNext(fit + 1); if ((existItNext != baseOpts.end()) && (fitNext != fitEnd)) { *existItNext = *fitNext; ++fit; diff --git a/Source/cmQtAutoMocUic.cxx b/Source/cmQtAutoMocUic.cxx index 14329c0..40ebdde 100644 --- a/Source/cmQtAutoMocUic.cxx +++ b/Source/cmQtAutoMocUic.cxx @@ -1797,7 +1797,7 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile) BaseConst().ProjectBinaryDir, BaseConst().ProjectSourceDir }; for (cm::string_view const& ppath : movePaths) { - std::list<std::string>::iterator it = includes.begin(); + auto it = includes.begin(); while (it != includes.end()) { std::string const& path = *it; if (cmHasPrefix(path, ppath)) { diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx index 1f9aae8..aa394e5 100644 --- a/Source/cmRST.cxx +++ b/Source/cmRST.cxx @@ -320,8 +320,7 @@ std::string cmRST::ReplaceSubstitutions(std::string const& line) std::string::size_type start = this->Substitution.start(2); std::string::size_type end = this->Substitution.end(2); std::string substitute = this->Substitution.match(3); - std::map<std::string, std::string>::iterator replace = - this->Replace.find(substitute); + auto replace = this->Replace.find(substitute); if (replace != this->Replace.end()) { std::pair<std::set<std::string>::iterator, bool> replaced = this->Replaced.insert(substitute); @@ -451,10 +450,10 @@ void cmRST::UnindentLines(std::vector<std::string>& lines) } } - std::vector<std::string>::const_iterator it = lines.begin(); + auto it = lines.cbegin(); size_t leadingEmpty = std::distance(it, cmFindNot(lines, std::string())); - std::vector<std::string>::const_reverse_iterator rit = lines.rbegin(); + auto rit = lines.crbegin(); size_t trailingEmpty = std::distance(rit, cmFindNot(cmReverseRange(lines), std::string())); @@ -464,7 +463,7 @@ void cmRST::UnindentLines(std::vector<std::string>& lines) return; } - std::vector<std::string>::iterator contentEnd = cmRotate( - lines.begin(), lines.begin() + leadingEmpty, lines.end() - trailingEmpty); + auto contentEnd = cmRotate(lines.begin(), lines.begin() + leadingEmpty, + lines.end() - trailingEmpty); lines.erase(contentEnd, lines.end()); } diff --git a/Source/cmRemoveDefinitionsCommand.cxx b/Source/cmRemoveDefinitionsCommand.cxx index 8d3f688..339ff9d 100644 --- a/Source/cmRemoveDefinitionsCommand.cxx +++ b/Source/cmRemoveDefinitionsCommand.cxx @@ -2,21 +2,15 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmRemoveDefinitionsCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" -class cmExecutionStatus; - -// cmRemoveDefinitionsCommand -bool cmRemoveDefinitionsCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmRemoveDefinitionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { - // it is OK to have no arguments - if (args.empty()) { - return true; - } - + cmMakefile& mf = status.GetMakefile(); for (std::string const& i : args) { - this->Makefile->RemoveDefineFlag(i); + mf.RemoveDefineFlag(i); } return true; } diff --git a/Source/cmRemoveDefinitionsCommand.h b/Source/cmRemoveDefinitionsCommand.h index 85d01d4..868416b 100644 --- a/Source/cmRemoveDefinitionsCommand.h +++ b/Source/cmRemoveDefinitionsCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmRemoveDefinitionsCommand - * \brief Specify a list of compiler defines - * - * cmRemoveDefinitionsCommand specifies a list of compiler defines. - * These defines will - * be removed from the compile command. - */ -class cmRemoveDefinitionsCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmRemoveDefinitionsCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmRemoveDefinitionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmRulePlaceholderExpander.cxx b/Source/cmRulePlaceholderExpander.cxx index 33389ca..6c954a6 100644 --- a/Source/cmRulePlaceholderExpander.cxx +++ b/Source/cmRulePlaceholderExpander.cxx @@ -235,8 +235,7 @@ std::string cmRulePlaceholderExpander::ExpandRuleVariable( cmOutputConverter::SHELL); } - std::map<std::string, std::string>::iterator compIt = - this->Compilers.find(variable); + auto compIt = this->Compilers.find(variable); if (compIt != this->Compilers.end()) { std::string ret = outputConverter->ConvertToOutputForExisting( @@ -292,8 +291,7 @@ std::string cmRulePlaceholderExpander::ExpandRuleVariable( return ret; } - std::map<std::string, std::string>::iterator mapIt = - this->VariableMappings.find(variable); + auto mapIt = this->VariableMappings.find(variable); if (mapIt != this->VariableMappings.end()) { if (variable.find("_FLAG") == std::string::npos) { return outputConverter->ConvertToOutputForExisting(mapIt->second); diff --git a/Source/cmScriptGenerator.h b/Source/cmScriptGenerator.h index eee331f..c8bb1ab 100644 --- a/Source/cmScriptGenerator.h +++ b/Source/cmScriptGenerator.h @@ -25,7 +25,7 @@ public: } cmScriptGeneratorIndent Next(int step = 2) const { - return cmScriptGeneratorIndent(this->Level + step); + return { this->Level + step }; } private: diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index 670161d..d576f36 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -167,7 +167,7 @@ bool cmServerProtocol::DoActivate(const cmServerRequest& /*request*/, std::pair<int, int> cmServerProtocol1::ProtocolVersion() const { - return std::make_pair(1, 2); + return { 1, 2 }; } static void setErrorMessage(std::string* errorMessage, const std::string& text) diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index 7e3a340..387c3fc 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -375,8 +375,7 @@ bool HandleTestMode(cmExecutionStatus& status, std::set<std::string>& names, { // Look for tests with all names given. std::set<std::string>::iterator next; - for (std::set<std::string>::iterator ni = names.begin(); ni != names.end(); - ni = next) { + for (auto ni = names.begin(); ni != names.end(); ni = next) { next = ni; ++next; if (cmTest* test = status.GetMakefile().GetTest(*ni)) { diff --git a/Source/cmSetSourceFilesPropertiesCommand.cxx b/Source/cmSetSourceFilesPropertiesCommand.cxx index 8e3217f..7ff604b 100644 --- a/Source/cmSetSourceFilesPropertiesCommand.cxx +++ b/Source/cmSetSourceFilesPropertiesCommand.cxx @@ -2,18 +2,23 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmSetSourceFilesPropertiesCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" -class cmExecutionStatus; +static bool RunCommand(cmMakefile* mf, + std::vector<std::string>::const_iterator filebeg, + std::vector<std::string>::const_iterator fileend, + std::vector<std::string>::const_iterator propbeg, + std::vector<std::string>::const_iterator propend, + std::string& errors); -// cmSetSourceFilesPropertiesCommand -bool cmSetSourceFilesPropertiesCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmSetSourceFilesPropertiesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } @@ -29,22 +34,24 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass( ++j; } + cmMakefile& mf = status.GetMakefile(); + // now call the worker function std::string errors; - bool ret = cmSetSourceFilesPropertiesCommand::RunCommand( - this->Makefile, args.begin(), args.begin() + numFiles, - args.begin() + numFiles, args.end(), errors); + bool ret = RunCommand(&mf, args.begin(), args.begin() + numFiles, + args.begin() + numFiles, args.end(), errors); if (!ret) { - this->SetError(errors); + status.SetError(errors); } return ret; } -bool cmSetSourceFilesPropertiesCommand::RunCommand( - cmMakefile* mf, std::vector<std::string>::const_iterator filebeg, - std::vector<std::string>::const_iterator fileend, - std::vector<std::string>::const_iterator propbeg, - std::vector<std::string>::const_iterator propend, std::string& errors) +static bool RunCommand(cmMakefile* mf, + std::vector<std::string>::const_iterator filebeg, + std::vector<std::string>::const_iterator fileend, + std::vector<std::string>::const_iterator propbeg, + std::vector<std::string>::const_iterator propend, + std::string& errors) { std::vector<std::string> propertyPairs; bool generated = false; diff --git a/Source/cmSetSourceFilesPropertiesCommand.h b/Source/cmSetSourceFilesPropertiesCommand.h index 6fd6c41..5eef785 100644 --- a/Source/cmSetSourceFilesPropertiesCommand.h +++ b/Source/cmSetSourceFilesPropertiesCommand.h @@ -8,34 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmMakefile; - -class cmSetSourceFilesPropertiesCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmSetSourceFilesPropertiesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - static bool RunCommand(cmMakefile* mf, - std::vector<std::string>::const_iterator filebeg, - std::vector<std::string>::const_iterator fileend, - std::vector<std::string>::const_iterator propbeg, - std::vector<std::string>::const_iterator propend, - std::string& errors); -}; +bool cmSetSourceFilesPropertiesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmSetTestsPropertiesCommand.cxx b/Source/cmSetTestsPropertiesCommand.cxx index ed909c6..de61eda 100644 --- a/Source/cmSetTestsPropertiesCommand.cxx +++ b/Source/cmSetTestsPropertiesCommand.cxx @@ -5,21 +5,25 @@ #include <iterator> #include "cmAlgorithms.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmStringAlgorithms.h" #include "cmTest.h" -class cmExecutionStatus; +static bool SetOneTest(const std::string& tname, + std::vector<std::string>& propertyPairs, cmMakefile* mf, + std::string& errors); -// cmSetTestsPropertiesCommand -bool cmSetTestsPropertiesCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // first collect up the list of files std::vector<std::string> propertyPairs; int numFiles = 0; @@ -29,7 +33,7 @@ bool cmSetTestsPropertiesCommand::InitialPass( // now loop through the rest of the arguments, new style ++j; if (std::distance(j, args.end()) % 2 != 0) { - this->SetError("called with incorrect number of arguments."); + status.SetError("called with incorrect number of arguments."); return false; } cmAppend(propertyPairs, j, args.end()); @@ -38,8 +42,8 @@ bool cmSetTestsPropertiesCommand::InitialPass( numFiles++; } if (propertyPairs.empty()) { - this->SetError("called with illegal arguments, maybe " - "missing a PROPERTIES specifier?"); + status.SetError("called with illegal arguments, maybe " + "missing a PROPERTIES specifier?"); return false; } @@ -47,10 +51,9 @@ bool cmSetTestsPropertiesCommand::InitialPass( int i; for (i = 0; i < numFiles; ++i) { std::string errors; - bool ret = cmSetTestsPropertiesCommand::SetOneTest(args[i], propertyPairs, - this->Makefile, errors); + bool ret = SetOneTest(args[i], propertyPairs, &mf, errors); if (!ret) { - this->SetError(errors); + status.SetError(errors); return ret; } } @@ -58,9 +61,9 @@ bool cmSetTestsPropertiesCommand::InitialPass( return true; } -bool cmSetTestsPropertiesCommand::SetOneTest( - const std::string& tname, std::vector<std::string>& propertyPairs, - cmMakefile* mf, std::string& errors) +static bool SetOneTest(const std::string& tname, + std::vector<std::string>& propertyPairs, cmMakefile* mf, + std::string& errors) { if (cmTest* test = mf->GetTest(tname)) { // now loop through all the props and set them diff --git a/Source/cmSetTestsPropertiesCommand.h b/Source/cmSetTestsPropertiesCommand.h index d73e95a..4b75464 100644 --- a/Source/cmSetTestsPropertiesCommand.h +++ b/Source/cmSetTestsPropertiesCommand.h @@ -8,31 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmMakefile; - -class cmSetTestsPropertiesCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmSetTestsPropertiesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - static bool SetOneTest(const std::string& tname, - std::vector<std::string>& propertyPairs, - cmMakefile* mf, std::string& errors); -}; +bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index 399f1da..c239a1f 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -284,8 +284,7 @@ bool cmSourceGroupCommand::checkSingleParameterArgumentPreconditions( const std::string& argument, const ParsedArguments& parsedArguments, std::string& errorMsg) const { - ParsedArguments::const_iterator foundArgument = - parsedArguments.find(argument); + auto foundArgument = parsedArguments.find(argument); if (foundArgument != parsedArguments.end()) { const std::vector<std::string>& optionArguments = foundArgument->second; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 902287c..751eb77 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -324,7 +324,7 @@ cmStateSnapshot cmState::Reset() this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::TARGET, "", "", true); this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::TARGET, "", "", true); - return cmStateSnapshot(this, pos); + return { this, pos }; } void cmState::DefineProperty(const std::string& name, @@ -350,8 +350,7 @@ cmPropertyDefinition const* cmState::GetPropertyDefinition( bool cmState::IsPropertyDefined(const std::string& name, cmProperty::ScopeType scope) const { - std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it = - this->PropertyDefinitions.find(scope); + auto it = this->PropertyDefinitions.find(scope); if (it == this->PropertyDefinitions.end()) { return false; } @@ -361,8 +360,7 @@ bool cmState::IsPropertyDefined(const std::string& name, bool cmState::IsPropertyChained(const std::string& name, cmProperty::ScopeType scope) const { - std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it = - this->PropertyDefinitions.find(scope); + auto it = this->PropertyDefinitions.find(scope); if (it == this->PropertyDefinitions.end()) { return false; } @@ -371,8 +369,8 @@ bool cmState::IsPropertyChained(const std::string& name, void cmState::SetLanguageEnabled(std::string const& l) { - std::vector<std::string>::iterator it = std::lower_bound( - this->EnabledLanguages.begin(), this->EnabledLanguages.end(), l); + auto it = std::lower_bound(this->EnabledLanguages.begin(), + this->EnabledLanguages.end(), l); if (it == this->EnabledLanguages.end() || *it != l) { this->EnabledLanguages.insert(it, l); } @@ -789,7 +787,7 @@ cmStateSnapshot cmState::CreateBaseSnapshot() assert(pos->Vars.IsValid()); pos->Parent = this->VarTree.Root(); pos->Root = this->VarTree.Root(); - return cmStateSnapshot(this, pos); + return { this, pos }; } cmStateSnapshot cmState::CreateBuildsystemDirectorySnapshot( @@ -842,7 +840,7 @@ cmStateSnapshot cmState::CreateFunctionCallSnapshot( cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars; pos->Parent = origin; pos->Vars = this->VarTree.Push(origin); - return cmStateSnapshot(this, pos); + return { this, pos }; } cmStateSnapshot cmState::CreateMacroCallSnapshot( @@ -857,7 +855,7 @@ cmStateSnapshot cmState::CreateMacroCallSnapshot( assert(originSnapshot.Position->Vars.IsValid()); pos->BuildSystemDirectory->DirectoryEnd = pos; pos->PolicyScope = originSnapshot.Position->Policies; - return cmStateSnapshot(this, pos); + return { this, pos }; } cmStateSnapshot cmState::CreateIncludeFileSnapshot( @@ -872,7 +870,7 @@ cmStateSnapshot cmState::CreateIncludeFileSnapshot( assert(originSnapshot.Position->Vars.IsValid()); pos->BuildSystemDirectory->DirectoryEnd = pos; pos->PolicyScope = originSnapshot.Position->Policies; - return cmStateSnapshot(this, pos); + return { this, pos }; } cmStateSnapshot cmState::CreateVariableScopeSnapshot( @@ -890,7 +888,7 @@ cmStateSnapshot cmState::CreateVariableScopeSnapshot( pos->Parent = origin; pos->Vars = this->VarTree.Push(origin); assert(pos->Vars.IsValid()); - return cmStateSnapshot(this, pos); + return { this, pos }; } cmStateSnapshot cmState::CreateInlineListFileSnapshot( @@ -904,7 +902,7 @@ cmStateSnapshot cmState::CreateInlineListFileSnapshot( originSnapshot.Position->ExecutionListFile, fileName); pos->BuildSystemDirectory->DirectoryEnd = pos; pos->PolicyScope = originSnapshot.Position->Policies; - return cmStateSnapshot(this, pos); + return { this, pos }; } cmStateSnapshot cmState::CreatePolicyScopeSnapshot( @@ -916,7 +914,7 @@ cmStateSnapshot cmState::CreatePolicyScopeSnapshot( pos->Keep = false; pos->BuildSystemDirectory->DirectoryEnd = pos; pos->PolicyScope = originSnapshot.Position->Policies; - return cmStateSnapshot(this, pos); + return { this, pos }; } cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot) @@ -948,7 +946,7 @@ cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot) this->SnapshotData.Pop(pos); } - return cmStateSnapshot(this, prevPos); + return { this, prevPos }; } static bool ParseEntryWithoutType(const std::string& entry, std::string& var, diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index df96bd3..c14bf4a 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -175,11 +175,9 @@ cmStateDirectory::cmStateDirectory( template <typename T, typename U> cmStringRange GetPropertyContent(T const& content, U contentEndPosition) { - std::vector<std::string>::const_iterator end = - content.begin() + contentEndPosition; + auto end = content.begin() + contentEndPosition; - std::vector<std::string>::const_reverse_iterator rbegin = - cmMakeReverseIterator(end); + auto rbegin = cmMakeReverseIterator(end); rbegin = std::find(rbegin, content.rend(), cmPropertySentinal); return cmMakeRange(rbegin.base(), end); @@ -189,17 +187,14 @@ template <typename T, typename U, typename V> cmBacktraceRange GetPropertyBacktraces(T const& content, U const& backtraces, V contentEndPosition) { - std::vector<std::string>::const_iterator entryEnd = - content.begin() + contentEndPosition; + auto entryEnd = content.begin() + contentEndPosition; - std::vector<std::string>::const_reverse_iterator rbegin = - cmMakeReverseIterator(entryEnd); + auto rbegin = cmMakeReverseIterator(entryEnd); rbegin = std::find(rbegin, content.rend(), cmPropertySentinal); - std::vector<cmListFileBacktrace>::const_iterator it = - backtraces.begin() + std::distance(content.begin(), rbegin.base()); + auto it = backtraces.begin() + std::distance(content.begin(), rbegin.base()); - std::vector<cmListFileBacktrace>::const_iterator end = backtraces.end(); + auto end = backtraces.end(); return cmMakeRange(it, end); } @@ -271,22 +266,17 @@ void cmStateDirectory::AppendIncludeDirectoriesEntry( void cmStateDirectory::PrependIncludeDirectoriesEntry( const std::string& vec, const cmListFileBacktrace& lfbt) { - std::vector<std::string>::iterator entryEnd = - this->DirectoryState->IncludeDirectories.begin() + + auto entryEnd = this->DirectoryState->IncludeDirectories.begin() + this->Snapshot_.Position->IncludeDirectoryPosition; - std::vector<std::string>::reverse_iterator rend = - this->DirectoryState->IncludeDirectories.rend(); - std::vector<std::string>::reverse_iterator rbegin = - cmMakeReverseIterator(entryEnd); + auto rend = this->DirectoryState->IncludeDirectories.rend(); + auto rbegin = cmMakeReverseIterator(entryEnd); rbegin = std::find(rbegin, rend, cmPropertySentinal); - std::vector<std::string>::iterator entryIt = rbegin.base(); - std::vector<std::string>::iterator entryBegin = - this->DirectoryState->IncludeDirectories.begin(); + auto entryIt = rbegin.base(); + auto entryBegin = this->DirectoryState->IncludeDirectories.begin(); - std::vector<cmListFileBacktrace>::iterator btIt = - this->DirectoryState->IncludeDirectoryBacktraces.begin() + + auto btIt = this->DirectoryState->IncludeDirectoryBacktraces.begin() + std::distance(entryBegin, entryIt); this->DirectoryState->IncludeDirectories.insert(entryIt, vec); @@ -446,22 +436,17 @@ void cmStateDirectory::AppendLinkDirectoriesEntry( void cmStateDirectory::PrependLinkDirectoriesEntry( const std::string& vec, const cmListFileBacktrace& lfbt) { - std::vector<std::string>::iterator entryEnd = - this->DirectoryState->LinkDirectories.begin() + + auto entryEnd = this->DirectoryState->LinkDirectories.begin() + this->Snapshot_.Position->LinkDirectoriesPosition; - std::vector<std::string>::reverse_iterator rend = - this->DirectoryState->LinkDirectories.rend(); - std::vector<std::string>::reverse_iterator rbegin = - cmMakeReverseIterator(entryEnd); + auto rend = this->DirectoryState->LinkDirectories.rend(); + auto rbegin = cmMakeReverseIterator(entryEnd); rbegin = std::find(rbegin, rend, cmPropertySentinal); - std::vector<std::string>::iterator entryIt = rbegin.base(); - std::vector<std::string>::iterator entryBegin = - this->DirectoryState->LinkDirectories.begin(); + auto entryIt = rbegin.base(); + auto entryBegin = this->DirectoryState->LinkDirectories.begin(); - std::vector<cmListFileBacktrace>::iterator btIt = - this->DirectoryState->LinkDirectoriesBacktraces.begin() + + auto btIt = this->DirectoryState->LinkDirectoriesBacktraces.begin() + std::distance(entryBegin, entryIt); this->DirectoryState->LinkDirectories.insert(entryIt, vec); diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 121923d..b3e33ea 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -66,8 +66,7 @@ bool cmStateSnapshot::IsValid() const cmStateSnapshot cmStateSnapshot::GetBuildsystemDirectory() const { - return cmStateSnapshot(this->State, - this->Position->BuildSystemDirectory->DirectoryEnd); + return { this->State, this->Position->BuildSystemDirectory->DirectoryEnd }; } cmStateSnapshot cmStateSnapshot::GetBuildsystemDirectoryParent() const @@ -126,7 +125,7 @@ cmStateSnapshot cmStateSnapshot::GetCallStackBottom() const pos != this->State->SnapshotData.Root()) { ++pos; } - return cmStateSnapshot(this->State, pos); + return { this->State, pos }; } void cmStateSnapshot::PushPolicy(cmPolicies::PolicyMap const& entry, bool weak) @@ -277,22 +276,18 @@ void InitializeContentFromParent(T& parentContent, T& thisContent, U& parentBacktraces, U& thisBacktraces, V& contentEndPosition) { - std::vector<std::string>::const_iterator parentBegin = parentContent.begin(); - std::vector<std::string>::const_iterator parentEnd = parentContent.end(); + auto parentBegin = parentContent.begin(); + auto parentEnd = parentContent.end(); - std::vector<std::string>::const_reverse_iterator parentRbegin = - cmMakeReverseIterator(parentEnd); - std::vector<std::string>::const_reverse_iterator parentRend = - parentContent.rend(); + auto parentRbegin = cmMakeReverseIterator(parentEnd); + auto parentRend = parentContent.rend(); parentRbegin = std::find(parentRbegin, parentRend, cmPropertySentinal); - std::vector<std::string>::const_iterator parentIt = parentRbegin.base(); + auto parentIt = parentRbegin.base(); thisContent = std::vector<std::string>(parentIt, parentEnd); - std::vector<cmListFileBacktrace>::const_iterator btIt = - parentBacktraces.begin() + std::distance(parentBegin, parentIt); - std::vector<cmListFileBacktrace>::const_iterator btEnd = - parentBacktraces.end(); + auto btIt = parentBacktraces.begin() + std::distance(parentBegin, parentIt); + auto btEnd = parentBacktraces.end(); thisBacktraces = std::vector<cmListFileBacktrace>(btIt, btEnd); @@ -426,7 +421,7 @@ cmState* cmStateSnapshot::GetState() const cmStateDirectory cmStateSnapshot::GetDirectory() const { - return cmStateDirectory(this->Position->BuildSystemDirectory, *this); + return { this->Position->BuildSystemDirectory, *this }; } void cmStateSnapshot::SetProjectName(const std::string& name) diff --git a/Source/cmSubdirCommand.cxx b/Source/cmSubdirCommand.cxx index 07f8efe..2477d7a 100644 --- a/Source/cmSubdirCommand.cxx +++ b/Source/cmSubdirCommand.cxx @@ -2,22 +2,21 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmSubdirCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; - -// cmSubdirCommand -bool cmSubdirCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmSubdirCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } bool res = true; bool excludeFromAll = false; + cmMakefile& mf = status.GetMakefile(); for (std::string const& i : args) { if (i == "EXCLUDE_FROM_ALL") { @@ -30,24 +29,21 @@ bool cmSubdirCommand::InitialPass(std::vector<std::string> const& args, } // if they specified a relative path then compute the full - std::string srcPath = - this->Makefile->GetCurrentSourceDirectory() + "/" + i; + std::string srcPath = mf.GetCurrentSourceDirectory() + "/" + i; if (cmSystemTools::FileIsDirectory(srcPath)) { - std::string binPath = - this->Makefile->GetCurrentBinaryDirectory() + "/" + i; - this->Makefile->AddSubDirectory(srcPath, binPath, excludeFromAll, false); + std::string binPath = mf.GetCurrentBinaryDirectory() + "/" + i; + mf.AddSubDirectory(srcPath, binPath, excludeFromAll, false); } // otherwise it is a full path else if (cmSystemTools::FileIsDirectory(i)) { // we must compute the binPath from the srcPath, we just take the last // element from the source path and use that - std::string binPath = this->Makefile->GetCurrentBinaryDirectory() + "/" + + std::string binPath = mf.GetCurrentBinaryDirectory() + "/" + cmSystemTools::GetFilenameName(i); - this->Makefile->AddSubDirectory(i, binPath, excludeFromAll, false); + mf.AddSubDirectory(i, binPath, excludeFromAll, false); } else { - std::string error = cmStrCat("Incorrect SUBDIRS command. Directory: ", i, - " does not exist."); - this->SetError(error); + status.SetError(cmStrCat("Incorrect SUBDIRS command. Directory: ", i, + " does not exist.")); res = false; } } diff --git a/Source/cmSubdirCommand.h b/Source/cmSubdirCommand.h index 3499c46..3254e84 100644 --- a/Source/cmSubdirCommand.h +++ b/Source/cmSubdirCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmSubdirCommand - * \brief Specify a list of subdirectories to build. - * - * cmSubdirCommand specifies a list of subdirectories to process - * by CMake. For each subdirectory listed, CMake will descend - * into that subdirectory and process any CMakeLists.txt found. - */ -class cmSubdirCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmSubdirCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmSubdirCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index b7287d9..86af683 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -855,6 +855,18 @@ bool cmSystemTools::RenameFile(const std::string& oldname, #endif } +void cmSystemTools::MoveFileIfDifferent(const std::string& source, + const std::string& destination) +{ + if (FilesDiffer(source, destination)) { + if (RenameFile(source, destination)) { + return; + } + CopyFileAlways(source, destination); + } + RemoveFile(source); +} + std::string cmSystemTools::ComputeFileHash(const std::string& source, cmCryptoHash::Algo algo) { @@ -1633,8 +1645,8 @@ int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line, std::vector<char>& err) { line.clear(); - std::vector<char>::iterator outiter = out.begin(); - std::vector<char>::iterator erriter = err.begin(); + auto outiter = out.begin(); + auto erriter = err.begin(); cmProcessOutput processOutput; std::string strdata; while (true) { @@ -2540,8 +2552,7 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg, // Adjust the entry list as necessary to remove the run path unsigned long entriesErased = 0; - for (cmELF::DynamicEntryList::iterator it = dentries.begin(); - it != dentries.end();) { + for (auto it = dentries.begin(); it != dentries.end();) { if (it->first == cmELF::TagRPath || it->first == cmELF::TagRunPath) { it = dentries.erase(it); entriesErased++; diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 863db3f..8ca4939 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -131,6 +131,10 @@ public: static bool RenameFile(const std::string& oldname, const std::string& newname); + //! Rename a file if contents are different, delete the source otherwise + static void MoveFileIfDifferent(const std::string& source, + const std::string& destination); + //! Compute the hash of a file static std::string ComputeFileHash(const std::string& source, cmCryptoHash::Algo algo); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 10ea7dd..2420810 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1361,13 +1361,11 @@ void cmTarget::AppendBuildInterfaceIncludes() void cmTarget::InsertInclude(std::string const& entry, cmListFileBacktrace const& bt, bool before) { - std::vector<std::string>::iterator position = before - ? impl->IncludeDirectoriesEntries.begin() - : impl->IncludeDirectoriesEntries.end(); + auto position = before ? impl->IncludeDirectoriesEntries.begin() + : impl->IncludeDirectoriesEntries.end(); - std::vector<cmListFileBacktrace>::iterator btPosition = before - ? impl->IncludeDirectoriesBacktraces.begin() - : impl->IncludeDirectoriesBacktraces.end(); + auto btPosition = before ? impl->IncludeDirectoriesBacktraces.begin() + : impl->IncludeDirectoriesBacktraces.end(); impl->IncludeDirectoriesEntries.insert(position, entry); impl->IncludeDirectoriesBacktraces.insert(btPosition, bt); @@ -1376,13 +1374,11 @@ void cmTarget::InsertInclude(std::string const& entry, void cmTarget::InsertCompileOption(std::string const& entry, cmListFileBacktrace const& bt, bool before) { - std::vector<std::string>::iterator position = before - ? impl->CompileOptionsEntries.begin() - : impl->CompileOptionsEntries.end(); + auto position = before ? impl->CompileOptionsEntries.begin() + : impl->CompileOptionsEntries.end(); - std::vector<cmListFileBacktrace>::iterator btPosition = before - ? impl->CompileOptionsBacktraces.begin() - : impl->CompileOptionsBacktraces.end(); + auto btPosition = before ? impl->CompileOptionsBacktraces.begin() + : impl->CompileOptionsBacktraces.end(); impl->CompileOptionsEntries.insert(position, entry); impl->CompileOptionsBacktraces.insert(btPosition, bt); @@ -1398,12 +1394,11 @@ void cmTarget::InsertCompileDefinition(std::string const& entry, void cmTarget::InsertLinkOption(std::string const& entry, cmListFileBacktrace const& bt, bool before) { - std::vector<std::string>::iterator position = + auto position = before ? impl->LinkOptionsEntries.begin() : impl->LinkOptionsEntries.end(); - std::vector<cmListFileBacktrace>::iterator btPosition = before - ? impl->LinkOptionsBacktraces.begin() - : impl->LinkOptionsBacktraces.end(); + auto btPosition = before ? impl->LinkOptionsBacktraces.begin() + : impl->LinkOptionsBacktraces.end(); impl->LinkOptionsEntries.insert(position, entry); impl->LinkOptionsBacktraces.insert(btPosition, bt); @@ -1412,13 +1407,11 @@ void cmTarget::InsertLinkOption(std::string const& entry, void cmTarget::InsertLinkDirectory(std::string const& entry, cmListFileBacktrace const& bt, bool before) { - std::vector<std::string>::iterator position = before - ? impl->LinkDirectoriesEntries.begin() - : impl->LinkDirectoriesEntries.end(); + auto position = before ? impl->LinkDirectoriesEntries.begin() + : impl->LinkDirectoriesEntries.end(); - std::vector<cmListFileBacktrace>::iterator btPosition = before - ? impl->LinkDirectoriesBacktraces.begin() - : impl->LinkDirectoriesBacktraces.end(); + auto btPosition = before ? impl->LinkDirectoriesBacktraces.begin() + : impl->LinkDirectoriesBacktraces.end(); impl->LinkDirectoriesEntries.insert(position, entry); impl->LinkDirectoriesBacktraces.insert(btPosition, bt); @@ -1496,8 +1489,7 @@ static void cmTargetCheckIMPORTED_GLOBAL(const cmTarget* target, cmMakefile* context) { std::vector<cmTarget*> targets = context->GetOwnedImportedTargets(); - std::vector<cmTarget*>::const_iterator it = - std::find(targets.begin(), targets.end(), target); + auto it = std::find(targets.begin(), targets.end(), target); if (it == targets.end()) { std::ostringstream e; e << "Attempt to promote imported target \"" << target->GetName() @@ -1947,7 +1939,7 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config, (this->IsAIX() && this->IsExecutableWithExports()); // If a mapping was found, check its configurations. - for (std::vector<std::string>::const_iterator mci = mappedConfigs.begin(); + for (auto mci = mappedConfigs.begin(); !*loc && !*imp && mci != mappedConfigs.end(); ++mci) { // Look for this configuration. if (mci->empty()) { @@ -2018,8 +2010,7 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config, if (const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) { cmExpandList(iconfigs, availableConfigs); } - for (std::vector<std::string>::const_iterator aci = - availableConfigs.begin(); + for (auto aci = availableConfigs.begin(); !*loc && !*imp && aci != availableConfigs.end(); ++aci) { suffix = cmStrCat('_', cmSystemTools::UpperCase(*aci)); std::string locProp = cmStrCat(locPropBase, suffix); diff --git a/Source/cmUVStreambuf.h b/Source/cmUVStreambuf.h index 873352b..0737629 100644 --- a/Source/cmUVStreambuf.h +++ b/Source/cmUVStreambuf.h @@ -61,7 +61,7 @@ public: cmBasicUVStreambuf* close(); protected: - typename cmBasicUVStreambuf::int_type underflow() override; + typename cmBasicUVStreambuf<CharT, Traits>::int_type underflow() override; std::streamsize showmanyc() override; // FIXME: Add write support diff --git a/Source/cmUseMangledMesaCommand.cxx b/Source/cmUseMangledMesaCommand.cxx index cfc00e8..1fd386b 100644 --- a/Source/cmUseMangledMesaCommand.cxx +++ b/Source/cmUseMangledMesaCommand.cxx @@ -98,7 +98,6 @@ void CopyAndFullPathMesaHeader(const std::string& source, // close the files before attempting to copy fin.close(); fout.close(); - cmSystemTools::CopyFileIfDifferent(tempOutputFile, outFile); - cmSystemTools::RemoveFile(tempOutputFile); + cmSystemTools::MoveFileIfDifferent(tempOutputFile, outFile); } } diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx index 25fe4ad..6b3590f 100644 --- a/Source/cmUtilitySourceCommand.cxx +++ b/Source/cmUtilitySourceCommand.cxx @@ -20,7 +20,7 @@ bool cmUtilitySourceCommand(std::vector<std::string> const& args, return false; } - std::vector<std::string>::const_iterator arg = args.begin(); + auto arg = args.begin(); // The first argument is the cache entry name. std::string const& cacheEntry = *arg++; diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx index 3df1420..4995da9 100644 --- a/Source/cmVariableWatch.cxx +++ b/Source/cmVariableWatch.cxx @@ -66,8 +66,7 @@ bool cmVariableWatch::VariableAccessed(const std::string& variable, int access_type, const char* newValue, const cmMakefile* mf) const { - cmVariableWatch::StringToVectorOfPairs::const_iterator mit = - this->WatchMap.find(variable); + auto mit = this->WatchMap.find(variable); if (mit != this->WatchMap.end()) { // The strategy here is to copy the list of callbacks, and ignore // new callbacks that existing ones may add. diff --git a/Source/cmVariableWatchCommand.cxx b/Source/cmVariableWatchCommand.cxx index db23efd..f9f7d66 100644 --- a/Source/cmVariableWatchCommand.cxx +++ b/Source/cmVariableWatchCommand.cxx @@ -91,6 +91,7 @@ static void deleteVariableWatchCallbackData(void* client_data) class FinalAction { public: + /* NOLINTNEXTLINE(performance-unnecessary-value-param) */ FinalAction(cmMakefile* makefile, std::string variable) : Action(std::make_shared<Impl>(makefile, std::move(variable))) { diff --git a/Source/cmWriteFileCommand.cxx b/Source/cmWriteFileCommand.cxx index 5009b16..fdf07bb 100644 --- a/Source/cmWriteFileCommand.cxx +++ b/Source/cmWriteFileCommand.cxx @@ -19,7 +19,7 @@ bool cmWriteFileCommand(std::vector<std::string> const& args, return false; } std::string message; - std::vector<std::string>::const_iterator i = args.begin(); + auto i = args.begin(); std::string const& fileName = *i; bool overwrite = true; diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h index 0552676..d9be3d2 100644 --- a/Source/cmXCodeObject.h +++ b/Source/cmXCodeObject.h @@ -106,8 +106,7 @@ public: bool HasComment() const { return (!this->Comment.empty()); } cmXCodeObject* GetObject(const char* name) const { - std::map<std::string, cmXCodeObject*>::const_iterator i = - this->ObjectAttributes.find(name); + auto const i = this->ObjectAttributes.find(name); if (i != this->ObjectAttributes.end()) { return i->second; } diff --git a/Source/cmXMLWriter.h b/Source/cmXMLWriter.h index a5b06af..c4103cc 100644 --- a/Source/cmXMLWriter.h +++ b/Source/cmXMLWriter.h @@ -77,14 +77,11 @@ private: void CloseStartElement(); private: - static cmXMLSafe SafeAttribute(const char* value) - { - return cmXMLSafe(value); - } + static cmXMLSafe SafeAttribute(const char* value) { return { value }; } static cmXMLSafe SafeAttribute(std::string const& value) { - return cmXMLSafe(value); + return { value }; } template <typename T> diff --git a/Source/cmake.cxx b/Source/cmake.cxx index ace9198..170e09b 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1081,20 +1081,18 @@ createExtraGenerator( const std::vector<std::string> generators = i->GetSupportedGlobalGenerators(); if (i->GetName() == name) { // Match aliases - return std::make_pair(i->CreateExternalMakefileProjectGenerator(), - generators.at(0)); + return { i->CreateExternalMakefileProjectGenerator(), generators.at(0) }; } for (std::string const& g : generators) { const std::string fullName = cmExternalMakefileProjectGenerator::CreateFullGeneratorName( g, i->GetName()); if (fullName == name) { - return std::make_pair(i->CreateExternalMakefileProjectGenerator(), g); + return { i->CreateExternalMakefileProjectGenerator(), g }; } } } - return std::make_pair( - static_cast<cmExternalMakefileProjectGenerator*>(nullptr), name); + return { nullptr, name }; } cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname) @@ -1273,8 +1271,7 @@ int cmake::HandleDeleteCacheVariables(const std::string& var) << "Configure will be re-run and you may have to reset some variables.\n" << "The following variables have changed:\n"; /* clang-format on */ - for (std::vector<std::string>::iterator i = argsSplit.begin(); - i != argsSplit.end(); ++i) { + for (auto i = argsSplit.begin(); i != argsSplit.end(); ++i) { SaveCacheEntry save; save.key = *i; warning << *i << "= "; @@ -2190,7 +2187,7 @@ int cmake::CheckBuildSystem() } // Find the newest dependency. - std::vector<std::string>::iterator dep = depends.begin(); + auto dep = depends.begin(); std::string dep_newest = *dep++; for (; dep != depends.end(); ++dep) { int result = 0; @@ -2208,7 +2205,7 @@ int cmake::CheckBuildSystem() } // Find the oldest output. - std::vector<std::string>::iterator out = outputs.begin(); + auto out = outputs.begin(); std::string out_oldest = *out++; for (; out != outputs.end(); ++out) { int result = 0; @@ -2310,8 +2307,7 @@ bool cmake::GetPropertyAsBool(const std::string& prop) cmInstalledFile* cmake::GetOrCreateInstalledFile(cmMakefile* mf, const std::string& name) { - std::map<std::string, cmInstalledFile>::iterator i = - this->InstalledFiles.find(name); + auto i = this->InstalledFiles.find(name); if (i != this->InstalledFiles.end()) { cmInstalledFile& file = i->second; @@ -2324,8 +2320,7 @@ cmInstalledFile* cmake::GetOrCreateInstalledFile(cmMakefile* mf, cmInstalledFile const* cmake::GetInstalledFile(const std::string& name) const { - std::map<std::string, cmInstalledFile>::const_iterator i = - this->InstalledFiles.find(name); + auto i = this->InstalledFiles.find(name); if (i != this->InstalledFiles.end()) { cmInstalledFile const& file = i->second; diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index a79a2ff..ba2ba33 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -562,19 +562,36 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args) "objlistfile [-nm=nm-path]\n"; return 1; } - FILE* fout = cmsys::SystemTools::Fopen(args[2].c_str(), "w+"); - if (!fout) { - std::cerr << "could not open output .def file: " << args[2].c_str() - << "\n"; - return 1; - } cmsys::ifstream fin(args[3].c_str(), std::ios::in | std::ios::binary); if (!fin) { std::cerr << "could not open object list file: " << args[3].c_str() << "\n"; return 1; } - std::string file; + std::vector<std::string> files; + { + std::string file; + cmFileTime outTime; + bool outValid = outTime.Load(args[2]); + while (cmSystemTools::GetLineFromStream(fin, file)) { + files.push_back(file); + if (outValid) { + cmFileTime inTime; + outValid = inTime.Load(file) && inTime.Older(outTime); + } + } + if (outValid) { + // The def file already exists and all input files are older than the + // existing def file. + return 0; + } + } + FILE* fout = cmsys::SystemTools::Fopen(args[2].c_str(), "w+"); + if (!fout) { + std::cerr << "could not open output .def file: " << args[2].c_str() + << "\n"; + return 1; + } bindexplib deffile; if (args.size() >= 5) { auto a = args[4]; @@ -585,7 +602,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args) std::cerr << "unknown argument: " << a << "\n"; } } - while (cmSystemTools::GetLineFromStream(fin, file)) { + for (auto const& file : files) { std::string const& ext = cmSystemTools::GetFilenameLastExtension(file); if (cmSystemTools::LowerCase(ext) == ".def") { if (!deffile.AddDefinitionFile(file.c_str())) { @@ -1713,7 +1730,7 @@ bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg, { // Parse our own arguments. std::string intDir; - std::vector<std::string>::const_iterator arg = argBeg; + auto arg = argBeg; while (arg != argEnd && cmHasLiteralPrefix(*arg, "-")) { if (*arg == "--") { ++arg; diff --git a/Tests/CMakeLib/run_compile_commands.cxx b/Tests/CMakeLib/run_compile_commands.cxx index b1541e2..010e17a 100644 --- a/Tests/CMakeLib/run_compile_commands.cxx +++ b/Tests/CMakeLib/run_compile_commands.cxx @@ -18,7 +18,7 @@ public: public: std::string const& at(std::string const& k) const { - const_iterator i = this->find(k); + auto i = this->find(k); if (i != this->end()) { return i->second; } diff --git a/Tests/CMakeLib/testUVProcessChainHelper.cxx b/Tests/CMakeLib/testUVProcessChainHelper.cxx index 263665d..a77ec90 100644 --- a/Tests/CMakeLib/testUVProcessChainHelper.cxx +++ b/Tests/CMakeLib/testUVProcessChainHelper.cxx @@ -44,7 +44,7 @@ int main(int argc, char** argv) } if (command == "dedup") { // Use a nested scope to free all resources before aborting below. - { + try { std::string input = getStdin(); std::set<char> seen; std::string output; @@ -56,6 +56,7 @@ int main(int argc, char** argv) } std::cout << output << std::flush; std::cerr << "3" << std::flush; + } catch (...) { } // On Windows, the exit code of abort() is different between debug and diff --git a/Tests/CustomCommandByproducts/CMakeLists.txt b/Tests/CustomCommandByproducts/CMakeLists.txt index d0bf648..bfa69ce 100644 --- a/Tests/CustomCommandByproducts/CMakeLists.txt +++ b/Tests/CustomCommandByproducts/CMakeLists.txt @@ -28,6 +28,7 @@ add_custom_target(Producer3_4 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct3.c.in byproduct3.c BYPRODUCTS byproduct3.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct3.c.in ) # Generate a byproduct in a custom target POST_BUILD command. @@ -36,32 +37,36 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct4.c.in byproduct4.c BYPRODUCTS byproduct4.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct4.c.in ) -add_executable(ProducerExe ProducerExe.c) +add_executable(ProducerExe5_6_7 ProducerExe.c) # Generate a byproduct in an executable POST_BUILD command. add_custom_command( - TARGET ProducerExe POST_BUILD + TARGET ProducerExe5_6_7 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct5.c.in byproduct5.c BYPRODUCTS byproduct5.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct5.c.in ) # Generate a byproduct in an executable PRE_LINK command. add_custom_command( - TARGET ProducerExe PRE_LINK + TARGET ProducerExe5_6_7 PRE_LINK COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct6.c.in byproduct6.c BYPRODUCTS byproduct6.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct6.c.in ) # Generate a byproduct in an executable PRE_BUILD command. add_custom_command( - TARGET ProducerExe PRE_BUILD + TARGET ProducerExe5_6_7 PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct7.c.in byproduct7.c BYPRODUCTS byproduct7.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct7.c.in ) # Generate a byproduct in a custom command that consumes other byproducts. @@ -80,6 +85,25 @@ add_custom_command(OUTPUT timestamp8.txt ${CMAKE_CURRENT_SOURCE_DIR}/byproduct8.c.in ) +add_executable(ProducerExe9 ProducerExe.c) + +# Generate a byproduct in a custom target which depends on a byproduct of a +# POST_BUILD command (test if dependency of custom target Producer9 to +# ProducerExe9 is added). +add_custom_command( + TARGET ProducerExe9 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct9.c.in byproduct9a.c + BYPRODUCTS byproduct9a.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct9.c.in + ) +add_custom_target(Producer9 + COMMAND ${CMAKE_COMMAND} -E copy_if_different + byproduct9a.c byproduct9.c + BYPRODUCTS byproduct9.c + DEPENDS byproduct9a.c + ) + # Generate the library file of an imported target as a byproduct # of an external project. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) @@ -136,10 +160,13 @@ add_executable(CustomCommandByproducts byproduct6.c byproduct7.c byproduct8.c timestamp8.txt + byproduct9.c ) + +# Dependencies to byproducts of custom commands other than build events are not +# yet traced (see issue #19005). add_dependencies(CustomCommandByproducts Producer2) -add_dependencies(CustomCommandByproducts Producer3_4) -add_dependencies(CustomCommandByproducts ProducerExe) + target_link_libraries(CustomCommandByproducts ExternalLibrary) if(CMAKE_GENERATOR STREQUAL "Ninja") diff --git a/Tests/CustomCommandByproducts/CustomCommandByproducts.c b/Tests/CustomCommandByproducts/CustomCommandByproducts.c index 02ad7ea..0658d05 100644 --- a/Tests/CustomCommandByproducts/CustomCommandByproducts.c +++ b/Tests/CustomCommandByproducts/CustomCommandByproducts.c @@ -6,10 +6,11 @@ extern int byproduct5(void); extern int byproduct6(void); extern int byproduct7(void); extern int byproduct8(void); +extern int byproduct9(void); extern int ExternalLibrary(void); int main(void) { return (byproduct1() + byproduct2() + byproduct3() + byproduct4() + byproduct5() + byproduct6() + byproduct7() + byproduct8() + - ExternalLibrary() + 0); + byproduct9() + ExternalLibrary() + 0); } diff --git a/Tests/CustomCommandByproducts/byproduct9.c.in b/Tests/CustomCommandByproducts/byproduct9.c.in new file mode 100644 index 0000000..11eed2c --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct9.c.in @@ -0,0 +1 @@ +int byproduct9(void) { return 0; } diff --git a/Tests/RunCMake/AutoExportDll/RunCMakeTest.cmake b/Tests/RunCMake/AutoExportDll/RunCMakeTest.cmake index 27a609d..6c9be4b 100644 --- a/Tests/RunCMake/AutoExportDll/RunCMakeTest.cmake +++ b/Tests/RunCMake/AutoExportDll/RunCMakeTest.cmake @@ -7,9 +7,13 @@ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") run_cmake(AutoExport) unset(RunCMake_TEST_OPTIONS) # don't run this test on Watcom or Borland make as it is not supported -if("${RunCMake_GENERATOR}" MATCHES "Watcom WMake|Borland Makefiles") +if(RunCMake_GENERATOR MATCHES "Watcom WMake|Borland Makefiles") return() endif() +if(RunCMake_GENERATOR MATCHES "Ninja|Visual Studio" AND + CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(EXPORTS TRUE) +endif() # we build debug so the say.exe will be found in Debug/say.exe for # Visual Studio generators if(RunCMake_GENERATOR_IS_MULTI_CONFIG) @@ -18,9 +22,36 @@ endif() # build AutoExport run_cmake_command(AutoExportBuild ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR} --config Debug --clean-first) +# save the current timestamp of exports.def +if(EXPORTS) + set(EXPORTS_DEF "${RunCMake_TEST_BINARY_DIR}/say.dir/${INTDIR}exports.def") + if(NOT EXISTS "${EXPORTS_DEF}") + set(EXPORTS_DEF + "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/say.dir/${INTDIR}exports.def") + endif() + file(TIMESTAMP "${EXPORTS_DEF}" timestamp) + if(NOT timestamp) + message(SEND_ERROR "Could not get timestamp for \"${EXPORTS_DEF}\"") + endif() +endif() # run the executable that uses symbols from the dll if(WIN32) set(EXE_EXT ".exe") endif() run_cmake_command(AutoExportRun - ${RunCMake_BINARY_DIR}/AutoExport-build/bin/${INTDIR}say${EXE_EXT}) + ${RunCMake_TEST_BINARY_DIR}/bin/${INTDIR}say${EXE_EXT}) +# build AutoExport again without modification +run_cmake_command(AutoExportBuildAgain ${CMAKE_COMMAND} --build + ${RunCMake_TEST_BINARY_DIR} --config Debug) +# compare timestamps of exports.def to make sure it has not been updated +if(EXPORTS) + file(TIMESTAMP "${EXPORTS_DEF}" timestamp_after) + if(NOT timestamp_after) + message(SEND_ERROR "Could not get timestamp for \"${EXPORTS_DEF}\"") + endif() + if (timestamp_after STREQUAL timestamp) + message(STATUS "AutoExportTimeStamp - PASSED") + else() + message(SEND_ERROR "\"${EXPORTS_DEF}\" has been updated.") + endif() +endif() diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 8fd5234..c663484 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -543,7 +543,7 @@ set(cpack_tests add_RunCMake_test_group(CPack "${cpack_tests}") # add a test to make sure symbols are exported from a shared library # for MSVC compilers CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS property is used -add_RunCMake_test(AutoExportDll) +add_RunCMake_test(AutoExportDll -DCMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}) add_RunCMake_test(AndroidMK) diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-check.py b/Tests/RunCMake/FileAPI/codemodel-v2-check.py index 89f63d0..2a24421 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-check.py +++ b/Tests/RunCMake/FileAPI/codemodel-v2-check.py @@ -232,17 +232,37 @@ def check_target(c): assert is_string(obj["link"]["language"], expected["link"]["language"]) - # FIXME: Properly test commandFragments if "commandFragments" in obj["link"]: link_keys.append("commandFragments") assert is_list(obj["link"]["commandFragments"]) for f in obj["link"]["commandFragments"]: assert is_dict(f) - assert sorted(f.keys()) == ["fragment", "role"] + assert sorted(f.keys()) == ["fragment", "role"] or sorted(f.keys()) == ["backtrace", "fragment", "role"] assert is_string(f["fragment"]) assert is_string(f["role"]) assert f["role"] in ("flags", "libraries", "libraryPath", "frameworkPath") + if expected["link"]["commandFragments"] is not None: + def check_link_command_fragments(actual, expected): + assert is_dict(actual) + expected_keys = ["fragment", "role"] + + if expected["backtrace"] is not None: + expected_keys.append("backtrace") + assert actual["fragment"] == expected["fragment"] + assert actual["role"] == expected["role"] + check_backtrace(obj, actual["backtrace"], expected["backtrace"]) + + assert sorted(actual.keys()) == sorted(expected_keys) + + check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]), + obj["link"]["commandFragments"], expected["link"]["commandFragments"], + check=check_link_command_fragments, + check_exception=lambda a, e: "Link fragment: %s" % a["fragment"], + missing_exception=lambda e: "Link fragment: %s" % e["fragment"], + extra_exception=lambda a: "Link fragment: %s" % a["fragment"], + allow_extra=True) + if expected["link"]["lto"] is not None: link_keys.append("lto") assert is_bool(obj["link"]["lto"], expected["link"]["lto"]) @@ -327,15 +347,33 @@ def check_target(c): missing_exception=lambda e: "Source path: %s" % e, extra_exception=lambda a: "Source path: %s" % obj["sources"][a]["path"]) - # FIXME: Properly test compileCommandFragments if "compileCommandFragments" in actual: expected_keys.append("compileCommandFragments") assert is_list(actual["compileCommandFragments"]) for f in actual["compileCommandFragments"]: assert is_dict(f) - assert sorted(f.keys()) == ["fragment"] assert is_string(f["fragment"]) + if expected["compileCommandFragments"] is not None: + def check_compile_command_fragments(actual, expected): + assert is_dict(actual) + expected_keys = ["fragment"] + + if expected["backtrace"] is not None: + expected_keys.append("backtrace") + assert actual["fragment"] == expected["fragment"] + check_backtrace(obj, actual["backtrace"], expected["backtrace"]) + + assert sorted(actual.keys()) == sorted(expected_keys) + + check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]), + actual["compileCommandFragments"], expected["compileCommandFragments"], + check=check_compile_command_fragments, + check_exception=lambda a, e: "Compile fragment: %s" % a["fragment"], + missing_exception=lambda e: "Compile fragment: %s" % e["fragment"], + extra_exception=lambda a: "Compile fragment: %s" % a["fragment"], + allow_extra=True) + if expected["includes"] is not None: expected_keys.append("includes") @@ -931,6 +969,7 @@ def gen_check_targets(c, g, inSource): "backtrace": None, }, ], + "compileCommandFragments": None, }, ], "backtrace": [ @@ -998,6 +1037,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1064,6 +1104,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1171,6 +1212,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1217,6 +1259,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1317,6 +1360,7 @@ def gen_check_targets(c, g, inSource): "backtrace": None, }, ], + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1367,6 +1411,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": True, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1433,6 +1478,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1479,6 +1525,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": True, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1574,6 +1621,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1681,6 +1729,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1727,6 +1776,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1979,6 +2029,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2062,6 +2113,25 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": [ + { + "fragment" : "TargetCompileOptions", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 17, + "command": "target_compile_options", + "hasParent": True, + }, + { + "file" : "^cxx/CMakeLists\\.txt$", + "line": None, + "command": None, + "hasParent": False, + }, + ], + } + ], }, ], "backtrace": [ @@ -2129,6 +2199,26 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": [ + { + "fragment" : "TargetLinkOptions", + "role" : "flags", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 18, + "command": "target_link_options", + "hasParent": True, + }, + { + "file" : "^cxx/CMakeLists\\.txt$", + "line": None, + "command": None, + "hasParent": False, + }, + ], + }, + ], }, "archive": None, "dependencies": [ @@ -2205,6 +2295,7 @@ def gen_check_targets(c, g, inSource): "backtrace": None, }, ], + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2243,6 +2334,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -2297,6 +2389,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2331,6 +2424,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -2402,6 +2496,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2485,6 +2580,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2519,6 +2615,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -2743,6 +2840,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2777,6 +2875,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -2848,6 +2947,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2882,6 +2982,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3114,6 +3215,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3221,6 +3323,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3276,6 +3379,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3337,6 +3441,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3444,6 +3549,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3499,6 +3605,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3725,6 +3832,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3759,6 +3867,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3813,6 +3922,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3847,6 +3957,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3901,6 +4012,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3935,6 +4047,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3989,6 +4102,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -4023,6 +4137,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -4077,6 +4192,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -4111,6 +4227,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -4401,6 +4518,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -4435,6 +4553,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -4748,6 +4867,7 @@ def gen_check_targets(c, g, inSource): ], }, ], + "compileCommandFragments": None, }, { "language": "CXX", @@ -4810,6 +4930,7 @@ def gen_check_targets(c, g, inSource): ], }, ], + "compileCommandFragments": None, }, ], "backtrace": [ @@ -4844,6 +4965,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ diff --git a/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt b/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt index 29b61b8..17ff455 100644 --- a/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt +++ b/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt @@ -13,3 +13,6 @@ target_link_libraries(cxx_shared_exe PRIVATE cxx_shared_lib) add_library(cxx_static_lib STATIC ../empty.cxx) add_executable(cxx_static_exe ../empty.cxx) target_link_libraries(cxx_static_exe PRIVATE cxx_static_lib) + +target_compile_options(cxx_exe PUBLIC TargetCompileOptions) +target_link_options(cxx_exe PUBLIC TargetLinkOptions) diff --git a/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp b/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp index 4b17875..593822a 100644 --- a/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp +++ b/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp @@ -10,7 +10,8 @@ std::wstring get_property(MSIHANDLE msi_handle, std::wstring const& name) { DWORD size = 0; - UINT status = MsiGetPropertyW(msi_handle, name.c_str(), L"", &size); + WCHAR value_buffer[] = L""; + UINT status = MsiGetPropertyW(msi_handle, name.c_str(), value_buffer, &size); if (status == ERROR_MORE_DATA) { std::vector<wchar_t> buffer(size + 1); |