cmInstalledFile.cxx 2.7 KB

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