/src/CMake/Source/cmInstallDirectoryGenerator.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmInstallDirectoryGenerator.h" |
4 | | |
5 | | #include <algorithm> |
6 | | #include <utility> |
7 | | |
8 | | #include "cmGeneratorExpression.h" |
9 | | #include "cmInstallType.h" |
10 | | #include "cmList.h" |
11 | | #include "cmListFileCache.h" |
12 | | #include "cmLocalGenerator.h" |
13 | | #include "cmMakefile.h" |
14 | | #include "cmStringAlgorithms.h" |
15 | | #include "cmSystemTools.h" |
16 | | |
17 | | cmInstallDirectoryGenerator::cmInstallDirectoryGenerator( |
18 | | std::vector<std::string> const& dirs, std::string const& dest, |
19 | | std::string file_permissions, std::string dir_permissions, |
20 | | std::vector<std::string> const& configurations, std::string const& component, |
21 | | MessageLevel message, bool exclude_from_all, std::string literal_args, |
22 | | bool optional, cmListFileBacktrace backtrace) |
23 | 0 | : cmInstallGenerator(dest, configurations, component, message, |
24 | 0 | exclude_from_all, false, std::move(backtrace)) |
25 | 0 | , Directories(dirs) |
26 | 0 | , FilePermissions(std::move(file_permissions)) |
27 | 0 | , DirPermissions(std::move(dir_permissions)) |
28 | 0 | , LiteralArguments(std::move(literal_args)) |
29 | 0 | , Optional(optional) |
30 | 0 | { |
31 | | // We need per-config actions if destination have generator expressions. |
32 | 0 | if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) { |
33 | 0 | this->ActionsPerConfig = true; |
34 | 0 | } |
35 | | |
36 | | // We need per-config actions if any directories have generator expressions. |
37 | 0 | if (!this->ActionsPerConfig) { |
38 | 0 | for (std::string const& dir : dirs) { |
39 | 0 | if (cmGeneratorExpression::Find(dir) != std::string::npos) { |
40 | 0 | this->ActionsPerConfig = true; |
41 | 0 | break; |
42 | 0 | } |
43 | 0 | } |
44 | 0 | } |
45 | 0 | } |
46 | | |
47 | 0 | cmInstallDirectoryGenerator::~cmInstallDirectoryGenerator() = default; |
48 | | |
49 | | bool cmInstallDirectoryGenerator::Compute(cmLocalGenerator* lg) |
50 | 0 | { |
51 | 0 | this->LocalGenerator = lg; |
52 | 0 | return true; |
53 | 0 | } |
54 | | |
55 | | std::vector<std::string> cmInstallDirectoryGenerator::GetDirectories( |
56 | | std::string const& config) const |
57 | 0 | { |
58 | | // If given only empty directories, collapse into a single specification to |
59 | | // avoid redundant calls. This supports the use case of installing an empty |
60 | | // directory into a destination when a directory is not specified. |
61 | 0 | if (std::all_of(this->Directories.begin(), this->Directories.end(), |
62 | 0 | [](std::string const& d) { return d.empty(); })) { |
63 | 0 | return std::vector<std::string>{ "" }; |
64 | 0 | } |
65 | 0 | cmList directories; |
66 | 0 | if (this->ActionsPerConfig) { |
67 | 0 | for (std::string const& f : this->Directories) { |
68 | 0 | directories.append( |
69 | 0 | cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config)); |
70 | 0 | } |
71 | 0 | } else { |
72 | 0 | directories = this->Directories; |
73 | 0 | } |
74 | 0 | return std::move(directories.data()); |
75 | 0 | } |
76 | | |
77 | | void cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os, |
78 | | Indent indent) |
79 | 0 | { |
80 | 0 | if (this->ActionsPerConfig) { |
81 | 0 | this->cmInstallGenerator::GenerateScriptActions(os, indent); |
82 | 0 | } else { |
83 | 0 | this->AddDirectoryInstallRule(os, "", indent, this->Directories); |
84 | 0 | } |
85 | 0 | } |
86 | | |
87 | | void cmInstallDirectoryGenerator::GenerateScriptForConfig( |
88 | | std::ostream& os, std::string const& config, Indent indent) |
89 | 0 | { |
90 | 0 | std::vector<std::string> dirs = this->GetDirectories(config); |
91 | |
|
92 | 0 | if (!(dirs.size() == 1 && dirs[0].empty())) { |
93 | | // Make sure all dirs have absolute paths. |
94 | 0 | cmMakefile const& mf = *this->LocalGenerator->GetMakefile(); |
95 | 0 | for (std::string& d : dirs) { |
96 | 0 | if (!cmSystemTools::FileIsFullPath(d)) { |
97 | 0 | d = cmStrCat(mf.GetCurrentSourceDirectory(), '/', d); |
98 | 0 | } |
99 | 0 | } |
100 | 0 | } |
101 | |
|
102 | 0 | this->AddDirectoryInstallRule(os, config, indent, dirs); |
103 | 0 | } |
104 | | |
105 | | void cmInstallDirectoryGenerator::AddDirectoryInstallRule( |
106 | | std::ostream& os, std::string const& config, Indent indent, |
107 | | std::vector<std::string> const& dirs) |
108 | 0 | { |
109 | | // Write code to install the directories. |
110 | 0 | char const* no_rename = nullptr; |
111 | 0 | this->AddInstallRule(os, this->GetDestination(config), |
112 | 0 | cmInstallType_DIRECTORY, dirs, this->Optional, |
113 | 0 | this->FilePermissions.c_str(), |
114 | 0 | this->DirPermissions.c_str(), no_rename, |
115 | 0 | this->LiteralArguments.c_str(), indent); |
116 | 0 | } |
117 | | |
118 | | std::string cmInstallDirectoryGenerator::GetDestination( |
119 | | std::string const& config) const |
120 | 0 | { |
121 | 0 | return cmGeneratorExpression::Evaluate(this->Destination, |
122 | 0 | this->LocalGenerator, config); |
123 | 0 | } |