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"
8 #include <cmext/string_view>
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();
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()) {
78 if (this->GenericArguments
!= nullptr) {
79 return this->GenericArguments
->GetRename();
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();
95 bool cmInstallCommandArguments::GetOptional() const
100 if (this->GenericArguments
!= nullptr) {
101 return this->GenericArguments
->GetOptional();
106 bool cmInstallCommandArguments::GetExcludeFromAll() const
108 if (this->ExcludeFromAll
) {
111 if (this->GenericArguments
!= nullptr) {
112 return this->GenericArguments
->GetExcludeFromAll();
117 bool cmInstallCommandArguments::GetNamelinkOnly() const
119 if (this->NamelinkOnly
) {
122 if (this->GenericArguments
!= nullptr) {
123 return this->GenericArguments
->GetNamelinkOnly();
128 bool cmInstallCommandArguments::GetNamelinkSkip() const
130 if (this->NamelinkSkip
) {
133 if (this->GenericArguments
!= nullptr) {
134 return this->GenericArguments
->GetNamelinkSkip();
139 bool cmInstallCommandArguments::HasNamelinkComponent() const
141 if (!this->NamelinkComponent
.empty()) {
144 if (this->GenericArguments
!= nullptr) {
145 return this->GenericArguments
->HasNamelinkComponent();
150 const std::string
& cmInstallCommandArguments::GetType() const
155 const std::string
& cmInstallCommandArguments::GetDefaultComponent() const
157 return this->DefaultComponentName
;
160 const std::vector
<std::string
>& cmInstallCommandArguments::GetConfigurations()
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()) {
177 this->DestinationString
= this->Destination
;
178 cmSystemTools::ConvertToUnixSlashes(this->DestinationString
);
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
;
198 if (onePermission
== *valid
) {
199 // This is a valid permission.
201 permissions
+= onePermission
;
205 // This is not a valid permission.
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
>*)
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
);