cmInstalledFile.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmInstalledFile.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmListFileCache.h"
  6. #include "cmMakefile.h"
  7. #include "cmSystemTools.h"
  8. #include <utility>
  9. cmInstalledFile::cmInstalledFile()
  10. : NameExpression(nullptr)
  11. {
  12. }
  13. cmInstalledFile::~cmInstalledFile()
  14. {
  15. if (NameExpression) {
  16. delete NameExpression;
  17. }
  18. }
  19. cmInstalledFile::Property::Property()
  20. {
  21. }
  22. cmInstalledFile::Property::~Property()
  23. {
  24. cmDeleteAll(this->ValueExpressions);
  25. }
  26. void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name)
  27. {
  28. cmListFileBacktrace backtrace = mf->GetBacktrace();
  29. cmGeneratorExpression ge(backtrace);
  30. this->Name = name;
  31. this->NameExpression = ge.Parse(name).release();
  32. }
  33. std::string const& cmInstalledFile::GetName() const
  34. {
  35. return this->Name;
  36. }
  37. cmCompiledGeneratorExpression const& cmInstalledFile::GetNameExpression() const
  38. {
  39. return *(this->NameExpression);
  40. }
  41. void cmInstalledFile::RemoveProperty(const std::string& prop)
  42. {
  43. this->Properties.erase(prop);
  44. }
  45. void cmInstalledFile::SetProperty(cmMakefile const* mf,
  46. const std::string& prop, const char* value)
  47. {
  48. this->RemoveProperty(prop);
  49. this->AppendProperty(mf, prop, value);
  50. }
  51. void cmInstalledFile::AppendProperty(cmMakefile const* mf,
  52. const std::string& prop,
  53. const char* value, bool /*asString*/)
  54. {
  55. cmListFileBacktrace backtrace = mf->GetBacktrace();
  56. cmGeneratorExpression ge(backtrace);
  57. Property& property = this->Properties[prop];
  58. property.ValueExpressions.push_back(ge.Parse(value).release());
  59. }
  60. bool cmInstalledFile::HasProperty(const std::string& prop) const
  61. {
  62. return this->Properties.find(prop) != this->Properties.end();
  63. }
  64. bool cmInstalledFile::GetProperty(const std::string& prop,
  65. std::string& value) const
  66. {
  67. PropertyMapType::const_iterator i = this->Properties.find(prop);
  68. if (i == this->Properties.end()) {
  69. return false;
  70. }
  71. Property const& property = i->second;
  72. std::string output;
  73. std::string separator;
  74. for (auto ve : property.ValueExpressions) {
  75. output += separator;
  76. output += ve->GetInput();
  77. separator = ";";
  78. }
  79. value = output;
  80. return true;
  81. }
  82. bool cmInstalledFile::GetPropertyAsBool(const std::string& prop) const
  83. {
  84. std::string value;
  85. bool isSet = this->GetProperty(prop, value);
  86. return isSet && cmSystemTools::IsOn(value.c_str());
  87. }
  88. void cmInstalledFile::GetPropertyAsList(const std::string& prop,
  89. std::vector<std::string>& list) const
  90. {
  91. std::string value;
  92. this->GetProperty(prop, value);
  93. list.clear();
  94. cmSystemTools::ExpandListArgument(value, list);
  95. }