cmPropertyMap.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "cmPropertyMap.h"
  14. #include "cmSystemTools.h"
  15. #include "cmake.h"
  16. cmProperty *cmPropertyMap::GetOrCreateProperty(const char *name)
  17. {
  18. cmPropertyMap::iterator it = this->find(name);
  19. cmProperty *prop;
  20. if (it == this->end())
  21. {
  22. prop = &(*this)[name];
  23. }
  24. else
  25. {
  26. prop = &(it->second);
  27. }
  28. return prop;
  29. }
  30. void cmPropertyMap::SetProperty(const char *name, const char *value,
  31. cmProperty::ScopeType scope)
  32. {
  33. if (!name)
  34. {
  35. return;
  36. }
  37. if(!value)
  38. {
  39. this->erase(name);
  40. return;
  41. }
  42. #ifdef CMAKE_STRICT
  43. if (!this->CMakeInstance)
  44. {
  45. cmSystemTools::Error("CMakeInstance not set on a property map!");
  46. abort();
  47. }
  48. else if (!this->CMakeInstance->IsPropertyDefined(name,scope))
  49. {
  50. // is a property being queried without being defined first? If so then
  51. // report it as we probably need to document it
  52. std::string msg = "Property ";
  53. msg += name;
  54. msg += " set yet undefined on ";
  55. switch (scope)
  56. {
  57. case cmProperty::TARGET:
  58. msg += "target.";
  59. break;
  60. case cmProperty::SOURCE_FILE:
  61. msg += "source file.";
  62. break;
  63. case cmProperty::DIRECTORY:
  64. msg += "directory.";
  65. break;
  66. case cmProperty::TEST:
  67. msg += "test.";
  68. break;
  69. case cmProperty::VARIABLE:
  70. msg += "variable.";
  71. break;
  72. case cmProperty::CACHED_VARIABLE:
  73. msg += "cached variable.";
  74. break;
  75. default:
  76. msg += "unknown.";
  77. break;
  78. }
  79. cmSystemTools::Error(msg.c_str());
  80. }
  81. #else
  82. (void)scope;
  83. #endif
  84. cmProperty *prop = this->GetOrCreateProperty(name);
  85. prop->Set(name,value);
  86. }
  87. const char *cmPropertyMap
  88. ::GetPropertyValue(const char *name,
  89. cmProperty::ScopeType scope,
  90. bool &chain) const
  91. {
  92. chain = false;
  93. if (!name)
  94. {
  95. return 0;
  96. }
  97. // has the property been defined?
  98. #ifdef CMAKE_STRICT
  99. if (!this->CMakeInstance)
  100. {
  101. cmSystemTools::Error("CMakeInstance not set on a property map!");
  102. abort();
  103. }
  104. else if (!this->CMakeInstance->IsPropertyDefined(name,scope))
  105. {
  106. // is a property being queried without being defined first? If so then
  107. // report it as we probably need to document it
  108. std::string msg = "Property ";
  109. msg += name;
  110. msg += " queried yet undefined on ";
  111. switch (scope)
  112. {
  113. case cmProperty::TARGET:
  114. msg += "target.";
  115. break;
  116. case cmProperty::SOURCE_FILE:
  117. msg += "source file.";
  118. break;
  119. case cmProperty::DIRECTORY:
  120. msg += "directory.";
  121. break;
  122. case cmProperty::TEST:
  123. msg += "test.";
  124. break;
  125. case cmProperty::VARIABLE:
  126. msg += "variable.";
  127. break;
  128. case cmProperty::CACHED_VARIABLE:
  129. msg += "cached variable.";
  130. break;
  131. default:
  132. msg += "unknown.";
  133. break;
  134. }
  135. cmSystemTools::Error(msg.c_str());
  136. }
  137. #endif
  138. cmPropertyMap::const_iterator it = this->find(name);
  139. if (it == this->end())
  140. {
  141. // should we chain up?
  142. if (this->CMakeInstance)
  143. {
  144. chain = this->CMakeInstance->IsPropertyChained(name,scope);
  145. }
  146. return 0;
  147. }
  148. return it->second.GetValue();
  149. }