cmInstallCommandArguments.cxx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. : Destination(&Parser, "DESTINATION", &ArgumentGroup)
  16. , Component(&Parser, "COMPONENT", &ArgumentGroup)
  17. , NamelinkComponent(&Parser, "NAMELINK_COMPONENT", &ArgumentGroup)
  18. , ExcludeFromAll(&Parser, "EXCLUDE_FROM_ALL", &ArgumentGroup)
  19. , Rename(&Parser, "RENAME", &ArgumentGroup)
  20. , Permissions(&Parser, "PERMISSIONS", &ArgumentGroup)
  21. , Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup)
  22. , Optional(&Parser, "OPTIONAL", &ArgumentGroup)
  23. , NamelinkOnly(&Parser, "NAMELINK_ONLY", &ArgumentGroup)
  24. , NamelinkSkip(&Parser, "NAMELINK_SKIP", &ArgumentGroup)
  25. , Type(&Parser, "TYPE", &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::GetNamelinkComponent() const
  55. {
  56. if (!this->NamelinkComponent.GetString().empty()) {
  57. return this->NamelinkComponent.GetString();
  58. }
  59. return this->GetComponent();
  60. }
  61. const std::string& cmInstallCommandArguments::GetRename() const
  62. {
  63. if (!this->Rename.GetString().empty()) {
  64. return this->Rename.GetString();
  65. }
  66. if (this->GenericArguments != nullptr) {
  67. return this->GenericArguments->GetRename();
  68. }
  69. return EmptyString;
  70. }
  71. const std::string& cmInstallCommandArguments::GetPermissions() const
  72. {
  73. if (!this->PermissionsString.empty()) {
  74. return this->PermissionsString;
  75. }
  76. if (this->GenericArguments != nullptr) {
  77. return this->GenericArguments->GetPermissions();
  78. }
  79. return EmptyString;
  80. }
  81. bool cmInstallCommandArguments::GetOptional() const
  82. {
  83. if (this->Optional.IsEnabled()) {
  84. return true;
  85. }
  86. if (this->GenericArguments != nullptr) {
  87. return this->GenericArguments->GetOptional();
  88. }
  89. return false;
  90. }
  91. bool cmInstallCommandArguments::GetExcludeFromAll() const
  92. {
  93. if (this->ExcludeFromAll.IsEnabled()) {
  94. return true;
  95. }
  96. if (this->GenericArguments != nullptr) {
  97. return this->GenericArguments->GetExcludeFromAll();
  98. }
  99. return false;
  100. }
  101. bool cmInstallCommandArguments::GetNamelinkOnly() const
  102. {
  103. if (this->NamelinkOnly.IsEnabled()) {
  104. return true;
  105. }
  106. if (this->GenericArguments != nullptr) {
  107. return this->GenericArguments->GetNamelinkOnly();
  108. }
  109. return false;
  110. }
  111. bool cmInstallCommandArguments::GetNamelinkSkip() const
  112. {
  113. if (this->NamelinkSkip.IsEnabled()) {
  114. return true;
  115. }
  116. if (this->GenericArguments != nullptr) {
  117. return this->GenericArguments->GetNamelinkSkip();
  118. }
  119. return false;
  120. }
  121. bool cmInstallCommandArguments::HasNamelinkComponent() const
  122. {
  123. if (!this->NamelinkComponent.GetString().empty()) {
  124. return true;
  125. }
  126. if (this->GenericArguments != nullptr) {
  127. return this->GenericArguments->HasNamelinkComponent();
  128. }
  129. return false;
  130. }
  131. const std::string& cmInstallCommandArguments::GetType() const
  132. {
  133. return this->Type.GetString();
  134. }
  135. const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
  136. const
  137. {
  138. if (!this->Configurations.GetVector().empty()) {
  139. return this->Configurations.GetVector();
  140. }
  141. if (this->GenericArguments != nullptr) {
  142. return this->GenericArguments->GetConfigurations();
  143. }
  144. return this->Configurations.GetVector();
  145. }
  146. bool cmInstallCommandArguments::Finalize()
  147. {
  148. if (!this->CheckPermissions()) {
  149. return false;
  150. }
  151. this->DestinationString = this->Destination.GetString();
  152. cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
  153. return true;
  154. }
  155. void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
  156. std::vector<std::string>* unconsumedArgs)
  157. {
  158. this->Parser.Parse(args, unconsumedArgs);
  159. }
  160. bool cmInstallCommandArguments::CheckPermissions()
  161. {
  162. this->PermissionsString.clear();
  163. for (std::string const& perm : this->Permissions.GetVector()) {
  164. if (!cmInstallCommandArguments::CheckPermissions(
  165. perm, this->PermissionsString)) {
  166. return false;
  167. }
  168. }
  169. return true;
  170. }
  171. bool cmInstallCommandArguments::CheckPermissions(
  172. const std::string& onePermission, std::string& permissions)
  173. {
  174. // Check the permission against the table.
  175. for (const char** valid = cmInstallCommandArguments::PermissionsTable;
  176. *valid; ++valid) {
  177. if (onePermission == *valid) {
  178. // This is a valid permission.
  179. permissions += " ";
  180. permissions += onePermission;
  181. return true;
  182. }
  183. }
  184. // This is not a valid permission.
  185. return false;
  186. }
  187. cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument()
  188. {
  189. }
  190. const std::vector<std::string>&
  191. cmInstallCommandIncludesArgument::GetIncludeDirs() const
  192. {
  193. return this->IncludeDirs;
  194. }
  195. void cmInstallCommandIncludesArgument::Parse(
  196. const std::vector<std::string>* args, std::vector<std::string>*)
  197. {
  198. if (args->empty()) {
  199. return;
  200. }
  201. std::vector<std::string>::const_iterator it = args->begin();
  202. ++it;
  203. for (; it != args->end(); ++it) {
  204. std::string dir = *it;
  205. cmSystemTools::ConvertToUnixSlashes(dir);
  206. this->IncludeDirs.push_back(std::move(dir));
  207. }
  208. }