diff options
-rw-r--r-- | Source/cmInstallCommand.cxx | 172 | ||||
-rw-r--r-- | Source/cmInstallCommandArguments.cxx | 66 | ||||
-rw-r--r-- | Source/cmInstallCommandArguments.h | 35 |
3 files changed, 134 insertions, 139 deletions
diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 20d1a31..9736b41 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallCommand.h" +#include "cm_static_string_view.hxx" #include "cmsys/Glob.hxx" #include <set> #include <sstream> @@ -9,7 +10,7 @@ #include <utility> #include "cmAlgorithms.h" -#include "cmCommandArgumentsHelper.h" +#include "cmArgumentParser.h" #include "cmExportSet.h" #include "cmExportSetMap.h" #include "cmGeneratorExpression.h" @@ -219,49 +220,51 @@ bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args) return true; } -/*struct InstallPart -{ - InstallPart(cmCommandArgumentsHelper* helper, const char* key, - cmCommandArgumentGroup* group); - cmCAStringVector argVector; - cmInstallCommandArguments args; -};*/ - bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) { // This is the TARGETS mode. std::vector<cmTarget*> targets; - cmCommandArgumentsHelper argHelper; - cmCommandArgumentGroup group; - cmCAStringVector genericArgVector(&argHelper, nullptr); - cmCAStringVector archiveArgVector(&argHelper, "ARCHIVE", &group); - cmCAStringVector libraryArgVector(&argHelper, "LIBRARY", &group); - cmCAStringVector runtimeArgVector(&argHelper, "RUNTIME", &group); - cmCAStringVector objectArgVector(&argHelper, "OBJECTS", &group); - cmCAStringVector frameworkArgVector(&argHelper, "FRAMEWORK", &group); - cmCAStringVector bundleArgVector(&argHelper, "BUNDLE", &group); - cmCAStringVector includesArgVector(&argHelper, "INCLUDES", &group); - cmCAStringVector privateHeaderArgVector(&argHelper, "PRIVATE_HEADER", - &group); - cmCAStringVector publicHeaderArgVector(&argHelper, "PUBLIC_HEADER", &group); - cmCAStringVector resourceArgVector(&argHelper, "RESOURCE", &group); - genericArgVector.Follows(nullptr); - group.Follows(&genericArgVector); - - argHelper.Parse(&args, nullptr); + struct ArgVectors + { + std::vector<std::string> Archive; + std::vector<std::string> Library; + std::vector<std::string> Runtime; + std::vector<std::string> Object; + std::vector<std::string> Framework; + std::vector<std::string> Bundle; + std::vector<std::string> Includes; + std::vector<std::string> PrivateHeader; + std::vector<std::string> PublicHeader; + std::vector<std::string> Resource; + }; + + static auto const argHelper = + cmArgumentParser<ArgVectors>{} + .Bind("ARCHIVE"_s, &ArgVectors::Archive) + .Bind("LIBRARY"_s, &ArgVectors::Library) + .Bind("RUNTIME"_s, &ArgVectors::Runtime) + .Bind("OBJECTS"_s, &ArgVectors::Object) + .Bind("FRAMEWORK"_s, &ArgVectors::Framework) + .Bind("BUNDLE"_s, &ArgVectors::Bundle) + .Bind("INCLUDES"_s, &ArgVectors::Includes) + .Bind("PRIVATE_HEADER"_s, &ArgVectors::PrivateHeader) + .Bind("PUBLIC_HEADER"_s, &ArgVectors::PublicHeader) + .Bind("RESOURCE"_s, &ArgVectors::Resource); + + std::vector<std::string> genericArgVector; + ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector); // now parse the generic args (i.e. the ones not specialized on LIBRARY/ // ARCHIVE, RUNTIME etc. (see above) // These generic args also contain the targets and the export stuff + std::vector<std::string> targetList; + std::string exports; std::vector<std::string> unknownArgs; cmInstallCommandArguments genericArgs(this->DefaultComponentName); - cmCAStringVector targetList(&genericArgs.Parser, "TARGETS"); - cmCAString exports(&genericArgs.Parser, "EXPORT", - &genericArgs.ArgumentGroup); - targetList.Follows(nullptr); - genericArgs.ArgumentGroup.Follows(&targetList); - genericArgs.Parse(&genericArgVector.GetVector(), &unknownArgs); + genericArgs.Bind("TARGETS"_s, targetList); + genericArgs.Bind("EXPORT"_s, exports); + genericArgs.Parse(genericArgVector, &unknownArgs); bool success = genericArgs.Finalize(); cmInstallCommandArguments archiveArgs(this->DefaultComponentName); @@ -277,16 +280,16 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) // now parse the args for specific parts of the target (e.g. LIBRARY, // RUNTIME, ARCHIVE etc. - archiveArgs.Parse(&archiveArgVector.GetVector(), &unknownArgs); - libraryArgs.Parse(&libraryArgVector.GetVector(), &unknownArgs); - runtimeArgs.Parse(&runtimeArgVector.GetVector(), &unknownArgs); - objectArgs.Parse(&objectArgVector.GetVector(), &unknownArgs); - frameworkArgs.Parse(&frameworkArgVector.GetVector(), &unknownArgs); - bundleArgs.Parse(&bundleArgVector.GetVector(), &unknownArgs); - privateHeaderArgs.Parse(&privateHeaderArgVector.GetVector(), &unknownArgs); - publicHeaderArgs.Parse(&publicHeaderArgVector.GetVector(), &unknownArgs); - resourceArgs.Parse(&resourceArgVector.GetVector(), &unknownArgs); - includesArgs.Parse(&includesArgVector.GetVector(), &unknownArgs); + archiveArgs.Parse(argVectors.Archive, &unknownArgs); + libraryArgs.Parse(argVectors.Library, &unknownArgs); + runtimeArgs.Parse(argVectors.Runtime, &unknownArgs); + objectArgs.Parse(argVectors.Object, &unknownArgs); + frameworkArgs.Parse(argVectors.Framework, &unknownArgs); + bundleArgs.Parse(argVectors.Bundle, &unknownArgs); + privateHeaderArgs.Parse(argVectors.PrivateHeader, &unknownArgs); + publicHeaderArgs.Parse(argVectors.PublicHeader, &unknownArgs); + resourceArgs.Parse(argVectors.Resource, &unknownArgs); + includesArgs.Parse(&argVectors.Includes, &unknownArgs); if (!unknownArgs.empty()) { // Unknown argument. @@ -382,7 +385,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) } // Check if there is something to do. - if (targetList.GetVector().empty()) { + if (targetList.empty()) { return true; } @@ -390,7 +393,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) bool dll_platform = !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); - for (std::string const& tgt : targetList.GetVector()) { + for (std::string const& tgt : targetList) { if (this->Makefile->IsAlias(tgt)) { std::ostringstream e; @@ -748,7 +751,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) // Add this install rule to an export if one was specified and // this is not a namelink-only rule. - if (!exports.GetString().empty() && !namelinkOnly) { + if (!exports.empty() && !namelinkOnly) { cmTargetExport* te = new cmTargetExport; te->TargetName = target.GetName(); te->ArchiveGenerator = archiveGenerator; @@ -759,7 +762,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) te->RuntimeGenerator = runtimeGenerator; te->ObjectsGenerator = objectGenerator; this->Makefile->GetGlobalGenerator() - ->GetExportSets()[exports.GetString()] + ->GetExportSets()[exports] ->AddTargetExport(te); te->InterfaceIncludeDirectories = @@ -818,11 +821,10 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args) // This is the FILES mode. bool programs = (args[0] == "PROGRAMS"); cmInstallCommandArguments ica(this->DefaultComponentName); - cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES"); - files.Follows(nullptr); - ica.ArgumentGroup.Follows(&files); + std::vector<std::string> files; + ica.Bind(programs ? "PROGRAMS"_s : "FILES"_s, files); std::vector<std::string> unknownArgs; - ica.Parse(&args, &unknownArgs); + ica.Parse(args, &unknownArgs); if (!unknownArgs.empty()) { // Unknown argument. @@ -840,7 +842,7 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args) return false; } - const std::vector<std::string>& filesVector = files.GetVector(); + const std::vector<std::string>& filesVector = files; // Check if there is something to do. if (filesVector.empty()) { @@ -1271,16 +1273,19 @@ bool cmInstallCommand::HandleExportAndroidMKMode( #ifdef CMAKE_BUILD_WITH_CMAKE // This is the EXPORT mode. cmInstallCommandArguments ica(this->DefaultComponentName); - cmCAString exp(&ica.Parser, "EXPORT_ANDROID_MK"); - cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup); - cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES", - &ica.ArgumentGroup); - cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup); - exp.Follows(nullptr); - - ica.ArgumentGroup.Follows(&exp); + + std::string exp; + std::string name_space; + bool exportOld = false; + std::string filename; + + ica.Bind("EXPORT_ANDROID_MK"_s, exp); + ica.Bind("NAMESPACE"_s, name_space); + ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld); + ica.Bind("FILE"_s, filename); + std::vector<std::string> unknownArgs; - ica.Parse(&args, &unknownArgs); + ica.Parse(args, &unknownArgs); if (!unknownArgs.empty()) { // Unknown argument. @@ -1304,7 +1309,7 @@ bool cmInstallCommand::HandleExportAndroidMKMode( } // Check the file name. - std::string fname = filename.GetString(); + std::string fname = filename; if (fname.find_first_of(":/\\") != std::string::npos) { std::ostringstream e; e << args[0] << " given invalid export file name \"" << fname << "\". " @@ -1325,7 +1330,7 @@ bool cmInstallCommand::HandleExportAndroidMKMode( } if (fname.find_first_of(":/\\") != std::string::npos) { std::ostringstream e; - e << args[0] << " given export name \"" << exp.GetString() << "\". " + e << args[0] << " given export name \"" << exp << "\". " << "This name cannot be safely converted to a file name. " << "Specify a different export name or use the FILE option to set " << "a file name explicitly."; @@ -1338,7 +1343,7 @@ bool cmInstallCommand::HandleExportAndroidMKMode( } cmExportSet* exportSet = - this->Makefile->GetGlobalGenerator()->GetExportSets()[exp.GetString()]; + this->Makefile->GetGlobalGenerator()->GetExportSets()[exp]; cmInstallGenerator::MessageLevel message = cmInstallGenerator::SelectMessageLevel(this->Makefile); @@ -1347,8 +1352,8 @@ bool cmInstallCommand::HandleExportAndroidMKMode( cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator( exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), ica.GetConfigurations(), ica.GetComponent().c_str(), message, - ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(), - exportOld.IsEnabled(), true); + ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld, + true); this->Makefile->AddInstallGenerator(exportGenerator); return true; @@ -1363,16 +1368,19 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) { // This is the EXPORT mode. cmInstallCommandArguments ica(this->DefaultComponentName); - cmCAString exp(&ica.Parser, "EXPORT"); - cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup); - cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES", - &ica.ArgumentGroup); - cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup); - exp.Follows(nullptr); - - ica.ArgumentGroup.Follows(&exp); + + std::string exp; + std::string name_space; + bool exportOld = false; + std::string filename; + + ica.Bind("EXPORT"_s, exp); + ica.Bind("NAMESPACE"_s, name_space); + ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld); + ica.Bind("FILE"_s, filename); + std::vector<std::string> unknownArgs; - ica.Parse(&args, &unknownArgs); + ica.Parse(args, &unknownArgs); if (!unknownArgs.empty()) { // Unknown argument. @@ -1396,7 +1404,7 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) } // Check the file name. - std::string fname = filename.GetString(); + std::string fname = filename; if (fname.find_first_of(":/\\") != std::string::npos) { std::ostringstream e; e << args[0] << " given invalid export file name \"" << fname << "\". " @@ -1418,12 +1426,12 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) // Construct the file name. if (fname.empty()) { - fname = exp.GetString(); + fname = exp; fname += ".cmake"; if (fname.find_first_of(":/\\") != std::string::npos) { std::ostringstream e; - e << args[0] << " given export name \"" << exp.GetString() << "\". " + e << args[0] << " given export name \"" << exp << "\". " << "This name cannot be safely converted to a file name. " << "Specify a different export name or use the FILE option to set " << "a file name explicitly."; @@ -1433,8 +1441,8 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) } cmExportSet* exportSet = - this->Makefile->GetGlobalGenerator()->GetExportSets()[exp.GetString()]; - if (exportOld.IsEnabled()) { + this->Makefile->GetGlobalGenerator()->GetExportSets()[exp]; + if (exportOld) { for (cmTargetExport* te : *exportSet->GetTargetExports()) { cmTarget* tgt = this->Makefile->GetGlobalGenerator()->FindTarget(te->TargetName); @@ -1461,8 +1469,8 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator( exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), ica.GetConfigurations(), ica.GetComponent().c_str(), message, - ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(), - exportOld.IsEnabled(), false); + ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld, + false); this->Makefile->AddInstallGenerator(exportGenerator); return true; diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx index c64bd8a..8b33782 100644 --- a/Source/cmInstallCommandArguments.cxx +++ b/Source/cmInstallCommandArguments.cxx @@ -4,6 +4,7 @@ #include "cmRange.h" #include "cmSystemTools.h" +#include "cm_static_string_view.hxx" #include <utility> @@ -18,20 +19,19 @@ const std::string cmInstallCommandArguments::EmptyString; cmInstallCommandArguments::cmInstallCommandArguments( std::string defaultComponent) - : Destination(&Parser, "DESTINATION", &ArgumentGroup) - , Component(&Parser, "COMPONENT", &ArgumentGroup) - , NamelinkComponent(&Parser, "NAMELINK_COMPONENT", &ArgumentGroup) - , ExcludeFromAll(&Parser, "EXCLUDE_FROM_ALL", &ArgumentGroup) - , Rename(&Parser, "RENAME", &ArgumentGroup) - , Permissions(&Parser, "PERMISSIONS", &ArgumentGroup) - , Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup) - , Optional(&Parser, "OPTIONAL", &ArgumentGroup) - , NamelinkOnly(&Parser, "NAMELINK_ONLY", &ArgumentGroup) - , NamelinkSkip(&Parser, "NAMELINK_SKIP", &ArgumentGroup) - , Type(&Parser, "TYPE", &ArgumentGroup) - , GenericArguments(nullptr) - , DefaultComponentName(std::move(defaultComponent)) + : DefaultComponentName(std::move(defaultComponent)) { + this->Bind("DESTINATION"_s, this->Destination); + this->Bind("COMPONENT"_s, this->Component); + this->Bind("NAMELINK_COMPONENT"_s, this->NamelinkComponent); + this->Bind("EXCLUDE_FROM_ALL"_s, this->ExcludeFromAll); + this->Bind("RENAME"_s, this->Rename); + this->Bind("PERMISSIONS"_s, this->Permissions); + this->Bind("CONFIGURATIONS"_s, this->Configurations); + this->Bind("OPTIONAL"_s, this->Optional); + this->Bind("NAMELINK_ONLY"_s, this->NamelinkOnly); + this->Bind("NAMELINK_SKIP"_s, this->NamelinkSkip); + this->Bind("TYPE"_s, this->Type); } const std::string& cmInstallCommandArguments::GetDestination() const @@ -47,8 +47,8 @@ const std::string& cmInstallCommandArguments::GetDestination() const const std::string& cmInstallCommandArguments::GetComponent() const { - if (!this->Component.GetString().empty()) { - return this->Component.GetString(); + if (!this->Component.empty()) { + return this->Component; } if (this->GenericArguments != nullptr) { return this->GenericArguments->GetComponent(); @@ -62,16 +62,16 @@ const std::string& cmInstallCommandArguments::GetComponent() const const std::string& cmInstallCommandArguments::GetNamelinkComponent() const { - if (!this->NamelinkComponent.GetString().empty()) { - return this->NamelinkComponent.GetString(); + if (!this->NamelinkComponent.empty()) { + return this->NamelinkComponent; } return this->GetComponent(); } const std::string& cmInstallCommandArguments::GetRename() const { - if (!this->Rename.GetString().empty()) { - return this->Rename.GetString(); + if (!this->Rename.empty()) { + return this->Rename; } if (this->GenericArguments != nullptr) { return this->GenericArguments->GetRename(); @@ -92,7 +92,7 @@ const std::string& cmInstallCommandArguments::GetPermissions() const bool cmInstallCommandArguments::GetOptional() const { - if (this->Optional.IsEnabled()) { + if (this->Optional) { return true; } if (this->GenericArguments != nullptr) { @@ -103,7 +103,7 @@ bool cmInstallCommandArguments::GetOptional() const bool cmInstallCommandArguments::GetExcludeFromAll() const { - if (this->ExcludeFromAll.IsEnabled()) { + if (this->ExcludeFromAll) { return true; } if (this->GenericArguments != nullptr) { @@ -114,7 +114,7 @@ bool cmInstallCommandArguments::GetExcludeFromAll() const bool cmInstallCommandArguments::GetNamelinkOnly() const { - if (this->NamelinkOnly.IsEnabled()) { + if (this->NamelinkOnly) { return true; } if (this->GenericArguments != nullptr) { @@ -125,7 +125,7 @@ bool cmInstallCommandArguments::GetNamelinkOnly() const bool cmInstallCommandArguments::GetNamelinkSkip() const { - if (this->NamelinkSkip.IsEnabled()) { + if (this->NamelinkSkip) { return true; } if (this->GenericArguments != nullptr) { @@ -136,7 +136,7 @@ bool cmInstallCommandArguments::GetNamelinkSkip() const bool cmInstallCommandArguments::HasNamelinkComponent() const { - if (!this->NamelinkComponent.GetString().empty()) { + if (!this->NamelinkComponent.empty()) { return true; } if (this->GenericArguments != nullptr) { @@ -147,19 +147,19 @@ bool cmInstallCommandArguments::HasNamelinkComponent() const const std::string& cmInstallCommandArguments::GetType() const { - return this->Type.GetString(); + return this->Type; } const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations() const { - if (!this->Configurations.GetVector().empty()) { - return this->Configurations.GetVector(); + if (!this->Configurations.empty()) { + return this->Configurations; } if (this->GenericArguments != nullptr) { return this->GenericArguments->GetConfigurations(); } - return this->Configurations.GetVector(); + return this->Configurations; } bool cmInstallCommandArguments::Finalize() @@ -167,21 +167,15 @@ bool cmInstallCommandArguments::Finalize() if (!this->CheckPermissions()) { return false; } - this->DestinationString = this->Destination.GetString(); + this->DestinationString = this->Destination; cmSystemTools::ConvertToUnixSlashes(this->DestinationString); return true; } -void cmInstallCommandArguments::Parse(const std::vector<std::string>* args, - std::vector<std::string>* unconsumedArgs) -{ - this->Parser.Parse(args, unconsumedArgs); -} - bool cmInstallCommandArguments::CheckPermissions() { this->PermissionsString.clear(); - for (std::string const& perm : this->Permissions.GetVector()) { + for (std::string const& perm : this->Permissions) { if (!cmInstallCommandArguments::CheckPermissions( perm, this->PermissionsString)) { return false; diff --git a/Source/cmInstallCommandArguments.h b/Source/cmInstallCommandArguments.h index 9c0d417..5d2ee0a 100644 --- a/Source/cmInstallCommandArguments.h +++ b/Source/cmInstallCommandArguments.h @@ -8,9 +8,9 @@ #include <string> #include <vector> -#include "cmCommandArgumentsHelper.h" +#include "cmArgumentParser.h" -class cmInstallCommandArguments +class cmInstallCommandArguments : public cmArgumentParser<void> { public: cmInstallCommandArguments(std::string defaultComponent); @@ -18,8 +18,6 @@ public: { this->GenericArguments = args; } - void Parse(const std::vector<std::string>* args, - std::vector<std::string>* unconsumedArgs); // Compute destination path.and check permissions bool Finalize(); @@ -37,30 +35,25 @@ public: bool HasNamelinkComponent() const; const std::string& GetType() const; - // once HandleDirectoryMode() is also switched to using - // cmInstallCommandArguments then these two functions can become non-static - // private member functions without arguments static bool CheckPermissions(const std::string& onePerm, std::string& perm); - cmCommandArgumentsHelper Parser; - cmCommandArgumentGroup ArgumentGroup; private: - cmCAString Destination; - cmCAString Component; - cmCAString NamelinkComponent; - cmCAEnabler ExcludeFromAll; - cmCAString Rename; - cmCAStringVector Permissions; - cmCAStringVector Configurations; - cmCAEnabler Optional; - cmCAEnabler NamelinkOnly; - cmCAEnabler NamelinkSkip; - cmCAString Type; + std::string Destination; + std::string Component; + std::string NamelinkComponent; + bool ExcludeFromAll = false; + std::string Rename; + std::vector<std::string> Permissions; + std::vector<std::string> Configurations; + bool Optional = false; + bool NamelinkOnly = false; + bool NamelinkSkip = false; + std::string Type; std::string DestinationString; std::string PermissionsString; - cmInstallCommandArguments* GenericArguments; + cmInstallCommandArguments* GenericArguments = nullptr; static const char* PermissionsTable[]; static const std::string EmptyString; std::string DefaultComponentName; |