cmInstallCommandArguments.cxx 5.5 KB

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