CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmInstallCommandArguments.cxx
blob7309316454730657b1f6d610706555595785e10e
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmInstallCommandArguments.h"
5 #include <algorithm>
6 #include <utility>
8 #include <cmext/string_view>
10 #include "cmRange.h"
11 #include "cmSystemTools.h"
13 // Table of valid permissions.
14 const char* cmInstallCommandArguments::PermissionsTable[] = {
15 "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE", "GROUP_READ",
16 "GROUP_WRITE", "GROUP_EXECUTE", "WORLD_READ", "WORLD_WRITE",
17 "WORLD_EXECUTE", "SETUID", "SETGID", nullptr
20 const std::string cmInstallCommandArguments::EmptyString;
22 cmInstallCommandArguments::cmInstallCommandArguments(
23 std::string defaultComponent)
24 : DefaultComponentName(std::move(defaultComponent))
26 this->Bind("DESTINATION"_s, this->Destination);
27 this->Bind("COMPONENT"_s, this->Component);
28 this->Bind("NAMELINK_COMPONENT"_s, this->NamelinkComponent);
29 this->Bind("EXCLUDE_FROM_ALL"_s, this->ExcludeFromAll);
30 this->Bind("RENAME"_s, this->Rename);
31 this->Bind("PERMISSIONS"_s, this->Permissions);
32 this->Bind("CONFIGURATIONS"_s, this->Configurations);
33 this->Bind("OPTIONAL"_s, this->Optional);
34 this->Bind("NAMELINK_ONLY"_s, this->NamelinkOnly);
35 this->Bind("NAMELINK_SKIP"_s, this->NamelinkSkip);
36 this->Bind("TYPE"_s, this->Type);
39 const std::string& cmInstallCommandArguments::GetDestination() const
41 if (!this->DestinationString.empty()) {
42 return this->DestinationString;
44 if (this->GenericArguments != nullptr) {
45 return this->GenericArguments->GetDestination();
47 return EmptyString;
50 const std::string& cmInstallCommandArguments::GetComponent() const
52 if (!this->Component.empty()) {
53 return this->Component;
55 if (this->GenericArguments != nullptr) {
56 return this->GenericArguments->GetComponent();
58 if (!this->DefaultComponentName.empty()) {
59 return this->DefaultComponentName;
61 static std::string unspecifiedComponent = "Unspecified";
62 return unspecifiedComponent;
65 const std::string& cmInstallCommandArguments::GetNamelinkComponent() const
67 if (!this->NamelinkComponent.empty()) {
68 return this->NamelinkComponent;
70 return this->GetComponent();
73 const std::string& cmInstallCommandArguments::GetRename() const
75 if (!this->Rename.empty()) {
76 return this->Rename;
78 if (this->GenericArguments != nullptr) {
79 return this->GenericArguments->GetRename();
81 return EmptyString;
84 const std::string& cmInstallCommandArguments::GetPermissions() const
86 if (!this->PermissionsString.empty()) {
87 return this->PermissionsString;
89 if (this->GenericArguments != nullptr) {
90 return this->GenericArguments->GetPermissions();
92 return EmptyString;
95 bool cmInstallCommandArguments::GetOptional() const
97 if (this->Optional) {
98 return true;
100 if (this->GenericArguments != nullptr) {
101 return this->GenericArguments->GetOptional();
103 return false;
106 bool cmInstallCommandArguments::GetExcludeFromAll() const
108 if (this->ExcludeFromAll) {
109 return true;
111 if (this->GenericArguments != nullptr) {
112 return this->GenericArguments->GetExcludeFromAll();
114 return false;
117 bool cmInstallCommandArguments::GetNamelinkOnly() const
119 if (this->NamelinkOnly) {
120 return true;
122 if (this->GenericArguments != nullptr) {
123 return this->GenericArguments->GetNamelinkOnly();
125 return false;
128 bool cmInstallCommandArguments::GetNamelinkSkip() const
130 if (this->NamelinkSkip) {
131 return true;
133 if (this->GenericArguments != nullptr) {
134 return this->GenericArguments->GetNamelinkSkip();
136 return false;
139 bool cmInstallCommandArguments::HasNamelinkComponent() const
141 if (!this->NamelinkComponent.empty()) {
142 return true;
144 if (this->GenericArguments != nullptr) {
145 return this->GenericArguments->HasNamelinkComponent();
147 return false;
150 const std::string& cmInstallCommandArguments::GetType() const
152 return this->Type;
155 const std::string& cmInstallCommandArguments::GetDefaultComponent() const
157 return this->DefaultComponentName;
160 const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
161 const
163 if (!this->Configurations.empty()) {
164 return this->Configurations;
166 if (this->GenericArguments != nullptr) {
167 return this->GenericArguments->GetConfigurations();
169 return this->Configurations;
172 bool cmInstallCommandArguments::Finalize()
174 if (!this->CheckPermissions()) {
175 return false;
177 this->DestinationString = this->Destination;
178 cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
179 return true;
182 bool cmInstallCommandArguments::CheckPermissions()
184 this->PermissionsString.clear();
185 return std::all_of(this->Permissions.begin(), this->Permissions.end(),
186 [this](std::string const& perm) -> bool {
187 return cmInstallCommandArguments::CheckPermissions(
188 perm, this->PermissionsString);
192 bool cmInstallCommandArguments::CheckPermissions(
193 const std::string& onePermission, std::string& permissions)
195 // Check the permission against the table.
196 for (const char** valid = cmInstallCommandArguments::PermissionsTable;
197 *valid; ++valid) {
198 if (onePermission == *valid) {
199 // This is a valid permission.
200 permissions += " ";
201 permissions += onePermission;
202 return true;
205 // This is not a valid permission.
206 return false;
209 cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument() = default;
211 const std::vector<std::string>&
212 cmInstallCommandIncludesArgument::GetIncludeDirs() const
214 return this->IncludeDirs;
217 void cmInstallCommandIncludesArgument::Parse(
218 const std::vector<std::string>* args, std::vector<std::string>*)
220 if (args->empty()) {
221 return;
223 for (std::string dir : cmMakeRange(*args).advance(1)) {
224 cmSystemTools::ConvertToUnixSlashes(dir);
225 this->IncludeDirs.push_back(std::move(dir));
229 cmInstallCommandFileSetArguments::cmInstallCommandFileSetArguments(
230 std::string defaultComponent)
231 : cmInstallCommandArguments(std::move(defaultComponent))
233 this->Bind("FILE_SET"_s, this->FileSet);
236 void cmInstallCommandFileSetArguments::Parse(
237 std::vector<std::string> args, std::vector<std::string>* unconsumedArgs)
239 args.insert(args.begin(), "FILE_SET");
240 this->cmInstallCommandArguments::Parse(args, unconsumedArgs);