cmInstalledFile.cxx 2.8 KB

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