/src/CMake/Source/cmLocalGenerator.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 <cstddef> |
8 | | #include <iosfwd> |
9 | | #include <map> |
10 | | #include <memory> |
11 | | #include <set> |
12 | | #include <string> |
13 | | #include <unordered_map> |
14 | | #include <utility> |
15 | | #include <vector> |
16 | | |
17 | | #include <cm/optional> |
18 | | #include <cm/string_view> |
19 | | |
20 | | #include "cmCustomCommandTypes.h" |
21 | | #include "cmDiagnosticContext.h" |
22 | | #include "cmDiagnostics.h" |
23 | | #include "cmGeneratorOptions.h" |
24 | | #include "cmGeneratorTarget.h" |
25 | | #include "cmListFileCache.h" |
26 | | #include "cmMessageType.h" // IWYU pragma: keep |
27 | | #include "cmOutputConverter.h" |
28 | | #include "cmPolicies.h" |
29 | | #include "cmStateSnapshot.h" |
30 | | #include "cmStateTypes.h" |
31 | | #include "cmValue.h" |
32 | | |
33 | | class cmCompiledGeneratorExpression; |
34 | | class cmComputeLinkInformation; |
35 | | class cmCustomCommand; |
36 | | class cmCustomCommandGenerator; |
37 | | class cmCustomCommandLines; |
38 | | class cmGlobalGenerator; |
39 | | class cmImplicitDependsList; |
40 | | class cmLinkLineComputer; |
41 | | class cmLinkLineDeviceComputer; |
42 | | class cmMakefile; |
43 | | struct cmObjectLocation; |
44 | | struct cmObjectLocations; |
45 | | class cmRulePlaceholderExpander; |
46 | | class cmSourceFile; |
47 | | class cmSourceGroup; |
48 | | class cmState; |
49 | | class cmTarget; |
50 | | class cmake; |
51 | | |
52 | | template <typename Iter> |
53 | | class cmRange; |
54 | | |
55 | | namespace cm { |
56 | | enum class TargetType; |
57 | | } // namespace cm |
58 | | |
59 | | /** Target and source file which have a specific output. */ |
60 | | struct cmSourcesWithOutput |
61 | | { |
62 | | /** Target with byproduct. */ |
63 | | cmTarget* Target = nullptr; |
64 | | |
65 | | /** Source file with output or byproduct. */ |
66 | | cmSourceFile* Source = nullptr; |
67 | | bool SourceIsByproduct = false; |
68 | | }; |
69 | | |
70 | | /** \class cmLocalGenerator |
71 | | * \brief Create required build files for a directory. |
72 | | * |
73 | | * Subclasses of this abstract class generate makefiles, DSP, etc for various |
74 | | * platforms. This class should never be constructed directly. A |
75 | | * GlobalGenerator will create it and invoke the appropriate commands on it. |
76 | | */ |
77 | | class cmLocalGenerator : public cmOutputConverter |
78 | | { |
79 | | public: |
80 | | cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile); |
81 | | ~cmLocalGenerator() override; |
82 | | |
83 | | /** |
84 | | * Generate the makefile for this directory. |
85 | | */ |
86 | 0 | virtual void Generate() {} |
87 | | |
88 | 0 | virtual void ComputeHomeRelativeOutputPath() {} |
89 | | |
90 | | /** |
91 | | * Calls TraceVSDependencies() on all targets of this generator. |
92 | | */ |
93 | | void TraceDependencies() const; |
94 | | |
95 | | #ifndef CMAKE_BOOTSTRAP |
96 | | /** |
97 | | * Resolve source group genex. |
98 | | */ |
99 | | void ResolveSourceGroupGenex(); |
100 | | #endif |
101 | | |
102 | 0 | virtual void AddHelperCommands() {} |
103 | | |
104 | | /** |
105 | | * Generate the install rules files in this directory. |
106 | | */ |
107 | | void GenerateInstallRules(); |
108 | | |
109 | | /** |
110 | | * Generate the test files for tests. |
111 | | */ |
112 | | void GenerateTestFiles(); |
113 | | |
114 | | /** |
115 | | * Generate a manifest of target files that will be built. |
116 | | */ |
117 | | void ComputeTargetManifest(); |
118 | | |
119 | | bool ComputeTargetCompileFeatures(); |
120 | | |
121 | | bool IsRootMakefile() const; |
122 | | |
123 | | //! Get the makefile for this generator |
124 | 0 | cmMakefile* GetMakefile() const { return this->Makefile; } |
125 | | |
126 | | //! Get the GlobalGenerator this is associated with |
127 | 0 | cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; } |
128 | | cmGlobalGenerator const* GetGlobalGenerator() const |
129 | 0 | { |
130 | 0 | return this->GlobalGenerator; |
131 | 0 | } |
132 | | |
133 | | virtual std::unique_ptr<cmRulePlaceholderExpander> |
134 | | CreateRulePlaceholderExpander( |
135 | | cmBuildStep buildStep = cmBuildStep::Compile) const; |
136 | | |
137 | | std::string GetExeExportFlags(std::string const& linkLanguage, |
138 | | cmGeneratorTarget& tgt) const; |
139 | | |
140 | | cmState* GetState() const; |
141 | | cmStateSnapshot GetStateSnapshot() const; |
142 | | |
143 | | void AddArchitectureFlags(std::string& flags, |
144 | | cmGeneratorTarget const* target, |
145 | | std::string const& lang, std::string const& config, |
146 | | std::string const& filterArch = std::string()); |
147 | | |
148 | | void AddLanguageFlags(std::string& flags, cmGeneratorTarget const* target, |
149 | | cmBuildStep compileOrLink, std::string const& lang, |
150 | | std::string const& config); |
151 | | void AddLanguageFlagsForLinking(std::string& flags, |
152 | | cmGeneratorTarget const* target, |
153 | | std::string const& lang, |
154 | | std::string const& config); |
155 | | void AddFeatureFlags(std::string& flags, cmGeneratorTarget const* target, |
156 | | std::string const& lang, std::string const& config); |
157 | | void AddVisibilityPresetFlags(std::string& flags, |
158 | | cmGeneratorTarget const* target, |
159 | | std::string const& lang); |
160 | | void AddConfigVariableFlags(std::string& flags, std::string const& var, |
161 | | std::string const& config); |
162 | | // Handle prefixes processing (like LINKER:) |
163 | | void AddConfigVariableFlags(std::string& flags, std::string const& var, |
164 | | cmGeneratorTarget const* target, |
165 | | cmBuildStep compileOrLink, |
166 | | std::string const& lang, |
167 | | std::string const& config); |
168 | | void AddColorDiagnosticsFlags(std::string& flags, std::string const& lang); |
169 | | //! Append flags to a string. |
170 | | virtual void AppendFlags(std::string& flags, |
171 | | std::string const& newFlags) const; |
172 | | virtual void AppendFlags(std::string& flags, |
173 | | std::vector<BT<std::string>> const& newFlags) const; |
174 | | virtual void AppendFlagEscape(std::string& flags, |
175 | | std::string const& rawFlag) const; |
176 | | /** |
177 | | * Append flags after parsing, prefixes processing (like LINKER:) and |
178 | | * escaping |
179 | | */ |
180 | | void AppendLinkFlagsWithParsing(std::string& flags, |
181 | | std::string const& newFlags, |
182 | | cmGeneratorTarget const* target, |
183 | | std::string const& lang); |
184 | | void AppendFlags(std::string& flags, std::string const& newFlags, |
185 | | std::string const& name, cmGeneratorTarget const* target, |
186 | | cmBuildStep compileOrLink, std::string const& lang); |
187 | | void AddISPCDependencies(cmGeneratorTarget* target); |
188 | | void AddPchDependencies(cmGeneratorTarget* target); |
189 | | void AddUnityBuild(cmGeneratorTarget* target); |
190 | 0 | virtual void AddXCConfigSources(cmGeneratorTarget* /* target */) {} |
191 | | void AddPerLanguageLinkFlags(std::string& flags, |
192 | | cmGeneratorTarget const* target, |
193 | | std::string const& lang, |
194 | | std::string const& config); |
195 | | void AppendTargetCreationLinkFlags(std::string& flags, |
196 | | cmGeneratorTarget const* target, |
197 | | std::string const& linkLanguage); |
198 | | void AppendLinkerTypeFlags(std::string& flags, cmGeneratorTarget* target, |
199 | | std::string const& config, |
200 | | std::string const& linkLanguage); |
201 | | void AddTargetTypeLinkerFlags(std::string& flags, |
202 | | cmGeneratorTarget const* target, |
203 | | std::string const& lang, |
204 | | std::string const& config); |
205 | | void AddTargetPropertyLinkFlags(std::string& flags, |
206 | | cmGeneratorTarget const* target, |
207 | | std::string const& config); |
208 | | void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target, |
209 | | std::string const& config, |
210 | | std::string const& lang); |
211 | | void AppendPositionIndependentLinkerFlags(std::string& flags, |
212 | | cmGeneratorTarget* target, |
213 | | std::string const& config, |
214 | | std::string const& lang); |
215 | | void AppendWarningAsErrorLinkerFlags(std::string& flags, |
216 | | cmGeneratorTarget* target, |
217 | | std::string const& lang); |
218 | | void AppendDependencyInfoLinkerFlags(std::string& flags, |
219 | | cmGeneratorTarget* target, |
220 | | std::string const& config, |
221 | | std::string const& lang); |
222 | | virtual std::string GetLinkDependencyFile(cmGeneratorTarget* target, |
223 | | std::string const& config) const; |
224 | | void AppendModuleDefinitionFlag(std::string& flags, |
225 | | cmGeneratorTarget const* target, |
226 | | cmLinkLineComputer* linkLineComputer, |
227 | | std::string const& config, |
228 | | std::string const& lang); |
229 | | bool AppendLWYUFlags(std::string& flags, cmGeneratorTarget const* target, |
230 | | std::string const& lang); |
231 | | |
232 | | //! Get the include flags for the current makefile and language |
233 | | std::string GetIncludeFlags(std::vector<std::string> const& includes, |
234 | | cmGeneratorTarget* target, |
235 | | std::string const& lang, |
236 | | std::string const& config, |
237 | | bool forResponseFile = false); |
238 | | |
239 | | using GeneratorTargetVector = |
240 | | std::vector<std::unique_ptr<cmGeneratorTarget>>; |
241 | | GeneratorTargetVector const& GetGeneratorTargets() const |
242 | 0 | { |
243 | 0 | return this->GeneratorTargets; |
244 | 0 | } |
245 | | |
246 | | GeneratorTargetVector const& GetOwnedImportedGeneratorTargets() const |
247 | 0 | { |
248 | 0 | return this->OwnedImportedGeneratorTargets; |
249 | 0 | } |
250 | | |
251 | | void AddGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt); |
252 | | void AddImportedGeneratorTarget(cmGeneratorTarget* gt); |
253 | | void AddOwnedImportedGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt); |
254 | | |
255 | | cmGeneratorTarget* FindLocalNonAliasGeneratorTarget( |
256 | | std::string const& name) const; |
257 | | cmGeneratorTarget* FindGeneratorTargetToUse(std::string const& name) const; |
258 | | |
259 | | /** |
260 | | * Process a list of include directories |
261 | | */ |
262 | | void AppendIncludeDirectories(std::vector<std::string>& includes, |
263 | | std::string const& includes_list, |
264 | | cmSourceFile const& sourceFile) const; |
265 | | void AppendIncludeDirectories(std::vector<std::string>& includes, |
266 | | std::vector<std::string> const& includes_vec, |
267 | | cmSourceFile const& sourceFile) const; |
268 | | |
269 | | /** |
270 | | * Encode a list of preprocessor definitions for the compiler |
271 | | * command line. |
272 | | */ |
273 | | void AppendDefines(std::set<std::string>& defines, |
274 | | std::string const& defines_list) const; |
275 | | void AppendDefines(std::set<std::string>& defines, |
276 | | std::vector<BT<std::string>> const& defines_vec) const; |
277 | | void AppendDefines(std::set<BT<std::string>>& defines, |
278 | | std::string const& defines_list) const; |
279 | | void AppendDefines(std::set<BT<std::string>>& defines, |
280 | | std::vector<BT<std::string>> const& defines_vec) const; |
281 | | |
282 | | /** |
283 | | * Encode a list of compile options for the compiler |
284 | | * command line. |
285 | | */ |
286 | | void AppendCompileOptions(std::string& options, |
287 | | std::string const& options_list, |
288 | | char const* regex = nullptr) const; |
289 | | void AppendCompileOptions(std::string& options, |
290 | | std::vector<std::string> const& options_vec, |
291 | | char const* regex = nullptr) const; |
292 | | void AppendCompileOptions(std::vector<BT<std::string>>& options, |
293 | | std::vector<BT<std::string>> const& options_vec, |
294 | | char const* regex = nullptr) const; |
295 | | |
296 | | /** |
297 | | * Join a set of defines into a definesString with a space separator. |
298 | | */ |
299 | | void JoinDefines(std::set<std::string> const& defines, |
300 | | std::string& definesString, std::string const& lang); |
301 | | |
302 | | /** Lookup and append options associated with a particular feature. */ |
303 | | void AppendFeatureOptions(std::string& flags, std::string const& lang, |
304 | | char const* feature); |
305 | | |
306 | | cmValue GetFeature(std::string const& feature, std::string const& config); |
307 | | |
308 | | /** \brief Get absolute path to dependency \a name |
309 | | * |
310 | | * Translate a dependency as given in CMake code to the name to |
311 | | * appear in a generated build file. |
312 | | * - If \a name is a utility target, returns false. |
313 | | * - If \a name is a CMake target, it will be transformed to the real output |
314 | | * location of that target for the given configuration. |
315 | | * - If \a name is the full path to a file, it will be returned. |
316 | | * - Otherwise \a name is treated as a relative path with respect to |
317 | | * the source directory of this generator. This should only be |
318 | | * used for dependencies of custom commands. |
319 | | */ |
320 | | bool GetRealDependency(std::string const& name, std::string const& config, |
321 | | std::string& dep, cmPolicies::PolicyStatus cmp0212); |
322 | | |
323 | | /** Called from command-line hook to clear dependencies. */ |
324 | 0 | virtual void ClearDependencies(cmMakefile* /* mf */, bool /* verbose */) {} |
325 | | |
326 | | /** Called from command-line hook to update dependencies. */ |
327 | | virtual bool UpdateDependencies(std::string const& /* tgtInfo */, |
328 | | std::string const& /* targetName */, |
329 | | bool /*verbose*/, bool /*color*/) |
330 | 0 | { |
331 | 0 | return true; |
332 | 0 | } |
333 | | |
334 | | /** @brief Get the include directories for the current makefile and language |
335 | | * and optional the compiler implicit include directories. |
336 | | * |
337 | | * @arg stripImplicitDirs Strip all directories found in |
338 | | * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES from the result. |
339 | | * @arg appendAllImplicitDirs Append all directories found in |
340 | | * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES to the result. |
341 | | */ |
342 | | std::vector<BT<std::string>> GetIncludeDirectoriesImplicit( |
343 | | cmGeneratorTarget const* target, std::string const& lang = "C", |
344 | | std::string const& config = "", bool stripImplicitDirs = true, |
345 | | bool appendAllImplicitDirs = false) const; |
346 | | |
347 | | /** @brief Get the include directories for the current makefile and language |
348 | | * and optional the compiler implicit include directories. |
349 | | * |
350 | | * @arg dirs Directories are appended to this list |
351 | | */ |
352 | | void GetIncludeDirectoriesImplicit(std::vector<std::string>& dirs, |
353 | | cmGeneratorTarget const* target, |
354 | | std::string const& lang = "C", |
355 | | std::string const& config = "", |
356 | | bool stripImplicitDirs = true, |
357 | | bool appendAllImplicitDirs = false) const; |
358 | | |
359 | | /** @brief Get the include directories for the current makefile and language. |
360 | | * @arg dirs Include directories are appended to this list |
361 | | */ |
362 | | void GetIncludeDirectories(std::vector<std::string>& dirs, |
363 | | cmGeneratorTarget const* target, |
364 | | std::string const& lang = "C", |
365 | | std::string const& config = "") const; |
366 | | |
367 | | /** @brief Get the include directories for the current makefile and language. |
368 | | * @return The include directory list |
369 | | */ |
370 | | std::vector<BT<std::string>> GetIncludeDirectories( |
371 | | cmGeneratorTarget const* target, std::string const& lang = "C", |
372 | | std::string const& config = "") const; |
373 | | |
374 | | void AddCompileOptions(std::string& flags, cmGeneratorTarget* target, |
375 | | std::string const& lang, std::string const& config); |
376 | | void AddCompileOptions(std::vector<BT<std::string>>& flags, |
377 | | cmGeneratorTarget* target, std::string const& lang, |
378 | | std::string const& config); |
379 | | |
380 | | /** |
381 | | * Add a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a target. |
382 | | */ |
383 | | cmTarget* AddCustomCommandToTarget( |
384 | | std::string const& target, cmCustomCommandType type, |
385 | | std::unique_ptr<cmCustomCommand> cc, |
386 | | cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject); |
387 | | |
388 | | /** |
389 | | * Add a custom command to a source file. |
390 | | */ |
391 | | cmSourceFile* AddCustomCommandToOutput(std::unique_ptr<cmCustomCommand> cc, |
392 | | bool replace = false); |
393 | | |
394 | | /** |
395 | | * Add a utility to the build. A utility target is a command that is run |
396 | | * every time the target is built. |
397 | | */ |
398 | | cmTarget* AddUtilityCommand(std::string const& utilityName, |
399 | | bool excludeFromAll, |
400 | | std::unique_ptr<cmCustomCommand> cc); |
401 | | |
402 | | virtual std::string CreateUtilityOutput( |
403 | | std::string const& targetName, std::vector<std::string> const& byproducts, |
404 | | cmListFileBacktrace const& bt); |
405 | | |
406 | | virtual std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators( |
407 | | cmCustomCommand const& cc, std::string const& config); |
408 | | |
409 | | std::vector<std::string> ExpandCustomCommandOutputPaths( |
410 | | cmCompiledGeneratorExpression const& cge, std::string const& config); |
411 | | std::vector<std::string> ExpandCustomCommandOutputGenex( |
412 | | std::string const& o, cmListFileBacktrace const& bt); |
413 | | |
414 | | /** |
415 | | * Add target byproducts. |
416 | | */ |
417 | | void AddTargetByproducts(cmTarget* target, |
418 | | std::vector<std::string> const& byproducts, |
419 | | cmListFileBacktrace const& bt, |
420 | | cmCommandOrigin origin); |
421 | | |
422 | | enum class OutputRole |
423 | | { |
424 | | Primary, |
425 | | Byproduct, |
426 | | }; |
427 | | |
428 | | /** |
429 | | * Add source file outputs. |
430 | | */ |
431 | | void AddSourceOutputs(cmSourceFile* source, |
432 | | std::vector<std::string> const& outputs, |
433 | | OutputRole role, cmListFileBacktrace const& bt, |
434 | | cmCommandOrigin origin); |
435 | | |
436 | | /** |
437 | | * Return the target if the provided source name is a byproduct of a utility |
438 | | * target or a PRE_BUILD, PRE_LINK, or POST_BUILD command. |
439 | | * Return the source file which has the provided source name as output. |
440 | | */ |
441 | | cmSourcesWithOutput GetSourcesWithOutput(std::string const& name) const; |
442 | | |
443 | | /** |
444 | | * Is there a source file that has the provided source name as an output? |
445 | | * If so then return it. |
446 | | */ |
447 | | cmSourceFile* GetSourceFileWithOutput( |
448 | | std::string const& name, |
449 | | cmSourceOutputKind kind = cmSourceOutputKind::OutputOnly) const; |
450 | | |
451 | | std::string GetProjectName() const; |
452 | | |
453 | | /** Compute the language used to compile the given source file. */ |
454 | | std::string GetSourceFileLanguage(cmSourceFile const& source); |
455 | | |
456 | | // Fill the vector with the target names for the object files, |
457 | | // preprocessed files and assembly files. |
458 | 0 | void GetIndividualFileTargets(std::vector<std::string>&) {} |
459 | | |
460 | | /** |
461 | | * Get the relative path from the generator output directory to a |
462 | | * per-target support directory. |
463 | | */ |
464 | | virtual std::string GetTargetDirectory( |
465 | | cmGeneratorTarget const* target, |
466 | | cmStateEnums::IntermediateDirKind kind) const; |
467 | | |
468 | | cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const; |
469 | | |
470 | | cmake* GetCMakeInstance() const; |
471 | | |
472 | | std::string const& GetSourceDirectory() const; |
473 | | std::string const& GetBinaryDirectory() const; |
474 | | |
475 | | std::string const& GetCurrentBinaryDirectory() const; |
476 | | std::string const& GetCurrentSourceDirectory() const; |
477 | | |
478 | | bool UseShortObjectNames( |
479 | | cmStateEnums::IntermediateDirKind kind = |
480 | | cmStateEnums::IntermediateDirKind::ObjectFiles) const; |
481 | | virtual std::string GetObjectOutputRoot( |
482 | | cmStateEnums::IntermediateDirKind kind = |
483 | | cmStateEnums::IntermediateDirKind::ObjectFiles) const; |
484 | | virtual bool AlwaysUsesCMFPaths() const; |
485 | | virtual std::string GetShortObjectFileName(cmSourceFile const& source) const; |
486 | | virtual std::string ComputeShortTargetDirectory( |
487 | | cmGeneratorTarget const* gt) const; |
488 | | std::string GetCustomObjectFileName(cmSourceFile const& source) const; |
489 | | std::string GetCustomInstallObjectFileName(cmSourceFile const& source, |
490 | | std::string const& config, |
491 | | char const* custom_ext) const; |
492 | | void FillCustomInstallObjectLocations( |
493 | | cmSourceFile const& source, std::string const& config, |
494 | | char const* custom_ext, |
495 | | std::map<std::string, cmObjectLocation>& mapping) const; |
496 | | |
497 | | /** |
498 | | * Generate a macOS application bundle Info.plist file. |
499 | | */ |
500 | | void GenerateAppleInfoPList(cmGeneratorTarget* target, |
501 | | std::string const& targetName, |
502 | | std::string const& fname); |
503 | | |
504 | | /** |
505 | | * Generate a macOS framework Info.plist file. |
506 | | */ |
507 | | void GenerateFrameworkInfoPList(cmGeneratorTarget* target, |
508 | | std::string const& targetName, |
509 | | std::string const& fname); |
510 | | /** Construct a comment for a custom command. */ |
511 | | std::string ConstructComment(cmCustomCommandGenerator const& ccg, |
512 | | char const* default_comment = "") const; |
513 | | // Computes relative path to source respective to source or binary dir. |
514 | | std::string GetRelativeSourceFileName(cmSourceFile const& source) const; |
515 | | // Compute object file names. |
516 | | std::string GetObjectFileNameWithoutTarget( |
517 | | cmSourceFile const& source, std::string const& dir_max, |
518 | | bool* hasSourceExtension = nullptr, |
519 | | char const* customOutputExtension = nullptr, |
520 | | bool const* forceShortObjectName = nullptr); |
521 | | |
522 | | /** Fill out the static linker flags for the given target. */ |
523 | | void GetStaticLibraryFlags(std::string& flags, std::string const& config, |
524 | | std::string const& linkLanguage, |
525 | | cmGeneratorTarget* target); |
526 | | std::vector<BT<std::string>> GetStaticLibraryFlags( |
527 | | std::string const& config, std::string const& linkLanguage, |
528 | | cmGeneratorTarget* target); |
529 | | |
530 | | /** Fill out these strings for the given target. Libraries to link, |
531 | | * flags, and linkflags. */ |
532 | | void GetDeviceLinkFlags(cmLinkLineDeviceComputer& linkLineComputer, |
533 | | std::string const& config, std::string& linkLibs, |
534 | | std::string& linkFlags, std::string& frameworkPath, |
535 | | std::string& linkPath, cmGeneratorTarget* target); |
536 | | |
537 | | void GetTargetFlags(cmLinkLineComputer* linkLineComputer, |
538 | | std::string const& config, std::string& linkLibs, |
539 | | std::string& flags, std::string& linkFlags, |
540 | | std::string& frameworkPath, std::string& linkPath, |
541 | | cmGeneratorTarget* target); |
542 | | void GetTargetFlags( |
543 | | cmLinkLineComputer* linkLineComputer, std::string const& config, |
544 | | std::vector<BT<std::string>>& linkLibs, std::string& flags, |
545 | | std::vector<BT<std::string>>& linkFlags, std::string& frameworkPath, |
546 | | std::vector<BT<std::string>>& linkPath, cmGeneratorTarget* target); |
547 | | void GetTargetDefines(cmGeneratorTarget const* target, |
548 | | std::string const& config, std::string const& lang, |
549 | | std::set<std::string>& defines) const; |
550 | | std::set<BT<std::string>> GetTargetDefines(cmGeneratorTarget const* target, |
551 | | std::string const& config, |
552 | | std::string const& lang) const; |
553 | | void GetTargetCompileFlags(cmGeneratorTarget* target, |
554 | | std::string const& config, |
555 | | std::string const& lang, std::string& flags, |
556 | | std::string const& arch); |
557 | | std::vector<BT<std::string>> GetTargetCompileFlags( |
558 | | cmGeneratorTarget* target, std::string const& config, |
559 | | std::string const& lang, std::string const& arch = std::string()); |
560 | | |
561 | | std::string GetFrameworkFlags(std::string const& l, |
562 | | std::string const& config, |
563 | | cmGeneratorTarget* target); |
564 | | std::string GetXcFrameworkFlags(std::string const& l, |
565 | | std::string const& config, |
566 | | cmGeneratorTarget* target); |
567 | | virtual std::string GetTargetFortranFlags(cmGeneratorTarget const* target, |
568 | | std::string const& config); |
569 | | |
570 | | virtual void ComputeObjectFilenames( |
571 | | std::map<cmSourceFile const*, cmObjectLocations>& mapping, |
572 | | std::string const& config, cmGeneratorTarget const* gt = nullptr); |
573 | | |
574 | | bool IsWindowsShell() const; |
575 | | bool IsWatcomWMake() const; |
576 | | bool IsMinGWMake() const; |
577 | | bool IsNMake() const; |
578 | | bool IsNinjaMulti() const; |
579 | | bool IsWindowsVSIDE() const; |
580 | | |
581 | | void IssueMessage(MessageType type, std::string const& text) const |
582 | 0 | { |
583 | 0 | this->IssueMessage(type, text, this->DirectoryBacktrace); |
584 | 0 | } |
585 | | void IssueMessage(MessageType type, std::string const& text, |
586 | | cmListFileBacktrace const& bt) const; |
587 | | void IssueDiagnostic(cmDiagnosticCategory category, |
588 | | std::string const& text) const |
589 | 0 | { |
590 | 0 | this->IssueDiagnostic(category, text, |
591 | 0 | cmDiagnosticContext{ this->DirectoryBacktrace }); |
592 | 0 | } |
593 | | void IssueDiagnostic(cmDiagnosticCategory category, std::string const& text, |
594 | | cmListFileBacktrace const& bt) const |
595 | 0 | { |
596 | 0 | this->IssueDiagnostic(category, text, cmDiagnosticContext{ bt }); |
597 | 0 | } |
598 | | void IssueDiagnostic(cmDiagnosticCategory category, std::string const& text, |
599 | | cmDiagnosticContext const& context) const; |
600 | | void IssuePolicyWarning(cmPolicies::PolicyID policy, cm::string_view preface, |
601 | | cm::string_view postface, |
602 | | cmListFileBacktrace const& bt) const; |
603 | | void IssuePolicyWarning(cmPolicies::PolicyID policy, |
604 | | cm::string_view preface = {}, |
605 | | cm::string_view postface = {}) const |
606 | 0 | { |
607 | 0 | this->IssuePolicyWarning(policy, preface, postface, |
608 | 0 | this->DirectoryBacktrace); |
609 | 0 | } |
610 | | |
611 | | void CreateEvaluationFileOutputs(); |
612 | | void CreateEvaluationFileOutputs(std::string const& config); |
613 | | void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles); |
614 | | |
615 | | std::string GetRuleLauncher(cmGeneratorTarget* target, |
616 | | std::string const& prop, |
617 | | std::string const& config); |
618 | | |
619 | | // Return Swift_COMPILATION_MODE value if CMP0157 is NEW. |
620 | | cm::optional<cmSwiftCompileMode> GetSwiftCompileMode( |
621 | | cmGeneratorTarget const* target, std::string const& config); |
622 | | |
623 | | // Can we build Swift with a separate object build and link step |
624 | | // (If CMP0157 is NEW, we can do a split build) |
625 | | bool IsSplitSwiftBuild() const; |
626 | | |
627 | | std::string CreateSafeObjectFileName(std::string const& sin) const; |
628 | | |
629 | | /** |
630 | | * find what source group this source is in |
631 | | */ |
632 | | cmSourceGroup* FindSourceGroup(cmGeneratorTarget const* target, |
633 | | cmSourceFile const* source, |
634 | | std::string const& config); |
635 | | cmSourceGroup* FindSourceGroup(std::string const& source); |
636 | | |
637 | | protected: |
638 | | // The default implementation converts to a Windows shortpath to |
639 | | // help older toolchains handle spaces and such. A generator may |
640 | | // override this to avoid that conversion. |
641 | | virtual std::string ConvertToIncludeReference( |
642 | | std::string const& path, cmOutputConverter::OutputFormat format); |
643 | | |
644 | | //! put all the libraries for a target on into the given stream |
645 | | void OutputLinkLibraries(cmComputeLinkInformation* pcli, |
646 | | cmLinkLineComputer* linkLineComputer, |
647 | | std::string& linkLibraries, |
648 | | std::string& frameworkPath, std::string& linkPath); |
649 | | void OutputLinkLibraries(cmComputeLinkInformation* pcli, |
650 | | cmLinkLineComputer* linkLineComputer, |
651 | | std::vector<BT<std::string>>& linkLibraries, |
652 | | std::string& frameworkPath, |
653 | | std::vector<BT<std::string>>& linkPath); |
654 | | |
655 | | // Handle old-style install rules stored in the targets. |
656 | | void GenerateTargetInstallRules( |
657 | | std::ostream& os, std::string const& config, |
658 | | std::vector<std::string> const& configurationTypes); |
659 | | |
660 | 0 | virtual void AddGeneratorSpecificInstallSetup(std::ostream&) {} |
661 | | |
662 | | std::string& CreateSafeUniqueObjectFileName(std::string const& sin, |
663 | | std::string const& dir_max); |
664 | | |
665 | | /** Check whether the native build system supports the given |
666 | | definition. Issues a warning. */ |
667 | | virtual bool CheckDefinition(std::string const& define) const; |
668 | | |
669 | | cmMakefile* Makefile; |
670 | | cmListFileBacktrace DirectoryBacktrace; |
671 | | cmGlobalGenerator* GlobalGenerator; |
672 | | std::map<std::string, std::string> UniqueObjectNamesMap; |
673 | | std::string::size_type ObjectPathMax; |
674 | | std::set<std::string> ObjectMaxPathViolations; |
675 | | |
676 | | std::vector<std::string> EnvCPATH; |
677 | | |
678 | | using GeneratorTargetMap = |
679 | | std::unordered_map<std::string, cmGeneratorTarget*>; |
680 | | GeneratorTargetMap GeneratorTargetSearchIndex; |
681 | | GeneratorTargetVector GeneratorTargets; |
682 | | |
683 | | GeneratorTargetMap ImportedGeneratorTargets; |
684 | | GeneratorTargetVector OwnedImportedGeneratorTargets; |
685 | | std::map<std::string, std::string> AliasTargets; |
686 | | |
687 | | std::map<std::string, std::string> Compilers; |
688 | | std::map<std::string, std::string> VariableMappings; |
689 | | std::string CompilerSysroot; |
690 | | std::string LinkerSysroot; |
691 | | std::unordered_map<std::string, std::string> AppleArchSysroots; |
692 | | |
693 | | bool EmitUniversalBinaryFlags; |
694 | | |
695 | | #if !defined(CMAKE_BOOTSTRAP) |
696 | | // Map from source file path to source group for lookup acceleration |
697 | | using SourceGroupMap = std::unordered_map<std::string, cmSourceGroup*>; |
698 | | SourceGroupMap SourceGroupSearchIndex; |
699 | | #endif |
700 | | |
701 | | private: |
702 | | /** |
703 | | * See LinearGetSourceFileWithOutput for background information |
704 | | */ |
705 | | cmTarget* LinearGetTargetWithOutput(std::string const& name) const; |
706 | | |
707 | | /** |
708 | | * Generalized old version of GetSourceFileWithOutput kept for |
709 | | * backward-compatibility. It implements a linear search and supports |
710 | | * relative file paths. It is used as a fall back by GetSourceFileWithOutput |
711 | | * and GetSourcesWithOutput. |
712 | | */ |
713 | | cmSourceFile* LinearGetSourceFileWithOutput(std::string const& name, |
714 | | cmSourceOutputKind kind, |
715 | | bool& byproduct) const; |
716 | | struct SourceEntry |
717 | | { |
718 | | cmSourcesWithOutput Sources; |
719 | | }; |
720 | | |
721 | | // A map for fast output to input look up. |
722 | | using OutputToSourceMap = std::unordered_map<std::string, SourceEntry>; |
723 | | OutputToSourceMap OutputToSource; |
724 | | |
725 | | void UpdateOutputToSourceMap(std::string const& byproduct, cmTarget* target, |
726 | | cmListFileBacktrace const& bt, |
727 | | cmCommandOrigin origin); |
728 | | void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source, |
729 | | OutputRole role, cmListFileBacktrace const& bt, |
730 | | cmCommandOrigin origin); |
731 | | |
732 | | void AddPositionIndependentFlags(std::string& flags, std::string const& l, |
733 | | cm::TargetType targetType); |
734 | | |
735 | | void ComputeObjectMaxPath(); |
736 | | bool AllAppleArchSysrootsAreTheSame(std::vector<std::string> const& archs, |
737 | | cmValue sysroot); |
738 | | |
739 | | void CopyPchCompilePdb(std::string const& config, |
740 | | std::string const& language, |
741 | | cmGeneratorTarget* target, |
742 | | cmGeneratorTarget* reuseTarget, |
743 | | std::vector<std::string> const& extensions); |
744 | | |
745 | | // Returns MSVC_DEBUG_INFORMATION_FORMAT value if CMP0141 is NEW. |
746 | | cm::optional<std::string> GetMSVCDebugFormatName( |
747 | | std::string const& config, cmGeneratorTarget const* target); |
748 | | |
749 | | struct UnityBatchedSource |
750 | | { |
751 | | cmSourceFile* Source = nullptr; |
752 | | std::vector<size_t> Configs; |
753 | | UnityBatchedSource(cmSourceFile* sf) |
754 | 0 | : Source(sf) |
755 | 0 | { |
756 | 0 | } |
757 | | }; |
758 | | struct UnitySource |
759 | | { |
760 | | std::string Path; |
761 | | bool PerConfig = false; |
762 | | UnitySource(std::string path, bool perConfig) |
763 | 0 | : Path(std::move(path)) |
764 | 0 | , PerConfig(perConfig) |
765 | 0 | { |
766 | 0 | } |
767 | | }; |
768 | | /** Whether to insert relative or absolute paths into unity files */ |
769 | | enum class UnityPathMode |
770 | | { |
771 | | Absolute, |
772 | | Relative |
773 | | }; |
774 | | |
775 | | UnitySource WriteUnitySource( |
776 | | cmGeneratorTarget* target, std::vector<std::string> const& configs, |
777 | | cmRange<std::vector<UnityBatchedSource>::const_iterator> sources, |
778 | | cmValue beforeInclude, cmValue afterInclude, std::string filename, |
779 | | std::string const& unityFileDirectory, UnityPathMode pathMode) const; |
780 | | void WriteUnitySourceInclude(std::ostream& unity_file, |
781 | | cm::optional<std::string> const& cond, |
782 | | std::string const& sf_full_path, |
783 | | cmValue beforeInclude, cmValue afterInclude, |
784 | | cmValue uniqueIdName, UnityPathMode pathMode, |
785 | | std::string const& unityFileDirectory) const; |
786 | | std::vector<UnitySource> AddUnityFilesModeAuto( |
787 | | cmGeneratorTarget* target, std::string const& lang, |
788 | | std::vector<std::string> const& configs, |
789 | | std::vector<UnityBatchedSource> const& filtered_sources, |
790 | | cmValue beforeInclude, cmValue afterInclude, |
791 | | std::string const& filename_base, UnityPathMode pathMode, |
792 | | size_t batchSize); |
793 | | std::vector<UnitySource> AddUnityFilesModeGroup( |
794 | | cmGeneratorTarget* target, std::string const& lang, |
795 | | std::vector<std::string> const& configs, |
796 | | std::vector<UnityBatchedSource> const& filtered_sources, |
797 | | cmValue beforeInclude, cmValue afterInclude, |
798 | | std::string const& filename_base, UnityPathMode pathMode); |
799 | | }; |
800 | | |
801 | | namespace detail { |
802 | | void AddCustomCommandToTarget(cmLocalGenerator& lg, cmCommandOrigin origin, |
803 | | cmTarget* target, cmCustomCommandType type, |
804 | | std::unique_ptr<cmCustomCommand> cc); |
805 | | |
806 | | cmSourceFile* AddCustomCommandToOutput(cmLocalGenerator& lg, |
807 | | cmCommandOrigin origin, |
808 | | std::unique_ptr<cmCustomCommand> cc, |
809 | | bool replace); |
810 | | |
811 | | void AppendCustomCommandToOutput(cmLocalGenerator& lg, |
812 | | cmListFileBacktrace const& lfbt, |
813 | | std::string const& output, |
814 | | std::vector<std::string> const& depends, |
815 | | cmImplicitDependsList const& implicit_depends, |
816 | | cmCustomCommandLines const& commandLines); |
817 | | |
818 | | void AddUtilityCommand(cmLocalGenerator& lg, cmCommandOrigin origin, |
819 | | cmTarget* target, std::unique_ptr<cmCustomCommand> cc); |
820 | | |
821 | | std::vector<std::string> ComputeISPCObjectSuffixes(cmGeneratorTarget* target); |
822 | | std::vector<std::string> ComputeISPCExtraObjects( |
823 | | std::string const& objectName, std::string const& buildDirectory, |
824 | | std::vector<std::string> const& ispcSuffixes); |
825 | | } |