cmInstalledFile.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2014 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmInstalledFile.h"
  11. #include "cmSystemTools.h"
  12. #include "cmMakefile.h"
  13. //----------------------------------------------------------------------------
  14. cmInstalledFile::cmInstalledFile():
  15. NameExpression(0)
  16. {
  17. }
  18. //----------------------------------------------------------------------------
  19. cmInstalledFile::~cmInstalledFile()
  20. {
  21. if(NameExpression)
  22. {
  23. delete NameExpression;
  24. }
  25. }
  26. //----------------------------------------------------------------------------
  27. void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name)
  28. {
  29. cmListFileBacktrace backtrace = mf->GetBacktrace();
  30. cmGeneratorExpression ge(&backtrace);
  31. this->Name = name;
  32. this->NameExpression = ge.Parse(name).release();
  33. }
  34. //----------------------------------------------------------------------------
  35. std::string const& cmInstalledFile::GetName() const
  36. {
  37. return this->Name;
  38. }
  39. //----------------------------------------------------------------------------
  40. cmCompiledGeneratorExpression const& cmInstalledFile::GetNameExpression() const
  41. {
  42. return *(this->NameExpression);
  43. }
  44. //----------------------------------------------------------------------------
  45. void cmInstalledFile::RemoveProperty(const std::string& prop)
  46. {
  47. this->Properties.erase(prop);
  48. }
  49. //----------------------------------------------------------------------------
  50. void cmInstalledFile::SetProperty(cmMakefile const* mf,
  51. const std::string& prop, const char* value)
  52. {
  53. this->RemoveProperty(prop);
  54. this->AppendProperty(mf, prop, value);
  55. }
  56. //----------------------------------------------------------------------------
  57. void cmInstalledFile::AppendProperty(cmMakefile const* mf,
  58. const std::string& prop, const char* value, bool /*asString*/)
  59. {
  60. cmListFileBacktrace backtrace = mf->GetBacktrace();
  61. cmGeneratorExpression ge(&backtrace);
  62. Property& property = this->Properties[prop];
  63. property.ValueExpressions.push_back(ge.Parse(value).release());
  64. }
  65. //----------------------------------------------------------------------------
  66. bool cmInstalledFile::GetProperty(
  67. const std::string& prop, std::string& value) const
  68. {
  69. PropertyMapType::const_iterator i = this->Properties.find(prop);
  70. if(i == this->Properties.end())
  71. {
  72. return false;
  73. }
  74. Property const& property = i->second;
  75. std::string output;
  76. std::string separator;
  77. for(ExpressionVectorType::const_iterator
  78. j = property.ValueExpressions.begin();
  79. j != property.ValueExpressions.end(); ++j)
  80. {
  81. output += separator;
  82. output += (*j)->GetInput();
  83. separator = ";";
  84. }
  85. value = output;
  86. return true;
  87. }
  88. //----------------------------------------------------------------------------
  89. bool cmInstalledFile::GetPropertyAsBool(const std::string& prop) const
  90. {
  91. std::string value;
  92. bool isSet = this->GetProperty(prop, value);
  93. return isSet && cmSystemTools::IsOn(value.c_str());
  94. }
  95. //----------------------------------------------------------------------------
  96. void cmInstalledFile::GetPropertyAsList(const std::string& prop,
  97. std::vector<std::string>& list) const
  98. {
  99. std::string value;
  100. this->GetProperty(prop, value);
  101. list.clear();
  102. cmSystemTools::ExpandListArgument(value, list);
  103. }