1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmInstallCommandArguments.h"
13 #include "cmSystemTools.h"
15 // Table of valid permissions.
16 const char* cmInstallCommandArguments::PermissionsTable[] =
18 "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE",
19 "GROUP_READ", "GROUP_WRITE", "GROUP_EXECUTE",
20 "WORLD_READ", "WORLD_WRITE", "WORLD_EXECUTE",
24 const std::string cmInstallCommandArguments::EmptyString;
26 cmInstallCommandArguments::cmInstallCommandArguments(
27 const std::string& defaultComponent)
30 ,Destination (&Parser, "DESTINATION" , &ArgumentGroup)
31 ,Component (&Parser, "COMPONENT" , &ArgumentGroup)
32 ,Rename (&Parser, "RENAME" , &ArgumentGroup)
33 ,Permissions (&Parser, "PERMISSIONS" , &ArgumentGroup)
34 ,Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup)
35 ,Optional (&Parser, "OPTIONAL" , &ArgumentGroup)
36 ,NamelinkOnly (&Parser, "NAMELINK_ONLY" , &ArgumentGroup)
37 ,NamelinkSkip (&Parser, "NAMELINK_SKIP" , &ArgumentGroup)
39 ,DefaultComponentName(defaultComponent)
43 const std::string& cmInstallCommandArguments::GetDestination() const
45 if (!this->DestinationString.empty())
47 return this->DestinationString;
49 if (this->GenericArguments!=0)
51 return this->GenericArguments->GetDestination();
53 return this->EmptyString;
56 const std::string& cmInstallCommandArguments::GetComponent() const
58 if (!this->Component.GetString().empty())
60 return this->Component.GetString();
62 if (this->GenericArguments!=0)
64 return this->GenericArguments->GetComponent();
66 if (!this->DefaultComponentName.empty())
68 return this->DefaultComponentName;
70 static std::string unspecifiedComponent = "Unspecified";
71 return unspecifiedComponent;
74 const std::string& cmInstallCommandArguments::GetRename() const
76 if (!this->Rename.GetString().empty())
78 return this->Rename.GetString();
80 if (this->GenericArguments!=0)
82 return this->GenericArguments->GetRename();
84 return this->EmptyString;
87 const std::string& cmInstallCommandArguments::GetPermissions() const
89 if (!this->PermissionsString.empty())
91 return this->PermissionsString;
93 if (this->GenericArguments!=0)
95 return this->GenericArguments->GetPermissions();
97 return this->EmptyString;
100 bool cmInstallCommandArguments::GetOptional() const
102 if (this->Optional.IsEnabled())
106 if (this->GenericArguments!=0)
108 return this->GenericArguments->GetOptional();
113 bool cmInstallCommandArguments::GetNamelinkOnly() const
115 if (this->NamelinkOnly.IsEnabled())
119 if (this->GenericArguments!=0)
121 return this->GenericArguments->GetNamelinkOnly();
126 bool cmInstallCommandArguments::GetNamelinkSkip() const
128 if (this->NamelinkSkip.IsEnabled())
132 if (this->GenericArguments!=0)
134 return this->GenericArguments->GetNamelinkSkip();
139 const std::vector<std::string>&
140 cmInstallCommandArguments::GetConfigurations() const
142 if (!this->Configurations.GetVector().empty())
144 return this->Configurations.GetVector();
146 if (this->GenericArguments!=0)
148 return this->GenericArguments->GetConfigurations();
150 return this->Configurations.GetVector();
154 bool cmInstallCommandArguments::Finalize()
156 if (!this->CheckPermissions())
160 this->DestinationString = this->Destination.GetString();
161 cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
165 void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
166 std::vector<std::string>* unconsumedArgs)
168 this->Parser.Parse(args, unconsumedArgs);
172 bool cmInstallCommandArguments::CheckPermissions()
174 this->PermissionsString = "";
175 for(std::vector<std::string>::const_iterator
176 permIt = this->Permissions.GetVector().begin();
177 permIt != this->Permissions.GetVector().end();
180 if (!this->CheckPermissions(*permIt, this->PermissionsString))
188 bool cmInstallCommandArguments::CheckPermissions(
189 const std::string& onePermission, std::string& permissions)
191 // Check the permission against the table.
192 for(const char** valid = cmInstallCommandArguments::PermissionsTable;
195 if(onePermission == *valid)
197 // This is a valid permission.
199 permissions += onePermission;
203 // This is not a valid permission.