cmake/Source/cmInstallCommandArguments.cxx

224 lines
5.7 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallCommandArguments.h"
2016-07-09 11:21:54 +02:00
2020-02-01 23:06:01 +01:00
#include <utility>
2020-08-30 11:54:41 +02:00
#include <cmext/string_view>
2020-02-01 23:06:01 +01:00
#include "cmRange.h"
#include "cmSystemTools.h"
2018-04-23 21:13:27 +02:00
// Table of valid permissions.
2016-07-09 11:21:54 +02:00
const char* cmInstallCommandArguments::PermissionsTable[] = {
"OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE", "GROUP_READ",
"GROUP_WRITE", "GROUP_EXECUTE", "WORLD_READ", "WORLD_WRITE",
2018-01-26 17:06:56 +01:00
"WORLD_EXECUTE", "SETUID", "SETGID", nullptr
};
const std::string cmInstallCommandArguments::EmptyString;
2012-06-27 20:52:58 +03:00
cmInstallCommandArguments::cmInstallCommandArguments(
2019-11-11 23:01:05 +01:00
std::string 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);
2012-06-27 20:52:58 +03:00
}
const std::string& cmInstallCommandArguments::GetDestination() const
{
2016-07-09 11:21:54 +02:00
if (!this->DestinationString.empty()) {
return this->DestinationString;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetDestination();
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
return EmptyString;
}
const std::string& cmInstallCommandArguments::GetComponent() const
{
2019-11-11 23:01:05 +01:00
if (!this->Component.empty()) {
return this->Component;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetComponent();
2016-07-09 11:21:54 +02:00
}
if (!this->DefaultComponentName.empty()) {
2012-08-04 10:26:08 +03:00
return this->DefaultComponentName;
2016-07-09 11:21:54 +02:00
}
static std::string unspecifiedComponent = "Unspecified";
return unspecifiedComponent;
}
2018-08-09 18:06:22 +02:00
const std::string& cmInstallCommandArguments::GetNamelinkComponent() const
{
2019-11-11 23:01:05 +01:00
if (!this->NamelinkComponent.empty()) {
return this->NamelinkComponent;
2018-08-09 18:06:22 +02:00
}
return this->GetComponent();
}
const std::string& cmInstallCommandArguments::GetRename() const
{
2019-11-11 23:01:05 +01:00
if (!this->Rename.empty()) {
return this->Rename;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetRename();
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
return EmptyString;
}
const std::string& cmInstallCommandArguments::GetPermissions() const
{
2016-07-09 11:21:54 +02:00
if (!this->PermissionsString.empty()) {
return this->PermissionsString;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetPermissions();
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
return EmptyString;
}
bool cmInstallCommandArguments::GetOptional() const
{
2019-11-11 23:01:05 +01:00
if (this->Optional) {
return true;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetOptional();
2016-07-09 11:21:54 +02:00
}
return false;
}
bool cmInstallCommandArguments::GetExcludeFromAll() const
{
2019-11-11 23:01:05 +01:00
if (this->ExcludeFromAll) {
2016-07-09 11:21:54 +02:00
return true;
}
2018-01-26 17:06:56 +01:00
if (this->GenericArguments != nullptr) {
2016-07-09 11:21:54 +02:00
return this->GenericArguments->GetExcludeFromAll();
}
return false;
}
bool cmInstallCommandArguments::GetNamelinkOnly() const
{
2019-11-11 23:01:05 +01:00
if (this->NamelinkOnly) {
return true;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetNamelinkOnly();
2016-07-09 11:21:54 +02:00
}
return false;
}
bool cmInstallCommandArguments::GetNamelinkSkip() const
{
2019-11-11 23:01:05 +01:00
if (this->NamelinkSkip) {
return true;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetNamelinkSkip();
2016-07-09 11:21:54 +02:00
}
return false;
}
2018-08-09 18:06:22 +02:00
bool cmInstallCommandArguments::HasNamelinkComponent() const
{
2019-11-11 23:01:05 +01:00
if (!this->NamelinkComponent.empty()) {
2018-08-09 18:06:22 +02:00
return true;
}
if (this->GenericArguments != nullptr) {
return this->GenericArguments->HasNamelinkComponent();
}
return false;
}
2019-11-11 23:01:05 +01:00
const std::string& cmInstallCommandArguments::GetType() const
{
return this->Type;
}
2016-07-09 11:21:54 +02:00
const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
const
{
2019-11-11 23:01:05 +01:00
if (!this->Configurations.empty()) {
return this->Configurations;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetConfigurations();
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
return this->Configurations;
}
bool cmInstallCommandArguments::Finalize()
{
2016-07-09 11:21:54 +02:00
if (!this->CheckPermissions()) {
return false;
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
this->DestinationString = this->Destination;
cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
return true;
}
bool cmInstallCommandArguments::CheckPermissions()
{
2018-01-26 17:06:56 +01:00
this->PermissionsString.clear();
2019-11-11 23:01:05 +01:00
for (std::string const& perm : this->Permissions) {
if (!cmInstallCommandArguments::CheckPermissions(
perm, this->PermissionsString)) {
return false;
}
2016-07-09 11:21:54 +02:00
}
return true;
}
bool cmInstallCommandArguments::CheckPermissions(
2016-07-09 11:21:54 +02:00
const std::string& onePermission, std::string& permissions)
{
// Check the permission against the table.
2016-07-09 11:21:54 +02:00
for (const char** valid = cmInstallCommandArguments::PermissionsTable;
*valid; ++valid) {
if (onePermission == *valid) {
// This is a valid permission.
permissions += " ";
permissions += onePermission;
return true;
}
2016-07-09 11:21:54 +02:00
}
// This is not a valid permission.
return false;
}
2013-11-03 12:27:13 +02:00
2019-11-11 23:01:05 +01:00
cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument() = default;
2013-11-03 12:27:13 +02:00
const std::vector<std::string>&
cmInstallCommandIncludesArgument::GetIncludeDirs() const
{
return this->IncludeDirs;
}
void cmInstallCommandIncludesArgument::Parse(
2016-07-09 11:21:54 +02:00
const std::vector<std::string>* args, std::vector<std::string>*)
2013-11-03 12:27:13 +02:00
{
2016-07-09 11:21:54 +02:00
if (args->empty()) {
2013-11-03 12:27:13 +02:00
return;
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
for (std::string dir : cmMakeRange(*args).advance(1)) {
2013-11-03 12:27:13 +02:00
cmSystemTools::ConvertToUnixSlashes(dir);
2018-04-23 21:13:27 +02:00
this->IncludeDirs.push_back(std::move(dir));
2016-07-09 11:21:54 +02:00
}
2013-11-03 12:27:13 +02:00
}