/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 "cmDiagnosticContext.h" |
9 | | #include "cmGeneratorExpression.h" |
10 | | #include "cmInstallType.h" |
11 | | #include "cmList.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 filePermissions, std::string dirPermissions, |
20 | | std::vector<std::string> const& configurations, std::string const& component, |
21 | | std::vector<std::string> buildDepends, MessageLevel message, |
22 | | bool excludeFromAll, std::string literalArgs, bool optional, |
23 | | cmDiagnosticContext context) |
24 | 0 | : cmInstallGenerator(dest, configurations, component, message, |
25 | 0 | excludeFromAll, false, std::move(context)) |
26 | 0 | , Directories(dirs) |
27 | 0 | , FilePermissions(std::move(filePermissions)) |
28 | 0 | , DirPermissions(std::move(dirPermissions)) |
29 | 0 | , LiteralArguments(std::move(literalArgs)) |
30 | 0 | , BuildDepends(std::move(buildDepends)) |
31 | 0 | , Optional(optional) |
32 | 0 | { |
33 | | // We need per-config actions if destination have generator expressions. |
34 | 0 | if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) { |
35 | 0 | this->ActionsPerConfig = true; |
36 | 0 | } |
37 | | |
38 | | // We need per-config actions if any directories have generator expressions. |
39 | 0 | if (!this->ActionsPerConfig) { |
40 | 0 | for (std::string const& dir : dirs) { |
41 | 0 | if (cmGeneratorExpression::Find(dir) != std::string::npos) { |
42 | 0 | this->ActionsPerConfig = true; |
43 | 0 | break; |
44 | 0 | } |
45 | 0 | } |
46 | 0 | } |
47 | 0 | } |
48 | | |
49 | 0 | cmInstallDirectoryGenerator::~cmInstallDirectoryGenerator() = default; |
50 | | |
51 | | bool cmInstallDirectoryGenerator::Compute(cmLocalGenerator* lg) |
52 | 0 | { |
53 | 0 | this->LocalGenerator = lg; |
54 | 0 | return this->ResolveBuildDepends(lg, "DIRECTORY", this->BuildDepends, |
55 | 0 | this->ResolvedBuildDepends); |
56 | 0 | } |
57 | | |
58 | | void cmInstallDirectoryGenerator::GetInstallBuildDependencies( |
59 | | std::string const& config, std::vector<BuildDependency>& dependencies) const |
60 | 0 | { |
61 | 0 | AddBuildDependsDependencies(this->LocalGenerator, config, |
62 | 0 | this->ResolvedBuildDepends, dependencies); |
63 | 0 | } |
64 | | |
65 | | std::vector<std::string> cmInstallDirectoryGenerator::GetDirectories( |
66 | | std::string const& config) const |
67 | 0 | { |
68 | | // If given only empty directories, collapse into a single specification to |
69 | | // avoid redundant calls. This supports the use case of installing an empty |
70 | | // directory into a destination when a directory is not specified. |
71 | 0 | if (std::all_of(this->Directories.begin(), this->Directories.end(), |
72 | 0 | [](std::string const& d) { return d.empty(); })) { |
73 | 0 | return std::vector<std::string>{ "" }; |
74 | 0 | } |
75 | 0 | cmList directories; |
76 | 0 | if (this->ActionsPerConfig) { |
77 | 0 | for (std::string const& f : this->Directories) { |
78 | 0 | directories.append( |
79 | 0 | cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config)); |
80 | 0 | } |
81 | 0 | } else { |
82 | 0 | directories = this->Directories; |
83 | 0 | } |
84 | 0 | return std::move(directories.data()); |
85 | 0 | } |
86 | | |
87 | | void cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os, |
88 | | Indent indent) |
89 | 0 | { |
90 | 0 | if (this->ActionsPerConfig) { |
91 | 0 | this->cmInstallGenerator::GenerateScriptActions(os, indent); |
92 | 0 | } else { |
93 | 0 | this->AddDirectoryInstallRule(os, "", indent, this->Directories); |
94 | 0 | } |
95 | 0 | } |
96 | | |
97 | | void cmInstallDirectoryGenerator::GenerateScriptForConfig( |
98 | | std::ostream& os, std::string const& config, Indent indent) |
99 | 0 | { |
100 | 0 | std::vector<std::string> dirs = this->GetDirectories(config); |
101 | |
|
102 | 0 | if (!(dirs.size() == 1 && dirs[0].empty())) { |
103 | | // Make sure all dirs have absolute paths. |
104 | 0 | cmMakefile const& mf = *this->LocalGenerator->GetMakefile(); |
105 | 0 | for (std::string& d : dirs) { |
106 | 0 | if (!cmSystemTools::FileIsFullPath(d)) { |
107 | 0 | d = cmStrCat(mf.GetCurrentSourceDirectory(), '/', std::move(d)); |
108 | 0 | } |
109 | 0 | } |
110 | 0 | } |
111 | |
|
112 | 0 | this->AddDirectoryInstallRule(os, config, indent, dirs); |
113 | 0 | } |
114 | | |
115 | | void cmInstallDirectoryGenerator::AddDirectoryInstallRule( |
116 | | std::ostream& os, std::string const& config, Indent indent, |
117 | | std::vector<std::string> const& dirs) |
118 | 0 | { |
119 | | // Write code to install the directories. |
120 | 0 | char const* noRename = nullptr; |
121 | 0 | this->AddInstallRule(os, this->GetDestination(config), |
122 | 0 | cmInstallType_DIRECTORY, dirs, this->Optional, |
123 | 0 | this->FilePermissions.c_str(), |
124 | 0 | this->DirPermissions.c_str(), noRename, |
125 | 0 | this->LiteralArguments.c_str(), indent); |
126 | 0 | } |
127 | | |
128 | | std::string cmInstallDirectoryGenerator::GetDestination( |
129 | | std::string const& config) const |
130 | 0 | { |
131 | 0 | std::string dest = cmGeneratorExpression::Evaluate( |
132 | 0 | this->Destination, this->LocalGenerator, config); |
133 | 0 | this->CheckAbsoluteDestination(dest, this->LocalGenerator); |
134 | 0 | return dest; |
135 | 0 | } |