cmDefinePropertyCommand.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "cmDefinePropertyCommand.h"
  4. #include <sstream>
  5. #include "cmMakefile.h"
  6. #include "cmProperty.h"
  7. #include "cmState.h"
  8. class cmExecutionStatus;
  9. bool cmDefinePropertyCommand::InitialPass(std::vector<std::string> const& args,
  10. cmExecutionStatus&)
  11. {
  12. if (args.empty()) {
  13. this->SetError("called with incorrect number of arguments");
  14. return false;
  15. }
  16. // Get the scope in which to define the property.
  17. cmProperty::ScopeType scope;
  18. std::string const& scope_arg = args[0];
  19. if (scope_arg == "GLOBAL") {
  20. scope = cmProperty::GLOBAL;
  21. } else if (scope_arg == "DIRECTORY") {
  22. scope = cmProperty::DIRECTORY;
  23. } else if (scope_arg == "TARGET") {
  24. scope = cmProperty::TARGET;
  25. } else if (scope_arg == "SOURCE") {
  26. scope = cmProperty::SOURCE_FILE;
  27. } else if (scope_arg == "TEST") {
  28. scope = cmProperty::TEST;
  29. } else if (scope_arg == "VARIABLE") {
  30. scope = cmProperty::VARIABLE;
  31. } else if (scope_arg == "CACHED_VARIABLE") {
  32. scope = cmProperty::CACHED_VARIABLE;
  33. } else {
  34. std::ostringstream e;
  35. e << "given invalid scope " << scope_arg << ". "
  36. << "Valid scopes are "
  37. << "GLOBAL, DIRECTORY, TARGET, SOURCE, "
  38. << "TEST, VARIABLE, CACHED_VARIABLE.";
  39. this->SetError(e.str());
  40. return false;
  41. }
  42. // Parse remaining arguments.
  43. bool inherited = false;
  44. enum Doing
  45. {
  46. DoingNone,
  47. DoingProperty,
  48. DoingBrief,
  49. DoingFull
  50. };
  51. Doing doing = DoingNone;
  52. for (unsigned int i = 1; i < args.size(); ++i) {
  53. if (args[i] == "PROPERTY") {
  54. doing = DoingProperty;
  55. } else if (args[i] == "BRIEF_DOCS") {
  56. doing = DoingBrief;
  57. } else if (args[i] == "FULL_DOCS") {
  58. doing = DoingFull;
  59. } else if (args[i] == "INHERITED") {
  60. doing = DoingNone;
  61. inherited = true;
  62. } else if (doing == DoingProperty) {
  63. doing = DoingNone;
  64. this->PropertyName = args[i];
  65. } else if (doing == DoingBrief) {
  66. this->BriefDocs += args[i];
  67. } else if (doing == DoingFull) {
  68. this->FullDocs += args[i];
  69. } else {
  70. std::ostringstream e;
  71. e << "given invalid argument \"" << args[i] << "\".";
  72. this->SetError(e.str());
  73. return false;
  74. }
  75. }
  76. // Make sure a property name was found.
  77. if (this->PropertyName.empty()) {
  78. this->SetError("not given a PROPERTY <name> argument.");
  79. return false;
  80. }
  81. // Make sure documentation was given.
  82. if (this->BriefDocs.empty()) {
  83. this->SetError("not given a BRIEF_DOCS <brief-doc> argument.");
  84. return false;
  85. }
  86. if (this->FullDocs.empty()) {
  87. this->SetError("not given a FULL_DOCS <full-doc> argument.");
  88. return false;
  89. }
  90. // Actually define the property.
  91. this->Makefile->GetState()->DefineProperty(
  92. this->PropertyName, scope, this->BriefDocs.c_str(), this->FullDocs.c_str(),
  93. inherited);
  94. return true;
  95. }