cmInstallCommandArguments.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmInstallCommandArguments.h"
  4. #include <utility>
  5. #include <cmext/string_view>
  6. #include "cmRange.h"
  7. #include "cmSystemTools.h"
  8. // Table of valid permissions.
  9. const char* cmInstallCommandArguments::PermissionsTable[] = {
  10. "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE", "GROUP_READ",
  11. "GROUP_WRITE", "GROUP_EXECUTE", "WORLD_READ", "WORLD_WRITE",
  12. "WORLD_EXECUTE", "SETUID", "SETGID", nullptr
  13. };
  14. const std::string cmInstallCommandArguments::EmptyString;
  15. cmInstallCommandArguments::cmInstallCommandArguments(
  16. std::string defaultComponent)
  17. : DefaultComponentName(std::move(defaultComponent))
  18. {
  19. this->Bind("DESTINATION"_s, this->Destination);
  20. this->Bind("COMPONENT"_s, this->Component);
  21. this->Bind("NAMELINK_COMPONENT"_s, this->NamelinkComponent);
  22. this->Bind("EXCLUDE_FROM_ALL"_s, this->ExcludeFromAll);
  23. this->Bind("RENAME"_s, this->Rename);
  24. this->Bind("PERMISSIONS"_s, this->Permissions);
  25. this->Bind("CONFIGURATIONS"_s, this->Configurations);
  26. this->Bind("OPTIONAL"_s, this->Optional);
  27. this->Bind("NAMELINK_ONLY"_s, this->NamelinkOnly);
  28. this->Bind("NAMELINK_SKIP"_s, this->NamelinkSkip);
  29. this->Bind("TYPE"_s, this->Type);
  30. }
  31. const std::string& cmInstallCommandArguments::GetDestination() const
  32. {
  33. if (!this->DestinationString.empty()) {
  34. return this->DestinationString;
  35. }
  36. if (this->GenericArguments != nullptr) {
  37. return this->GenericArguments->GetDestination();
  38. }
  39. return EmptyString;
  40. }
  41. const std::string& cmInstallCommandArguments::GetComponent() const
  42. {
  43. if (!this->Component.empty()) {
  44. return this->Component;
  45. }
  46. if (this->GenericArguments != nullptr) {
  47. return this->GenericArguments->GetComponent();
  48. }
  49. if (!this->DefaultComponentName.empty()) {
  50. return this->DefaultComponentName;
  51. }
  52. static std::string unspecifiedComponent = "Unspecified";
  53. return unspecifiedComponent;
  54. }
  55. const std::string& cmInstallCommandArguments::GetNamelinkComponent() const
  56. {
  57. if (!this->NamelinkComponent.empty()) {
  58. return this->NamelinkComponent;
  59. }
  60. return this->GetComponent();
  61. }
  62. const std::string& cmInstallCommandArguments::GetRename() const
  63. {
  64. if (!this->Rename.empty()) {
  65. return this->Rename;
  66. }
  67. if (this->GenericArguments != nullptr) {
  68. return this->GenericArguments->GetRename();
  69. }
  70. return EmptyString;
  71. }
  72. const std::string& cmInstallCommandArguments::GetPermissions() const
  73. {
  74. if (!this->PermissionsString.empty()) {
  75. return this->PermissionsString;
  76. }
  77. if (this->GenericArguments != nullptr) {
  78. return this->GenericArguments->GetPermissions();
  79. }
  80. return EmptyString;
  81. }
  82. bool cmInstallCommandArguments::GetOptional() const
  83. {
  84. if (this->Optional) {
  85. return true;
  86. }
  87. if (this->GenericArguments != nullptr) {
  88. return this->GenericArguments->GetOptional();
  89. }
  90. return false;
  91. }
  92. bool cmInstallCommandArguments::GetExcludeFromAll() const
  93. {
  94. if (this->ExcludeFromAll) {
  95. return true;
  96. }
  97. if (this->GenericArguments != nullptr) {
  98. return this->GenericArguments->GetExcludeFromAll();
  99. }
  100. return false;
  101. }
  102. bool cmInstallCommandArguments::GetNamelinkOnly() const
  103. {
  104. if (this->NamelinkOnly) {
  105. return true;
  106. }
  107. if (this->GenericArguments != nullptr) {
  108. return this->GenericArguments->GetNamelinkOnly();
  109. }
  110. return false;
  111. }
  112. bool cmInstallCommandArguments::GetNamelinkSkip() const
  113. {
  114. if (this->NamelinkSkip) {
  115. return true;
  116. }
  117. if (this->GenericArguments != nullptr) {
  118. return this->GenericArguments->GetNamelinkSkip();
  119. }
  120. return false;
  121. }
  122. bool cmInstallCommandArguments::HasNamelinkComponent() const
  123. {
  124. if (!this->NamelinkComponent.empty()) {
  125. return true;
  126. }
  127. if (this->GenericArguments != nullptr) {
  128. return this->GenericArguments->HasNamelinkComponent();
  129. }
  130. return false;
  131. }
  132. const std::string& cmInstallCommandArguments::GetType() const
  133. {
  134. return this->Type;
  135. }
  136. const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
  137. const
  138. {
  139. if (!this->Configurations.empty()) {
  140. return this->Configurations;
  141. }
  142. if (this->GenericArguments != nullptr) {
  143. return this->GenericArguments->GetConfigurations();
  144. }
  145. return this->Configurations;
  146. }
  147. bool cmInstallCommandArguments::Finalize()
  148. {
  149. if (!this->CheckPermissions()) {
  150. return false;
  151. }
  152. this->DestinationString = this->Destination;
  153. cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
  154. return true;
  155. }
  156. bool cmInstallCommandArguments::CheckPermissions()
  157. {
  158. this->PermissionsString.clear();
  159. for (std::string const& perm : this->Permissions) {
  160. if (!cmInstallCommandArguments::CheckPermissions(
  161. perm, this->PermissionsString)) {
  162. return false;
  163. }
  164. }
  165. return true;
  166. }
  167. bool cmInstallCommandArguments::CheckPermissions(
  168. const std::string& onePermission, std::string& permissions)
  169. {
  170. // Check the permission against the table.
  171. for (const char** valid = cmInstallCommandArguments::PermissionsTable;
  172. *valid; ++valid) {
  173. if (onePermission == *valid) {
  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. }
  183. cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument() = default;
  184. const std::vector<std::string>&
  185. cmInstallCommandIncludesArgument::GetIncludeDirs() const
  186. {
  187. return this->IncludeDirs;
  188. }
  189. void cmInstallCommandIncludesArgument::Parse(
  190. const std::vector<std::string>* args, std::vector<std::string>*)
  191. {
  192. if (args->empty()) {
  193. return;
  194. }
  195. for (std::string dir : cmMakeRange(*args).advance(1)) {
  196. cmSystemTools::ConvertToUnixSlashes(dir);
  197. this->IncludeDirs.push_back(std::move(dir));
  198. }
  199. }