resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmInstallCommandArguments.cxx
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"
4
5 #include <algorithm>
6 #include <utility>
7
8 #include <cmext/string_view>
9
10 #include "cmRange.h"
11 #include "cmSystemTools.h"
12
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
18 };
19
20 const std::string cmInstallCommandArguments::EmptyString;
21
22 cmInstallCommandArguments::cmInstallCommandArguments(
23   std::string defaultComponent)
24   : DefaultComponentName(std::move(defaultComponent))
25 {
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);
37 }
38
39 const std::string& cmInstallCommandArguments::GetDestination() const
40 {
41   if (!this->DestinationString.empty()) {
42     return this->DestinationString;
43   }
44   if (this->GenericArguments != nullptr) {
45     return this->GenericArguments->GetDestination();
46   }
47   return EmptyString;
48 }
49
50 const std::string& cmInstallCommandArguments::GetComponent() const
51 {
52   if (!this->Component.empty()) {
53     return this->Component;
54   }
55   if (this->GenericArguments != nullptr) {
56     return this->GenericArguments->GetComponent();
57   }
58   if (!this->DefaultComponentName.empty()) {
59     return this->DefaultComponentName;
60   }
61   static std::string unspecifiedComponent = "Unspecified";
62   return unspecifiedComponent;
63 }
64
65 const std::string& cmInstallCommandArguments::GetNamelinkComponent() const
66 {
67   if (!this->NamelinkComponent.empty()) {
68     return this->NamelinkComponent;
69   }
70   return this->GetComponent();
71 }
72
73 const std::string& cmInstallCommandArguments::GetRename() const
74 {
75   if (!this->Rename.empty()) {
76     return this->Rename;
77   }
78   if (this->GenericArguments != nullptr) {
79     return this->GenericArguments->GetRename();
80   }
81   return EmptyString;
82 }
83
84 const std::string& cmInstallCommandArguments::GetPermissions() const
85 {
86   if (!this->PermissionsString.empty()) {
87     return this->PermissionsString;
88   }
89   if (this->GenericArguments != nullptr) {
90     return this->GenericArguments->GetPermissions();
91   }
92   return EmptyString;
93 }
94
95 bool cmInstallCommandArguments::GetOptional() const
96 {
97   if (this->Optional) {
98     return true;
99   }
100   if (this->GenericArguments != nullptr) {
101     return this->GenericArguments->GetOptional();
102   }
103   return false;
104 }
105
106 bool cmInstallCommandArguments::GetExcludeFromAll() const
107 {
108   if (this->ExcludeFromAll) {
109     return true;
110   }
111   if (this->GenericArguments != nullptr) {
112     return this->GenericArguments->GetExcludeFromAll();
113   }
114   return false;
115 }
116
117 bool cmInstallCommandArguments::GetNamelinkOnly() const
118 {
119   if (this->NamelinkOnly) {
120     return true;
121   }
122   if (this->GenericArguments != nullptr) {
123     return this->GenericArguments->GetNamelinkOnly();
124   }
125   return false;
126 }
127
128 bool cmInstallCommandArguments::GetNamelinkSkip() const
129 {
130   if (this->NamelinkSkip) {
131     return true;
132   }
133   if (this->GenericArguments != nullptr) {
134     return this->GenericArguments->GetNamelinkSkip();
135   }
136   return false;
137 }
138
139 bool cmInstallCommandArguments::HasNamelinkComponent() const
140 {
141   if (!this->NamelinkComponent.empty()) {
142     return true;
143   }
144   if (this->GenericArguments != nullptr) {
145     return this->GenericArguments->HasNamelinkComponent();
146   }
147   return false;
148 }
149
150 const std::string& cmInstallCommandArguments::GetType() const
151 {
152   return this->Type;
153 }
154
155 const std::string& cmInstallCommandArguments::GetDefaultComponent() const
156 {
157   return this->DefaultComponentName;
158 }
159
160 const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
161   const
162 {
163   if (!this->Configurations.empty()) {
164     return this->Configurations;
165   }
166   if (this->GenericArguments != nullptr) {
167     return this->GenericArguments->GetConfigurations();
168   }
169   return this->Configurations;
170 }
171
172 bool cmInstallCommandArguments::Finalize()
173 {
174   if (!this->CheckPermissions()) {
175     return false;
176   }
177   this->DestinationString = this->Destination;
178   cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
179   return true;
180 }
181
182 bool cmInstallCommandArguments::CheckPermissions()
183 {
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);
189                      });
190 }
191
192 bool cmInstallCommandArguments::CheckPermissions(
193   const std::string& onePermission, std::string& permissions)
194 {
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;
203     }
204   }
205   // This is not a valid permission.
206   return false;
207 }
208
209 cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument() = default;
210
211 const std::vector<std::string>&
212 cmInstallCommandIncludesArgument::GetIncludeDirs() const
213 {
214   return this->IncludeDirs;
215 }
216
217 void cmInstallCommandIncludesArgument::Parse(
218   const std::vector<std::string>* args, std::vector<std::string>*)
219 {
220   if (args->empty()) {
221     return;
222   }
223   for (std::string dir : cmMakeRange(*args).advance(1)) {
224     cmSystemTools::ConvertToUnixSlashes(dir);
225     this->IncludeDirs.push_back(std::move(dir));
226   }
227 }
228
229 cmInstallCommandFileSetArguments::cmInstallCommandFileSetArguments(
230   std::string defaultComponent)
231   : cmInstallCommandArguments(std::move(defaultComponent))
232 {
233   this->Bind("FILE_SET"_s, this->FileSet);
234 }
235
236 void cmInstallCommandFileSetArguments::Parse(
237   std::vector<std::string> args, std::vector<std::string>* unconsumedArgs)
238 {
239   args.insert(args.begin(), "FILE_SET");
240   this->cmInstallCommandArguments::Parse(args, unconsumedArgs);
241 }