/src/CMake/Source/cmMakefileTargetGenerator.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 <iosfwd> |
8 | | #include <map> |
9 | | #include <memory> |
10 | | #include <set> |
11 | | #include <string> |
12 | | #include <vector> |
13 | | |
14 | | #include "cmCommonTargetGenerator.h" |
15 | | #include "cmGeneratorTarget.h" |
16 | | #include "cmLocalUnixMakefileGenerator3.h" |
17 | | #include "cmOSXBundleGenerator.h" |
18 | | |
19 | | class cmCustomCommandGenerator; |
20 | | class cmGeneratedFileStream; |
21 | | class cmGlobalUnixMakefileGenerator3; |
22 | | class cmLinkLineComputer; |
23 | | class cmOutputConverter; |
24 | | class cmSourceFile; |
25 | | class cmStateDirectory; |
26 | | |
27 | | /** \class cmMakefileTargetGenerator |
28 | | * \brief Support Routines for writing makefiles |
29 | | * |
30 | | */ |
31 | | class cmMakefileTargetGenerator : public cmCommonTargetGenerator |
32 | | { |
33 | | public: |
34 | | // constructor to set the ivars |
35 | | cmMakefileTargetGenerator(cmGeneratorTarget* target); |
36 | | cmMakefileTargetGenerator(cmMakefileTargetGenerator const&) = delete; |
37 | | ~cmMakefileTargetGenerator() override; |
38 | | |
39 | | cmMakefileTargetGenerator& operator=(cmMakefileTargetGenerator const&) = |
40 | | delete; |
41 | | |
42 | | // construct using this factory call |
43 | | static std::unique_ptr<cmMakefileTargetGenerator> New( |
44 | | cmGeneratorTarget* tgt); |
45 | | |
46 | | /* the main entry point for this class. Writes the Makefiles associated |
47 | | with this target */ |
48 | | virtual void WriteRuleFiles() = 0; |
49 | | |
50 | | /* return the number of actions that have progress reporting on them */ |
51 | | virtual unsigned long GetNumberOfProgressActions() |
52 | 0 | { |
53 | 0 | return this->NumberOfProgressActions; |
54 | 0 | } |
55 | 0 | std::string GetProgressFileNameFull() { return this->ProgressFileNameFull; } |
56 | | |
57 | 0 | cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget; } |
58 | | |
59 | | std::string const& GetConfigName() const; |
60 | | |
61 | | protected: |
62 | | void GetDeviceLinkFlags(std::string& linkFlags, |
63 | | std::string const& linkLanguage); |
64 | | void GetTargetLinkFlags(std::string& flags, std::string const& linkLanguage); |
65 | | |
66 | | // create the file and directory etc |
67 | | void CreateRuleFile(); |
68 | | |
69 | | // outputs the rules for object files and custom commands used by |
70 | | // this target |
71 | | void WriteTargetBuildRules(); |
72 | | |
73 | | // write some common code at the top of build.make |
74 | | void WriteCommonCodeRules(); |
75 | | void WriteTargetLanguageFlags(); |
76 | | |
77 | | // write the clean rules for this target |
78 | | void WriteTargetCleanRules(); |
79 | | |
80 | | // write the linker depend rules for this target |
81 | | void WriteTargetLinkDependRules(); |
82 | | // write the depend rules for this target |
83 | | void WriteTargetDependRules(); |
84 | | |
85 | | std::string GetClangTidyReplacementsFilePath( |
86 | | std::string const& directory, cmSourceFile const& source, |
87 | | std::string const& config) const override; |
88 | | |
89 | | // write rules for macOS Application Bundle content. |
90 | | struct MacOSXContentGeneratorType |
91 | | : cmOSXBundleGenerator::MacOSXContentGeneratorType |
92 | | { |
93 | | MacOSXContentGeneratorType(cmMakefileTargetGenerator* gen) |
94 | 0 | : Generator(gen) |
95 | 0 | { |
96 | 0 | } |
97 | | |
98 | | void operator()(cmSourceFile const& source, char const* pkgloc, |
99 | | std::string const& config) override; |
100 | | |
101 | | private: |
102 | | cmMakefileTargetGenerator* Generator; |
103 | | }; |
104 | | friend struct MacOSXContentGeneratorType; |
105 | | |
106 | | // write the rules for an object |
107 | | void WriteObjectRuleFiles(cmSourceFile const& source); |
108 | | |
109 | | // write the depend.make file for an object |
110 | | void WriteObjectDependRules(cmSourceFile const& source, |
111 | | std::vector<std::string>& depends); |
112 | | |
113 | | // CUDA device linking. |
114 | | void WriteDeviceLinkRule(std::vector<std::string>& commands, |
115 | | std::string const& output); |
116 | | |
117 | | // write the build rule for a custom command |
118 | | void GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg); |
119 | | |
120 | | // write a rule to drive building of more than one output from |
121 | | // another rule |
122 | | void GenerateExtraOutput(char const* out, char const* in, |
123 | | bool symbolic = false); |
124 | | |
125 | | void MakeEchoProgress(cmLocalUnixMakefileGenerator3::EchoProgress&) const; |
126 | | |
127 | | // write out the variable that lists the objects for this target |
128 | | void WriteObjectsVariable(std::string& variableName, |
129 | | std::string& variableNameExternal, |
130 | | bool useWatcomQuote); |
131 | | void WriteObjectsStrings(std::vector<std::string>& objStrings, |
132 | | bool useWatcomQuote, |
133 | | std::string::size_type limit = std::string::npos); |
134 | | |
135 | | // write the driver rule to build target outputs |
136 | | void WriteTargetDriverRule(std::string const& main_output, bool relink); |
137 | | |
138 | | void DriveCustomCommands(std::vector<std::string>& depends); |
139 | | |
140 | | // append intertarget dependencies |
141 | | void AppendTargetDepends(std::vector<std::string>& depends, |
142 | | bool ignoreType = false); |
143 | | |
144 | | // Append object file dependencies. |
145 | | void AppendObjectDepends(std::vector<std::string>& depends); |
146 | | |
147 | | // Append link rule dependencies (objects, etc.). |
148 | | void AppendLinkDepends(std::vector<std::string>& depends, |
149 | | std::string const& linkLanguage); |
150 | | |
151 | | // Lookup the link rule for this target. |
152 | | std::string GetLinkRule(std::string const& linkRuleVar); |
153 | | |
154 | | /** Create a script to hold link rules and a command to invoke the |
155 | | script at build time. */ |
156 | | void CreateLinkScript(char const* name, |
157 | | std::vector<std::string> const& link_commands, |
158 | | std::vector<std::string>& makefile_commands, |
159 | | std::vector<std::string>& makefile_depends); |
160 | | |
161 | | std::unique_ptr<cmLinkLineComputer> CreateLinkLineComputer( |
162 | | cmOutputConverter* outputConverter, cmStateDirectory const& stateDir); |
163 | | |
164 | | /** Create a response file with the given set of options. Returns |
165 | | the relative path from the target build working directory to the |
166 | | response file name. */ |
167 | | std::string CreateResponseFile(std::string const& name, |
168 | | std::string const& options, |
169 | | std::vector<std::string>& makefile_depends, |
170 | | std::string const& language); |
171 | | |
172 | | bool CheckUseResponseFileForObjects(std::string const& l) const; |
173 | | bool CheckUseResponseFileForLibraries(std::string const& l) const; |
174 | | |
175 | | enum ResponseFlagFor |
176 | | { |
177 | | Link, |
178 | | DeviceLink |
179 | | }; |
180 | | |
181 | | /** Create list of flags for link libraries. */ |
182 | | void CreateLinkLibs(cmLinkLineComputer* linkLineComputer, |
183 | | std::string& linkLibs, bool useResponseFile, |
184 | | std::vector<std::string>& makefile_depends, |
185 | | std::string const& linkLanguage, |
186 | | ResponseFlagFor responseMode = ResponseFlagFor::Link); |
187 | | |
188 | | /** Create lists of object files for linking and cleaning. */ |
189 | | void CreateObjectLists(bool useLinkScript, bool useArchiveRules, |
190 | | bool useResponseFile, std::string& buildObjs, |
191 | | std::vector<std::string>& makefile_depends, |
192 | | bool useWatcomQuote, std::string const& linkLanguage, |
193 | | ResponseFlagFor responseMode = ResponseFlagFor::Link); |
194 | | |
195 | | /** Add commands for generate def files */ |
196 | | void GenDefFile(std::vector<std::string>& real_link_commands); |
197 | | |
198 | | void AddIncludeFlags(std::string& flags, std::string const& lang, |
199 | | std::string const& config) override; |
200 | | |
201 | | /** Return the response flag for the given configuration */ |
202 | | std::string GetResponseFlag(ResponseFlagFor mode) const; |
203 | | |
204 | | virtual void CloseFileStreams(); |
205 | | cmLocalUnixMakefileGenerator3* LocalGenerator; |
206 | | cmGlobalUnixMakefileGenerator3* GlobalGenerator; |
207 | | |
208 | | enum CustomCommandDriveType |
209 | | { |
210 | | OnBuild, |
211 | | OnDepends, |
212 | | OnUtility |
213 | | }; |
214 | | CustomCommandDriveType CustomCommandDriver; |
215 | | |
216 | | // the full path to the build file |
217 | | std::string BuildFileName; |
218 | | std::string BuildFileNameFull; |
219 | | |
220 | | // the full path to the progress file |
221 | | std::string ProgressFileNameFull; |
222 | | unsigned long NumberOfProgressActions; |
223 | | bool NoRuleMessages; |
224 | | |
225 | | bool CMP0113New = false; |
226 | | |
227 | | // the path to the directory the build file is in |
228 | | std::string TargetBuildDirectory; |
229 | | std::string TargetBuildDirectoryFull; |
230 | | |
231 | | // the stream for the build file |
232 | | std::unique_ptr<cmGeneratedFileStream> BuildFileStream; |
233 | | |
234 | | // the stream for the flag file |
235 | | std::string FlagFileNameFull; |
236 | | std::unique_ptr<cmGeneratedFileStream> FlagFileStream; |
237 | | class StringList : public std::vector<std::string> |
238 | | { |
239 | | }; |
240 | | std::map<std::string, StringList> FlagFileDepends; |
241 | | |
242 | | // the stream for the info file |
243 | | std::string InfoFileNameFull; |
244 | | std::unique_ptr<cmGeneratedFileStream> InfoFileStream; |
245 | | |
246 | | // files to clean |
247 | | std::set<std::string> CleanFiles; |
248 | | |
249 | | // objects used by this target |
250 | | std::vector<std::string> Objects; |
251 | | std::vector<std::string> ExternalObjects; |
252 | | |
253 | | // Set of object file names that will be built in this directory. |
254 | | std::set<std::string> ObjectFiles; |
255 | | |
256 | | // Set of extra output files to be driven by the build. |
257 | | std::set<std::string> ExtraFiles; |
258 | | |
259 | | // Set of custom command output files to be driven by the build. |
260 | | std::set<std::string> CustomCommandOutputs; |
261 | | |
262 | | using MultipleOutputPairsType = std::map<std::string, std::string>; |
263 | | MultipleOutputPairsType MultipleOutputPairs; |
264 | | bool WriteMakeRule(std::ostream& os, char const* comment, |
265 | | std::vector<std::string> const& outputs, |
266 | | std::vector<std::string> const& depends, |
267 | | std::vector<std::string> const& commands, |
268 | | bool in_help = false); |
269 | | |
270 | | // Target name info. |
271 | | cmGeneratorTarget::Names TargetNames; |
272 | | |
273 | | // macOS content info. |
274 | | std::set<std::string> MacContentFolders; |
275 | | std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator; |
276 | | std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator; |
277 | | }; |