cmInstalledFile.cxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2014 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 "cmInstalledFile.h"
  11. #include "cmSystemTools.h"
  12. #include "cmMakefile.h"
  13. #include "cmAlgorithms.h"
  14. //----------------------------------------------------------------------------
  15. cmInstalledFile::cmInstalledFile():
  16. NameExpression(0)
  17. {
  18. }
  19. //----------------------------------------------------------------------------
  20. cmInstalledFile::~cmInstalledFile()
  21. {
  22. if(NameExpression)
  23. {
  24. delete NameExpression;
  25. }
  26. }
  27. cmInstalledFile::Property::Property()
  28. {
  29. }
  30. cmInstalledFile::Property::~Property()
  31. {
  32. cmDeleteAll(this->ValueExpressions);
  33. }
  34. //----------------------------------------------------------------------------
  35. void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name)
  36. {
  37. cmListFileBacktrace backtrace = mf->GetBacktrace();
  38. cmGeneratorExpression ge(backtrace);
  39. this->Name = name;
  40. this->NameExpression = ge.Parse(name).release();
  41. }
  42. //----------------------------------------------------------------------------
  43. std::string const& cmInstalledFile::GetName() const
  44. {
  45. return this->Name;
  46. }
  47. //----------------------------------------------------------------------------
  48. cmCompiledGeneratorExpression const& cmInstalledFile::GetNameExpression() const
  49. {
  50. return *(this->NameExpression);
  51. }
  52. //----------------------------------------------------------------------------
  53. void cmInstalledFile::RemoveProperty(const std::string& prop)
  54. {
  55. this->Properties.erase(prop);
  56. }
  57. //----------------------------------------------------------------------------
  58. void cmInstalledFile::SetProperty(cmMakefile const* mf,
  59. const std::string& prop, const char* value)
  60. {
  61. this->RemoveProperty(prop);
  62. this->AppendProperty(mf, prop, value);
  63. }
  64. //----------------------------------------------------------------------------
  65. void cmInstalledFile::AppendProperty(cmMakefile const* mf,
  66. const std::string& prop, const char* value, bool /*asString*/)
  67. {
  68. cmListFileBacktrace backtrace = mf->GetBacktrace();
  69. cmGeneratorExpression ge(backtrace);
  70. Property& property = this->Properties[prop];
  71. property.ValueExpressions.push_back(ge.Parse(value).release());
  72. }
  73. //----------------------------------------------------------------------------
  74. bool cmInstalledFile::HasProperty(
  75. const std::string& prop) const
  76. {
  77. return this->Properties.find(prop) != this->Properties.end();
  78. }
  79. //----------------------------------------------------------------------------
  80. bool cmInstalledFile::GetProperty(
  81. const std::string& prop, std::string& value) const
  82. {
  83. PropertyMapType::const_iterator i = this->Properties.find(prop);
  84. if(i == this->Properties.end())
  85. {
  86. return false;
  87. }
  88. Property const& property = i->second;
  89. std::string output;
  90. std::string separator;
  91. for(ExpressionVectorType::const_iterator
  92. j = property.ValueExpressions.begin();
  93. j != property.ValueExpressions.end(); ++j)
  94. {
  95. output += separator;
  96. output += (*j)->GetInput();
  97. separator = ";";
  98. }
  99. value = output;
  100. return true;
  101. }
  102. //----------------------------------------------------------------------------
  103. bool cmInstalledFile::GetPropertyAsBool(const std::string& prop) const
  104. {
  105. std::string value;
  106. bool isSet = this->GetProperty(prop, value);
  107. return isSet && cmSystemTools::IsOn(value.c_str());
  108. }
  109. //----------------------------------------------------------------------------
  110. void cmInstalledFile::GetPropertyAsList(const std::string& prop,
  111. std::vector<std::string>& list) const
  112. {
  113. std::string value;
  114. this->GetProperty(prop, value);
  115. list.clear();
  116. cmSystemTools::ExpandListArgument(value, list);
  117. }