1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmInstallFilesGenerator.h"
7 #include "cmGeneratorExpression.h"
8 #include "cmInstallType.h"
9 #include "cmListFileCache.h"
10 #include "cmStringAlgorithms.h"
12 class cmLocalGenerator;
14 cmInstallFilesGenerator::cmInstallFilesGenerator(
15 std::vector<std::string> const& files, std::string const& dest,
16 bool programs, std::string file_permissions,
17 std::vector<std::string> const& configurations, std::string const& component,
18 MessageLevel message, bool exclude_from_all, std::string rename,
19 bool optional, cmListFileBacktrace backtrace)
20 : cmInstallGenerator(dest, configurations, component, message,
21 exclude_from_all, false, std::move(backtrace))
23 , FilePermissions(std::move(file_permissions))
24 , Rename(std::move(rename))
28 // We need per-config actions if the destination and rename have generator
30 if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) {
31 this->ActionsPerConfig = true;
33 if (cmGeneratorExpression::Find(this->Rename) != std::string::npos) {
34 this->ActionsPerConfig = true;
37 // We need per-config actions if any directories have generator expressions.
38 if (!this->ActionsPerConfig) {
39 for (std::string const& file : files) {
40 if (cmGeneratorExpression::Find(file) != std::string::npos) {
41 this->ActionsPerConfig = true;
48 cmInstallFilesGenerator::~cmInstallFilesGenerator() = default;
50 bool cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
52 this->LocalGenerator = lg;
56 std::string cmInstallFilesGenerator::GetDestination(
57 std::string const& config) const
59 return cmGeneratorExpression::Evaluate(this->Destination,
60 this->LocalGenerator, config);
63 std::string cmInstallFilesGenerator::GetRename(std::string const& config) const
65 return cmGeneratorExpression::Evaluate(this->Rename, this->LocalGenerator,
69 std::vector<std::string> cmInstallFilesGenerator::GetFiles(
70 std::string const& config) const
72 std::vector<std::string> files;
73 if (this->ActionsPerConfig) {
74 for (std::string const& f : this->Files) {
76 cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config),
85 void cmInstallFilesGenerator::AddFilesInstallRule(
86 std::ostream& os, std::string const& config, Indent indent,
87 std::vector<std::string> const& files)
89 // Write code to install the files.
90 const char* no_dir_permissions = nullptr;
92 os, this->GetDestination(config),
93 (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
94 this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
95 this->GetRename(config).c_str(), nullptr, indent);
98 void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
101 if (this->ActionsPerConfig) {
102 this->cmInstallGenerator::GenerateScriptActions(os, indent);
104 this->AddFilesInstallRule(os, "", indent, this->Files);
108 void cmInstallFilesGenerator::GenerateScriptForConfig(
109 std::ostream& os, const std::string& config, Indent indent)
111 std::vector<std::string> files = this->GetFiles(config);
112 this->AddFilesInstallRule(os, config, indent, files);