cmInstallCommandArguments.cxx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 "cmSystemTools.h"
  5. #include <utility>
  6. // Table of valid permissions.
  7. const char* cmInstallCommandArguments::PermissionsTable[] = {
  8. "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE", "GROUP_READ",
  9. "GROUP_WRITE", "GROUP_EXECUTE", "WORLD_READ", "WORLD_WRITE",
  10. "WORLD_EXECUTE", "SETUID", "SETGID", nullptr
  11. };
  12. const std::string cmInstallCommandArguments::EmptyString;
  13. cmInstallCommandArguments::cmInstallCommandArguments(
  14. const std::string& defaultComponent)
  15. : Parser()
  16. , ArgumentGroup()
  17. , Destination(&Parser, "DESTINATION", &ArgumentGroup)
  18. , Component(&Parser, "COMPONENT", &ArgumentGroup)
  19. , NamelinkComponent(&Parser, "NAMELINK_COMPONENT", &ArgumentGroup)
  20. , ExcludeFromAll(&Parser, "EXCLUDE_FROM_ALL", &ArgumentGroup)
  21. , Rename(&Parser, "RENAME", &ArgumentGroup)
  22. , Permissions(&Parser, "PERMISSIONS", &ArgumentGroup)
  23. , Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup)
  24. , Optional(&Parser, "OPTIONAL", &ArgumentGroup)
  25. , NamelinkOnly(&Parser, "NAMELINK_ONLY", &ArgumentGroup)
  26. , NamelinkSkip(&Parser, "NAMELINK_SKIP", &ArgumentGroup)
  27. , GenericArguments(nullptr)
  28. , DefaultComponentName(defaultComponent)
  29. {
  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.GetString().empty()) {
  44. return this->Component.GetString();
  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.GetString().empty()) {
  58. return this->NamelinkComponent.GetString();
  59. }
  60. return this->GetComponent();
  61. }
  62. const std::string& cmInstallCommandArguments::GetRename() const
  63. {
  64. if (!this->Rename.GetString().empty()) {
  65. return this->Rename.GetString();
  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.IsEnabled()) {
  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.IsEnabled()) {
  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.IsEnabled()) {
  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.IsEnabled()) {
  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.GetString().empty()) {
  125. return true;
  126. }
  127. if (this->GenericArguments != nullptr) {
  128. return this->GenericArguments->HasNamelinkComponent();
  129. }
  130. return false;
  131. }
  132. const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
  133. const
  134. {
  135. if (!this->Configurations.GetVector().empty()) {
  136. return this->Configurations.GetVector();
  137. }
  138. if (this->GenericArguments != nullptr) {
  139. return this->GenericArguments->GetConfigurations();
  140. }
  141. return this->Configurations.GetVector();
  142. }
  143. bool cmInstallCommandArguments::Finalize()
  144. {
  145. if (!this->CheckPermissions()) {
  146. return false;
  147. }
  148. this->DestinationString = this->Destination.GetString();
  149. cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
  150. return true;
  151. }
  152. void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
  153. std::vector<std::string>* unconsumedArgs)
  154. {
  155. this->Parser.Parse(args, unconsumedArgs);
  156. }
  157. bool cmInstallCommandArguments::CheckPermissions()
  158. {
  159. this->PermissionsString.clear();
  160. for (std::string const& perm : this->Permissions.GetVector()) {
  161. if (!this->CheckPermissions(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()
  184. {
  185. }
  186. const std::vector<std::string>&
  187. cmInstallCommandIncludesArgument::GetIncludeDirs() const
  188. {
  189. return this->IncludeDirs;
  190. }
  191. void cmInstallCommandIncludesArgument::Parse(
  192. const std::vector<std::string>* args, std::vector<std::string>*)
  193. {
  194. if (args->empty()) {
  195. return;
  196. }
  197. std::vector<std::string>::const_iterator it = args->begin();
  198. ++it;
  199. for (; it != args->end(); ++it) {
  200. std::string dir = *it;
  201. cmSystemTools::ConvertToUnixSlashes(dir);
  202. this->IncludeDirs.push_back(std::move(dir));
  203. }
  204. }