cmake/Source/cmInstallFilesGenerator.cxx

112 lines
3.5 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. */
#include "cmInstallFilesGenerator.h"
2020-08-30 11:54:41 +02:00
#include <utility>
2014-08-03 19:52:23 +02:00
#include "cmGeneratorExpression.h"
2016-10-30 18:24:19 +01:00
#include "cmInstallType.h"
2023-07-02 19:51:09 +02:00
#include "cmList.h"
2022-08-04 22:12:04 +02:00
#include "cmListFileCache.h"
2016-10-30 18:24:19 +01:00
class cmLocalGenerator;
2014-08-03 19:52:23 +02:00
2016-07-09 11:21:54 +02:00
cmInstallFilesGenerator::cmInstallFilesGenerator(
2020-08-30 11:54:41 +02:00
std::vector<std::string> const& files, std::string const& dest,
bool programs, std::string file_permissions,
std::vector<std::string> const& configurations, std::string const& component,
MessageLevel message, bool exclude_from_all, std::string rename,
2021-09-14 00:13:48 +02:00
bool optional, cmListFileBacktrace backtrace)
2016-07-09 11:21:54 +02:00
: cmInstallGenerator(dest, configurations, component, message,
2021-09-14 00:13:48 +02:00
exclude_from_all, false, std::move(backtrace))
2016-07-09 11:21:54 +02:00
, Files(files)
2020-08-30 11:54:41 +02:00
, FilePermissions(std::move(file_permissions))
, Rename(std::move(rename))
2016-07-09 11:21:54 +02:00
, Programs(programs)
, Optional(optional)
{
2021-09-14 00:13:48 +02:00
// We need per-config actions if the destination and rename have generator
// expressions.
if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) {
this->ActionsPerConfig = true;
}
if (cmGeneratorExpression::Find(this->Rename) != std::string::npos) {
2015-11-17 17:22:37 +01:00
this->ActionsPerConfig = true;
2016-07-09 11:21:54 +02:00
}
2015-11-17 17:22:37 +01:00
2019-11-11 23:01:05 +01:00
// We need per-config actions if any directories have generator expressions.
if (!this->ActionsPerConfig) {
for (std::string const& file : files) {
if (cmGeneratorExpression::Find(file) != std::string::npos) {
this->ActionsPerConfig = true;
break;
}
2014-08-03 19:52:23 +02:00
}
2016-07-09 11:21:54 +02:00
}
}
2019-11-11 23:01:05 +01:00
cmInstallFilesGenerator::~cmInstallFilesGenerator() = default;
2019-11-11 23:01:05 +01:00
bool cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
2015-11-17 17:22:37 +01:00
{
this->LocalGenerator = lg;
2019-11-11 23:01:05 +01:00
return true;
2015-11-17 17:22:37 +01:00
}
2016-07-09 11:21:54 +02:00
std::string cmInstallFilesGenerator::GetDestination(
std::string const& config) const
2015-11-17 17:22:37 +01:00
{
2020-02-01 23:06:01 +01:00
return cmGeneratorExpression::Evaluate(this->Destination,
this->LocalGenerator, config);
2015-11-17 17:22:37 +01:00
}
2021-09-14 00:13:48 +02:00
std::string cmInstallFilesGenerator::GetRename(std::string const& config) const
{
return cmGeneratorExpression::Evaluate(this->Rename, this->LocalGenerator,
config);
}
std::vector<std::string> cmInstallFilesGenerator::GetFiles(
std::string const& config) const
{
if (this->ActionsPerConfig) {
2023-07-02 19:51:09 +02:00
cmList files;
2021-09-14 00:13:48 +02:00
for (std::string const& f : this->Files) {
2023-07-02 19:51:09 +02:00
files.append(
cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config));
2021-09-14 00:13:48 +02:00
}
2023-07-02 19:51:09 +02:00
return std::move(files.data());
2021-09-14 00:13:48 +02:00
}
2023-07-02 19:51:09 +02:00
return this->Files;
2021-09-14 00:13:48 +02:00
}
2014-08-03 19:52:23 +02:00
void cmInstallFilesGenerator::AddFilesInstallRule(
2017-07-20 19:35:53 +02:00
std::ostream& os, std::string const& config, Indent indent,
2014-08-03 19:52:23 +02:00
std::vector<std::string> const& files)
{
// Write code to install the files.
2018-01-26 17:06:56 +01:00
const char* no_dir_permissions = nullptr;
2016-07-09 11:21:54 +02:00
this->AddInstallRule(
os, this->GetDestination(config),
(this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
2021-09-14 00:13:48 +02:00
this->GetRename(config).c_str(), nullptr, indent);
}
2014-08-03 19:52:23 +02:00
void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
2017-07-20 19:35:53 +02:00
Indent indent)
2014-08-03 19:52:23 +02:00
{
2016-07-09 11:21:54 +02:00
if (this->ActionsPerConfig) {
2014-08-03 19:52:23 +02:00
this->cmInstallGenerator::GenerateScriptActions(os, indent);
2016-07-09 11:21:54 +02:00
} else {
2015-11-17 17:22:37 +01:00
this->AddFilesInstallRule(os, "", indent, this->Files);
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
}
2016-07-09 11:21:54 +02:00
void cmInstallFilesGenerator::GenerateScriptForConfig(
2017-07-20 19:35:53 +02:00
std::ostream& os, const std::string& config, Indent indent)
2014-08-03 19:52:23 +02:00
{
2021-09-14 00:13:48 +02:00
std::vector<std::string> files = this->GetFiles(config);
2015-11-17 17:22:37 +01:00
this->AddFilesInstallRule(os, config, indent, files);
2014-08-03 19:52:23 +02:00
}