cmInstalledFile.cxx 2.7 KB

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