cmake/Source/cmInstalledFile.cxx

108 lines
2.7 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
2020-02-01 23:06:01 +01:00
#include <utility>
#include "cmGeneratorExpression.h"
2023-07-02 19:51:09 +02:00
#include "cmList.h"
2016-10-30 18:24:19 +01:00
#include "cmListFileCache.h"
2016-07-09 11:21:54 +02:00
#include "cmMakefile.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2016-10-30 18:24:19 +01:00
2019-11-11 23:01:05 +01:00
cmInstalledFile::cmInstalledFile() = default;
2015-04-27 22:25:09 +02:00
2020-08-30 11:54:41 +02:00
cmInstalledFile::~cmInstalledFile() = default;
2015-04-27 22:25:09 +02:00
2019-11-11 23:01:05 +01:00
cmInstalledFile::Property::Property() = default;
2015-08-17 11:37:30 +02:00
2020-08-30 11:54:41 +02:00
cmInstalledFile::Property::~Property() = default;
2015-08-17 11:37:30 +02:00
2015-04-27 22:25:09 +02:00
void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name)
{
cmListFileBacktrace backtrace = mf->GetBacktrace();
2023-05-23 16:38:00 +02:00
cmGeneratorExpression ge(*mf->GetCMakeInstance(), backtrace);
2015-04-27 22:25:09 +02:00
this->Name = name;
2020-08-30 11:54:41 +02:00
this->NameExpression = ge.Parse(name);
2015-04-27 22:25:09 +02:00
}
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,
2020-08-30 11:54:41 +02:00
const std::string& prop,
const std::string& 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,
2020-08-30 11:54:41 +02:00
const std::string& value,
bool /*asString*/)
2015-04-27 22:25:09 +02:00
{
cmListFileBacktrace backtrace = mf->GetBacktrace();
2023-05-23 16:38:00 +02:00
cmGeneratorExpression ge(*mf->GetCMakeInstance(), backtrace);
2015-04-27 22:25:09 +02:00
Property& property = this->Properties[prop];
2020-08-30 11:54:41 +02:00
property.ValueExpressions.push_back(ge.Parse(value));
2015-04-27 22:25:09 +02:00
}
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
{
2020-02-01 23:06:01 +01:00
auto 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;
2020-08-30 11:54:41 +02:00
for (const 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);
2020-02-01 23:06:01 +01:00
return isSet && cmIsOn(value);
2015-04-27 22:25:09 +02:00
}
2023-07-02 19:51:09 +02:00
std::vector<std::string> cmInstalledFile::GetPropertyAsList(
const std::string& prop) const
2015-04-27 22:25:09 +02:00
{
std::string value;
this->GetProperty(prop, value);
2023-07-02 19:51:09 +02:00
return std::move(cmList(value).data());
2015-04-27 22:25:09 +02:00
}