cmDefinePropertyCommand.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "cmExecutionStatus.h"
  5. #include "cmMakefile.h"
  6. #include "cmProperty.h"
  7. #include "cmState.h"
  8. #include "cmStringAlgorithms.h"
  9. bool cmDefinePropertyCommand(std::vector<std::string> const& args,
  10. cmExecutionStatus& status)
  11. {
  12. if (args.empty()) {
  13. status.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. status.SetError(cmStrCat("given invalid scope ", scope_arg,
  35. ". Valid scopes are GLOBAL, DIRECTORY, TARGET, "
  36. "SOURCE, TEST, VARIABLE, CACHED_VARIABLE."));
  37. return false;
  38. }
  39. // Parse remaining arguments.
  40. bool inherited = false;
  41. std::string PropertyName;
  42. std::string BriefDocs;
  43. std::string FullDocs;
  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. PropertyName = args[i];
  65. } else if (doing == DoingBrief) {
  66. BriefDocs += args[i];
  67. } else if (doing == DoingFull) {
  68. FullDocs += args[i];
  69. } else {
  70. status.SetError(cmStrCat("given invalid argument \"", args[i], "\"."));
  71. return false;
  72. }
  73. }
  74. // Make sure a property name was found.
  75. if (PropertyName.empty()) {
  76. status.SetError("not given a PROPERTY <name> argument.");
  77. return false;
  78. }
  79. // Make sure documentation was given.
  80. if (BriefDocs.empty()) {
  81. status.SetError("not given a BRIEF_DOCS <brief-doc> argument.");
  82. return false;
  83. }
  84. if (FullDocs.empty()) {
  85. status.SetError("not given a FULL_DOCS <full-doc> argument.");
  86. return false;
  87. }
  88. // Actually define the property.
  89. status.GetMakefile().GetState()->DefineProperty(
  90. PropertyName, scope, BriefDocs, FullDocs, inherited);
  91. return true;
  92. }