cmake/Source/cmInstallCommandArguments.cxx

210 lines
5.6 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
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
// 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",
2016-10-30 18:24:19 +01:00
"WORLD_EXECUTE", "SETUID", "SETGID", CM_NULLPTR
};
const std::string cmInstallCommandArguments::EmptyString;
2012-06-27 20:52:58 +03:00
cmInstallCommandArguments::cmInstallCommandArguments(
2016-07-09 11:21:54 +02:00
const std::string& defaultComponent)
: Parser()
, ArgumentGroup()
, Destination(&Parser, "DESTINATION", &ArgumentGroup)
, Component(&Parser, "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)
2016-10-30 18:24:19 +01:00
, GenericArguments(CM_NULLPTR)
2016-07-09 11:21:54 +02:00
, DefaultComponentName(defaultComponent)
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
}
2016-10-30 18:24:19 +01:00
if (this->GenericArguments != CM_NULLPTR) {
return this->GenericArguments->GetDestination();
2016-07-09 11:21:54 +02:00
}
return this->EmptyString;
}
const std::string& cmInstallCommandArguments::GetComponent() const
{
2016-07-09 11:21:54 +02:00
if (!this->Component.GetString().empty()) {
return this->Component.GetString();
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
if (this->GenericArguments != CM_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;
}
const std::string& cmInstallCommandArguments::GetRename() const
{
2016-07-09 11:21:54 +02:00
if (!this->Rename.GetString().empty()) {
return this->Rename.GetString();
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
if (this->GenericArguments != CM_NULLPTR) {
return this->GenericArguments->GetRename();
2016-07-09 11:21:54 +02:00
}
return this->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
}
2016-10-30 18:24:19 +01:00
if (this->GenericArguments != CM_NULLPTR) {
return this->GenericArguments->GetPermissions();
2016-07-09 11:21:54 +02:00
}
return this->EmptyString;
}
bool cmInstallCommandArguments::GetOptional() const
{
2016-07-09 11:21:54 +02:00
if (this->Optional.IsEnabled()) {
return true;
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
if (this->GenericArguments != CM_NULLPTR) {
return this->GenericArguments->GetOptional();
2016-07-09 11:21:54 +02:00
}
return false;
}
bool cmInstallCommandArguments::GetExcludeFromAll() const
{
if (this->ExcludeFromAll.IsEnabled()) {
return true;
}
2016-10-30 18:24:19 +01:00
if (this->GenericArguments != CM_NULLPTR) {
2016-07-09 11:21:54 +02:00
return this->GenericArguments->GetExcludeFromAll();
}
return false;
}
bool cmInstallCommandArguments::GetNamelinkOnly() const
{
2016-07-09 11:21:54 +02:00
if (this->NamelinkOnly.IsEnabled()) {
return true;
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
if (this->GenericArguments != CM_NULLPTR) {
return this->GenericArguments->GetNamelinkOnly();
2016-07-09 11:21:54 +02:00
}
return false;
}
bool cmInstallCommandArguments::GetNamelinkSkip() const
{
2016-07-09 11:21:54 +02:00
if (this->NamelinkSkip.IsEnabled()) {
return true;
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
if (this->GenericArguments != CM_NULLPTR) {
return this->GenericArguments->GetNamelinkSkip();
2016-07-09 11:21:54 +02:00
}
return false;
}
2016-07-09 11:21:54 +02:00
const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
const
{
2016-07-09 11:21:54 +02:00
if (!this->Configurations.GetVector().empty()) {
return this->Configurations.GetVector();
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
if (this->GenericArguments != CM_NULLPTR) {
return this->GenericArguments->GetConfigurations();
2016-07-09 11:21:54 +02:00
}
return this->Configurations.GetVector();
}
bool cmInstallCommandArguments::Finalize()
{
2016-07-09 11:21:54 +02:00
if (!this->CheckPermissions()) {
return false;
2016-07-09 11:21:54 +02:00
}
this->DestinationString = this->Destination.GetString();
cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
return true;
}
2012-06-27 20:52:58 +03:00
void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
std::vector<std::string>* unconsumedArgs)
{
this->Parser.Parse(args, unconsumedArgs);
}
bool cmInstallCommandArguments::CheckPermissions()
{
this->PermissionsString = "";
2016-07-09 11:21:54 +02:00
for (std::vector<std::string>::const_iterator permIt =
this->Permissions.GetVector().begin();
permIt != this->Permissions.GetVector().end(); ++permIt) {
if (!this->CheckPermissions(*permIt, 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
cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument()
{
}
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
}
2013-11-03 12:27:13 +02:00
std::vector<std::string>::const_iterator it = args->begin();
++it;
2016-07-09 11:21:54 +02:00
for (; it != args->end(); ++it) {
2013-11-03 12:27:13 +02:00
std::string dir = *it;
cmSystemTools::ConvertToUnixSlashes(dir);
this->IncludeDirs.push_back(dir);
2016-07-09 11:21:54 +02:00
}
2013-11-03 12:27:13 +02:00
}