cmInstallCommandArguments.cxx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. :Parser()
  23. ,ArgumentGroup()
  24. ,Destination (&Parser, "DESTINATION" , &ArgumentGroup)
  25. ,Component (&Parser, "COMPONENT" , &ArgumentGroup)
  26. ,Rename (&Parser, "RENAME" , &ArgumentGroup)
  27. ,Permissions (&Parser, "PERMISSIONS" , &ArgumentGroup)
  28. ,Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup)
  29. ,Optional (&Parser, "OPTIONAL" , &ArgumentGroup)
  30. ,NamelinkOnly (&Parser, "NAMELINK_ONLY" , &ArgumentGroup)
  31. ,NamelinkSkip (&Parser, "NAMELINK_SKIP" , &ArgumentGroup)
  32. ,GenericArguments(0)
  33. {}
  34. const std::string& cmInstallCommandArguments::GetDestination() const
  35. {
  36. if (!this->DestinationString.empty())
  37. {
  38. return this->DestinationString;
  39. }
  40. if (this->GenericArguments!=0)
  41. {
  42. return this->GenericArguments->GetDestination();
  43. }
  44. return this->EmptyString;
  45. }
  46. const std::string& cmInstallCommandArguments::GetComponent() const
  47. {
  48. if (!this->Component.GetString().empty())
  49. {
  50. return this->Component.GetString();
  51. }
  52. if (this->GenericArguments!=0)
  53. {
  54. return this->GenericArguments->GetComponent();
  55. }
  56. static std::string unspecifiedComponent = "Unspecified";
  57. return unspecifiedComponent;
  58. }
  59. const std::string& cmInstallCommandArguments::GetRename() const
  60. {
  61. if (!this->Rename.GetString().empty())
  62. {
  63. return this->Rename.GetString();
  64. }
  65. if (this->GenericArguments!=0)
  66. {
  67. return this->GenericArguments->GetRename();
  68. }
  69. return this->EmptyString;
  70. }
  71. const std::string& cmInstallCommandArguments::GetPermissions() const
  72. {
  73. if (!this->PermissionsString.empty())
  74. {
  75. return this->PermissionsString;
  76. }
  77. if (this->GenericArguments!=0)
  78. {
  79. return this->GenericArguments->GetPermissions();
  80. }
  81. return this->EmptyString;
  82. }
  83. bool cmInstallCommandArguments::GetOptional() const
  84. {
  85. if (this->Optional.IsEnabled())
  86. {
  87. return true;
  88. }
  89. if (this->GenericArguments!=0)
  90. {
  91. return this->GenericArguments->GetOptional();
  92. }
  93. return false;
  94. }
  95. bool cmInstallCommandArguments::GetNamelinkOnly() const
  96. {
  97. if (this->NamelinkOnly.IsEnabled())
  98. {
  99. return true;
  100. }
  101. if (this->GenericArguments!=0)
  102. {
  103. return this->GenericArguments->GetNamelinkOnly();
  104. }
  105. return false;
  106. }
  107. bool cmInstallCommandArguments::GetNamelinkSkip() const
  108. {
  109. if (this->NamelinkSkip.IsEnabled())
  110. {
  111. return true;
  112. }
  113. if (this->GenericArguments!=0)
  114. {
  115. return this->GenericArguments->GetNamelinkSkip();
  116. }
  117. return false;
  118. }
  119. const std::vector<std::string>&
  120. cmInstallCommandArguments::GetConfigurations() const
  121. {
  122. if (!this->Configurations.GetVector().empty())
  123. {
  124. return this->Configurations.GetVector();
  125. }
  126. if (this->GenericArguments!=0)
  127. {
  128. return this->GenericArguments->GetConfigurations();
  129. }
  130. return this->Configurations.GetVector();
  131. }
  132. bool cmInstallCommandArguments::Finalize()
  133. {
  134. if (!this->CheckPermissions())
  135. {
  136. return false;
  137. }
  138. this->DestinationString = this->Destination.GetString();
  139. cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
  140. return true;
  141. }
  142. void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
  143. std::vector<std::string>* unconsumedArgs)
  144. {
  145. this->Parser.Parse(args, unconsumedArgs);
  146. }
  147. bool cmInstallCommandArguments::CheckPermissions()
  148. {
  149. this->PermissionsString = "";
  150. for(std::vector<std::string>::const_iterator
  151. permIt = this->Permissions.GetVector().begin();
  152. permIt != this->Permissions.GetVector().end();
  153. ++permIt)
  154. {
  155. if (!this->CheckPermissions(*permIt, this->PermissionsString))
  156. {
  157. return false;
  158. }
  159. }
  160. return true;
  161. }
  162. bool cmInstallCommandArguments::CheckPermissions(
  163. const std::string& onePermission, std::string& permissions)
  164. {
  165. // Check the permission against the table.
  166. for(const char** valid = cmInstallCommandArguments::PermissionsTable;
  167. *valid; ++valid)
  168. {
  169. if(onePermission == *valid)
  170. {
  171. // This is a valid permission.
  172. permissions += " ";
  173. permissions += onePermission;
  174. return true;
  175. }
  176. }
  177. // This is not a valid permission.
  178. return false;
  179. }