cmDefinePropertyCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmDefinePropertyCommand.h"
  11. #include "cmake.h"
  12. bool cmDefinePropertyCommand
  13. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  14. {
  15. if(args.size() < 1)
  16. {
  17. this->SetError("called with incorrect number of arguments");
  18. return false;
  19. }
  20. // Get the scope in which to define the property.
  21. cmProperty::ScopeType scope;
  22. if(args[0] == "GLOBAL")
  23. {
  24. scope = cmProperty::GLOBAL;
  25. }
  26. else if(args[0] == "DIRECTORY")
  27. {
  28. scope = cmProperty::DIRECTORY;
  29. }
  30. else if(args[0] == "TARGET")
  31. {
  32. scope = cmProperty::TARGET;
  33. }
  34. else if(args[0] == "SOURCE")
  35. {
  36. scope = cmProperty::SOURCE_FILE;
  37. }
  38. else if(args[0] == "TEST")
  39. {
  40. scope = cmProperty::TEST;
  41. }
  42. else if(args[0] == "VARIABLE")
  43. {
  44. scope = cmProperty::VARIABLE;
  45. }
  46. else if (args[0] == "CACHED_VARIABLE")
  47. {
  48. scope = cmProperty::CACHED_VARIABLE;
  49. }
  50. else
  51. {
  52. std::ostringstream e;
  53. e << "given invalid scope " << args[0] << ". "
  54. << "Valid scopes are "
  55. << "GLOBAL, DIRECTORY, TARGET, SOURCE, "
  56. << "TEST, VARIABLE, CACHED_VARIABLE.";
  57. this->SetError(e.str());
  58. return false;
  59. }
  60. // Parse remaining arguments.
  61. bool inherited = false;
  62. enum Doing { DoingNone, DoingProperty, DoingBrief, DoingFull };
  63. Doing doing = DoingNone;
  64. for(unsigned int i=1; i < args.size(); ++i)
  65. {
  66. if(args[i] == "PROPERTY")
  67. {
  68. doing = DoingProperty;
  69. }
  70. else if(args[i] == "BRIEF_DOCS")
  71. {
  72. doing = DoingBrief;
  73. }
  74. else if(args[i] == "FULL_DOCS")
  75. {
  76. doing = DoingFull;
  77. }
  78. else if(args[i] == "INHERITED")
  79. {
  80. doing = DoingNone;
  81. inherited = true;
  82. }
  83. else if(doing == DoingProperty)
  84. {
  85. doing = DoingNone;
  86. this->PropertyName = args[i];
  87. }
  88. else if(doing == DoingBrief)
  89. {
  90. this->BriefDocs += args[i];
  91. }
  92. else if(doing == DoingFull)
  93. {
  94. this->FullDocs += args[i];
  95. }
  96. else
  97. {
  98. std::ostringstream e;
  99. e << "given invalid argument \"" << args[i] << "\".";
  100. this->SetError(e.str());
  101. return false;
  102. }
  103. }
  104. // Make sure a property name was found.
  105. if(this->PropertyName.empty())
  106. {
  107. this->SetError("not given a PROPERTY <name> argument.");
  108. return false;
  109. }
  110. // Make sure documentation was given.
  111. if(this->BriefDocs.empty())
  112. {
  113. this->SetError("not given a BRIEF_DOCS <brief-doc> argument.");
  114. return false;
  115. }
  116. if(this->FullDocs.empty())
  117. {
  118. this->SetError("not given a FULL_DOCS <full-doc> argument.");
  119. return false;
  120. }
  121. // Actually define the property.
  122. this->Makefile->GetCMakeInstance()->DefineProperty
  123. (this->PropertyName, scope,
  124. this->BriefDocs.c_str(), this->FullDocs.c_str(), inherited);
  125. return true;
  126. }