resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmInstallFilesGenerator.cxx
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"
4
5 #include <utility>
6
7 #include "cmGeneratorExpression.h"
8 #include "cmInstallType.h"
9 #include "cmListFileCache.h"
10 #include "cmStringAlgorithms.h"
11
12 class cmLocalGenerator;
13
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))
22   , Files(files)
23   , FilePermissions(std::move(file_permissions))
24   , Rename(std::move(rename))
25   , Programs(programs)
26   , Optional(optional)
27 {
28   // We need per-config actions if the destination and rename have generator
29   // expressions.
30   if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) {
31     this->ActionsPerConfig = true;
32   }
33   if (cmGeneratorExpression::Find(this->Rename) != std::string::npos) {
34     this->ActionsPerConfig = true;
35   }
36
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;
42         break;
43       }
44     }
45   }
46 }
47
48 cmInstallFilesGenerator::~cmInstallFilesGenerator() = default;
49
50 bool cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
51 {
52   this->LocalGenerator = lg;
53   return true;
54 }
55
56 std::string cmInstallFilesGenerator::GetDestination(
57   std::string const& config) const
58 {
59   return cmGeneratorExpression::Evaluate(this->Destination,
60                                          this->LocalGenerator, config);
61 }
62
63 std::string cmInstallFilesGenerator::GetRename(std::string const& config) const
64 {
65   return cmGeneratorExpression::Evaluate(this->Rename, this->LocalGenerator,
66                                          config);
67 }
68
69 std::vector<std::string> cmInstallFilesGenerator::GetFiles(
70   std::string const& config) const
71 {
72   std::vector<std::string> files;
73   if (this->ActionsPerConfig) {
74     for (std::string const& f : this->Files) {
75       cmExpandList(
76         cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config),
77         files);
78     }
79   } else {
80     files = this->Files;
81   }
82   return files;
83 }
84
85 void cmInstallFilesGenerator::AddFilesInstallRule(
86   std::ostream& os, std::string const& config, Indent indent,
87   std::vector<std::string> const& files)
88 {
89   // Write code to install the files.
90   const char* no_dir_permissions = nullptr;
91   this->AddInstallRule(
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);
96 }
97
98 void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
99                                                     Indent indent)
100 {
101   if (this->ActionsPerConfig) {
102     this->cmInstallGenerator::GenerateScriptActions(os, indent);
103   } else {
104     this->AddFilesInstallRule(os, "", indent, this->Files);
105   }
106 }
107
108 void cmInstallFilesGenerator::GenerateScriptForConfig(
109   std::ostream& os, const std::string& config, Indent indent)
110 {
111   std::vector<std::string> files = this->GetFiles(config);
112   this->AddFilesInstallRule(os, config, indent, files);
113 }