1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
12 #include <unordered_map>
13 #include <unordered_set>
17 #include <cm/optional>
19 #include "cmAlgorithms.h"
20 #include "cmLinkItem.h"
21 #include "cmListFileCache.h"
22 #include "cmPolicies.h"
23 #include "cmStateTypes.h"
26 enum class cmBuildStep;
27 class cmComputeLinkInformation;
28 class cmCustomCommand;
29 class cmGlobalGenerator;
30 class cmLocalGenerator;
35 struct cmGeneratorExpressionContext;
36 struct cmGeneratorExpressionDAGChecker;
38 class cmGeneratorTarget
41 cmGeneratorTarget(cmTarget*, cmLocalGenerator* lg);
44 cmGeneratorTarget(cmGeneratorTarget const&) = delete;
45 cmGeneratorTarget& operator=(cmGeneratorTarget const&) = delete;
47 cmLocalGenerator* GetLocalGenerator() const;
49 cmGlobalGenerator* GetGlobalGenerator() const;
51 bool IsInBuildSystem() const;
52 bool IsImported() const;
53 bool IsImportedGloballyVisible() const;
54 bool CanCompileSources() const;
55 const std::string& GetLocation(const std::string& config) const;
57 /** Get the full path to the target's main artifact, if known. */
58 cm::optional<std::string> MaybeGetLocation(std::string const& config) const;
60 std::vector<cmCustomCommand> const& GetPreBuildCommands() const;
61 std::vector<cmCustomCommand> const& GetPreLinkCommands() const;
62 std::vector<cmCustomCommand> const& GetPostBuildCommands() const;
64 void AppendCustomCommandSideEffects(
65 std::set<cmGeneratorTarget const*>& sideEffects) const;
66 void AppendLanguageSideEffects(
67 std::map<std::string, std::set<cmGeneratorTarget const*>>& sideEffects)
70 #define DECLARE_TARGET_POLICY(POLICY) \
71 cmPolicies::PolicyStatus GetPolicyStatus##POLICY() const \
73 return this->PolicyMap.Get(cmPolicies::POLICY); \
76 CM_FOR_EACH_TARGET_POLICY(DECLARE_TARGET_POLICY)
78 #undef DECLARE_TARGET_POLICY
80 /** Get the location of the target in the build tree with a placeholder
81 referencing the configuration in the native build system. This
82 location is suitable for use as the LOCATION target property. */
83 const std::string& GetLocationForBuild() const;
85 cmComputeLinkInformation* GetLinkInformation(
86 const std::string& config) const;
88 // Perform validation checks on memoized link structures.
89 // Call this after generation is complete.
90 void CheckLinkLibraries() const;
92 cmStateEnums::TargetType GetType() const;
93 const std::string& GetName() const;
94 std::string GetExportName() const;
96 std::vector<std::string> GetPropertyKeys() const;
97 //! Might return a nullptr if the property is not set or invalid
98 cmValue GetProperty(const std::string& prop) const;
99 //! Always returns a valid pointer
100 std::string const& GetSafeProperty(std::string const& prop) const;
101 bool GetPropertyAsBool(const std::string& prop) const;
102 void GetSourceFiles(std::vector<cmSourceFile*>& files,
103 const std::string& config) const;
104 std::vector<BT<cmSourceFile*>> GetSourceFiles(
105 std::string const& config) const;
107 /** Source file kinds (classifications).
108 Generators use this to decide how to treat a source file. */
111 SourceKindAppManifest,
112 SourceKindCertificate,
113 SourceKindCustomCommand,
114 SourceKindExternalObject,
119 SourceKindModuleDefinition,
120 SourceKindObjectSource,
123 SourceKindUnityBatched
126 /** A source file paired with a kind (classification). */
129 BT<cmSourceFile*> Source;
133 /** All sources needed for a configuration with kinds assigned. */
136 std::vector<SourceAndKind> Sources;
137 bool Initialized = false;
140 /** Get all sources needed for a configuration with kinds assigned. */
141 KindedSources const& GetKindedSources(std::string const& config) const;
143 struct AllConfigSource
145 cmSourceFile* Source;
146 cmGeneratorTarget::SourceKind Kind;
147 std::vector<size_t> Configs;
150 /** Get all sources needed for all configurations with kinds and
151 per-source configurations assigned. */
152 std::vector<AllConfigSource> const& GetAllConfigSources() const;
154 /** Get all sources needed for all configurations with given kind. */
155 std::vector<AllConfigSource> GetAllConfigSources(SourceKind kind) const;
157 /** Get all languages used to compile sources in any configuration.
158 This excludes the languages of objects from object libraries. */
159 std::set<std::string> GetAllConfigCompileLanguages() const;
161 void GetObjectSources(std::vector<cmSourceFile const*>&,
162 const std::string& config) const;
163 const std::string& GetObjectName(cmSourceFile const* file);
164 const char* GetCustomObjectExtension() const;
166 bool HasExplicitObjectName(cmSourceFile const* file) const;
167 void AddExplicitObjectName(cmSourceFile const* sf);
169 BTs<std::string> const* GetLanguageStandardProperty(
170 std::string const& lang, std::string const& config) const;
172 cmValue GetLanguageStandard(std::string const& lang,
173 std::string const& config) const;
175 cmValue GetLanguageExtensions(std::string const& lang) const;
177 bool GetLanguageStandardRequired(std::string const& lang) const;
179 void GetModuleDefinitionSources(std::vector<cmSourceFile const*>&,
180 const std::string& config) const;
181 void GetExternalObjects(std::vector<cmSourceFile const*>&,
182 const std::string& config) const;
183 void GetHeaderSources(std::vector<cmSourceFile const*>&,
184 const std::string& config) const;
185 void GetExtraSources(std::vector<cmSourceFile const*>&,
186 const std::string& config) const;
187 void GetCustomCommands(std::vector<cmSourceFile const*>&,
188 const std::string& config) const;
189 void GetManifests(std::vector<cmSourceFile const*>&,
190 const std::string& config) const;
192 std::set<cmLinkItem> const& GetUtilityItems() const;
194 void ComputeObjectMapping();
196 cmValue GetFeature(const std::string& feature,
197 const std::string& config) const;
199 const char* GetLinkPIEProperty(const std::string& config) const;
201 bool IsIPOEnabled(std::string const& lang, std::string const& config) const;
203 bool IsLinkInterfaceDependentBoolProperty(const std::string& p,
204 const std::string& config) const;
205 bool IsLinkInterfaceDependentStringProperty(const std::string& p,
206 const std::string& config) const;
207 bool IsLinkInterfaceDependentNumberMinProperty(
208 const std::string& p, const std::string& config) const;
209 bool IsLinkInterfaceDependentNumberMaxProperty(
210 const std::string& p, const std::string& config) const;
212 bool GetLinkInterfaceDependentBoolProperty(const std::string& p,
213 const std::string& config) const;
215 const char* GetLinkInterfaceDependentStringProperty(
216 const std::string& p, const std::string& config) const;
217 const char* GetLinkInterfaceDependentNumberMinProperty(
218 const std::string& p, const std::string& config) const;
219 const char* GetLinkInterfaceDependentNumberMaxProperty(
220 const std::string& p, const std::string& config) const;
222 class DeviceLinkSetter
225 DeviceLinkSetter(cmGeneratorTarget& target)
228 this->PreviousState = target.SetDeviceLink(true);
230 ~DeviceLinkSetter() { this->Target.SetDeviceLink(this->PreviousState); }
233 cmGeneratorTarget& Target;
237 bool SetDeviceLink(bool deviceLink);
238 bool IsDeviceLink() const { return this->DeviceLink; }
240 cmLinkInterface const* GetLinkInterface(
241 const std::string& config, const cmGeneratorTarget* headTarget) const;
242 void ComputeLinkInterface(const std::string& config,
243 cmOptionalLinkInterface& iface,
244 const cmGeneratorTarget* head) const;
246 enum class LinkInterfaceFor
248 Usage, // Interface for usage requirements excludes $<LINK_ONLY>.
249 Link, // Interface for linking includes $<LINK_ONLY>.
252 cmLinkInterfaceLibraries const* GetLinkInterfaceLibraries(
253 const std::string& config, const cmGeneratorTarget* headTarget,
254 LinkInterfaceFor interfaceFor) const;
256 void ComputeLinkInterfaceLibraries(const std::string& config,
257 cmOptionalLinkInterface& iface,
258 const cmGeneratorTarget* head,
259 LinkInterfaceFor interfaceFor) const;
261 /** Get the library name for an imported interface library. */
262 std::string GetImportedLibName(std::string const& config) const;
264 /** Get the full path to the target according to the settings in its
265 makefile and the configuration type. */
266 std::string GetFullPath(
267 const std::string& config,
268 cmStateEnums::ArtifactType artifact = cmStateEnums::RuntimeBinaryArtifact,
269 bool realname = false) const;
270 std::string NormalGetFullPath(const std::string& config,
271 cmStateEnums::ArtifactType artifact,
272 bool realname) const;
273 std::string NormalGetRealName(const std::string& config) const;
275 /** Get the names of an object library's object files underneath
276 its object file directory. */
277 void GetTargetObjectNames(std::string const& config,
278 std::vector<std::string>& objects) const;
280 /** What hierarchy level should the reported directory contain */
281 enum BundleDirectoryLevel
288 /** @return the Mac App directory without the base */
289 std::string GetAppBundleDirectory(const std::string& config,
290 BundleDirectoryLevel level) const;
292 /** Return whether this target is marked as deprecated by the
294 bool IsDeprecated() const;
296 /** Returns the deprecation message provided by the maintainer */
297 std::string GetDeprecation() const;
299 /** Return whether this target is an executable Bundle, a framework
300 or CFBundle on Apple. */
301 bool IsBundleOnApple() const;
303 /** Return whether this target is a Win32 executable */
304 bool IsWin32Executable(const std::string& config) const;
306 /** Get the full name of the target according to the settings in its
308 std::string GetFullName(const std::string& config,
309 cmStateEnums::ArtifactType artifact =
310 cmStateEnums::RuntimeBinaryArtifact) const;
312 /** @return the Mac framework directory without the base. */
313 std::string GetFrameworkDirectory(const std::string& config,
314 BundleDirectoryLevel level) const;
316 /** Return the framework version string. Undefined if
317 IsFrameworkOnApple returns false. */
318 std::string GetFrameworkVersion() const;
320 /** @return the Mac CFBundle directory without the base */
321 std::string GetCFBundleDirectory(const std::string& config,
322 BundleDirectoryLevel level) const;
324 /** Return the install name directory for the target in the
325 * build tree. For example: "\@rpath/", "\@loader_path/",
326 * or "/full/path/to/library". */
327 std::string GetInstallNameDirForBuildTree(const std::string& config) const;
329 /** Return the install name directory for the target in the
330 * install tree. For example: "\@rpath/" or "\@loader_path/". */
331 std::string GetInstallNameDirForInstallTree(
332 const std::string& config, const std::string& installPrefix) const;
334 cmListFileBacktrace GetBacktrace() const;
336 std::set<BT<std::pair<std::string, bool>>> const& GetUtilities() const;
338 bool LinkLanguagePropagatesToDependents() const
340 return this->GetType() == cmStateEnums::STATIC_LIBRARY;
343 /** Get the macro to define when building sources in this target.
344 If no macro should be defined null is returned. */
345 const std::string* GetExportMacro() const;
347 /** Get the soname of the target. Allowed only for a shared library. */
348 std::string GetSOName(const std::string& config) const;
350 void GetFullNameComponents(std::string& prefix, std::string& base,
351 std::string& suffix, const std::string& config,
352 cmStateEnums::ArtifactType artifact =
353 cmStateEnums::RuntimeBinaryArtifact) const;
355 /** Append to @a base the bundle directory hierarchy up to a certain @a level
357 std::string BuildBundleDirectory(const std::string& base,
358 const std::string& config,
359 BundleDirectoryLevel level) const;
361 /** @return the mac content directory for this target. */
362 std::string GetMacContentDirectory(
363 const std::string& config, cmStateEnums::ArtifactType artifact) const;
365 /** @return folder prefix for IDEs. */
366 std::string GetEffectiveFolderName() const;
369 cmMakefile* Makefile;
370 cmLocalGenerator* LocalGenerator;
371 cmGlobalGenerator const* GlobalGenerator;
373 struct ModuleDefinitionInfo
376 bool DefFileGenerated;
377 bool WindowsExportAllSymbols;
378 std::vector<cmSourceFile const*> Sources;
380 ModuleDefinitionInfo const* GetModuleDefinitionInfo(
381 std::string const& config) const;
383 /** Return whether or not the target is for a DLL platform. */
384 bool IsDLLPlatform() const;
386 /** @return whether this target have a well defined output file name. */
387 bool HaveWellDefinedOutputFiles() const;
389 /** Link information from the transitive closure of the link
390 implementation and the interfaces of its dependencies. */
393 // The preferred linker language.
394 std::string LinkerLanguage;
396 // Languages whose runtime libraries must be linked.
397 std::vector<std::string> Languages;
400 LinkClosure const* GetLinkClosure(const std::string& config) const;
402 cmLinkImplementation const* GetLinkImplementation(
403 const std::string& config, LinkInterfaceFor implFor) const;
405 void ComputeLinkImplementationLanguages(
406 const std::string& config, cmOptionalLinkImplementation& impl) const;
408 cmLinkImplementationLibraries const* GetLinkImplementationLibraries(
409 const std::string& config, LinkInterfaceFor implFor) const;
411 void ComputeLinkImplementationLibraries(const std::string& config,
412 cmOptionalLinkImplementation& impl,
413 const cmGeneratorTarget* head,
414 LinkInterfaceFor implFor) const;
416 struct TargetOrString
419 cmGeneratorTarget* Target = nullptr;
421 TargetOrString ResolveTargetReference(std::string const& name) const;
422 TargetOrString ResolveTargetReference(std::string const& name,
423 cmLocalGenerator const* lg) const;
425 cmLinkItem ResolveLinkItem(BT<std::string> const& name) const;
426 cmLinkItem ResolveLinkItem(BT<std::string> const& name,
427 cmLocalGenerator const* lg) const;
429 bool HasPackageReferences() const;
430 std::vector<std::string> GetPackageReferences() const;
432 // Compute the set of languages compiled by the target. This is
433 // computed every time it is called because the languages can change
434 // when source file properties are changed and we do not have enough
435 // information to forward these property changes to the targets
436 // until we have per-target object file properties.
437 void GetLanguages(std::set<std::string>& languages,
438 std::string const& config) const;
439 bool IsLanguageUsed(std::string const& language,
440 std::string const& config) const;
442 bool IsCSharpOnly() const;
444 bool IsDotNetSdkTarget() const;
446 void GetObjectLibrariesCMP0026(
447 std::vector<cmGeneratorTarget*>& objlibs) const;
449 std::string GetFullNameImported(const std::string& config,
450 cmStateEnums::ArtifactType artifact) const;
452 /** Get source files common to all configurations and diagnose cases
453 with per-config sources. Excludes sources added by a TARGET_OBJECTS
454 generator expression. Do not use outside the Xcode generator. */
455 bool GetConfigCommonSourceFilesForXcode(
456 std::vector<cmSourceFile*>& files) const;
458 bool HaveBuildTreeRPATH(const std::string& config) const;
460 /** Full path with trailing slash to the top-level directory
461 holding object files for this target. Includes the build
462 time config name placeholder if needed for the generator. */
463 std::string ObjectDirectory;
465 /** Full path with trailing slash to the top-level directory
466 holding object files for the given configuration. */
467 std::string GetObjectDirectory(std::string const& config) const;
469 void GetAppleArchs(const std::string& config,
470 std::vector<std::string>& archVec) const;
472 void AddExplicitLanguageFlags(std::string& flags,
473 cmSourceFile const& sf) const;
475 void AddCUDAArchitectureFlags(cmBuildStep compileOrLink,
476 const std::string& config,
477 std::string& flags) const;
478 void AddCUDAToolkitFlags(std::string& flags) const;
480 void AddHIPArchitectureFlags(std::string& flags) const;
482 void AddISPCTargetFlags(std::string& flags) const;
484 std::string GetFeatureSpecificLinkRuleVariable(
485 std::string const& var, std::string const& lang,
486 std::string const& config) const;
488 /** Return the rule variable used to create this type of target. */
489 std::string GetCreateRuleVariable(std::string const& lang,
490 std::string const& config) const;
492 /** Get the include directories for this target. */
493 std::vector<BT<std::string>> GetIncludeDirectories(
494 const std::string& config, const std::string& lang) const;
496 void GetCompileOptions(std::vector<std::string>& result,
497 const std::string& config,
498 const std::string& language) const;
499 std::vector<BT<std::string>> GetCompileOptions(
500 std::string const& config, std::string const& language) const;
502 void GetCompileFeatures(std::vector<std::string>& features,
503 const std::string& config) const;
504 std::vector<BT<std::string>> GetCompileFeatures(
505 std::string const& config) const;
507 void GetCompileDefinitions(std::vector<std::string>& result,
508 const std::string& config,
509 const std::string& language) const;
510 std::vector<BT<std::string>> GetCompileDefinitions(
511 std::string const& config, std::string const& language) const;
513 void GetLinkOptions(std::vector<std::string>& result,
514 const std::string& config,
515 const std::string& language) const;
516 std::vector<BT<std::string>> GetLinkOptions(
517 std::string const& config, std::string const& language) const;
519 std::vector<BT<std::string>>& ResolveLinkerWrapper(
520 std::vector<BT<std::string>>& result, const std::string& language,
521 bool joinItems = false) const;
523 void GetStaticLibraryLinkOptions(std::vector<std::string>& result,
524 const std::string& config,
525 const std::string& language) const;
526 std::vector<BT<std::string>> GetStaticLibraryLinkOptions(
527 std::string const& config, std::string const& language) const;
529 void GetLinkDirectories(std::vector<std::string>& result,
530 const std::string& config,
531 const std::string& language) const;
532 std::vector<BT<std::string>> GetLinkDirectories(
533 std::string const& config, std::string const& language) const;
535 void GetLinkDepends(std::vector<std::string>& result,
536 const std::string& config,
537 const std::string& language) const;
538 std::vector<BT<std::string>> GetLinkDepends(
539 std::string const& config, std::string const& language) const;
541 std::vector<BT<std::string>> GetPrecompileHeaders(
542 const std::string& config, const std::string& language) const;
544 std::string GetPchHeader(const std::string& config,
545 const std::string& language,
546 const std::string& arch = std::string()) const;
547 std::string GetPchSource(const std::string& config,
548 const std::string& language,
549 const std::string& arch = std::string()) const;
550 std::string GetPchFileObject(const std::string& config,
551 const std::string& language,
552 const std::string& arch = std::string());
553 std::string GetPchFile(const std::string& config,
554 const std::string& language,
555 const std::string& arch = std::string());
556 std::string GetPchCreateCompileOptions(
557 const std::string& config, const std::string& language,
558 const std::string& arch = std::string());
559 std::string GetPchUseCompileOptions(const std::string& config,
560 const std::string& language,
561 const std::string& arch = std::string());
563 void AddSourceFileToUnityBatch(const std::string& sourceFilename);
564 bool IsSourceFilePartOfUnityBatch(const std::string& sourceFilename) const;
566 bool IsSystemIncludeDirectory(const std::string& dir,
567 const std::string& config,
568 const std::string& language) const;
570 /** Add the target output files to the global generator manifest. */
571 void ComputeTargetManifest(const std::string& config) const;
573 bool ComputeCompileFeatures(std::string const& config) const;
575 using LanguagePair = std::pair<std::string, std::string>;
576 bool ComputeCompileFeatures(
577 std::string const& config,
578 std::set<LanguagePair> const& languagePairs) const;
581 * Trace through the source files in this target and add al source files
582 * that they depend on, used by all generators
584 void TraceDependencies();
586 /** Get the directory in which this target will be built. If the
587 configuration name is given then the generator will add its
588 subdirectory for that configuration. Otherwise just the canonical
589 output directory is given. */
590 std::string GetDirectory(const std::string& config,
591 cmStateEnums::ArtifactType artifact =
592 cmStateEnums::RuntimeBinaryArtifact) const;
594 /** Get the directory in which to place the target compiler .pdb file.
595 If the configuration name is given then the generator will add its
596 subdirectory for that configuration. Otherwise just the canonical
597 compiler pdb output directory is given. */
598 std::string GetCompilePDBDirectory(const std::string& config) const;
600 /** Get sources that must be built before the given source. */
601 std::vector<cmSourceFile*> const* GetSourceDepends(
602 cmSourceFile const* sf) const;
604 /** Return whether this target uses the default value for its output
606 bool UsesDefaultOutputDir(const std::string& config,
607 cmStateEnums::ArtifactType artifact) const;
609 // Cache target output paths for each configuration.
617 return this->OutDir.empty() && this->ImpDir.empty() &&
618 this->PdbDir.empty();
622 OutputInfo const* GetOutputInfo(const std::string& config) const;
624 // Get the target PDB base name.
625 std::string GetPDBOutputName(const std::string& config) const;
627 /** Get the name of the pdb file for the target. */
628 std::string GetPDBName(const std::string& config) const;
630 /** Whether this library has soname enabled and platform supports it. */
631 bool HasSOName(const std::string& config) const;
635 std::string CompilePdbDir;
638 CompileInfo const* GetCompileInfo(const std::string& config) const;
640 using CompileInfoMapType = std::map<std::string, CompileInfo>;
641 mutable CompileInfoMapType CompileInfoMap;
643 bool IsNullImpliedByLinkLibraries(const std::string& p) const;
645 /** Get the name of the compiler pdb file for the target. */
646 std::string GetCompilePDBName(const std::string& config) const;
648 /** Get the path for the MSVC /Fd option for this target. */
649 std::string GetCompilePDBPath(const std::string& config) const;
651 // Get the target base name.
652 std::string GetOutputName(const std::string& config,
653 cmStateEnums::ArtifactType artifact) const;
655 /** Get target file prefix */
656 std::string GetFilePrefix(const std::string& config,
657 cmStateEnums::ArtifactType artifact =
658 cmStateEnums::RuntimeBinaryArtifact) const;
659 /** Get target file prefix */
660 std::string GetFileSuffix(const std::string& config,
661 cmStateEnums::ArtifactType artifact =
662 cmStateEnums::RuntimeBinaryArtifact) const;
664 /** Get target file postfix */
665 std::string GetFilePostfix(const std::string& config) const;
667 /** Get framework multi-config-specific postfix */
668 std::string GetFrameworkMultiConfigPostfix(const std::string& config) const;
670 /** Clears cached meta data for local and external source files.
671 * The meta data will be recomputed on demand.
673 void ClearSourcesCache();
675 // Do not use. This is only for a specific call site with a FIXME comment.
676 void ClearLinkInterfaceCache();
678 void AddSource(const std::string& src, bool before = false);
679 void AddTracedSources(std::vector<std::string> const& srcs);
682 * Adds an entry to the INCLUDE_DIRECTORIES list.
683 * If before is true the entry is pushed at the front.
685 void AddIncludeDirectory(const std::string& src, bool before = false);
688 * Flags for a given source file as used in this target. Typically assigned
689 * via SET_TARGET_PROPERTIES when the property is a list of source files.
693 SourceFileTypeNormal,
694 SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
695 SourceFileTypePublicHeader, // is in "PUBLIC_HEADER" target property
696 SourceFileTypeResource, // is in "RESOURCE" target property *or*
697 // has MACOSX_PACKAGE_LOCATION=="Resources"
698 SourceFileTypeDeepResource, // MACOSX_PACKAGE_LOCATION starts with
700 SourceFileTypeMacContent // has MACOSX_PACKAGE_LOCATION!="Resources[/]"
702 struct SourceFileFlags
704 SourceFileType Type = SourceFileTypeNormal;
705 const char* MacFolder = nullptr; // location inside Mac content folders
707 void GetAutoUicOptions(std::vector<std::string>& result,
708 const std::string& config) const;
715 std::string ImportLibrary;
717 std::string SharedObject;
720 /** Get the names of the executable needed to generate a build rule
721 that takes into account executable version numbers. This should
722 be called only on an executable target. */
723 Names GetExecutableNames(const std::string& config) const;
725 /** Get the names of the library needed to generate a build rule
726 that takes into account shared library version numbers. This
727 should be called only on a library target. */
728 Names GetLibraryNames(const std::string& config) const;
731 * Compute whether this target must be relinked before installing.
733 bool NeedRelinkBeforeInstall(const std::string& config) const;
735 /** Return true if builtin chrpath will work for this target */
736 bool IsChrpathUsed(const std::string& config) const;
738 /** Get the directory in which this targets .pdb files will be placed.
739 If the configuration name is given then the generator will add its
740 subdirectory for that configuration. Otherwise just the canonical
741 pdb output directory is given. */
742 std::string GetPDBDirectory(const std::string& config) const;
744 //! Return the preferred linker language for this target
745 std::string GetLinkerLanguage(const std::string& config) const;
747 /** Does this target have a GNU implib to convert to MS format? */
748 bool HasImplibGNUtoMS(std::string const& config) const;
750 /** Convert the given GNU import library name (.dll.a) to a name with a new
751 extension (.lib or ${CMAKE_IMPORT_LIBRARY_SUFFIX}). */
752 bool GetImplibGNUtoMS(std::string const& config, std::string const& gnuName,
753 std::string& out, const char* newExt = nullptr) const;
755 /** Can only ever return true if GetSourceFilePaths() was called before.
756 Otherwise, this is indeterminate and false will be assumed/returned! */
757 bool HasContextDependentSources() const;
759 bool IsExecutableWithExports() const;
761 /** Return whether or not the target has a DLL import library. */
762 bool HasImportLibrary(std::string const& config) const;
764 /** Get a build-tree directory in which to place target support files. */
765 std::string GetSupportDirectory() const;
767 /** Return whether this target may be used to link another target. */
768 bool IsLinkable() const;
770 /** Return whether this target is a shared library Framework on
772 bool IsFrameworkOnApple() const;
774 /** Return whether this target is an executable Bundle on Apple. */
775 bool IsAppBundleOnApple() const;
777 /** Return whether this target is a XCTest on Apple. */
778 bool IsXCTestOnApple() const;
780 /** Return whether this target is a CFBundle (plugin) on Apple. */
781 bool IsCFBundleOnApple() const;
783 /** Assembly types. The order of the values of this enum is relevant
784 because of smaller/larger comparison operations! */
787 Undefined = 0, // target is no lib or executable
788 Native, // target compiles to unmanaged binary.
789 Mixed, // target compiles to mixed (managed and unmanaged) binary.
790 Managed // target compiles to managed binary.
793 /** Return the type of assembly this target compiles to. */
794 ManagedType GetManagedType(const std::string& config) const;
796 struct SourceFileFlags GetTargetSourceFileFlags(
797 const cmSourceFile* sf) const;
799 void ReportPropertyOrigin(const std::string& p, const std::string& result,
800 const std::string& report,
801 const std::string& compatibilityType) const;
803 class TargetPropertyEntry;
805 std::string EvaluateInterfaceProperty(
806 std::string const& prop, cmGeneratorExpressionContext* context,
807 cmGeneratorExpressionDAGChecker* dagCheckerParent,
808 LinkInterfaceFor interfaceFor = LinkInterfaceFor::Usage) const;
810 bool HaveInstallTreeRPATH(const std::string& config) const;
812 bool GetBuildRPATH(const std::string& config, std::string& rpath) const;
813 bool GetInstallRPATH(const std::string& config, std::string& rpath) const;
815 /** Whether this library has \@rpath and platform supports it. */
816 bool HasMacOSXRpathInstallNameDir(const std::string& config) const;
818 /** Whether this library defaults to \@rpath. */
819 bool MacOSXRpathInstallNameDirDefault() const;
823 INSTALL_NAME_FOR_BUILD,
824 INSTALL_NAME_FOR_INSTALL
826 /** Whether to use INSTALL_NAME_DIR. */
827 bool MacOSXUseInstallNameDir() const;
828 /** Whether to generate an install_name. */
829 bool CanGenerateInstallNameDir(InstallNameType t) const;
831 /** Test for special case of a third-party shared library that has
833 bool IsImportedSharedLibWithoutSOName(const std::string& config) const;
835 std::string ImportedGetLocation(const std::string& config) const;
837 /** Get the target major and minor version numbers interpreted from
838 the VERSION property. Version 0 is returned if the property is
839 not set or cannot be parsed. */
840 void GetTargetVersion(int& major, int& minor) const;
842 /** Get the target major, minor, and patch version numbers
843 interpreted from the given property. Version 0
844 is returned if the property is not set or cannot be parsed. */
845 void GetTargetVersion(std::string const& property, int& major, int& minor,
848 /** Get the target major, minor, and patch version numbers
849 interpreted from the given property and if empty use the
850 fallback property. Version 0 is returned if the property is
851 not set or cannot be parsed. */
852 void GetTargetVersionFallback(const std::string& property,
853 const std::string& fallback_property,
854 int& major, int& minor, int& patch) const;
856 std::string GetRuntimeLinkLibrary(std::string const& lang,
857 std::string const& config) const;
859 std::string GetFortranModuleDirectory(std::string const& working_dir) const;
860 bool IsFortranBuildingInstrinsicModules() const;
862 bool IsLinkLookupScope(std::string const& n,
863 cmLocalGenerator const*& lg) const;
865 cmValue GetSourcesProperty() const;
867 void AddISPCGeneratedHeader(std::string const& header,
868 std::string const& config);
869 std::vector<std::string> GetGeneratedISPCHeaders(
870 std::string const& config) const;
872 void AddISPCGeneratedObject(std::vector<std::string>&& objs,
873 std::string const& config);
874 std::vector<std::string> GetGeneratedISPCObjects(
875 std::string const& config) const;
877 bool AddHeaderSetVerification();
878 std::string GenerateHeaderSetVerificationFile(
879 cmSourceFile& source, const std::string& dir,
880 cm::optional<std::set<std::string>>& languages) const;
883 void AddSourceCommon(const std::string& src, bool before = false);
885 std::string CreateFortranModuleDirectory(
886 std::string const& working_dir) const;
887 mutable bool FortranModuleDirectoryCreated = false;
888 mutable std::string FortranModuleDirectory;
890 friend class cmTargetTraceDependencies;
893 std::vector<cmSourceFile*> Depends;
895 using SourceEntriesType = std::map<cmSourceFile const*, SourceEntry>;
896 SourceEntriesType SourceDepends;
897 mutable std::set<std::string> VisitedConfigsForObjects;
898 mutable std::map<cmSourceFile const*, std::string> Objects;
899 std::set<cmSourceFile const*> ExplicitObjectName;
901 using TargetPtrToBoolMap = std::unordered_map<cmTarget*, bool>;
902 mutable std::unordered_map<std::string, TargetPtrToBoolMap>
903 MacOSXRpathInstallNameDirCache;
904 bool DetermineHasMacOSXRpathInstallNameDir(const std::string& config) const;
906 // "config/language" is the key
907 mutable std::map<std::string, std::vector<std::string>> SystemIncludesCache;
909 mutable std::string ExportMacro;
911 void ConstructSourceFileFlags() const;
912 mutable bool SourceFileFlagsConstructed = false;
913 mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
915 mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
917 bool NeedImportLibraryName(std::string const& config) const;
919 cmValue GetFilePrefixInternal(std::string const& config,
920 cmStateEnums::ArtifactType artifact,
921 const std::string& language = "") const;
922 cmValue GetFileSuffixInternal(std::string const& config,
923 cmStateEnums::ArtifactType artifact,
924 const std::string& language = "") const;
926 std::string GetFullNameInternal(const std::string& config,
927 cmStateEnums::ArtifactType artifact) const;
928 void GetFullNameInternal(const std::string& config,
929 cmStateEnums::ArtifactType artifact,
930 std::string& outPrefix, std::string& outBase,
931 std::string& outSuffix) const;
933 mutable std::string LinkerLanguage;
934 using LinkClosureMapType = std::map<std::string, LinkClosure>;
935 mutable LinkClosureMapType LinkClosureMap;
936 bool DeviceLink = false;
938 // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type.
939 const char* GetOutputTargetType(cmStateEnums::ArtifactType artifact) const;
941 void ComputeVersionedName(std::string& vName, std::string const& prefix,
942 std::string const& base, std::string const& suffix,
943 std::string const& name, cmValue version) const;
945 struct CompatibleInterfacesBase
947 std::set<std::string> PropsBool;
948 std::set<std::string> PropsString;
949 std::set<std::string> PropsNumberMax;
950 std::set<std::string> PropsNumberMin;
952 CompatibleInterfacesBase const& GetCompatibleInterfaces(
953 std::string const& config) const;
955 struct CompatibleInterfaces : public CompatibleInterfacesBase
959 mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
961 using cmTargetLinkInformationMap =
962 std::map<std::string, std::unique_ptr<cmComputeLinkInformation>>;
963 mutable cmTargetLinkInformationMap LinkInformation;
965 void CheckPropertyCompatibility(cmComputeLinkInformation& info,
966 const std::string& config) const;
968 void ComputeLinkClosure(const std::string& config, LinkClosure& lc) const;
969 bool ComputeLinkClosure(const std::string& config, LinkClosure& lc,
970 bool secondPass) const;
972 struct LinkImplClosure : public std::vector<cmGeneratorTarget const*>
976 mutable std::map<std::string, LinkImplClosure> LinkImplClosureMap;
978 using LinkInterfaceMapType = std::map<std::string, cmHeadToLinkInterfaceMap>;
979 mutable LinkInterfaceMapType LinkInterfaceMap;
980 mutable LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap;
982 cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceMap(
983 std::string const& config) const;
984 cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap(
985 std::string const& config) const;
987 std::string GetLinkInterfaceDependentStringAsBoolProperty(
988 const std::string& p, const std::string& config) const;
990 friend class cmTargetCollectLinkLanguages;
991 cmLinkInterface const* GetLinkInterface(const std::string& config,
992 const cmGeneratorTarget* headTarget,
993 bool secondPass) const;
994 void ComputeLinkInterface(const std::string& config,
995 cmOptionalLinkInterface& iface,
996 const cmGeneratorTarget* head,
997 bool secondPass) const;
998 cmLinkImplementation const* GetLinkImplementation(const std::string& config,
999 LinkInterfaceFor implFor,
1000 bool secondPass) const;
1002 enum class LinkItemRole
1007 bool VerifyLinkItemIsTarget(LinkItemRole role, cmLinkItem const& item) const;
1008 bool VerifyLinkItemColons(LinkItemRole role, cmLinkItem const& item) const;
1010 // Cache import information from properties for each configuration.
1013 bool NoSOName = false;
1014 ManagedType Managed = Native;
1015 unsigned int Multiplicity = 0;
1016 std::string Location;
1018 std::string ImportLibrary;
1019 std::string LibName;
1020 std::string Languages;
1021 std::string LibrariesProp;
1022 std::vector<BT<std::string>> Libraries;
1023 std::vector<BT<std::string>> LibrariesHeadInclude;
1024 std::vector<BT<std::string>> LibrariesHeadExclude;
1025 std::string SharedDeps;
1028 using ImportInfoMapType = std::map<std::string, ImportInfo>;
1029 mutable ImportInfoMapType ImportInfoMap;
1030 void ComputeImportInfo(std::string const& desired_config,
1031 ImportInfo& info) const;
1032 ImportInfo const* GetImportInfo(const std::string& config) const;
1034 /** Strip off leading and trailing whitespace from an item named in
1035 the link dependencies of this target. */
1036 std::string CheckCMP0004(std::string const& item) const;
1038 cmLinkInterface const* GetImportLinkInterface(const std::string& config,
1039 const cmGeneratorTarget* head,
1040 LinkInterfaceFor interfaceFor,
1041 bool secondPass = false) const;
1043 using KindedSourcesMapType = std::map<std::string, KindedSources>;
1044 mutable KindedSourcesMapType KindedSourcesMap;
1045 void ComputeKindedSources(KindedSources& files,
1046 std::string const& config) const;
1048 mutable std::vector<AllConfigSource> AllConfigSources;
1049 void ComputeAllConfigSources() const;
1051 mutable std::unordered_map<std::string, bool> MaybeInterfacePropertyExists;
1052 bool MaybeHaveInterfaceProperty(std::string const& prop,
1053 cmGeneratorExpressionContext* context,
1054 LinkInterfaceFor interfaceFor) const;
1056 using TargetPropertyEntryVector =
1057 std::vector<std::unique_ptr<TargetPropertyEntry>>;
1059 TargetPropertyEntryVector IncludeDirectoriesEntries;
1060 TargetPropertyEntryVector CompileOptionsEntries;
1061 TargetPropertyEntryVector CompileFeaturesEntries;
1062 TargetPropertyEntryVector CompileDefinitionsEntries;
1063 TargetPropertyEntryVector LinkOptionsEntries;
1064 TargetPropertyEntryVector LinkDirectoriesEntries;
1065 TargetPropertyEntryVector PrecompileHeadersEntries;
1066 TargetPropertyEntryVector SourceEntries;
1067 mutable std::set<std::string> LinkImplicitNullProperties;
1068 mutable std::map<std::string, std::string> PchHeaders;
1069 mutable std::map<std::string, std::string> PchSources;
1070 mutable std::map<std::string, std::string> PchObjectFiles;
1071 mutable std::map<std::string, std::string> PchFiles;
1072 mutable std::map<std::string, std::string> PchCreateCompileOptions;
1073 mutable std::map<std::string, std::string> PchUseCompileOptions;
1075 std::unordered_set<std::string> UnityBatchedSourceFiles;
1077 std::unordered_map<std::string, std::vector<std::string>>
1078 ISPCGeneratedHeaders;
1079 std::unordered_map<std::string, std::vector<std::string>>
1080 ISPCGeneratedObjects;
1082 enum class LinkInterfaceField
1088 void ExpandLinkItems(std::string const& prop, cmBTStringRange entries,
1089 std::string const& config,
1090 const cmGeneratorTarget* headTarget,
1091 LinkInterfaceFor interfaceFor, LinkInterfaceField field,
1092 cmLinkInterface& iface) const;
1094 struct LookupLinkItemScope
1096 cmLocalGenerator const* LG;
1098 enum class LookupSelf
1103 cm::optional<cmLinkItem> LookupLinkItem(std::string const& n,
1104 cmListFileBacktrace const& bt,
1105 LookupLinkItemScope* scope,
1106 LookupSelf lookupSelf) const;
1108 std::vector<BT<std::string>> GetSourceFilePaths(
1109 std::string const& config) const;
1110 std::vector<BT<cmSourceFile*>> GetSourceFilesWithoutObjectLibraries(
1111 std::string const& config) const;
1112 void GetSourceFilesWithoutObjectLibraries(std::vector<cmSourceFile*>& files,
1113 const std::string& config) const;
1115 struct HeadToLinkImplementationMap
1116 : public std::map<cmGeneratorTarget const*, cmOptionalLinkImplementation>
1119 using LinkImplMapType = std::map<std::string, HeadToLinkImplementationMap>;
1120 mutable LinkImplMapType LinkImplMap;
1121 mutable LinkImplMapType LinkImplUsageRequirementsOnlyMap;
1123 HeadToLinkImplementationMap& GetHeadToLinkImplementationMap(
1124 std::string const& config) const;
1125 HeadToLinkImplementationMap& GetHeadToLinkImplementationUsageRequirementsMap(
1126 std::string const& config) const;
1128 cmLinkImplementationLibraries const* GetLinkImplementationLibrariesInternal(
1129 const std::string& config, const cmGeneratorTarget* head,
1130 LinkInterfaceFor implFor) const;
1131 bool ComputeOutputDir(const std::string& config,
1132 cmStateEnums::ArtifactType artifact,
1133 std::string& out) const;
1135 using OutputInfoMapType = std::map<std::string, OutputInfo>;
1136 mutable OutputInfoMapType OutputInfoMap;
1138 using ModuleDefinitionInfoMapType =
1139 std::map<std::string, ModuleDefinitionInfo>;
1140 mutable ModuleDefinitionInfoMapType ModuleDefinitionInfoMap;
1141 void ComputeModuleDefinitionInfo(std::string const& config,
1142 ModuleDefinitionInfo& info) const;
1144 using OutputNameKey = std::pair<std::string, cmStateEnums::ArtifactType>;
1145 using OutputNameMapType = std::map<OutputNameKey, std::string>;
1146 mutable OutputNameMapType OutputNameMap;
1147 mutable std::set<cmLinkItem> UtilityItems;
1148 cmPolicies::PolicyMap PolicyMap;
1149 mutable bool PolicyWarnedCMP0022 = false;
1150 mutable bool PolicyReportedCMP0069 = false;
1151 mutable bool DebugIncludesDone = false;
1152 mutable bool DebugCompileOptionsDone = false;
1153 mutable bool DebugCompileFeaturesDone = false;
1154 mutable bool DebugCompileDefinitionsDone = false;
1155 mutable bool DebugLinkOptionsDone = false;
1156 mutable bool DebugLinkDirectoriesDone = false;
1157 mutable bool DebugPrecompileHeadersDone = false;
1158 mutable bool DebugSourcesDone = false;
1159 mutable bool UtilityItemsDone = false;
1166 mutable Tribool SourcesAreContextDependent = Tribool::Indeterminate;
1168 bool ComputePDBOutputDir(const std::string& kind, const std::string& config,
1169 std::string& out) const;
1171 ManagedType CheckManagedType(std::string const& propval) const;
1173 bool GetRPATH(const std::string& config, const std::string& prop,
1174 std::string& rpath) const;
1176 mutable std::map<std::string, BTs<std::string>> LanguageStandardMap;
1178 cmValue GetPropertyWithPairedLanguageSupport(std::string const& lang,
1179 const char* suffix) const;
1181 void ComputeLinkImplementationRuntimeLibraries(
1182 const std::string& config, cmOptionalLinkImplementation& impl) const;
1184 void ComputeLinkInterfaceRuntimeLibraries(
1185 const std::string& config, cmOptionalLinkInterface& iface) const;
1188 const std::vector<const cmGeneratorTarget*>& GetLinkImplementationClosure(
1189 const std::string& config) const;
1191 mutable std::map<std::string, std::string> MaxLanguageStandards;
1192 std::map<std::string, std::string> const& GetMaxLanguageStandards() const
1194 return this->MaxLanguageStandards;
1197 struct StrictTargetComparison
1199 bool operator()(cmGeneratorTarget const* t1,
1200 cmGeneratorTarget const* t2) const;
1203 // C++20 module support queries.
1206 * Query whether the target expects C++20 module support.
1208 * This will inspect the target itself to see if C++20 module
1209 * support is expected to work based on its sources.
1211 bool HaveCxx20ModuleSources() const;
1213 enum class Cxx20SupportLevel
1215 // C++ is not available.
1217 // The experimental feature is not available.
1218 MissingExperimentalFlag,
1219 // The target does not require at least C++20.
1221 // C++20 modules are available and working.
1225 * Query whether the target has C++20 module support available (regardless of
1226 * whether it is required or not).
1228 Cxx20SupportLevel HaveCxxModuleSupport(std::string const& config) const;
1230 // Check C++ module status for the target.
1231 void CheckCxxModuleStatus(std::string const& config) const;