cmake/Source/cmInstallFilesGenerator.cxx

92 lines
3.0 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"
2014-08-03 19:52:23 +02:00
#include "cmGeneratorExpression.h"
2016-10-30 18:24:19 +01:00
#include "cmInstallType.h"
2014-08-03 19:52:23 +02:00
#include "cmSystemTools.h"
2018-01-26 17:06:56 +01:00
#include <memory> // IWYU pragma: keep
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(
std::vector<std::string> const& files, const char* dest, bool programs,
const char* file_permissions, std::vector<std::string> const& configurations,
const char* component, MessageLevel message, bool exclude_from_all,
const char* rename, bool optional)
: cmInstallGenerator(dest, configurations, component, message,
exclude_from_all)
2018-01-26 17:06:56 +01:00
, LocalGenerator(nullptr)
2016-07-09 11:21:54 +02:00
, Files(files)
, FilePermissions(file_permissions)
, Rename(rename)
, Programs(programs)
, Optional(optional)
{
2015-11-17 17:22:37 +01:00
// We need per-config actions if the destination has generator expressions.
2016-07-09 11:21:54 +02:00
if (cmGeneratorExpression::Find(Destination) != 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
2014-08-03 19:52:23 +02:00
// We need per-config actions if any files have generator expressions.
2016-07-09 11:21:54 +02:00
for (std::vector<std::string>::const_iterator i = files.begin();
!this->ActionsPerConfig && i != files.end(); ++i) {
if (cmGeneratorExpression::Find(*i) != std::string::npos) {
2014-08-03 19:52:23 +02:00
this->ActionsPerConfig = true;
}
2016-07-09 11:21:54 +02:00
}
}
2016-07-09 11:21:54 +02:00
cmInstallFilesGenerator::~cmInstallFilesGenerator()
{
}
2015-11-17 17:22:37 +01:00
void cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
{
this->LocalGenerator = lg;
}
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
{
cmGeneratorExpression ge;
2016-07-09 11:21:54 +02:00
return ge.Parse(this->Destination)->Evaluate(this->LocalGenerator, config);
2015-11-17 17:22:37 +01: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,
2018-01-26 17:06:56 +01:00
this->Rename.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
{
std::vector<std::string> files;
2015-04-27 22:25:09 +02:00
cmGeneratorExpression ge;
2018-01-26 17:06:56 +01:00
for (std::string const& f : this->Files) {
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(f);
2016-07-09 11:21:54 +02:00
cmSystemTools::ExpandListArgument(
cge->Evaluate(this->LocalGenerator, config), files);
}
2015-11-17 17:22:37 +01:00
this->AddFilesInstallRule(os, config, indent, files);
2014-08-03 19:52:23 +02:00
}