cmDefinePropertyCommand.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. // cmDefinePropertiesCommand
  13. bool cmDefinePropertyCommand
  14. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  15. {
  16. if(args.size() < 1)
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. // Get the scope in which to define the property.
  22. cmProperty::ScopeType scope;
  23. if(args[0] == "GLOBAL")
  24. {
  25. scope = cmProperty::GLOBAL;
  26. }
  27. else if(args[0] == "DIRECTORY")
  28. {
  29. scope = cmProperty::DIRECTORY;
  30. }
  31. else if(args[0] == "TARGET")
  32. {
  33. scope = cmProperty::TARGET;
  34. }
  35. else if(args[0] == "SOURCE")
  36. {
  37. scope = cmProperty::SOURCE_FILE;
  38. }
  39. else if(args[0] == "TEST")
  40. {
  41. scope = cmProperty::TEST;
  42. }
  43. else if(args[0] == "VARIABLE")
  44. {
  45. scope = cmProperty::VARIABLE;
  46. }
  47. else if (args[0] == "CACHED_VARIABLE")
  48. {
  49. scope = cmProperty::CACHED_VARIABLE;
  50. }
  51. else
  52. {
  53. cmOStringStream e;
  54. e << "given invalid scope " << args[0] << ". "
  55. << "Valid scopes are "
  56. << "GLOBAL, DIRECTORY, TARGET, SOURCE, "
  57. << "TEST, VARIABLE, CACHED_VARIABLE.";
  58. this->SetError(e.str().c_str());
  59. return false;
  60. }
  61. // Parse remaining arguments.
  62. bool inherited = false;
  63. enum Doing { DoingNone, DoingProperty, DoingBrief, DoingFull };
  64. Doing doing = DoingNone;
  65. for(unsigned int i=1; i < args.size(); ++i)
  66. {
  67. if(args[i] == "PROPERTY")
  68. {
  69. doing = DoingProperty;
  70. }
  71. else if(args[i] == "BRIEF_DOCS")
  72. {
  73. doing = DoingBrief;
  74. }
  75. else if(args[i] == "FULL_DOCS")
  76. {
  77. doing = DoingFull;
  78. }
  79. else if(args[i] == "INHERITED")
  80. {
  81. doing = DoingNone;
  82. inherited = true;
  83. }
  84. else if(doing == DoingProperty)
  85. {
  86. doing = DoingNone;
  87. this->PropertyName = args[i];
  88. }
  89. else if(doing == DoingBrief)
  90. {
  91. this->BriefDocs += args[i];
  92. }
  93. else if(doing == DoingFull)
  94. {
  95. this->FullDocs += args[i];
  96. }
  97. else
  98. {
  99. cmOStringStream e;
  100. e << "given invalid argument \"" << args[i] << "\".";
  101. this->SetError(e.str().c_str());
  102. return false;
  103. }
  104. }
  105. // Make sure a property name was found.
  106. if(this->PropertyName.empty())
  107. {
  108. this->SetError("not given a PROPERTY <name> argument.");
  109. return false;
  110. }
  111. // Make sure documentation was given.
  112. if(this->BriefDocs.empty())
  113. {
  114. this->SetError("not given a BRIEF_DOCS <brief-doc> argument.");
  115. return false;
  116. }
  117. if(this->FullDocs.empty())
  118. {
  119. this->SetError("not given a FULL_DOCS <full-doc> argument.");
  120. return false;
  121. }
  122. // Actually define the property.
  123. this->Makefile->GetCMakeInstance()->DefineProperty
  124. (this->PropertyName.c_str(), scope,
  125. this->BriefDocs.c_str(), this->FullDocs.c_str(), inherited);
  126. return true;
  127. }