cmInstalledFile.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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;
  30. mf->GetBacktrace(backtrace);
  31. cmGeneratorExpression ge(backtrace);
  32. this->Name = name;
  33. this->NameExpression = ge.Parse(name).release();
  34. }
  35. //----------------------------------------------------------------------------
  36. std::string const& cmInstalledFile::GetName() const
  37. {
  38. return this->Name;
  39. }
  40. //----------------------------------------------------------------------------
  41. cmCompiledGeneratorExpression const& cmInstalledFile::GetNameExpression() const
  42. {
  43. return *(this->NameExpression);
  44. }
  45. //----------------------------------------------------------------------------
  46. void cmInstalledFile::RemoveProperty(const std::string& prop)
  47. {
  48. this->Properties.erase(prop);
  49. }
  50. //----------------------------------------------------------------------------
  51. void cmInstalledFile::SetProperty(cmMakefile const* mf,
  52. const std::string& prop, const char* value)
  53. {
  54. this->RemoveProperty(prop);
  55. this->AppendProperty(mf, prop, value);
  56. }
  57. //----------------------------------------------------------------------------
  58. void cmInstalledFile::AppendProperty(cmMakefile const* mf,
  59. const std::string& prop, const char* value, bool /*asString*/)
  60. {
  61. cmListFileBacktrace backtrace;
  62. mf->GetBacktrace(backtrace);
  63. cmGeneratorExpression ge(backtrace);
  64. Property& property = this->Properties[prop];
  65. property.ValueExpressions.push_back(ge.Parse(value).release());
  66. }
  67. //----------------------------------------------------------------------------
  68. bool cmInstalledFile::GetProperty(
  69. const std::string& prop, std::string& value) const
  70. {
  71. PropertyMapType::const_iterator i = this->Properties.find(prop);
  72. if(i == this->Properties.end())
  73. {
  74. return false;
  75. }
  76. Property const& property = i->second;
  77. std::string output;
  78. std::string separator;
  79. for(ExpressionVectorType::const_iterator
  80. j = property.ValueExpressions.begin();
  81. j != property.ValueExpressions.end(); ++j)
  82. {
  83. output += separator;
  84. output += (*j)->GetInput();
  85. separator = ";";
  86. }
  87. value = output;
  88. return true;
  89. }
  90. //----------------------------------------------------------------------------
  91. bool cmInstalledFile::GetPropertyAsBool(const std::string& prop) const
  92. {
  93. std::string value;
  94. bool isSet = this->GetProperty(prop, value);
  95. return isSet && cmSystemTools::IsOn(value.c_str());
  96. }