cmInstallCommandArguments.cxx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. {
  35. this->Component.SetDefaultString(defaultComponent.c_str());
  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. static std::string unspecifiedComponent = "Unspecified";
  60. return unspecifiedComponent;
  61. }
  62. const std::string& cmInstallCommandArguments::GetRename() const
  63. {
  64. if (!this->Rename.GetString().empty())
  65. {
  66. return this->Rename.GetString();
  67. }
  68. if (this->GenericArguments!=0)
  69. {
  70. return this->GenericArguments->GetRename();
  71. }
  72. return this->EmptyString;
  73. }
  74. const std::string& cmInstallCommandArguments::GetPermissions() const
  75. {
  76. if (!this->PermissionsString.empty())
  77. {
  78. return this->PermissionsString;
  79. }
  80. if (this->GenericArguments!=0)
  81. {
  82. return this->GenericArguments->GetPermissions();
  83. }
  84. return this->EmptyString;
  85. }
  86. bool cmInstallCommandArguments::GetOptional() const
  87. {
  88. if (this->Optional.IsEnabled())
  89. {
  90. return true;
  91. }
  92. if (this->GenericArguments!=0)
  93. {
  94. return this->GenericArguments->GetOptional();
  95. }
  96. return false;
  97. }
  98. bool cmInstallCommandArguments::GetNamelinkOnly() const
  99. {
  100. if (this->NamelinkOnly.IsEnabled())
  101. {
  102. return true;
  103. }
  104. if (this->GenericArguments!=0)
  105. {
  106. return this->GenericArguments->GetNamelinkOnly();
  107. }
  108. return false;
  109. }
  110. bool cmInstallCommandArguments::GetNamelinkSkip() const
  111. {
  112. if (this->NamelinkSkip.IsEnabled())
  113. {
  114. return true;
  115. }
  116. if (this->GenericArguments!=0)
  117. {
  118. return this->GenericArguments->GetNamelinkSkip();
  119. }
  120. return false;
  121. }
  122. const std::vector<std::string>&
  123. cmInstallCommandArguments::GetConfigurations() const
  124. {
  125. if (!this->Configurations.GetVector().empty())
  126. {
  127. return this->Configurations.GetVector();
  128. }
  129. if (this->GenericArguments!=0)
  130. {
  131. return this->GenericArguments->GetConfigurations();
  132. }
  133. return this->Configurations.GetVector();
  134. }
  135. bool cmInstallCommandArguments::Finalize()
  136. {
  137. if (!this->CheckPermissions())
  138. {
  139. return false;
  140. }
  141. this->DestinationString = this->Destination.GetString();
  142. cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
  143. return true;
  144. }
  145. void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
  146. std::vector<std::string>* unconsumedArgs)
  147. {
  148. this->Parser.Parse(args, unconsumedArgs);
  149. }
  150. bool cmInstallCommandArguments::CheckPermissions()
  151. {
  152. this->PermissionsString = "";
  153. for(std::vector<std::string>::const_iterator
  154. permIt = this->Permissions.GetVector().begin();
  155. permIt != this->Permissions.GetVector().end();
  156. ++permIt)
  157. {
  158. if (!this->CheckPermissions(*permIt, this->PermissionsString))
  159. {
  160. return false;
  161. }
  162. }
  163. return true;
  164. }
  165. bool cmInstallCommandArguments::CheckPermissions(
  166. const std::string& onePermission, std::string& permissions)
  167. {
  168. // Check the permission against the table.
  169. for(const char** valid = cmInstallCommandArguments::PermissionsTable;
  170. *valid; ++valid)
  171. {
  172. if(onePermission == *valid)
  173. {
  174. // This is a valid permission.
  175. permissions += " ";
  176. permissions += onePermission;
  177. return true;
  178. }
  179. }
  180. // This is not a valid permission.
  181. return false;
  182. }