cmake/Source/cmInstalledFile.cxx

117 lines
2.8 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2015-04-27 22:25:09 +02:00
#include "cmInstalledFile.h"
2016-07-09 11:21:54 +02:00
2015-08-17 11:37:30 +02:00
#include "cmAlgorithms.h"
2016-10-30 18:24:19 +01:00
#include "cmListFileCache.h"
2016-07-09 11:21:54 +02:00
#include "cmMakefile.h"
#include "cmSystemTools.h"
2015-04-27 22:25:09 +02:00
2016-10-30 18:24:19 +01:00
#include <utility>
2016-07-09 11:21:54 +02:00
cmInstalledFile::cmInstalledFile()
2018-01-26 17:06:56 +01:00
: NameExpression(nullptr)
2015-04-27 22:25:09 +02:00
{
}
cmInstalledFile::~cmInstalledFile()
{
2018-01-26 17:06:56 +01:00
delete NameExpression;
2015-04-27 22:25:09 +02:00
}
2015-08-17 11:37:30 +02:00
cmInstalledFile::Property::Property()
{
}
cmInstalledFile::Property::~Property()
{
cmDeleteAll(this->ValueExpressions);
}
2015-04-27 22:25:09 +02:00
void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name)
{
cmListFileBacktrace backtrace = mf->GetBacktrace();
2015-11-17 17:22:37 +01:00
cmGeneratorExpression ge(backtrace);
2015-04-27 22:25:09 +02:00
this->Name = name;
this->NameExpression = ge.Parse(name).release();
}
std::string const& cmInstalledFile::GetName() const
{
return this->Name;
}
cmCompiledGeneratorExpression const& cmInstalledFile::GetNameExpression() const
{
return *(this->NameExpression);
}
void cmInstalledFile::RemoveProperty(const std::string& prop)
{
this->Properties.erase(prop);
}
void cmInstalledFile::SetProperty(cmMakefile const* mf,
2016-07-09 11:21:54 +02:00
const std::string& prop, const char* value)
2015-04-27 22:25:09 +02:00
{
this->RemoveProperty(prop);
this->AppendProperty(mf, prop, value);
}
void cmInstalledFile::AppendProperty(cmMakefile const* mf,
2016-07-09 11:21:54 +02:00
const std::string& prop,
const char* value, bool /*asString*/)
2015-04-27 22:25:09 +02:00
{
cmListFileBacktrace backtrace = mf->GetBacktrace();
2015-11-17 17:22:37 +01:00
cmGeneratorExpression ge(backtrace);
2015-04-27 22:25:09 +02:00
Property& property = this->Properties[prop];
property.ValueExpressions.push_back(ge.Parse(value).release());
}
2016-07-09 11:21:54 +02:00
bool cmInstalledFile::HasProperty(const std::string& prop) const
2015-04-27 22:25:09 +02:00
{
return this->Properties.find(prop) != this->Properties.end();
}
2016-07-09 11:21:54 +02:00
bool cmInstalledFile::GetProperty(const std::string& prop,
std::string& value) const
2015-04-27 22:25:09 +02:00
{
PropertyMapType::const_iterator i = this->Properties.find(prop);
2016-07-09 11:21:54 +02:00
if (i == this->Properties.end()) {
2015-04-27 22:25:09 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
Property const& property = i->second;
std::string output;
std::string separator;
2018-01-26 17:06:56 +01:00
for (auto ve : property.ValueExpressions) {
2015-04-27 22:25:09 +02:00
output += separator;
2018-01-26 17:06:56 +01:00
output += ve->GetInput();
2015-04-27 22:25:09 +02:00
separator = ";";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
value = output;
return true;
}
bool cmInstalledFile::GetPropertyAsBool(const std::string& prop) const
{
std::string value;
bool isSet = this->GetProperty(prop, value);
return isSet && cmSystemTools::IsOn(value.c_str());
}
void cmInstalledFile::GetPropertyAsList(const std::string& prop,
2016-07-09 11:21:54 +02:00
std::vector<std::string>& list) const
2015-04-27 22:25:09 +02:00
{
std::string value;
this->GetProperty(prop, value);
list.clear();
cmSystemTools::ExpandListArgument(value, list);
}