cmInstalledFile.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. delete NameExpression;
  16. }
  17. cmInstalledFile::Property::Property()
  18. {
  19. }
  20. cmInstalledFile::Property::~Property()
  21. {
  22. cmDeleteAll(this->ValueExpressions);
  23. }
  24. void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name)
  25. {
  26. cmListFileBacktrace backtrace = mf->GetBacktrace();
  27. cmGeneratorExpression ge(backtrace);
  28. this->Name = name;
  29. this->NameExpression = ge.Parse(name).release();
  30. }
  31. std::string const& cmInstalledFile::GetName() const
  32. {
  33. return this->Name;
  34. }
  35. cmCompiledGeneratorExpression const& cmInstalledFile::GetNameExpression() const
  36. {
  37. return *(this->NameExpression);
  38. }
  39. void cmInstalledFile::RemoveProperty(const std::string& prop)
  40. {
  41. this->Properties.erase(prop);
  42. }
  43. void cmInstalledFile::SetProperty(cmMakefile const* mf,
  44. const std::string& prop, const char* value)
  45. {
  46. this->RemoveProperty(prop);
  47. this->AppendProperty(mf, prop, value);
  48. }
  49. void cmInstalledFile::AppendProperty(cmMakefile const* mf,
  50. const std::string& prop,
  51. const char* value, bool /*asString*/)
  52. {
  53. cmListFileBacktrace backtrace = mf->GetBacktrace();
  54. cmGeneratorExpression ge(backtrace);
  55. Property& property = this->Properties[prop];
  56. property.ValueExpressions.push_back(ge.Parse(value).release());
  57. }
  58. bool cmInstalledFile::HasProperty(const std::string& prop) const
  59. {
  60. return this->Properties.find(prop) != this->Properties.end();
  61. }
  62. bool cmInstalledFile::GetProperty(const std::string& prop,
  63. std::string& value) const
  64. {
  65. PropertyMapType::const_iterator i = this->Properties.find(prop);
  66. if (i == this->Properties.end()) {
  67. return false;
  68. }
  69. Property const& property = i->second;
  70. std::string output;
  71. std::string separator;
  72. for (auto ve : property.ValueExpressions) {
  73. output += separator;
  74. output += ve->GetInput();
  75. separator = ";";
  76. }
  77. value = output;
  78. return true;
  79. }
  80. bool cmInstalledFile::GetPropertyAsBool(const std::string& prop) const
  81. {
  82. std::string value;
  83. bool isSet = this->GetProperty(prop, value);
  84. return isSet && cmSystemTools::IsOn(value.c_str());
  85. }
  86. void cmInstalledFile::GetPropertyAsList(const std::string& prop,
  87. std::vector<std::string>& list) const
  88. {
  89. std::string value;
  90. this->GetProperty(prop, value);
  91. list.clear();
  92. cmSystemTools::ExpandListArgument(value, list);
  93. }