cmDefinePropertyCommand.cxx 3.5 KB

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