cmake/Source/cmInstallDirectoryGenerator.cxx

114 lines
3.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. */
#include "cmInstallDirectoryGenerator.h"
2020-08-30 11:54:41 +02:00
#include <utility>
2015-11-17 17:22:37 +01: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"
2015-11-17 17:22:37 +01:00
#include "cmLocalGenerator.h"
2016-10-30 18:24:19 +01:00
#include "cmMakefile.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2016-10-30 18:24:19 +01:00
#include "cmSystemTools.h"
2018-01-26 17:06:56 +01:00
2016-07-09 11:21:54 +02:00
cmInstallDirectoryGenerator::cmInstallDirectoryGenerator(
2020-08-30 11:54:41 +02:00
std::vector<std::string> const& dirs, std::string const& dest,
std::string file_permissions, std::string dir_permissions,
std::vector<std::string> const& configurations, std::string const& component,
MessageLevel message, bool exclude_from_all, std::string literal_args,
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
, Directories(dirs)
2020-08-30 11:54:41 +02:00
, FilePermissions(std::move(file_permissions))
, DirPermissions(std::move(dir_permissions))
, LiteralArguments(std::move(literal_args))
2016-07-09 11:21:54 +02:00
, Optional(optional)
{
2015-11-17 17:22:37 +01:00
// We need per-config actions if destination have generator expressions.
2021-09-14 00:13:48 +02:00
if (cmGeneratorExpression::Find(this->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.
2019-11-11 23:01:05 +01:00
if (!this->ActionsPerConfig) {
for (std::string const& dir : dirs) {
if (cmGeneratorExpression::Find(dir) != std::string::npos) {
this->ActionsPerConfig = true;
break;
}
2016-03-13 13:35:51 +01:00
}
2016-07-09 11:21:54 +02:00
}
}
2019-11-11 23:01:05 +01:00
cmInstallDirectoryGenerator::~cmInstallDirectoryGenerator() = default;
2019-11-11 23:01:05 +01:00
bool cmInstallDirectoryGenerator::Compute(cmLocalGenerator* lg)
2015-11-17 17:22:37 +01:00
{
2019-11-11 23:01:05 +01:00
this->LocalGenerator = lg;
return true;
2015-11-17 17:22:37 +01:00
}
2021-09-14 00:13:48 +02:00
std::vector<std::string> cmInstallDirectoryGenerator::GetDirectories(
std::string const& config) const
{
2023-07-02 19:51:09 +02:00
cmList directories;
2021-09-14 00:13:48 +02:00
if (this->ActionsPerConfig) {
for (std::string const& f : this->Directories) {
2023-07-02 19:51:09 +02:00
directories.append(
cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config));
2021-09-14 00:13:48 +02:00
}
} else {
directories = this->Directories;
}
2023-07-02 19:51:09 +02:00
return std::move(directories.data());
2021-09-14 00:13:48 +02:00
}
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
{
2021-09-14 00:13:48 +02:00
std::vector<std::string> dirs = this->GetDirectories(config);
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) {
2018-04-23 21:13:27 +02:00
if (!cmSystemTools::FileIsFullPath(d)) {
2020-02-01 23:06:01 +01:00
d = cmStrCat(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
{
2020-02-01 23:06:01 +01:00
return cmGeneratorExpression::Evaluate(this->Destination,
this->LocalGenerator, config);
2015-11-17 17:22:37 +01:00
}