/src/CMake/Source/cmInstallGenerator.h
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 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <functional> |
8 | | #include <iosfwd> |
9 | | #include <string> |
10 | | #include <utility> |
11 | | #include <vector> |
12 | | |
13 | | #include "cmDiagnosticContext.h" |
14 | | #include "cmInstallType.h" |
15 | | #include "cmScriptGenerator.h" |
16 | | |
17 | | class cmLocalGenerator; |
18 | | class cmMakefile; |
19 | | class cmListFileBacktrace; |
20 | | class cmGeneratorTarget; |
21 | | class cmGlobalGenerator; |
22 | | |
23 | | /** \class cmInstallGenerator |
24 | | * \brief Support class for generating install scripts. |
25 | | * |
26 | | */ |
27 | | class cmInstallGenerator : public cmScriptGenerator |
28 | | { |
29 | | public: |
30 | | enum class BuildDependencyType |
31 | | { |
32 | | Normal, |
33 | | InstallArtifact, |
34 | | GeneratedFile, |
35 | | }; |
36 | | |
37 | | struct BuildDependency |
38 | | { |
39 | | BuildDependency(cmGeneratorTarget const* target, BuildDependencyType type, |
40 | | std::string file = std::string()) |
41 | 0 | : Target(target) |
42 | 0 | , Type(type) |
43 | 0 | , File(std::move(file)) |
44 | 0 | { |
45 | 0 | } |
46 | | |
47 | | cmGeneratorTarget const* Target; |
48 | | BuildDependencyType Type; |
49 | | std::string File; // only for GeneratedFile dependencies |
50 | | }; |
51 | | |
52 | | enum MessageLevel |
53 | | { |
54 | | MessageDefault, |
55 | | MessageAlways, |
56 | | MessageLazy, |
57 | | MessageNever |
58 | | }; |
59 | | |
60 | | cmInstallGenerator(std::string destination, |
61 | | std::vector<std::string> const& configurations, |
62 | | std::string component, MessageLevel message, |
63 | | bool excludeFromAll, bool allComponents, |
64 | | cmDiagnosticContext context); |
65 | | ~cmInstallGenerator() override; |
66 | | |
67 | | cmInstallGenerator(cmInstallGenerator const&) = delete; |
68 | | cmInstallGenerator& operator=(cmInstallGenerator const&) = delete; |
69 | | |
70 | | virtual bool HaveInstall(); |
71 | | virtual void CheckCMP0082(bool& haveSubdirectoryInstall, |
72 | | bool& haveInstallAfterSubdirectory); |
73 | | |
74 | | void AddInstallRule( |
75 | | std::ostream& os, std::string const& dest, cmInstallType type, |
76 | | std::vector<std::string> const& files, bool optional = false, |
77 | | char const* permissionsFile = nullptr, |
78 | | char const* permissionsDir = nullptr, char const* rename = nullptr, |
79 | | char const* literalArgs = nullptr, Indent indent = Indent(), |
80 | | char const* filesVar = nullptr); |
81 | | |
82 | | /** Get the install destination as it should appear in the |
83 | | installation script. */ |
84 | | static std::string ConvertToAbsoluteDestination(std::string const& dest); |
85 | | void CheckAbsoluteDestination(std::string const& dest, |
86 | | cmLocalGenerator const* lg) const; |
87 | | |
88 | | /** Test if this generator installs something for a given configuration. */ |
89 | | bool InstallsForConfig(std::string const& config); |
90 | | |
91 | | /** Select message level from CMAKE_INSTALL_MESSAGE or 'never'. */ |
92 | | static MessageLevel SelectMessageLevel(cmMakefile* mf, bool never = false); |
93 | | |
94 | | /** Capture context for generator. */ |
95 | | static cmDiagnosticContext CaptureContext(cmMakefile const& mf); |
96 | | static cmDiagnosticContext CaptureContext(cmMakefile const* mf) |
97 | 0 | { |
98 | 0 | return cmInstallGenerator::CaptureContext(*mf); |
99 | 0 | } |
100 | | |
101 | 0 | virtual bool Compute(cmLocalGenerator*) { return true; } |
102 | | |
103 | | virtual void GetInstallBuildDependencies(std::string const&, |
104 | | std::vector<BuildDependency>&) const |
105 | 0 | { |
106 | 0 | } |
107 | | |
108 | | virtual void GetInstallBuildDependencyComponents( |
109 | | std::vector<std::string>& components) const |
110 | 0 | { |
111 | 0 | if (!this->Component.empty()) { |
112 | 0 | components.push_back(this->Component); |
113 | 0 | } |
114 | 0 | } |
115 | | |
116 | 0 | std::string const& GetComponent() const { return this->Component; } |
117 | | |
118 | 0 | bool GetExcludeFromAll() const { return this->ExcludeFromAll; } |
119 | 0 | bool GetAllComponentsFlag() const { return this->AllComponents; } |
120 | | |
121 | | cmListFileBacktrace const& GetBacktrace() const |
122 | 0 | { |
123 | 0 | return this->Context.GetBacktrace(); |
124 | 0 | } |
125 | | |
126 | | cmDiagnosticContext const& GetDiagnosticContext() const |
127 | 0 | { |
128 | 0 | return this->Context; |
129 | 0 | } |
130 | | |
131 | | static std::string GetDestDirPath(std::string const& file); |
132 | | |
133 | | protected: |
134 | | void GenerateScript(std::ostream& os) override; |
135 | | |
136 | | std::string CreateComponentTest(std::string const& component, |
137 | | bool excludeFromAll, |
138 | | bool allComponents = false); |
139 | | |
140 | | using TweakMethod = |
141 | | std::function<void(std::ostream& os, Indent indent, |
142 | | std::string const& config, std::string const& file)>; |
143 | | static void AddTweak(std::ostream& os, Indent indent, |
144 | | std::string const& config, std::string const& file, |
145 | | TweakMethod const& tweak); |
146 | | static void AddTweak(std::ostream& os, Indent indent, |
147 | | std::string const& config, std::string const& dir, |
148 | | std::vector<std::string> const& files, |
149 | | TweakMethod const& tweak); |
150 | | |
151 | | // BUILD_DEPENDS entries of an install(<signature>) rule, resolved. |
152 | | struct BuildDependsEntries |
153 | | { |
154 | | std::vector<cmGeneratorTarget const*> Targets; |
155 | | std::vector<std::string> Files; |
156 | | }; |
157 | | |
158 | | // Resolve each BUILD_DEPENDS entry to a target or file. Returns false after |
159 | | // reporting an error if an entry names neither a target nor a file that |
160 | | // exists or that the build produces. |
161 | | bool ResolveBuildDepends(cmLocalGenerator* lg, std::string const& signature, |
162 | | std::vector<std::string> const& names, |
163 | | BuildDependsEntries& entries); |
164 | | |
165 | | // Add dependencies for resolved BUILD_DEPENDS entries. |
166 | | static void AddBuildDependsDependencies( |
167 | | cmLocalGenerator* lg, std::string const& config, |
168 | | BuildDependsEntries const& entries, |
169 | | std::vector<BuildDependency>& dependencies); |
170 | | |
171 | | // Add dependencies for the files that the build produces among the given |
172 | | // files. A file linked by a target depends on building that target. Any |
173 | | // other generated file is attributed to the target owning the custom |
174 | | // command that produces it or, if no single target owns it, such as for a |
175 | | // byproduct, to the installing target, if any. |
176 | | static void AddGeneratedFileDependencies( |
177 | | cmGlobalGenerator* gg, std::string const& config, |
178 | | cmGeneratorTarget const* target, std::vector<std::string> const& files, |
179 | | std::vector<BuildDependency>& dependencies); |
180 | | |
181 | | // Information shared by most generator types. |
182 | | std::string Destination; |
183 | | std::string const Component; |
184 | | MessageLevel const Message; |
185 | | bool const ExcludeFromAll; |
186 | | bool const AllComponents; |
187 | | cmDiagnosticContext const Context; |
188 | | }; |