cmInstallCommandArguments.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmInstallCommandArguments.h"
  14. #include "cmSystemTools.h"
  15. // Table of valid permissions.
  16. const char* cmInstallCommandArguments::PermissionsTable[] =
  17. {
  18. "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE",
  19. "GROUP_READ", "GROUP_WRITE", "GROUP_EXECUTE",
  20. "WORLD_READ", "WORLD_WRITE", "WORLD_EXECUTE",
  21. "SETUID", "SETGID", 0
  22. };
  23. const std::string cmInstallCommandArguments::EmptyString;
  24. cmInstallCommandArguments::cmInstallCommandArguments()
  25. :Parser()
  26. ,ArgumentGroup()
  27. ,Destination (&Parser, "DESTINATION" , &ArgumentGroup)
  28. ,Component (&Parser, "COMPONENT" , &ArgumentGroup)
  29. ,Rename (&Parser, "RENAME" , &ArgumentGroup)
  30. ,Permissions (&Parser, "PERMISSIONS" , &ArgumentGroup)
  31. ,Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup)
  32. ,Optional (&Parser, "OPTIONAL" , &ArgumentGroup)
  33. ,GenericArguments(0)
  34. {
  35. this->Component.SetDefaultString("Unspecified");
  36. }
  37. const std::string& cmInstallCommandArguments::GetDestination() const
  38. {
  39. if (!this->DestinationString.empty())
  40. {
  41. return this->DestinationString;
  42. }
  43. if (this->GenericArguments!=0)
  44. {
  45. return this->GenericArguments->GetDestination();
  46. }
  47. return this->EmptyString;
  48. }
  49. const std::string& cmInstallCommandArguments::GetComponent() const
  50. {
  51. if (!this->Component.GetString().empty())
  52. {
  53. return this->Component.GetString();
  54. }
  55. if (this->GenericArguments!=0)
  56. {
  57. return this->GenericArguments->GetComponent();
  58. }
  59. return this->EmptyString;
  60. }
  61. const std::string& cmInstallCommandArguments::GetRename() const
  62. {
  63. if (!this->Rename.GetString().empty())
  64. {
  65. return this->Rename.GetString();
  66. }
  67. if (this->GenericArguments!=0)
  68. {
  69. return this->GenericArguments->GetRename();
  70. }
  71. return this->EmptyString;
  72. }
  73. const std::string& cmInstallCommandArguments::GetPermissions() const
  74. {
  75. if (!this->PermissionsString.empty())
  76. {
  77. return this->PermissionsString;
  78. }
  79. if (this->GenericArguments!=0)
  80. {
  81. return this->GenericArguments->GetPermissions();
  82. }
  83. return this->EmptyString;
  84. }
  85. bool cmInstallCommandArguments::GetOptional() const
  86. {
  87. if (this->Optional.IsEnabled())
  88. {
  89. return true;
  90. }
  91. if (this->GenericArguments!=0)
  92. {
  93. return this->GenericArguments->GetOptional();
  94. }
  95. return false;
  96. }
  97. const std::vector<std::string>&
  98. cmInstallCommandArguments::GetConfigurations() const
  99. {
  100. if (!this->Configurations.GetVector().empty())
  101. {
  102. return this->Configurations.GetVector();
  103. }
  104. if (this->GenericArguments!=0)
  105. {
  106. return this->GenericArguments->GetConfigurations();
  107. }
  108. return this->Configurations.GetVector();
  109. }
  110. bool cmInstallCommandArguments::Finalize()
  111. {
  112. if (!this->CheckPermissions())
  113. {
  114. return false;
  115. }
  116. this->DestinationString = this->Destination.GetString();
  117. cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
  118. return true;
  119. }
  120. void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
  121. std::vector<std::string>* unconsumedArgs)
  122. {
  123. this->Parser.Parse(args, unconsumedArgs);
  124. }
  125. bool cmInstallCommandArguments::CheckPermissions()
  126. {
  127. this->PermissionsString = "";
  128. for(std::vector<std::string>::const_iterator
  129. permIt = this->Permissions.GetVector().begin();
  130. permIt != this->Permissions.GetVector().end();
  131. ++permIt)
  132. {
  133. if (!this->CheckPermissions(*permIt, this->PermissionsString))
  134. {
  135. return false;
  136. }
  137. }
  138. return true;
  139. }
  140. bool cmInstallCommandArguments::CheckPermissions(
  141. const std::string& onePermission, std::string& permissions)
  142. {
  143. // Check the permission against the table.
  144. for(const char** valid = cmInstallCommandArguments::PermissionsTable;
  145. *valid; ++valid)
  146. {
  147. if(onePermission == *valid)
  148. {
  149. // This is a valid permission.
  150. permissions += " ";
  151. permissions += onePermission;
  152. return true;
  153. }
  154. }
  155. // This is not a valid permission.
  156. return false;
  157. }