cmGeneratorTarget.h 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  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. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <cstddef>
  6. #include <functional>
  7. #include <map>
  8. #include <memory>
  9. #include <set>
  10. #include <string>
  11. #include <unordered_map>
  12. #include <unordered_set>
  13. #include <utility>
  14. #include <vector>
  15. #include <cm/optional>
  16. #include <cm/string_view>
  17. #include "cmAlgorithms.h"
  18. #include "cmLinkItem.h"
  19. #include "cmList.h"
  20. #include "cmListFileCache.h"
  21. #include "cmObjectLocation.h"
  22. #include "cmPolicies.h"
  23. #include "cmStandardLevel.h"
  24. #include "cmStateTypes.h"
  25. #include "cmValue.h"
  26. namespace cm {
  27. namespace GenEx {
  28. struct Context;
  29. struct Evaluation;
  30. }
  31. }
  32. class cmake;
  33. enum class cmBuildStep;
  34. class cmCompiledGeneratorExpression;
  35. class cmComputeLinkInformation;
  36. class cmCustomCommand;
  37. class cmFileSet;
  38. class cmGlobalGenerator;
  39. class cmLocalGenerator;
  40. class cmMakefile;
  41. class cmSourceFile;
  42. struct cmSyntheticTargetCache;
  43. class cmTarget;
  44. struct cmGeneratorExpressionDAGChecker;
  45. class cmGeneratorTarget
  46. {
  47. public:
  48. cmGeneratorTarget(cmTarget*, cmLocalGenerator* lg);
  49. ~cmGeneratorTarget();
  50. cmGeneratorTarget(cmGeneratorTarget const&) = delete;
  51. cmGeneratorTarget& operator=(cmGeneratorTarget const&) = delete;
  52. cmLocalGenerator* GetLocalGenerator() const;
  53. cmGlobalGenerator* GetGlobalGenerator() const;
  54. bool IsInBuildSystem() const;
  55. bool IsNormal() const;
  56. bool IsRuntimeBinary() const;
  57. bool IsSynthetic() const;
  58. bool IsImported() const;
  59. bool IsImportedGloballyVisible() const;
  60. bool IsForeign() const;
  61. bool IsSymbolic() const;
  62. bool CanCompileSources() const;
  63. bool HasKnownRuntimeArtifactLocation(std::string const& config) const;
  64. std::string const& GetLocation(std::string const& config) const;
  65. /** Get the full path to the target's main artifact, if known. */
  66. cm::optional<std::string> MaybeGetLocation(std::string const& config) const;
  67. std::vector<cmCustomCommand> const& GetPreBuildCommands() const;
  68. std::vector<cmCustomCommand> const& GetPreLinkCommands() const;
  69. std::vector<cmCustomCommand> const& GetPostBuildCommands() const;
  70. void AppendCustomCommandSideEffects(
  71. std::set<cmGeneratorTarget const*>& sideEffects) const;
  72. void AppendLanguageSideEffects(
  73. std::map<std::string, std::set<cmGeneratorTarget const*>>& sideEffects)
  74. const;
  75. #define DECLARE_TARGET_POLICY(POLICY) \
  76. cmPolicies::PolicyStatus GetPolicyStatus##POLICY() const \
  77. { \
  78. return this->PolicyMap.Get(cmPolicies::POLICY); \
  79. }
  80. CM_FOR_EACH_TARGET_POLICY(DECLARE_TARGET_POLICY)
  81. #undef DECLARE_TARGET_POLICY
  82. /** Get the location of the target in the build tree with a placeholder
  83. referencing the configuration in the native build system. This
  84. location is suitable for use as the LOCATION target property. */
  85. std::string const& GetLocationForBuild() const;
  86. cmComputeLinkInformation* GetLinkInformation(
  87. std::string const& config) const;
  88. // Perform validation checks on memoized link structures.
  89. // Call this after generation is complete.
  90. void CheckLinkLibraries() const;
  91. class CheckLinkLibrariesSuppressionRAII
  92. {
  93. public:
  94. CheckLinkLibrariesSuppressionRAII();
  95. ~CheckLinkLibrariesSuppressionRAII();
  96. };
  97. cmStateEnums::TargetType GetType() const;
  98. std::string const& GetName() const;
  99. std::string GetFamilyName() const;
  100. std::string GetExportName() const;
  101. std::string GetFilesystemExportName() const;
  102. std::vector<std::string> GetPropertyKeys() const;
  103. //! Might return a nullptr if the property is not set or invalid
  104. cmValue GetProperty(std::string const& prop) const;
  105. //! Always returns a valid pointer
  106. std::string const& GetSafeProperty(std::string const& prop) const;
  107. bool GetPropertyAsBool(std::string const& prop) const;
  108. void GetSourceFiles(std::vector<cmSourceFile*>& files,
  109. std::string const& config) const;
  110. std::vector<BT<cmSourceFile*>> GetSourceFiles(
  111. std::string const& config) const;
  112. /** Source file kinds (classifications).
  113. Generators use this to decide how to treat a source file. */
  114. enum SourceKind
  115. {
  116. SourceKindAppManifest,
  117. SourceKindCertificate,
  118. SourceKindCustomCommand,
  119. SourceKindExternalObject,
  120. SourceKindCxxModuleSource,
  121. SourceKindExtra,
  122. SourceKindHeader,
  123. SourceKindIDL,
  124. SourceKindManifest,
  125. SourceKindModuleDefinition,
  126. SourceKindObjectSource,
  127. SourceKindResx,
  128. SourceKindXaml,
  129. SourceKindUnityBatched
  130. };
  131. /** A source file paired with a kind (classification). */
  132. struct SourceAndKind
  133. {
  134. BT<cmSourceFile*> Source;
  135. SourceKind Kind;
  136. };
  137. /** All sources needed for a configuration with kinds assigned. */
  138. struct KindedSources
  139. {
  140. std::vector<SourceAndKind> Sources;
  141. bool Initialized = false;
  142. };
  143. /** Get all sources needed for a configuration with kinds assigned. */
  144. KindedSources const& GetKindedSources(std::string const& config) const;
  145. struct AllConfigSource
  146. {
  147. cmSourceFile* Source;
  148. cmGeneratorTarget::SourceKind Kind;
  149. std::vector<size_t> Configs;
  150. };
  151. /** Get all sources needed for all configurations with kinds and
  152. per-source configurations assigned. */
  153. 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;
  156. /** Get all languages used to compile sources in any configuration.
  157. This excludes the languages of objects from object libraries. */
  158. std::set<std::string> GetAllConfigCompileLanguages() const;
  159. void GetObjectSources(std::vector<cmSourceFile const*>&,
  160. std::string const& config) const;
  161. std::string const& GetObjectName(cmSourceFile const* file);
  162. char const* GetCustomObjectExtension() const;
  163. bool HasExplicitObjectName(cmSourceFile const* file) const;
  164. void AddExplicitObjectName(cmSourceFile const* sf);
  165. BTs<std::string> const* GetLanguageStandardProperty(
  166. std::string const& lang, std::string const& config) const;
  167. cmValue GetLanguageStandard(std::string const& lang,
  168. std::string const& config) const;
  169. cmValue GetLanguageExtensions(std::string const& lang) const;
  170. bool GetLanguageStandardRequired(std::string const& lang) const;
  171. void GetModuleDefinitionSources(std::vector<cmSourceFile const*>&,
  172. std::string const& config) const;
  173. void GetExternalObjects(std::vector<cmSourceFile const*>&,
  174. std::string const& config) const;
  175. void GetHeaderSources(std::vector<cmSourceFile const*>&,
  176. std::string const& config) const;
  177. void GetCxxModuleSources(std::vector<cmSourceFile const*>&,
  178. std::string const& config) const;
  179. void GetExtraSources(std::vector<cmSourceFile const*>&,
  180. std::string const& config) const;
  181. void GetCustomCommands(std::vector<cmSourceFile const*>&,
  182. std::string const& config) const;
  183. void GetManifests(std::vector<cmSourceFile const*>&,
  184. std::string const& config) const;
  185. std::set<cmLinkItem> const& GetUtilityItems() const;
  186. void ComputeObjectMapping();
  187. cmValue GetFeature(std::string const& feature,
  188. std::string const& config) const;
  189. std::string GetLinkerTypeProperty(std::string const& lang,
  190. std::string const& config) const;
  191. char const* GetLinkPIEProperty(std::string const& config) const;
  192. bool IsIPOEnabled(std::string const& lang, std::string const& config) const;
  193. bool IsLinkInterfaceDependentBoolProperty(std::string const& p,
  194. std::string const& config) const;
  195. bool IsLinkInterfaceDependentStringProperty(std::string const& p,
  196. std::string const& config) const;
  197. bool IsLinkInterfaceDependentNumberMinProperty(
  198. std::string const& p, std::string const& config) const;
  199. bool IsLinkInterfaceDependentNumberMaxProperty(
  200. std::string const& p, std::string const& config) const;
  201. bool GetLinkInterfaceDependentBoolProperty(std::string const& p,
  202. std::string const& config) const;
  203. char const* GetLinkInterfaceDependentStringProperty(
  204. std::string const& p, std::string const& config) const;
  205. char const* GetLinkInterfaceDependentNumberMinProperty(
  206. std::string const& p, std::string const& config) const;
  207. char const* GetLinkInterfaceDependentNumberMaxProperty(
  208. std::string const& p, std::string const& config) const;
  209. class DeviceLinkSetter
  210. {
  211. public:
  212. DeviceLinkSetter(cmGeneratorTarget& target)
  213. : Target(target)
  214. {
  215. this->PreviousState = target.SetDeviceLink(true);
  216. }
  217. ~DeviceLinkSetter() { this->Target.SetDeviceLink(this->PreviousState); }
  218. private:
  219. cmGeneratorTarget& Target;
  220. bool PreviousState;
  221. };
  222. bool SetDeviceLink(bool deviceLink);
  223. bool IsDeviceLink() const { return this->DeviceLink; }
  224. cmLinkInterface const* GetLinkInterface(
  225. std::string const& config, cmGeneratorTarget const* headTarget) const;
  226. enum class UseTo
  227. {
  228. Compile, // Usage requirements for compiling. Excludes $<LINK_ONLY>.
  229. Link, // Usage requirements for linking. Includes $<LINK_ONLY>.
  230. };
  231. cmLinkInterfaceLibraries const* GetLinkInterfaceLibraries(
  232. std::string const& config, cmGeneratorTarget const* headTarget,
  233. UseTo usage) const;
  234. void ComputeLinkInterfaceLibraries(std::string const& config,
  235. cmOptionalLinkInterface& iface,
  236. cmGeneratorTarget const* head,
  237. UseTo usage) const;
  238. /** Get the library name for an imported interface library. */
  239. std::string GetImportedLibName(std::string const& config) const;
  240. /** Get the full path to the target according to the settings in its
  241. makefile and the configuration type. */
  242. std::string GetFullPath(
  243. std::string const& config,
  244. cmStateEnums::ArtifactType artifact = cmStateEnums::RuntimeBinaryArtifact,
  245. bool realname = false) const;
  246. std::string NormalGetFullPath(std::string const& config,
  247. cmStateEnums::ArtifactType artifact,
  248. bool realname) const;
  249. std::string NormalGetRealName(std::string const& config,
  250. cmStateEnums::ArtifactType artifact =
  251. cmStateEnums::RuntimeBinaryArtifact) const;
  252. /** Get the names of an object library's object files underneath
  253. its object file directory for the build. */
  254. void GetTargetObjectNames(std::string const& config,
  255. std::vector<std::string>& objects) const;
  256. /** Get the build and install locations of objects for a given context. */
  257. void GetTargetObjectLocations(
  258. std::string const& config,
  259. std::function<void(cmObjectLocation const&, cmObjectLocation const&)> cb)
  260. const;
  261. /** What hierarchy level should the reported directory contain */
  262. enum BundleDirectoryLevel
  263. {
  264. BundleDirLevel,
  265. ContentLevel,
  266. FullLevel
  267. };
  268. /** @return the Mac App directory without the base */
  269. std::string GetAppBundleDirectory(std::string const& config,
  270. BundleDirectoryLevel level) const;
  271. /** Return whether this target is marked as deprecated by the
  272. maintainer */
  273. bool IsDeprecated() const;
  274. /** Returns the deprecation message provided by the maintainer */
  275. std::string GetDeprecation() const;
  276. /** Return whether this target is an executable Bundle, a framework
  277. or CFBundle on Apple. */
  278. bool IsBundleOnApple() const;
  279. /** Return whether this target is a Win32 executable */
  280. bool IsWin32Executable(std::string const& config) const;
  281. /** Get the full name of the target according to the settings in its
  282. makefile. */
  283. std::string GetFullName(std::string const& config,
  284. cmStateEnums::ArtifactType artifact =
  285. cmStateEnums::RuntimeBinaryArtifact) const;
  286. /** @return the Mac framework directory without the base. */
  287. std::string GetFrameworkDirectory(std::string const& config,
  288. BundleDirectoryLevel level) const;
  289. /** Return the framework version string. Undefined if
  290. IsFrameworkOnApple returns false. */
  291. std::string GetFrameworkVersion() const;
  292. /** @return the Mac CFBundle directory without the base */
  293. std::string GetCFBundleDirectory(std::string const& config,
  294. BundleDirectoryLevel level) const;
  295. /** Return the install name directory for the target in the
  296. * build tree. For example: "\@rpath/", "\@loader_path/",
  297. * or "/full/path/to/library". */
  298. std::string GetInstallNameDirForBuildTree(std::string const& config) const;
  299. /** Return the install name directory for the target in the
  300. * install tree. For example: "\@rpath/" or "\@loader_path/". */
  301. std::string GetInstallNameDirForInstallTree(
  302. std::string const& config, std::string const& installPrefix) const;
  303. cmListFileBacktrace GetBacktrace() const;
  304. std::set<BT<std::pair<std::string, bool>>> const& GetUtilities() const;
  305. bool LinkLanguagePropagatesToDependents() const
  306. {
  307. return this->GetType() == cmStateEnums::STATIC_LIBRARY;
  308. }
  309. /** Get the macro to define when building sources in this target.
  310. If no macro should be defined null is returned. */
  311. std::string const* GetExportMacro() const;
  312. /** Get the list of preprocessor definitions, that should be defined
  313. when building sources in this target.
  314. If no macro should be defined the empty list is returned. */
  315. cmList const& GetSharedLibraryCompileDefs(std::string const& config) const;
  316. /** Get the soname of the target. Allowed only for a shared library. */
  317. std::string GetSOName(std::string const& config,
  318. cmStateEnums::ArtifactType artifact =
  319. cmStateEnums::RuntimeBinaryArtifact) const;
  320. struct NameComponents
  321. {
  322. std::string prefix;
  323. std::string base;
  324. std::string suffix;
  325. };
  326. NameComponents const& GetFullNameComponents(
  327. std::string const& config,
  328. cmStateEnums::ArtifactType artifact =
  329. cmStateEnums::RuntimeBinaryArtifact) const;
  330. /** Append to @a base the bundle directory hierarchy up to a certain @a level
  331. * and return it. */
  332. std::string BuildBundleDirectory(std::string const& base,
  333. std::string const& config,
  334. BundleDirectoryLevel level) const;
  335. /** @return the mac content directory for this target. */
  336. std::string GetMacContentDirectory(
  337. std::string const& config, cmStateEnums::ArtifactType artifact) const;
  338. /** @return folder prefix for IDEs. */
  339. std::string GetEffectiveFolderName() const;
  340. cmTarget* Target;
  341. cmMakefile* Makefile;
  342. cmLocalGenerator* LocalGenerator;
  343. cmGlobalGenerator const* GlobalGenerator;
  344. std::string targetLabelsString;
  345. struct ModuleDefinitionInfo
  346. {
  347. std::string DefFile;
  348. bool DefFileGenerated;
  349. bool WindowsExportAllSymbols;
  350. std::vector<cmSourceFile const*> Sources;
  351. };
  352. ModuleDefinitionInfo const* GetModuleDefinitionInfo(
  353. std::string const& config) const;
  354. /** Return whether or not we are targeting AIX. */
  355. bool IsAIX() const;
  356. /** Return whether or not we are targeting Apple. */
  357. bool IsApple() const;
  358. /** Return whether or not the target is for a DLL platform. */
  359. bool IsDLLPlatform() const;
  360. /** @return whether this target have a well defined output file name. */
  361. bool HaveWellDefinedOutputFiles() const;
  362. /** Link information from the transitive closure of the link
  363. implementation and the interfaces of its dependencies. */
  364. struct LinkClosure
  365. {
  366. // The preferred linker language.
  367. std::string LinkerLanguage;
  368. // Languages whose runtime libraries must be linked.
  369. std::vector<std::string> Languages;
  370. };
  371. LinkClosure const* GetLinkClosure(std::string const& config) const;
  372. cmLinkImplementation const* GetLinkImplementation(std::string const& config,
  373. UseTo usage) const;
  374. void ComputeLinkImplementationLanguages(
  375. std::string const& config, cmOptionalLinkImplementation& impl) const;
  376. cmLinkImplementationLibraries const* GetLinkImplementationLibraries(
  377. std::string const& config, UseTo usage) const;
  378. void ComputeLinkImplementationLibraries(std::string const& config,
  379. cmOptionalLinkImplementation& impl,
  380. UseTo usage) const;
  381. struct TargetOrString
  382. {
  383. std::string String;
  384. cmGeneratorTarget* Target = nullptr;
  385. };
  386. TargetOrString ResolveTargetReference(std::string const& name) const;
  387. TargetOrString ResolveTargetReference(std::string const& name,
  388. cmLocalGenerator const* lg) const;
  389. cmLinkItem ResolveLinkItem(
  390. BT<std::string> const& name,
  391. std::string const& linkFeature = cmLinkItem::DEFAULT) const;
  392. cmLinkItem ResolveLinkItem(
  393. BT<std::string> const& name, cmLocalGenerator const* lg,
  394. std::string const& linkFeature = cmLinkItem::DEFAULT) const;
  395. bool HasPackageReferences() const;
  396. std::vector<std::string> GetPackageReferences() const;
  397. // Compute the set of languages compiled by the target. This is
  398. // computed every time it is called because the languages can change
  399. // when source file properties are changed and we do not have enough
  400. // information to forward these property changes to the targets
  401. // until we have per-target object file properties.
  402. void GetLanguages(std::set<std::string>& languages,
  403. std::string const& config) const;
  404. bool IsLanguageUsed(std::string const& language,
  405. std::string const& config) const;
  406. // Get the set of targets directly referenced via `TARGET_OBJECTS` in the
  407. // source list for a configuration.
  408. std::set<cmGeneratorTarget const*> GetSourceObjectLibraries(
  409. std::string const& config) const;
  410. bool IsCSharpOnly() const;
  411. bool IsDotNetSdkTarget() const;
  412. void GetObjectLibrariesInSources(
  413. std::vector<cmGeneratorTarget*>& objlibs) const;
  414. std::string GetFullNameImported(std::string const& config,
  415. cmStateEnums::ArtifactType artifact) const;
  416. /** Get source files common to all configurations and diagnose cases
  417. with per-config sources. Excludes sources added by a TARGET_OBJECTS
  418. generator expression. Do not use outside the Xcode generator. */
  419. bool GetConfigCommonSourceFilesForXcode(
  420. std::vector<cmSourceFile*>& files) const;
  421. bool HaveBuildTreeRPATH(std::string const& config) const;
  422. /** Full path with trailing slash to the top-level directory
  423. holding object files for this target. Includes the build
  424. time config name placeholder if needed for the generator. */
  425. std::string ObjectDirectory;
  426. /** Full path with trailing slash to the top-level directory
  427. holding object files for the given configuration. */
  428. std::string GetObjectDirectory(std::string const& config) const;
  429. std::vector<std::string> GetAppleArchs(std::string const& config,
  430. cm::optional<std::string> lang) const;
  431. // The classification of the flag.
  432. enum class FlagClassification
  433. {
  434. // The flag is for the execution of the tool (e.g., the compiler itself,
  435. // any launchers, etc.).
  436. ExecutionFlag,
  437. // The flag is "baseline" and should be apply to TUs which may interact
  438. // with this compilation (e.g., imported modules).
  439. BaselineFlag,
  440. // The flag is "private" and doesn't need to apply to interacting TUs.
  441. PrivateFlag,
  442. // Flags for the TU itself (e.g., output paths, dependency scanning, etc.).
  443. LocationFlag,
  444. };
  445. enum class FlagKind
  446. {
  447. // Not a flag (executable or other entries).
  448. NotAFlag,
  449. // Flags for support of the build system.
  450. BuildSystem,
  451. // A compilation flag.
  452. Compile,
  453. // An include flag.
  454. Include,
  455. // A compile definition.
  456. Definition,
  457. };
  458. struct ClassifiedFlag
  459. {
  460. ClassifiedFlag(FlagClassification cls, FlagKind kind, std::string flag)
  461. : Classification(cls)
  462. , Kind(kind)
  463. , Flag(std::move(flag))
  464. {
  465. }
  466. FlagClassification Classification;
  467. FlagKind Kind;
  468. std::string Flag;
  469. };
  470. using ClassifiedFlags = std::vector<ClassifiedFlag>;
  471. ClassifiedFlags GetClassifiedFlagsForSource(cmSourceFile const* sf,
  472. std::string const& config);
  473. struct SourceVariables
  474. {
  475. std::string TargetPDB;
  476. std::string TargetCompilePDB;
  477. std::string ObjectDir;
  478. std::string TargetSupportDir;
  479. std::string ObjectFileDir;
  480. std::string DependencyFile;
  481. std::string DependencyTarget;
  482. // Dependency flags (if used)
  483. std::string DependencyFlags;
  484. };
  485. SourceVariables GetSourceVariables(cmSourceFile const* sf,
  486. std::string const& config);
  487. void AddExplicitLanguageFlags(std::string& flags,
  488. cmSourceFile const& sf) const;
  489. void AddCUDAArchitectureFlags(cmBuildStep compileOrLink,
  490. std::string const& config,
  491. std::string& flags) const;
  492. void AddCUDAArchitectureFlagsImpl(cmBuildStep compileOrLink,
  493. std::string const& config,
  494. std::string const& lang, std::string arch,
  495. std::string& flags) const;
  496. void AddCUDAToolkitFlags(std::string& flags) const;
  497. void AddHIPArchitectureFlags(cmBuildStep compileOrLink,
  498. std::string const& config,
  499. std::string& flags) const;
  500. void AddISPCTargetFlags(std::string& flags) const;
  501. std::string GetFeatureSpecificLinkRuleVariable(
  502. std::string const& var, std::string const& lang,
  503. std::string const& config) const;
  504. /** Return the rule variable used to create this type of target. */
  505. std::string GetCreateRuleVariable(std::string const& lang,
  506. std::string const& config) const;
  507. std::string GetClangTidyExportFixesDirectory(std::string const& lang) const;
  508. /** Return the swift module name for this target. */
  509. std::string GetSwiftModuleName() const;
  510. /** Return the path of the `.swiftmodule` for this target in
  511. the given configuration. */
  512. std::string GetSwiftModulePath(std::string const& config) const;
  513. /** Return the directory containing Swift module interface
  514. descriptions for this target (including its `.swiftmodule`,
  515. `.abi.json`, and `.swiftdoc`) in the given configuration. */
  516. std::string GetSwiftModuleDirectory(std::string const& config) const;
  517. private:
  518. /** Return the given property of this target if it exists; otherwise
  519. return defaultValue. */
  520. std::string GetPropertyOrDefault(std::string const& property,
  521. std::string defaultValue) const;
  522. /** Return the name of the `.swiftmodule` file for this target. */
  523. std::string GetSwiftModuleFileName() const;
  524. using ConfigAndLanguage = std::pair<std::string, std::string>;
  525. using ConfigAndLanguageToBTStrings =
  526. std::map<ConfigAndLanguage, std::vector<BT<std::string>>>;
  527. mutable ConfigAndLanguageToBTStrings IncludeDirectoriesCache;
  528. mutable ConfigAndLanguageToBTStrings CompileOptionsCache;
  529. mutable ConfigAndLanguageToBTStrings CompileDefinitionsCache;
  530. mutable ConfigAndLanguageToBTStrings PrecompileHeadersCache;
  531. mutable ConfigAndLanguageToBTStrings LinkOptionsCache;
  532. mutable ConfigAndLanguageToBTStrings LinkDirectoriesCache;
  533. public:
  534. /** Get the include directories for this target. */
  535. std::vector<BT<std::string>> GetIncludeDirectories(
  536. std::string const& config, std::string const& lang) const;
  537. void GetCompileOptions(std::vector<std::string>& result,
  538. std::string const& config,
  539. std::string const& language) const;
  540. std::vector<BT<std::string>> GetCompileOptions(
  541. std::string const& config, std::string const& language) const;
  542. void GetCompileFeatures(std::vector<std::string>& features,
  543. std::string const& config) const;
  544. std::vector<BT<std::string>> GetCompileFeatures(
  545. std::string const& config) const;
  546. void GetCompileDefinitions(std::vector<std::string>& result,
  547. std::string const& config,
  548. std::string const& language) const;
  549. std::vector<BT<std::string>> GetCompileDefinitions(
  550. std::string const& config, std::string const& language) const;
  551. void GetLinkOptions(std::vector<std::string>& result,
  552. std::string const& config,
  553. std::string const& language) const;
  554. std::vector<BT<std::string>> GetLinkOptions(
  555. std::string const& config, std::string const& language) const;
  556. std::vector<BT<std::string>>& ResolveLinkerWrapper(
  557. std::vector<BT<std::string>>& result, std::string const& language,
  558. bool joinItems = false) const;
  559. void GetStaticLibraryLinkOptions(std::vector<std::string>& result,
  560. std::string const& config,
  561. std::string const& language) const;
  562. std::vector<BT<std::string>> GetStaticLibraryLinkOptions(
  563. std::string const& config, std::string const& language) const;
  564. std::vector<BT<std::string>>& ResolveArchiverWrapper(
  565. std::vector<BT<std::string>>& result, std::string const& language,
  566. bool joinItems = false) const;
  567. void GetLinkDirectories(std::vector<std::string>& result,
  568. std::string const& config,
  569. std::string const& language) const;
  570. std::vector<BT<std::string>> GetLinkDirectories(
  571. std::string const& config, std::string const& language) const;
  572. void GetLinkDepends(std::vector<std::string>& result,
  573. std::string const& config,
  574. std::string const& language) const;
  575. std::vector<BT<std::string>> GetLinkDepends(
  576. std::string const& config, std::string const& language) const;
  577. std::vector<BT<std::string>> GetPrecompileHeaders(
  578. std::string const& config, std::string const& language) const;
  579. void MarkAsPchReused() { this->PchReused = true; }
  580. cmGeneratorTarget const* GetPchReuseTarget() const;
  581. cmGeneratorTarget* GetPchReuseTarget();
  582. std::vector<std::string> GetPchArchs(std::string const& config,
  583. std::string const& lang) const;
  584. std::string GetPchHeader(std::string const& config,
  585. std::string const& language,
  586. std::string const& arch = std::string()) const;
  587. std::string GetPchSource(std::string const& config,
  588. std::string const& language,
  589. std::string const& arch = std::string()) const;
  590. std::string GetPchFileObject(std::string const& config,
  591. std::string const& language,
  592. std::string const& arch = std::string());
  593. std::string GetPchFile(std::string const& config,
  594. std::string const& language,
  595. std::string const& arch = std::string());
  596. std::string GetPchCreateCompileOptions(
  597. std::string const& config, std::string const& language,
  598. std::string const& arch = std::string());
  599. std::string GetPchUseCompileOptions(std::string const& config,
  600. std::string const& language,
  601. std::string const& arch = std::string());
  602. void AddSourceFileToUnityBatch(std::string const& sourceFilename);
  603. bool IsSourceFilePartOfUnityBatch(std::string const& sourceFilename) const;
  604. bool IsSystemIncludeDirectory(std::string const& dir,
  605. std::string const& config,
  606. std::string const& language) const;
  607. void AddSystemIncludeCacheKey(std::string const& key,
  608. std::string const& config,
  609. std::string const& language) const;
  610. /** Add the target output files to the global generator manifest. */
  611. void ComputeTargetManifest(std::string const& config) const;
  612. bool ComputeCompileFeatures(std::string const& config);
  613. using LanguagePair = std::pair<std::string, std::string>;
  614. bool ComputeCompileFeatures(std::string const& config,
  615. std::set<LanguagePair> const& languagePairs);
  616. /**
  617. * Trace through the source files in this target and add al source files
  618. * that they depend on, used by all generators
  619. */
  620. void TraceDependencies();
  621. /** Get the directory in which this target will be built. If the
  622. configuration name is given then the generator will add its
  623. subdirectory for that configuration. Otherwise just the canonical
  624. output directory is given. */
  625. std::string GetDirectory(std::string const& config,
  626. cmStateEnums::ArtifactType artifact =
  627. cmStateEnums::RuntimeBinaryArtifact) const;
  628. /** Get the directory in which to place the target compiler .pdb file.
  629. If the configuration name is given then the generator will add its
  630. subdirectory for that configuration. Otherwise just the canonical
  631. compiler pdb output directory is given. */
  632. std::string GetCompilePDBDirectory(std::string const& config) const;
  633. /** Get sources that must be built before the given source. */
  634. std::vector<cmSourceFile*> const* GetSourceDepends(
  635. cmSourceFile const* sf) const;
  636. /** Return whether this target uses the default value for its output
  637. directory. */
  638. bool UsesDefaultOutputDir(std::string const& config,
  639. cmStateEnums::ArtifactType artifact) const;
  640. // Cache target output paths for each configuration.
  641. struct OutputInfo
  642. {
  643. std::string OutDir;
  644. std::string ImpDir;
  645. std::string PdbDir;
  646. bool empty() const
  647. {
  648. return this->OutDir.empty() && this->ImpDir.empty() &&
  649. this->PdbDir.empty();
  650. }
  651. };
  652. OutputInfo const* GetOutputInfo(std::string const& config) const;
  653. // Get the target PDB base name.
  654. std::string GetPDBOutputName(std::string const& config) const;
  655. /** Get the name of the pdb file for the target. */
  656. std::string GetPDBName(std::string const& config) const;
  657. /** Whether this library has soname enabled and platform supports it. */
  658. bool HasSOName(std::string const& config) const;
  659. struct CompileInfo
  660. {
  661. std::string CompilePdbDir;
  662. };
  663. CompileInfo const* GetCompileInfo(std::string const& config) const;
  664. using CompileInfoMapType = std::map<std::string, CompileInfo>;
  665. mutable CompileInfoMapType CompileInfoMap;
  666. bool IsNullImpliedByLinkLibraries(std::string const& p) const;
  667. /** Get the name of the compiler pdb file for the target. */
  668. std::string GetCompilePDBName(std::string const& config) const;
  669. /** Get the path for the MSVC /Fd option for this target. */
  670. std::string GetCompilePDBPath(std::string const& config) const;
  671. // Get the target base name.
  672. std::string GetOutputName(std::string const& config,
  673. cmStateEnums::ArtifactType artifact) const;
  674. /** Get target file prefix */
  675. std::string GetFilePrefix(std::string const& config,
  676. cmStateEnums::ArtifactType artifact =
  677. cmStateEnums::RuntimeBinaryArtifact) const;
  678. /** Get target file prefix */
  679. std::string GetFileSuffix(std::string const& config,
  680. cmStateEnums::ArtifactType artifact =
  681. cmStateEnums::RuntimeBinaryArtifact) const;
  682. /** Get target file postfix */
  683. std::string GetFilePostfix(std::string const& config) const;
  684. /** Get framework multi-config-specific postfix */
  685. std::string GetFrameworkMultiConfigPostfix(std::string const& config) const;
  686. /** Clears cached meta data for local and external source files.
  687. * The meta data will be recomputed on demand.
  688. */
  689. void ClearSourcesCache();
  690. /**
  691. * Clears cached evaluations of INTERFACE_LINK_LIBRARIES.
  692. * They will be recomputed on demand.
  693. */
  694. void ClearLinkInterfaceCache();
  695. cmSourceFile* AddSource(std::string const& src, bool before = false);
  696. void AddTracedSources(std::vector<std::string> const& srcs);
  697. /**
  698. * Adds an entry to the INCLUDE_DIRECTORIES list.
  699. * If before is true the entry is pushed at the front.
  700. */
  701. void AddIncludeDirectory(std::string const& src, bool before = false);
  702. /**
  703. * Flags for a given source file as used in this target. Typically assigned
  704. * via SET_TARGET_PROPERTIES when the property is a list of source files.
  705. */
  706. enum SourceFileType
  707. {
  708. SourceFileTypeNormal,
  709. SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
  710. SourceFileTypePublicHeader, // is in "PUBLIC_HEADER" target property
  711. SourceFileTypeResource, // is in "RESOURCE" target property *or*
  712. // has MACOSX_PACKAGE_LOCATION=="Resources"
  713. SourceFileTypeDeepResource, // MACOSX_PACKAGE_LOCATION starts with
  714. // "Resources/"
  715. SourceFileTypeMacContent // has MACOSX_PACKAGE_LOCATION!="Resources[/]"
  716. };
  717. struct SourceFileFlags
  718. {
  719. SourceFileType Type = SourceFileTypeNormal;
  720. char const* MacFolder = nullptr; // location inside Mac content folders
  721. };
  722. void GetAutoUicOptions(std::vector<std::string>& result,
  723. std::string const& config) const;
  724. struct Names
  725. {
  726. std::string Base;
  727. std::string Output;
  728. std::string Real;
  729. std::string ImportOutput;
  730. std::string ImportReal;
  731. std::string ImportLibrary;
  732. std::string PDB;
  733. std::string SharedObject;
  734. };
  735. /** Get the names of the executable needed to generate a build rule
  736. that takes into account executable version numbers. This should
  737. be called only on an executable target. */
  738. Names GetExecutableNames(std::string const& config) const;
  739. /** Get the names of the library needed to generate a build rule
  740. that takes into account shared library version numbers. This
  741. should be called only on a library target. */
  742. Names GetLibraryNames(std::string const& config) const;
  743. /**
  744. * Compute whether this target must be relinked before installing.
  745. */
  746. bool NeedRelinkBeforeInstall(std::string const& config) const;
  747. /** Return true if builtin chrpath will work for this target */
  748. bool IsChrpathUsed(std::string const& config) const;
  749. /** Get the directory in which this targets .pdb files will be placed.
  750. If the configuration name is given then the generator will add its
  751. subdirectory for that configuration. Otherwise just the canonical
  752. pdb output directory is given. */
  753. std::string GetPDBDirectory(std::string const& config) const;
  754. //! Return the preferred linker language for this target
  755. std::string GetLinkerLanguage(std::string const& config) const;
  756. //! Return the preferred linker tool for this target
  757. std::string GetLinkerTool(std::string const& config) const;
  758. std::string GetLinkerTool(std::string const& lang,
  759. std::string const& config) const;
  760. /** Is the linker known to enforce '--no-allow-shlib-undefined'? */
  761. bool LinkerEnforcesNoAllowShLibUndefined(std::string const& config) const;
  762. /** Does this target have a GNU implib to convert to MS format? */
  763. bool HasImplibGNUtoMS(std::string const& config) const;
  764. /** Convert the given GNU import library name (.dll.a) to a name with a new
  765. extension (.lib or ${CMAKE_IMPORT_LIBRARY_SUFFIX}). */
  766. bool GetImplibGNUtoMS(std::string const& config, std::string const& gnuName,
  767. std::string& out, char const* newExt = nullptr) const;
  768. /** Can only ever return true if GetSourceFilePaths() was called before.
  769. Otherwise, this is indeterminate and false will be assumed/returned! */
  770. bool HasContextDependentSources() const;
  771. bool IsExecutableWithExports() const;
  772. /* Return whether this target is a shared library with capability to generate
  773. * a file describing symbols exported (for example, .tbd file on Apple). */
  774. bool IsSharedLibraryWithExports() const;
  775. /** Return whether or not the target has a DLL import library. */
  776. bool HasImportLibrary(std::string const& config) const;
  777. bool GetUseShortObjectNames(
  778. cmStateEnums::IntermediateDirKind kind =
  779. cmStateEnums::IntermediateDirKind::ObjectFiles) const;
  780. cmObjectLocations::UseShortPath GetUseShortObjectNamesForInstall() const;
  781. /** Get a build-tree directory in which to place target support files. */
  782. std::string GetSupportDirectory(
  783. cmStateEnums::IntermediateDirKind kind =
  784. cmStateEnums::IntermediateDirKind::ObjectFiles) const;
  785. std::string GetCMFSupportDirectory(
  786. cmStateEnums::IntermediateDirKind kind =
  787. cmStateEnums::IntermediateDirKind::ObjectFiles) const;
  788. /** Return whether this target may be used to link another target. */
  789. bool IsLinkable() const;
  790. /** Return whether the link step generates a dependency file. */
  791. bool HasLinkDependencyFile(std::string const& config) const;
  792. /** Return whether this target is a shared library Framework on
  793. Apple. */
  794. bool IsFrameworkOnApple() const;
  795. /** Return whether this target is an IMPORTED library target on Apple
  796. with a .framework folder as its location. */
  797. bool IsImportedFrameworkFolderOnApple(std::string const& config) const;
  798. /** Return whether this target is an executable Bundle on Apple. */
  799. bool IsAppBundleOnApple() const;
  800. /** Return whether this target is an XCTest on Apple. */
  801. bool IsXCTestOnApple() const;
  802. /** Return whether this target is a CFBundle (plugin) on Apple. */
  803. bool IsCFBundleOnApple() const;
  804. /** Return whether this target is a shared library on AIX. */
  805. bool IsArchivedAIXSharedLibrary() const;
  806. /** Assembly types. The order of the values of this enum is relevant
  807. because of smaller/larger comparison operations! */
  808. enum ManagedType
  809. {
  810. Undefined = 0, // target is no lib or executable
  811. Native, // target compiles to unmanaged binary.
  812. Mixed, // target compiles to mixed (managed and unmanaged) binary.
  813. Managed // target compiles to managed binary.
  814. };
  815. /** Return the type of assembly this target compiles to. */
  816. ManagedType GetManagedType(std::string const& config) const;
  817. struct SourceFileFlags GetTargetSourceFileFlags(
  818. cmSourceFile const* sf) const;
  819. void ReportPropertyOrigin(std::string const& p, std::string const& result,
  820. std::string const& report,
  821. std::string const& compatibilityType) const;
  822. class TargetPropertyEntry;
  823. std::string EvaluateInterfaceProperty(
  824. std::string const& prop, cm::GenEx::Evaluation* eval,
  825. cmGeneratorExpressionDAGChecker* dagCheckerParent, UseTo usage) const;
  826. struct TransitiveProperty
  827. {
  828. #if defined(__SUNPRO_CC) || (defined(__ibmxl__) && defined(__clang__))
  829. TransitiveProperty(cm::string_view interfaceName, UseTo usage)
  830. : InterfaceName(interfaceName)
  831. , Usage(usage)
  832. {
  833. }
  834. #endif
  835. cm::string_view InterfaceName;
  836. UseTo Usage;
  837. };
  838. static std::map<cm::string_view, TransitiveProperty> const
  839. BuiltinTransitiveProperties;
  840. cm::optional<TransitiveProperty> IsTransitiveProperty(
  841. cm::string_view prop, cm::GenEx::Context const& context,
  842. cmGeneratorExpressionDAGChecker const* dagChecker) const;
  843. bool HaveInstallTreeRPATH(std::string const& config) const;
  844. bool GetBuildRPATH(std::string const& config, std::string& rpath) const;
  845. bool GetInstallRPATH(std::string const& config, std::string& rpath) const;
  846. /** Whether this library has \@rpath and platform supports it. */
  847. bool HasMacOSXRpathInstallNameDir(std::string const& config) const;
  848. /** Whether this library defaults to \@rpath. */
  849. bool MacOSXRpathInstallNameDirDefault() const;
  850. enum InstallNameType
  851. {
  852. INSTALL_NAME_FOR_BUILD,
  853. INSTALL_NAME_FOR_INSTALL
  854. };
  855. /** Whether to use INSTALL_NAME_DIR. */
  856. bool MacOSXUseInstallNameDir() const;
  857. /** Whether to generate an install_name. */
  858. bool CanGenerateInstallNameDir(InstallNameType t) const;
  859. /** Test for special case of a third-party shared library that has
  860. no soname at all. */
  861. bool IsImportedSharedLibWithoutSOName(std::string const& config) const;
  862. std::string ImportedGetLocation(std::string const& config) const;
  863. /** Get the target major and minor version numbers interpreted from
  864. the VERSION property. Version 0 is returned if the property is
  865. not set or cannot be parsed. */
  866. void GetTargetVersion(int& major, int& minor) const;
  867. /** Get the target major, minor, and patch version numbers
  868. interpreted from the given property. Version 0
  869. is returned if the property is not set or cannot be parsed. */
  870. void GetTargetVersion(std::string const& property, int& major, int& minor,
  871. int& patch) const;
  872. /** Get the target major, minor, and patch version numbers
  873. interpreted from the given property and if empty use the
  874. fallback property. Version 0 is returned if the property is
  875. not set or cannot be parsed. */
  876. void GetTargetVersionFallback(std::string const& property,
  877. std::string const& fallback_property,
  878. int& major, int& minor, int& patch) const;
  879. std::string GetRuntimeLinkLibrary(std::string const& lang,
  880. std::string const& config) const;
  881. std::string GetFortranModuleDirectory(std::string const& working_dir) const;
  882. bool IsFortranBuildingIntrinsicModules() const;
  883. bool IsLinkLookupScope(std::string const& n,
  884. cmLocalGenerator const*& lg) const;
  885. cmValue GetSourcesProperty() const;
  886. void AddISPCGeneratedHeader(std::string const& header,
  887. std::string const& config);
  888. std::vector<std::string> GetGeneratedISPCHeaders(
  889. std::string const& config) const;
  890. void AddISPCGeneratedObject(std::vector<std::string>&& objs,
  891. std::string const& config);
  892. std::vector<std::string> GetGeneratedISPCObjects(
  893. std::string const& config) const;
  894. void AddSystemIncludeDirectory(std::string const& inc,
  895. std::string const& lang);
  896. bool AddHeaderSetVerification();
  897. std::string GenerateHeaderSetVerificationFile(
  898. cmSourceFile& source, std::string const& dir,
  899. cm::optional<std::set<std::string>>& languages) const;
  900. std::string GetImportedXcFrameworkPath(std::string const& config) const;
  901. bool ApplyCXXStdTargets();
  902. bool DiscoverSyntheticTargets(cmSyntheticTargetCache& cache,
  903. std::string const& config);
  904. class CustomTransitiveProperty : public TransitiveProperty
  905. {
  906. std::unique_ptr<std::string> InterfaceNameBuf;
  907. CustomTransitiveProperty(std::unique_ptr<std::string> interfaceNameBuf,
  908. UseTo usage);
  909. public:
  910. CustomTransitiveProperty(std::string interfaceName, UseTo usage);
  911. };
  912. struct CustomTransitiveProperties
  913. : public std::map<std::string, CustomTransitiveProperty>
  914. {
  915. void Add(cmValue props, UseTo usage);
  916. };
  917. enum class PropertyFor
  918. {
  919. Build,
  920. Interface,
  921. };
  922. CustomTransitiveProperties const& GetCustomTransitiveProperties(
  923. std::string const& config, PropertyFor propertyFor) const;
  924. private:
  925. void AddSourceCommon(std::string const& src, bool before = false);
  926. std::string CreateFortranModuleDirectory(
  927. std::string const& working_dir) const;
  928. mutable bool FortranModuleDirectoryCreated = false;
  929. mutable std::string FortranModuleDirectory;
  930. friend class cmTargetTraceDependencies;
  931. struct SourceEntry
  932. {
  933. std::vector<cmSourceFile*> Depends;
  934. };
  935. using SourceEntriesType = std::map<cmSourceFile const*, SourceEntry>;
  936. SourceEntriesType SourceDepends;
  937. mutable std::set<std::string> VisitedConfigsForObjects;
  938. mutable std::map<cmSourceFile const*, cmObjectLocations> Objects;
  939. std::set<cmSourceFile const*> ExplicitObjectName;
  940. using TargetPtrToBoolMap = std::unordered_map<cmTarget*, bool>;
  941. mutable std::unordered_map<std::string, TargetPtrToBoolMap>
  942. MacOSXRpathInstallNameDirCache;
  943. bool DetermineHasMacOSXRpathInstallNameDir(std::string const& config) const;
  944. // "config/language" is the key
  945. mutable std::map<std::string, std::vector<std::string>> SystemIncludesCache;
  946. mutable std::string ExportMacro;
  947. mutable std::unordered_map<std::string, cmList> SharedLibraryCompileDefs;
  948. void ConstructSourceFileFlags() const;
  949. mutable bool SourceFileFlagsConstructed = false;
  950. mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  951. mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
  952. bool NeedImportLibraryName(std::string const& config) const;
  953. cmValue GetFilePrefixInternal(std::string const& config,
  954. cmStateEnums::ArtifactType artifact,
  955. std::string const& language = "") const;
  956. cmValue GetFileSuffixInternal(std::string const& config,
  957. cmStateEnums::ArtifactType artifact,
  958. std::string const& language = "") const;
  959. std::string GetFullNameInternal(std::string const& config,
  960. cmStateEnums::ArtifactType artifact) const;
  961. using FullNameCache = std::map<std::string, NameComponents>;
  962. mutable FullNameCache RuntimeBinaryFullNameCache;
  963. mutable FullNameCache ImportLibraryFullNameCache;
  964. NameComponents const& GetFullNameInternalComponents(
  965. std::string const& config, cmStateEnums::ArtifactType artifact) const;
  966. mutable std::string LinkerLanguage;
  967. using LinkClosureMapType = std::map<std::string, LinkClosure>;
  968. mutable LinkClosureMapType LinkClosureMap;
  969. bool DeviceLink = false;
  970. // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type.
  971. char const* GetOutputTargetType(cmStateEnums::ArtifactType artifact) const;
  972. std::string ComputeVersionedName(std::string const& prefix,
  973. std::string const& base,
  974. std::string const& suffix,
  975. std::string const& name,
  976. cmValue version) const;
  977. mutable std::map<std::string, CustomTransitiveProperties>
  978. CustomTransitiveBuildPropertiesMap;
  979. mutable std::map<std::string, CustomTransitiveProperties>
  980. CustomTransitiveInterfacePropertiesMap;
  981. struct CompatibleInterfacesBase
  982. {
  983. std::set<std::string> PropsBool;
  984. std::set<std::string> PropsString;
  985. std::set<std::string> PropsNumberMax;
  986. std::set<std::string> PropsNumberMin;
  987. };
  988. CompatibleInterfacesBase const& GetCompatibleInterfaces(
  989. std::string const& config) const;
  990. struct CompatibleInterfaces : public CompatibleInterfacesBase
  991. {
  992. bool Done = false;
  993. };
  994. mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
  995. using cmTargetLinkInformationMap =
  996. std::map<std::string, std::unique_ptr<cmComputeLinkInformation>>;
  997. mutable cmTargetLinkInformationMap LinkInformation;
  998. void CheckPropertyCompatibility(cmComputeLinkInformation& info,
  999. std::string const& config) const;
  1000. void ComputeLinkClosure(std::string const& config, LinkClosure& lc) const;
  1001. bool ComputeLinkClosure(std::string const& config, LinkClosure& lc,
  1002. bool secondPass) const;
  1003. struct LinkImplClosure : public std::vector<cmGeneratorTarget const*>
  1004. {
  1005. bool Done = false;
  1006. };
  1007. mutable std::map<std::string, LinkImplClosure> LinkImplClosureForLinkMap;
  1008. mutable std::map<std::string, LinkImplClosure> LinkImplClosureForUsageMap;
  1009. using LinkInterfaceMapType = std::map<std::string, cmHeadToLinkInterfaceMap>;
  1010. mutable LinkInterfaceMapType LinkInterfaceMap;
  1011. mutable LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap;
  1012. cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceMap(
  1013. std::string const& config) const;
  1014. cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap(
  1015. std::string const& config) const;
  1016. std::string GetLinkInterfaceDependentStringAsBoolProperty(
  1017. std::string const& p, std::string const& config) const;
  1018. friend class cmTargetCollectLinkLanguages;
  1019. cmLinkInterface const* GetLinkInterface(std::string const& config,
  1020. cmGeneratorTarget const* headTarget,
  1021. bool secondPass) const;
  1022. void ComputeLinkInterface(std::string const& config,
  1023. cmOptionalLinkInterface& iface,
  1024. bool secondPass) const;
  1025. cmLinkImplementation const* GetLinkImplementation(std::string const& config,
  1026. UseTo usage,
  1027. bool secondPass) const;
  1028. enum class LinkItemRole
  1029. {
  1030. Implementation,
  1031. Interface,
  1032. };
  1033. bool VerifyLinkItemIsTarget(LinkItemRole role, cmLinkItem const& item) const;
  1034. bool VerifyLinkItemColons(LinkItemRole role, cmLinkItem const& item) const;
  1035. // Cache import information from properties for each configuration.
  1036. struct ImportInfo
  1037. {
  1038. bool NoSOName = false;
  1039. ManagedType Managed = Native;
  1040. unsigned int Multiplicity = 0;
  1041. std::string Location;
  1042. std::string SOName;
  1043. std::string ImportLibrary;
  1044. std::string LibName;
  1045. std::string Languages;
  1046. std::string LibrariesProp;
  1047. std::vector<BT<std::string>> Libraries;
  1048. std::vector<BT<std::string>> LibrariesHeadInclude;
  1049. std::vector<BT<std::string>> LibrariesHeadExclude;
  1050. std::string SharedDeps;
  1051. };
  1052. using ImportInfoMapType = std::map<std::string, ImportInfo>;
  1053. mutable ImportInfoMapType ImportInfoMap;
  1054. void ComputeImportInfo(std::string const& desired_config,
  1055. ImportInfo& info) const;
  1056. ImportInfo const* GetImportInfo(std::string const& config) const;
  1057. /** Strip off leading and trailing whitespace from an item named in
  1058. the link dependencies of this target. */
  1059. std::string CheckCMP0004(std::string const& item) const;
  1060. cmLinkInterface const* GetImportLinkInterface(std::string const& config,
  1061. cmGeneratorTarget const* head,
  1062. UseTo usage,
  1063. bool secondPass = false) const;
  1064. using KindedSourcesMapType = std::map<std::string, KindedSources>;
  1065. mutable KindedSourcesMapType KindedSourcesMap;
  1066. void ComputeKindedSources(KindedSources& files,
  1067. std::string const& config) const;
  1068. mutable std::vector<AllConfigSource> AllConfigSources;
  1069. void ComputeAllConfigSources() const;
  1070. mutable std::unordered_map<std::string, bool> MaybeInterfacePropertyExists;
  1071. bool MaybeHaveInterfaceProperty(std::string const& prop,
  1072. cm::GenEx::Evaluation* eval,
  1073. UseTo usage) const;
  1074. using TargetPropertyEntryVector =
  1075. std::vector<std::unique_ptr<TargetPropertyEntry>>;
  1076. TargetPropertyEntryVector IncludeDirectoriesEntries;
  1077. TargetPropertyEntryVector CompileOptionsEntries;
  1078. TargetPropertyEntryVector CompileFeaturesEntries;
  1079. TargetPropertyEntryVector CompileDefinitionsEntries;
  1080. TargetPropertyEntryVector LinkOptionsEntries;
  1081. TargetPropertyEntryVector LinkDirectoriesEntries;
  1082. TargetPropertyEntryVector PrecompileHeadersEntries;
  1083. TargetPropertyEntryVector SourceEntries;
  1084. mutable std::set<std::string> LinkImplicitNullProperties;
  1085. mutable std::map<std::string, std::string> PchHeaders;
  1086. mutable std::map<std::string, std::string> PchSources;
  1087. mutable std::map<std::string, std::string> PchObjectFiles;
  1088. mutable std::map<std::string, std::string> PchFiles;
  1089. mutable std::map<std::string, std::string> PchCreateCompileOptions;
  1090. mutable std::map<std::string, std::string> PchUseCompileOptions;
  1091. std::unordered_set<std::string> UnityBatchedSourceFiles;
  1092. std::unordered_map<std::string, std::vector<std::string>>
  1093. ISPCGeneratedHeaders;
  1094. std::unordered_map<std::string, std::vector<std::string>>
  1095. ISPCGeneratedObjects;
  1096. enum class LinkInterfaceField
  1097. {
  1098. Libraries,
  1099. HeadExclude,
  1100. HeadInclude,
  1101. };
  1102. void ExpandLinkItems(std::string const& prop, cmBTStringRange entries,
  1103. std::string const& config,
  1104. cmGeneratorTarget const* headTarget, UseTo usage,
  1105. LinkInterfaceField field, cmLinkInterface& iface) const;
  1106. struct LookupLinkItemScope
  1107. {
  1108. cmLocalGenerator const* LG;
  1109. };
  1110. enum class LookupSelf
  1111. {
  1112. No,
  1113. Yes,
  1114. };
  1115. cm::optional<cmLinkItem> LookupLinkItem(std::string const& n,
  1116. cmListFileBacktrace const& bt,
  1117. std::string const& linkFeature,
  1118. LookupLinkItemScope* scope,
  1119. LookupSelf lookupSelf) const;
  1120. std::vector<BT<std::string>>& ResolvePrefixWrapper(
  1121. std::vector<BT<std::string>>& result, cm::string_view prefix,
  1122. std::string const& language, bool joinItems) const;
  1123. std::vector<BT<std::string>> GetSourceFilePaths(
  1124. std::string const& config) const;
  1125. std::vector<BT<cmSourceFile*>> GetSourceFilesWithoutObjectLibraries(
  1126. std::string const& config) const;
  1127. void GetSourceFilesWithoutObjectLibraries(std::vector<cmSourceFile*>& files,
  1128. std::string const& config) const;
  1129. using LinkImplMapType = std::map<std::string, cmOptionalLinkImplementation>;
  1130. mutable LinkImplMapType LinkImplMap;
  1131. mutable LinkImplMapType LinkImplUsageRequirementsOnlyMap;
  1132. bool ComputeOutputDir(std::string const& config,
  1133. cmStateEnums::ArtifactType artifact,
  1134. std::string& out) const;
  1135. using OutputInfoMapType = std::map<std::string, OutputInfo>;
  1136. mutable OutputInfoMapType OutputInfoMap;
  1137. using PdbOutputNameMapType = std::map<std::string, std::string>;
  1138. mutable PdbOutputNameMapType PdbOutputNameMap;
  1139. using ModuleDefinitionInfoMapType =
  1140. std::map<std::string, ModuleDefinitionInfo>;
  1141. mutable ModuleDefinitionInfoMapType ModuleDefinitionInfoMap;
  1142. void ComputeModuleDefinitionInfo(std::string const& config,
  1143. 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 PolicyReportedCMP0069 = false;
  1150. mutable bool DebugIncludesDone = false;
  1151. mutable bool DebugCompileOptionsDone = false;
  1152. mutable bool DebugCompileFeaturesDone = false;
  1153. mutable bool DebugCompileDefinitionsDone = false;
  1154. mutable bool DebugLinkOptionsDone = false;
  1155. mutable bool DebugLinkDirectoriesDone = false;
  1156. mutable bool DebugPrecompileHeadersDone = false;
  1157. mutable bool DebugSourcesDone = false;
  1158. mutable bool UtilityItemsDone = false;
  1159. enum class Tribool
  1160. {
  1161. False = 0x0,
  1162. True = 0x1,
  1163. Indeterminate = 0x2
  1164. };
  1165. mutable Tribool SourcesAreContextDependent = Tribool::Indeterminate;
  1166. bool ComputePDBOutputDir(std::string const& kind, std::string const& config,
  1167. std::string& out) const;
  1168. ManagedType CheckManagedType(std::string const& propval) const;
  1169. bool GetRPATH(std::string const& config, std::string const& prop,
  1170. std::string& rpath) const;
  1171. std::map<std::string, BTs<std::string>> LanguageStandardMap;
  1172. cm::optional<cmStandardLevel> GetExplicitStandardLevel(
  1173. std::string const& lang, std::string const& config) const;
  1174. void UpdateExplicitStandardLevel(std::string const& lang,
  1175. std::string const& config,
  1176. cmStandardLevel level);
  1177. std::map<std::string, cmStandardLevel> ExplicitStandardLevel;
  1178. cmValue GetPropertyWithPairedLanguageSupport(std::string const& lang,
  1179. char const* suffix) const;
  1180. void ComputeLinkImplementationRuntimeLibraries(
  1181. std::string const& config, cmOptionalLinkImplementation& impl) const;
  1182. void ComputeLinkInterfaceRuntimeLibraries(
  1183. std::string const& config, cmOptionalLinkInterface& iface) const;
  1184. // If this method is made public, or call sites are added outside of
  1185. // methods computing cached members, add dedicated caching members.
  1186. std::vector<cmGeneratorTarget const*> GetLinkInterfaceClosure(
  1187. std::string const& config, cmGeneratorTarget const* headTarget,
  1188. UseTo usage) const;
  1189. public:
  1190. std::vector<cmGeneratorTarget const*> const& GetLinkImplementationClosure(
  1191. std::string const& config, UseTo usage) const;
  1192. mutable std::map<std::string, std::string> MaxLanguageStandards;
  1193. std::map<std::string, std::string> const& GetMaxLanguageStandards() const
  1194. {
  1195. return this->MaxLanguageStandards;
  1196. }
  1197. struct StrictTargetComparison
  1198. {
  1199. bool operator()(cmGeneratorTarget const* t1,
  1200. cmGeneratorTarget const* t2) const;
  1201. };
  1202. bool HaveFortranSources() const;
  1203. bool HaveFortranSources(std::string const& config) const;
  1204. // C++20 module support queries.
  1205. /**
  1206. * Query whether the target expects C++20 module support.
  1207. *
  1208. * This will inspect the target itself to see if C++20 module
  1209. * support is expected to work based on its sources.
  1210. *
  1211. * If `errorMessage` is given a non-`nullptr`, any error message will be
  1212. * stored in it, otherwise the error will be reported directly.
  1213. */
  1214. bool HaveCxx20ModuleSources(std::string* errorMessage = nullptr) const;
  1215. enum class Cxx20SupportLevel
  1216. {
  1217. // C++ is not available.
  1218. MissingCxx,
  1219. // The target does not require at least C++20.
  1220. NoCxx20,
  1221. // C++20 module scanning rules are not present.
  1222. MissingRule,
  1223. // C++20 modules are available and working.
  1224. Supported,
  1225. };
  1226. /**
  1227. * Query whether the target has C++20 module support available (regardless of
  1228. * whether it is required or not).
  1229. */
  1230. Cxx20SupportLevel HaveCxxModuleSupport(std::string const& config) const;
  1231. // Check C++ module status for the target.
  1232. void CheckCxxModuleStatus(std::string const& config) const;
  1233. bool NeedCxxModuleSupport(std::string const& lang,
  1234. std::string const& config) const;
  1235. bool NeedDyndep(std::string const& lang, std::string const& config) const;
  1236. cmFileSet const* GetFileSetForSource(std::string const& config,
  1237. cmSourceFile const* sf) const;
  1238. bool NeedDyndepForSource(std::string const& lang, std::string const& config,
  1239. cmSourceFile const* sf) const;
  1240. enum class CxxModuleSupport
  1241. {
  1242. Unavailable,
  1243. Enabled,
  1244. Disabled,
  1245. };
  1246. CxxModuleSupport NeedCxxDyndep(std::string const& config) const;
  1247. std::string BuildDatabasePath(std::string const& lang,
  1248. std::string const& config) const;
  1249. private:
  1250. void BuildFileSetInfoCache(std::string const& config) const;
  1251. struct InfoByConfig
  1252. {
  1253. bool BuiltFileSetCache = false;
  1254. std::map<std::string, cmFileSet const*> FileSetCache;
  1255. std::map<cmGeneratorTarget const*, std::vector<cmGeneratorTarget const*>>
  1256. SyntheticDeps;
  1257. std::map<cmSourceFile const*, ClassifiedFlags> SourceFlags;
  1258. };
  1259. mutable std::map<std::string, InfoByConfig> Configs;
  1260. bool PchReused = false;
  1261. mutable bool ComputingPchReuse = false;
  1262. mutable bool PchReuseCycleDetected = false;
  1263. };
  1264. class cmGeneratorTarget::TargetPropertyEntry
  1265. {
  1266. protected:
  1267. static cmLinkImplItem NoLinkImplItem;
  1268. public:
  1269. TargetPropertyEntry(cmLinkImplItem const& item);
  1270. virtual ~TargetPropertyEntry() = default;
  1271. static std::unique_ptr<TargetPropertyEntry> Create(
  1272. cmake& cmakeInstance, const BT<std::string>& propertyValue,
  1273. bool evaluateForBuildsystem = false);
  1274. static std::unique_ptr<TargetPropertyEntry> CreateFileSet(
  1275. std::vector<std::string> dirs, bool contextSensitiveDirs,
  1276. std::unique_ptr<cmCompiledGeneratorExpression> entryCge,
  1277. cmFileSet const* fileSet, cmLinkImplItem const& item = NoLinkImplItem);
  1278. virtual std::string const& Evaluate(
  1279. cm::GenEx::Context const& context, cmGeneratorTarget const* headTarget,
  1280. cmGeneratorExpressionDAGChecker* dagChecker) const = 0;
  1281. virtual cmListFileBacktrace GetBacktrace() const = 0;
  1282. virtual std::string const& GetInput() const = 0;
  1283. virtual bool GetHadContextSensitiveCondition() const;
  1284. cmLinkImplItem const& LinkImplItem;
  1285. };