cmDefinePropertyCommand.cxx 2.8 KB

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