packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmInstallCommandArguments.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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"
14
15 // Table of valid permissions.
16 const char* cmInstallCommandArguments::PermissionsTable[] =
17 {
18   "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE",
19   "GROUP_READ", "GROUP_WRITE", "GROUP_EXECUTE",
20   "WORLD_READ", "WORLD_WRITE", "WORLD_EXECUTE",
21   "SETUID", "SETGID", 0
22 };
23
24 const std::string cmInstallCommandArguments::EmptyString;
25
26 cmInstallCommandArguments::cmInstallCommandArguments(
27                                            const std::string& defaultComponent)
28 :Parser()
29 ,ArgumentGroup()
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)
38 ,GenericArguments(0)
39 ,DefaultComponentName(defaultComponent)
40 {
41 }
42
43 const std::string& cmInstallCommandArguments::GetDestination() const
44 {
45   if (!this->DestinationString.empty())
46     {
47     return this->DestinationString;
48     }
49   if (this->GenericArguments!=0)
50     {
51     return this->GenericArguments->GetDestination();
52     }
53   return this->EmptyString;
54 }
55
56 const std::string& cmInstallCommandArguments::GetComponent() const
57 {
58   if (!this->Component.GetString().empty())
59     {
60     return this->Component.GetString();
61     }
62   if (this->GenericArguments!=0)
63     {
64     return this->GenericArguments->GetComponent();
65     }
66   if (!this->DefaultComponentName.empty())
67     {
68     return this->DefaultComponentName;
69     }
70   static std::string unspecifiedComponent = "Unspecified";
71   return unspecifiedComponent;
72 }
73
74 const std::string& cmInstallCommandArguments::GetRename() const
75 {
76   if (!this->Rename.GetString().empty())
77     {
78     return this->Rename.GetString();
79     }
80   if (this->GenericArguments!=0)
81     {
82     return this->GenericArguments->GetRename();
83     }
84   return this->EmptyString;
85 }
86
87 const std::string& cmInstallCommandArguments::GetPermissions() const
88 {
89   if (!this->PermissionsString.empty())
90     {
91     return this->PermissionsString;
92     }
93   if (this->GenericArguments!=0)
94     {
95     return this->GenericArguments->GetPermissions();
96     }
97   return this->EmptyString;
98 }
99
100 bool cmInstallCommandArguments::GetOptional() const
101 {
102   if (this->Optional.IsEnabled())
103     {
104     return true;
105     }
106   if (this->GenericArguments!=0)
107     {
108     return this->GenericArguments->GetOptional();
109     }
110   return false;
111 }
112
113 bool cmInstallCommandArguments::GetNamelinkOnly() const
114 {
115   if (this->NamelinkOnly.IsEnabled())
116     {
117     return true;
118     }
119   if (this->GenericArguments!=0)
120     {
121     return this->GenericArguments->GetNamelinkOnly();
122     }
123   return false;
124 }
125
126 bool cmInstallCommandArguments::GetNamelinkSkip() const
127 {
128   if (this->NamelinkSkip.IsEnabled())
129     {
130     return true;
131     }
132   if (this->GenericArguments!=0)
133     {
134     return this->GenericArguments->GetNamelinkSkip();
135     }
136   return false;
137 }
138
139 const std::vector<std::string>&
140     cmInstallCommandArguments::GetConfigurations() const
141 {
142   if (!this->Configurations.GetVector().empty())
143     {
144     return this->Configurations.GetVector();
145     }
146   if (this->GenericArguments!=0)
147     {
148     return this->GenericArguments->GetConfigurations();
149     }
150   return this->Configurations.GetVector();
151 }
152
153
154 bool cmInstallCommandArguments::Finalize()
155 {
156   if (!this->CheckPermissions())
157     {
158     return false;
159     }
160   this->DestinationString = this->Destination.GetString();
161   cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
162   return true;
163 }
164
165 void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
166                                       std::vector<std::string>* unconsumedArgs)
167 {
168   this->Parser.Parse(args, unconsumedArgs);
169 }
170
171
172 bool cmInstallCommandArguments::CheckPermissions()
173 {
174   this->PermissionsString = "";
175   for(std::vector<std::string>::const_iterator
176       permIt = this->Permissions.GetVector().begin();
177       permIt != this->Permissions.GetVector().end();
178       ++permIt)
179     {
180     if (!this->CheckPermissions(*permIt, this->PermissionsString))
181       {
182       return false;
183       }
184     }
185   return true;
186 }
187
188 bool cmInstallCommandArguments::CheckPermissions(
189                     const std::string& onePermission, std::string& permissions)
190 {
191   // Check the permission against the table.
192   for(const char** valid = cmInstallCommandArguments::PermissionsTable;
193       *valid; ++valid)
194     {
195     if(onePermission == *valid)
196       {
197       // This is a valid permission.
198       permissions += " ";
199       permissions += onePermission;
200       return true;
201       }
202     }
203   // This is not a valid permission.
204   return false;
205 }
206
207 cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument()
208 {
209
210 }
211
212 const std::vector<std::string>&
213 cmInstallCommandIncludesArgument::GetIncludeDirs() const
214 {
215   return this->IncludeDirs;
216 }
217
218 void cmInstallCommandIncludesArgument::Parse(
219                                         const std::vector<std::string>* args,
220                                         std::vector<std::string>*)
221 {
222   if(args->empty())
223     {
224     return;
225     }
226   std::vector<std::string>::const_iterator it = args->begin();
227   ++it;
228   for ( ; it != args->end(); ++it)
229     {
230     std::string dir = *it;
231     if (!cmSystemTools::FileIsFullPath(it->c_str())
232         && cmGeneratorExpression::Find(*it) == std::string::npos)
233       {
234       dir = "$<INSTALL_PREFIX>/" + dir;
235       }
236     cmSystemTools::ConvertToUnixSlashes(dir);
237     this->IncludeDirs.push_back(dir);
238     }
239 }