cmInstallCommandArguments.cxx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 <cmConfigure.h>
  5. #include "cmSystemTools.h"
  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", CM_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(CM_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 != CM_NULLPTR) {
  36. return this->GenericArguments->GetDestination();
  37. }
  38. return this->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 != CM_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 != CM_NULLPTR) {
  60. return this->GenericArguments->GetRename();
  61. }
  62. return this->EmptyString;
  63. }
  64. const std::string& cmInstallCommandArguments::GetPermissions() const
  65. {
  66. if (!this->PermissionsString.empty()) {
  67. return this->PermissionsString;
  68. }
  69. if (this->GenericArguments != CM_NULLPTR) {
  70. return this->GenericArguments->GetPermissions();
  71. }
  72. return this->EmptyString;
  73. }
  74. bool cmInstallCommandArguments::GetOptional() const
  75. {
  76. if (this->Optional.IsEnabled()) {
  77. return true;
  78. }
  79. if (this->GenericArguments != CM_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 != CM_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 != CM_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 != CM_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 != CM_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 = "";
  142. for (std::vector<std::string>::const_iterator permIt =
  143. this->Permissions.GetVector().begin();
  144. permIt != this->Permissions.GetVector().end(); ++permIt) {
  145. if (!this->CheckPermissions(*permIt, this->PermissionsString)) {
  146. return false;
  147. }
  148. }
  149. return true;
  150. }
  151. bool cmInstallCommandArguments::CheckPermissions(
  152. const std::string& onePermission, std::string& permissions)
  153. {
  154. // Check the permission against the table.
  155. for (const char** valid = cmInstallCommandArguments::PermissionsTable;
  156. *valid; ++valid) {
  157. if (onePermission == *valid) {
  158. // This is a valid permission.
  159. permissions += " ";
  160. permissions += onePermission;
  161. return true;
  162. }
  163. }
  164. // This is not a valid permission.
  165. return false;
  166. }
  167. cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument()
  168. {
  169. }
  170. const std::vector<std::string>&
  171. cmInstallCommandIncludesArgument::GetIncludeDirs() const
  172. {
  173. return this->IncludeDirs;
  174. }
  175. void cmInstallCommandIncludesArgument::Parse(
  176. const std::vector<std::string>* args, std::vector<std::string>*)
  177. {
  178. if (args->empty()) {
  179. return;
  180. }
  181. std::vector<std::string>::const_iterator it = args->begin();
  182. ++it;
  183. for (; it != args->end(); ++it) {
  184. std::string dir = *it;
  185. cmSystemTools::ConvertToUnixSlashes(dir);
  186. this->IncludeDirs.push_back(dir);
  187. }
  188. }