cmInstallCommandArguments.cxx 5.5 KB

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