cmake/Source/cmInstallDirectoryGenerator.cxx

102 lines
3.4 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 "cmInstallDirectoryGenerator.h"
2015-11-17 17:22:37 +01:00
#include "cmGeneratorExpression.h"
2016-10-30 18:24:19 +01:00
#include "cmInstallType.h"
2015-11-17 17:22:37 +01:00
#include "cmLocalGenerator.h"
2016-10-30 18:24:19 +01:00
#include "cmMakefile.h"
#include "cmSystemTools.h"
2018-01-26 17:06:56 +01:00
#include <memory> // IWYU pragma: keep
2016-07-09 11:21:54 +02:00
cmInstallDirectoryGenerator::cmInstallDirectoryGenerator(
std::vector<std::string> const& dirs, const char* dest,
const char* file_permissions, const char* dir_permissions,
std::vector<std::string> const& configurations, const char* component,
MessageLevel message, bool exclude_from_all, const char* literal_args,
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
, Directories(dirs)
, FilePermissions(file_permissions)
, DirPermissions(dir_permissions)
, LiteralArguments(literal_args)
, Optional(optional)
{
2015-11-17 17:22:37 +01:00
// We need per-config actions if destination have 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
}
2016-03-13 13:35:51 +01:00
// We need per-config actions if any directories have generator expressions.
2016-07-09 11:21:54 +02:00
for (std::vector<std::string>::const_iterator i = dirs.begin();
!this->ActionsPerConfig && i != dirs.end(); ++i) {
if (cmGeneratorExpression::Find(*i) != std::string::npos) {
2016-03-13 13:35:51 +01:00
this->ActionsPerConfig = true;
}
2016-07-09 11:21:54 +02:00
}
}
2016-07-09 11:21:54 +02:00
cmInstallDirectoryGenerator::~cmInstallDirectoryGenerator()
{
}
2015-11-17 17:22:37 +01:00
void cmInstallDirectoryGenerator::Compute(cmLocalGenerator* lg)
{
LocalGenerator = lg;
}
2016-07-09 11:21:54 +02:00
void cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os,
2017-07-20 19:35:53 +02:00
Indent indent)
2015-11-17 17:22:37 +01:00
{
2016-07-09 11:21:54 +02:00
if (this->ActionsPerConfig) {
2015-11-17 17:22:37 +01:00
this->cmInstallGenerator::GenerateScriptActions(os, indent);
2016-07-09 11:21:54 +02:00
} else {
2016-03-13 13:35:51 +01:00
this->AddDirectoryInstallRule(os, "", indent, this->Directories);
2016-07-09 11:21:54 +02:00
}
2015-11-17 17:22:37 +01:00
}
void cmInstallDirectoryGenerator::GenerateScriptForConfig(
2017-07-20 19:35:53 +02:00
std::ostream& os, const std::string& config, Indent indent)
2015-11-17 17:22:37 +01:00
{
2016-03-13 13:35:51 +01:00
std::vector<std::string> dirs;
cmGeneratorExpression ge;
2018-01-26 17:06:56 +01:00
for (std::string const& d : this->Directories) {
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(d);
2016-07-09 11:21:54 +02:00
cmSystemTools::ExpandListArgument(
cge->Evaluate(this->LocalGenerator, config), dirs);
}
2016-10-30 18:24:19 +01:00
// Make sure all dirs have absolute paths.
cmMakefile const& mf = *this->LocalGenerator->GetMakefile();
2018-01-26 17:06:56 +01:00
for (std::string& d : dirs) {
if (!cmSystemTools::FileIsFullPath(d.c_str())) {
d = std::string(mf.GetCurrentSourceDirectory()) + "/" + d;
2016-10-30 18:24:19 +01:00
}
}
2016-03-13 13:35:51 +01:00
this->AddDirectoryInstallRule(os, config, indent, dirs);
2015-11-17 17:22:37 +01:00
}
void cmInstallDirectoryGenerator::AddDirectoryInstallRule(
2017-07-20 19:35:53 +02:00
std::ostream& os, const std::string& config, Indent indent,
2016-03-13 13:35:51 +01:00
std::vector<std::string> const& dirs)
{
// Write code to install the directories.
2018-01-26 17:06:56 +01:00
const char* no_rename = nullptr;
2016-07-09 11:21:54 +02:00
this->AddInstallRule(os, this->GetDestination(config),
cmInstallType_DIRECTORY, dirs, this->Optional,
this->FilePermissions.c_str(),
2016-07-09 11:21:54 +02:00
this->DirPermissions.c_str(), no_rename,
this->LiteralArguments.c_str(), indent);
}
2015-11-17 17:22:37 +01:00
2016-07-09 11:21:54 +02:00
std::string cmInstallDirectoryGenerator::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
}