cmInstallCommandArguments.cxx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmInstallCommandArguments.h"
  11. #include "cmSystemTools.h"
  12. // Table of valid permissions.
  13. const char* cmInstallCommandArguments::PermissionsTable[] =
  14. {
  15. "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE",
  16. "GROUP_READ", "GROUP_WRITE", "GROUP_EXECUTE",
  17. "WORLD_READ", "WORLD_WRITE", "WORLD_EXECUTE",
  18. "SETUID", "SETGID", 0
  19. };
  20. const std::string cmInstallCommandArguments::EmptyString;
  21. cmInstallCommandArguments::cmInstallCommandArguments(
  22. const std::string& defaultComponent)
  23. :Parser()
  24. ,ArgumentGroup()
  25. ,Destination (&Parser, "DESTINATION" , &ArgumentGroup)
  26. ,Component (&Parser, "COMPONENT" , &ArgumentGroup)
  27. ,Rename (&Parser, "RENAME" , &ArgumentGroup)
  28. ,Permissions (&Parser, "PERMISSIONS" , &ArgumentGroup)
  29. ,Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup)
  30. ,Optional (&Parser, "OPTIONAL" , &ArgumentGroup)
  31. ,NamelinkOnly (&Parser, "NAMELINK_ONLY" , &ArgumentGroup)
  32. ,NamelinkSkip (&Parser, "NAMELINK_SKIP" , &ArgumentGroup)
  33. ,GenericArguments(0)
  34. ,DefaultComponentName(defaultComponent)
  35. {
  36. }
  37. const std::string& cmInstallCommandArguments::GetDestination() const
  38. {
  39. if (!this->DestinationString.empty())
  40. {
  41. return this->DestinationString;
  42. }
  43. if (this->GenericArguments!=0)
  44. {
  45. return this->GenericArguments->GetDestination();
  46. }
  47. return this->EmptyString;
  48. }
  49. const std::string& cmInstallCommandArguments::GetComponent() const
  50. {
  51. if (!this->Component.GetString().empty())
  52. {
  53. return this->Component.GetString();
  54. }
  55. if (this->GenericArguments!=0)
  56. {
  57. return this->GenericArguments->GetComponent();
  58. }
  59. if (!this->DefaultComponentName.empty())
  60. {
  61. return this->DefaultComponentName;
  62. }
  63. static std::string unspecifiedComponent = "Unspecified";
  64. return unspecifiedComponent;
  65. }
  66. const std::string& cmInstallCommandArguments::GetRename() const
  67. {
  68. if (!this->Rename.GetString().empty())
  69. {
  70. return this->Rename.GetString();
  71. }
  72. if (this->GenericArguments!=0)
  73. {
  74. return this->GenericArguments->GetRename();
  75. }
  76. return this->EmptyString;
  77. }
  78. const std::string& cmInstallCommandArguments::GetPermissions() const
  79. {
  80. if (!this->PermissionsString.empty())
  81. {
  82. return this->PermissionsString;
  83. }
  84. if (this->GenericArguments!=0)
  85. {
  86. return this->GenericArguments->GetPermissions();
  87. }
  88. return this->EmptyString;
  89. }
  90. bool cmInstallCommandArguments::GetOptional() const
  91. {
  92. if (this->Optional.IsEnabled())
  93. {
  94. return true;
  95. }
  96. if (this->GenericArguments!=0)
  97. {
  98. return this->GenericArguments->GetOptional();
  99. }
  100. return false;
  101. }
  102. bool cmInstallCommandArguments::GetNamelinkOnly() const
  103. {
  104. if (this->NamelinkOnly.IsEnabled())
  105. {
  106. return true;
  107. }
  108. if (this->GenericArguments!=0)
  109. {
  110. return this->GenericArguments->GetNamelinkOnly();
  111. }
  112. return false;
  113. }
  114. bool cmInstallCommandArguments::GetNamelinkSkip() const
  115. {
  116. if (this->NamelinkSkip.IsEnabled())
  117. {
  118. return true;
  119. }
  120. if (this->GenericArguments!=0)
  121. {
  122. return this->GenericArguments->GetNamelinkSkip();
  123. }
  124. return false;
  125. }
  126. const std::vector<std::string>&
  127. cmInstallCommandArguments::GetConfigurations() const
  128. {
  129. if (!this->Configurations.GetVector().empty())
  130. {
  131. return this->Configurations.GetVector();
  132. }
  133. if (this->GenericArguments!=0)
  134. {
  135. return this->GenericArguments->GetConfigurations();
  136. }
  137. return this->Configurations.GetVector();
  138. }
  139. bool cmInstallCommandArguments::Finalize()
  140. {
  141. if (!this->CheckPermissions())
  142. {
  143. return false;
  144. }
  145. this->DestinationString = this->Destination.GetString();
  146. cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
  147. return true;
  148. }
  149. void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
  150. std::vector<std::string>* unconsumedArgs)
  151. {
  152. this->Parser.Parse(args, unconsumedArgs);
  153. }
  154. bool cmInstallCommandArguments::CheckPermissions()
  155. {
  156. this->PermissionsString = "";
  157. for(std::vector<std::string>::const_iterator
  158. permIt = this->Permissions.GetVector().begin();
  159. permIt != this->Permissions.GetVector().end();
  160. ++permIt)
  161. {
  162. if (!this->CheckPermissions(*permIt, this->PermissionsString))
  163. {
  164. return false;
  165. }
  166. }
  167. return true;
  168. }
  169. bool cmInstallCommandArguments::CheckPermissions(
  170. const std::string& onePermission, std::string& permissions)
  171. {
  172. // Check the permission against the table.
  173. for(const char** valid = cmInstallCommandArguments::PermissionsTable;
  174. *valid; ++valid)
  175. {
  176. if(onePermission == *valid)
  177. {
  178. // This is a valid permission.
  179. permissions += " ";
  180. permissions += onePermission;
  181. return true;
  182. }
  183. }
  184. // This is not a valid permission.
  185. return false;
  186. }