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