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