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