cmInstalledFile.cxx 2.6 KB

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