cmGeneratorTarget.h 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmGeneratorTarget_h
  4. #define cmGeneratorTarget_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <cstddef>
  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 "cmLinkItem.h"
  16. #include "cmListFileCache.h"
  17. #include "cmPolicies.h"
  18. #include "cmProperty.h"
  19. #include "cmStateTypes.h"
  20. class cmComputeLinkInformation;
  21. class cmCustomCommand;
  22. class cmGlobalGenerator;
  23. class cmLocalGenerator;
  24. class cmMakefile;
  25. class cmSourceFile;
  26. class cmTarget;
  27. struct cmGeneratorExpressionContext;
  28. struct cmGeneratorExpressionDAGChecker;
  29. class cmGeneratorTarget
  30. {
  31. public:
  32. cmGeneratorTarget(cmTarget*, cmLocalGenerator* lg);
  33. ~cmGeneratorTarget();
  34. cmGeneratorTarget(cmGeneratorTarget const&) = delete;
  35. cmGeneratorTarget& operator=(cmGeneratorTarget const&) = delete;
  36. cmLocalGenerator* GetLocalGenerator() const;
  37. cmGlobalGenerator* GetGlobalGenerator() const;
  38. bool IsImported() const;
  39. bool IsImportedGloballyVisible() const;
  40. const std::string& GetLocation(const std::string& config) const;
  41. std::vector<cmCustomCommand> const& GetPreBuildCommands() const;
  42. std::vector<cmCustomCommand> const& GetPreLinkCommands() const;
  43. std::vector<cmCustomCommand> const& GetPostBuildCommands() const;
  44. #define DECLARE_TARGET_POLICY(POLICY) \
  45. cmPolicies::PolicyStatus GetPolicyStatus##POLICY() const \
  46. { \
  47. return this->PolicyMap.Get(cmPolicies::POLICY); \
  48. }
  49. CM_FOR_EACH_TARGET_POLICY(DECLARE_TARGET_POLICY)
  50. #undef DECLARE_TARGET_POLICY
  51. /** Get the location of the target in the build tree with a placeholder
  52. referencing the configuration in the native build system. This
  53. location is suitable for use as the LOCATION target property. */
  54. const std::string& GetLocationForBuild() const;
  55. cmComputeLinkInformation* GetLinkInformation(
  56. const std::string& config) const;
  57. cmStateEnums::TargetType GetType() const;
  58. const std::string& GetName() const;
  59. std::string GetExportName() const;
  60. std::vector<std::string> GetPropertyKeys() const;
  61. //! Might return a nullptr if the property is not set or invalid
  62. cmProp GetProperty(const std::string& prop) const;
  63. //! Always returns a valid pointer
  64. std::string const& GetSafeProperty(std::string const& prop) const;
  65. bool GetPropertyAsBool(const std::string& prop) const;
  66. void GetSourceFiles(std::vector<cmSourceFile*>& files,
  67. const std::string& config) const;
  68. std::vector<BT<cmSourceFile*>> GetSourceFiles(
  69. std::string const& config) const;
  70. /** Source file kinds (classifications).
  71. Generators use this to decide how to treat a source file. */
  72. enum SourceKind
  73. {
  74. SourceKindAppManifest,
  75. SourceKindCertificate,
  76. SourceKindCustomCommand,
  77. SourceKindExternalObject,
  78. SourceKindExtra,
  79. SourceKindHeader,
  80. SourceKindIDL,
  81. SourceKindManifest,
  82. SourceKindModuleDefinition,
  83. SourceKindObjectSource,
  84. SourceKindResx,
  85. SourceKindXaml,
  86. SourceKindUnityBatched
  87. };
  88. /** A source file paired with a kind (classification). */
  89. struct SourceAndKind
  90. {
  91. BT<cmSourceFile*> Source;
  92. SourceKind Kind;
  93. };
  94. /** All sources needed for a configuration with kinds assigned. */
  95. struct KindedSources
  96. {
  97. std::vector<SourceAndKind> Sources;
  98. bool Initialized = false;
  99. };
  100. /** Get all sources needed for a configuration with kinds assigned. */
  101. KindedSources const& GetKindedSources(std::string const& config) const;
  102. struct AllConfigSource
  103. {
  104. cmSourceFile* Source;
  105. cmGeneratorTarget::SourceKind Kind;
  106. std::vector<size_t> Configs;
  107. };
  108. /** Get all sources needed for all configurations with kinds and
  109. per-source configurations assigned. */
  110. std::vector<AllConfigSource> const& GetAllConfigSources() const;
  111. /** Get all sources needed for all configurations with given kind. */
  112. std::vector<AllConfigSource> GetAllConfigSources(SourceKind kind) const;
  113. /** Get all languages used to compile sources in any configuration.
  114. This excludes the languages of objects from object libraries. */
  115. std::set<std::string> GetAllConfigCompileLanguages() const;
  116. void GetObjectSources(std::vector<cmSourceFile const*>&,
  117. const std::string& config) const;
  118. const std::string& GetObjectName(cmSourceFile const* file);
  119. const char* GetCustomObjectExtension() const;
  120. bool HasExplicitObjectName(cmSourceFile const* file) const;
  121. void AddExplicitObjectName(cmSourceFile const* sf);
  122. void GetModuleDefinitionSources(std::vector<cmSourceFile const*>&,
  123. const std::string& config) const;
  124. void GetExternalObjects(std::vector<cmSourceFile const*>&,
  125. const std::string& config) const;
  126. void GetHeaderSources(std::vector<cmSourceFile const*>&,
  127. const std::string& config) const;
  128. void GetExtraSources(std::vector<cmSourceFile const*>&,
  129. const std::string& config) const;
  130. void GetCustomCommands(std::vector<cmSourceFile const*>&,
  131. const std::string& config) const;
  132. void GetManifests(std::vector<cmSourceFile const*>&,
  133. const std::string& config) const;
  134. std::set<cmLinkItem> const& GetUtilityItems() const;
  135. void ComputeObjectMapping();
  136. const char* GetFeature(const std::string& feature,
  137. const std::string& config) const;
  138. const char* GetLinkPIEProperty(const std::string& config) const;
  139. bool IsIPOEnabled(std::string const& lang, std::string const& config) const;
  140. bool IsLinkInterfaceDependentBoolProperty(const std::string& p,
  141. const std::string& config) const;
  142. bool IsLinkInterfaceDependentStringProperty(const std::string& p,
  143. const std::string& config) const;
  144. bool IsLinkInterfaceDependentNumberMinProperty(
  145. const std::string& p, const std::string& config) const;
  146. bool IsLinkInterfaceDependentNumberMaxProperty(
  147. const std::string& p, const std::string& config) const;
  148. bool GetLinkInterfaceDependentBoolProperty(const std::string& p,
  149. const std::string& config) const;
  150. const char* GetLinkInterfaceDependentStringProperty(
  151. const std::string& p, const std::string& config) const;
  152. const char* GetLinkInterfaceDependentNumberMinProperty(
  153. const std::string& p, const std::string& config) const;
  154. const char* GetLinkInterfaceDependentNumberMaxProperty(
  155. const std::string& p, const std::string& config) const;
  156. class DeviceLinkSetter
  157. {
  158. public:
  159. DeviceLinkSetter(cmGeneratorTarget& target)
  160. : Target(target)
  161. {
  162. this->PreviousState = target.SetDeviceLink(true);
  163. }
  164. ~DeviceLinkSetter() { this->Target.SetDeviceLink(this->PreviousState); };
  165. private:
  166. cmGeneratorTarget& Target;
  167. bool PreviousState;
  168. };
  169. bool SetDeviceLink(bool deviceLink);
  170. bool IsDeviceLink() const { return this->DeviceLink; }
  171. cmLinkInterface const* GetLinkInterface(
  172. const std::string& config, const cmGeneratorTarget* headTarget) const;
  173. void ComputeLinkInterface(const std::string& config,
  174. cmOptionalLinkInterface& iface,
  175. const cmGeneratorTarget* head) const;
  176. cmLinkInterfaceLibraries const* GetLinkInterfaceLibraries(
  177. const std::string& config, const cmGeneratorTarget* headTarget,
  178. bool usage_requirements_only) const;
  179. void ComputeLinkInterfaceLibraries(const std::string& config,
  180. cmOptionalLinkInterface& iface,
  181. const cmGeneratorTarget* head,
  182. bool usage_requirements_only) const;
  183. /** Get the library name for an imported interface library. */
  184. std::string GetImportedLibName(std::string const& config) const;
  185. /** Get the full path to the target according to the settings in its
  186. makefile and the configuration type. */
  187. std::string GetFullPath(
  188. const std::string& config,
  189. cmStateEnums::ArtifactType artifact = cmStateEnums::RuntimeBinaryArtifact,
  190. bool realname = false) const;
  191. std::string NormalGetFullPath(const std::string& config,
  192. cmStateEnums::ArtifactType artifact,
  193. bool realname) const;
  194. std::string NormalGetRealName(const std::string& config) const;
  195. /** Get the names of an object library's object files underneath
  196. its object file directory. */
  197. void GetTargetObjectNames(std::string const& config,
  198. std::vector<std::string>& objects) const;
  199. /** What hierarchy level should the reported directory contain */
  200. enum BundleDirectoryLevel
  201. {
  202. BundleDirLevel,
  203. ContentLevel,
  204. FullLevel
  205. };
  206. /** @return the Mac App directory without the base */
  207. std::string GetAppBundleDirectory(const std::string& config,
  208. BundleDirectoryLevel level) const;
  209. /** Return whether this target is marked as deprecated by the
  210. maintainer */
  211. bool IsDeprecated() const;
  212. /** Returns the deprecation message provided by the maintainer */
  213. std::string GetDeprecation() const;
  214. /** Return whether this target is an executable Bundle, a framework
  215. or CFBundle on Apple. */
  216. bool IsBundleOnApple() const;
  217. /** Get the full name of the target according to the settings in its
  218. makefile. */
  219. std::string GetFullName(const std::string& config,
  220. cmStateEnums::ArtifactType artifact =
  221. cmStateEnums::RuntimeBinaryArtifact) const;
  222. /** @return the Mac framework directory without the base. */
  223. std::string GetFrameworkDirectory(const std::string& config,
  224. BundleDirectoryLevel level) const;
  225. /** Return the framework version string. Undefined if
  226. IsFrameworkOnApple returns false. */
  227. std::string GetFrameworkVersion() const;
  228. /** @return the Mac CFBundle directory without the base */
  229. std::string GetCFBundleDirectory(const std::string& config,
  230. BundleDirectoryLevel level) const;
  231. /** Return the install name directory for the target in the
  232. * build tree. For example: "\@rpath/", "\@loader_path/",
  233. * or "/full/path/to/library". */
  234. std::string GetInstallNameDirForBuildTree(const std::string& config) const;
  235. /** Return the install name directory for the target in the
  236. * install tree. For example: "\@rpath/" or "\@loader_path/". */
  237. std::string GetInstallNameDirForInstallTree(
  238. const std::string& config, const std::string& installPrefix) const;
  239. cmListFileBacktrace GetBacktrace() const;
  240. std::set<BT<std::pair<std::string, bool>>> const& GetUtilities() const;
  241. bool LinkLanguagePropagatesToDependents() const
  242. {
  243. return this->GetType() == cmStateEnums::STATIC_LIBRARY;
  244. }
  245. /** Get the macro to define when building sources in this target.
  246. If no macro should be defined null is returned. */
  247. const std::string* GetExportMacro() const;
  248. /** Get the soname of the target. Allowed only for a shared library. */
  249. std::string GetSOName(const std::string& config) const;
  250. void GetFullNameComponents(std::string& prefix, std::string& base,
  251. std::string& suffix, const std::string& config,
  252. cmStateEnums::ArtifactType artifact =
  253. cmStateEnums::RuntimeBinaryArtifact) const;
  254. /** Append to @a base the bundle directory hierarchy up to a certain @a level
  255. * and return it. */
  256. std::string BuildBundleDirectory(const std::string& base,
  257. const std::string& config,
  258. BundleDirectoryLevel level) const;
  259. /** @return the mac content directory for this target. */
  260. std::string GetMacContentDirectory(
  261. const std::string& config, cmStateEnums::ArtifactType artifact) const;
  262. /** @return folder prefix for IDEs. */
  263. std::string GetEffectiveFolderName() const;
  264. cmTarget* Target;
  265. cmMakefile* Makefile;
  266. cmLocalGenerator* LocalGenerator;
  267. cmGlobalGenerator const* GlobalGenerator;
  268. struct ModuleDefinitionInfo
  269. {
  270. std::string DefFile;
  271. bool DefFileGenerated;
  272. bool WindowsExportAllSymbols;
  273. std::vector<cmSourceFile const*> Sources;
  274. };
  275. ModuleDefinitionInfo const* GetModuleDefinitionInfo(
  276. std::string const& config) const;
  277. /** Return whether or not the target is for a DLL platform. */
  278. bool IsDLLPlatform() const;
  279. /** @return whether this target have a well defined output file name. */
  280. bool HaveWellDefinedOutputFiles() const;
  281. /** Link information from the transitive closure of the link
  282. implementation and the interfaces of its dependencies. */
  283. struct LinkClosure
  284. {
  285. // The preferred linker language.
  286. std::string LinkerLanguage;
  287. // Languages whose runtime libraries must be linked.
  288. std::vector<std::string> Languages;
  289. };
  290. LinkClosure const* GetLinkClosure(const std::string& config) const;
  291. cmLinkImplementation const* GetLinkImplementation(
  292. const std::string& config) const;
  293. void ComputeLinkImplementationLanguages(
  294. const std::string& config, cmOptionalLinkImplementation& impl) const;
  295. cmLinkImplementationLibraries const* GetLinkImplementationLibraries(
  296. const std::string& config) const;
  297. void ComputeLinkImplementationLibraries(const std::string& config,
  298. cmOptionalLinkImplementation& impl,
  299. const cmGeneratorTarget* head) const;
  300. struct TargetOrString
  301. {
  302. std::string String;
  303. cmGeneratorTarget* Target = nullptr;
  304. };
  305. TargetOrString ResolveTargetReference(std::string const& name) const;
  306. TargetOrString ResolveTargetReference(std::string const& name,
  307. cmLocalGenerator const* lg) const;
  308. cmLinkItem ResolveLinkItem(std::string const& name,
  309. cmListFileBacktrace const& bt) const;
  310. cmLinkItem ResolveLinkItem(std::string const& name,
  311. cmListFileBacktrace const& bt,
  312. cmLocalGenerator const* lg) const;
  313. // Compute the set of languages compiled by the target. This is
  314. // computed every time it is called because the languages can change
  315. // when source file properties are changed and we do not have enough
  316. // information to forward these property changes to the targets
  317. // until we have per-target object file properties.
  318. void GetLanguages(std::set<std::string>& languages,
  319. std::string const& config) const;
  320. bool IsLanguageUsed(std::string const& language,
  321. std::string const& config) const;
  322. bool IsCSharpOnly() const;
  323. void GetObjectLibrariesCMP0026(
  324. std::vector<cmGeneratorTarget*>& objlibs) const;
  325. std::string GetFullNameImported(const std::string& config,
  326. cmStateEnums::ArtifactType artifact) const;
  327. /** Get source files common to all configurations and diagnose cases
  328. with per-config sources. Excludes sources added by a TARGET_OBJECTS
  329. generator expression. */
  330. bool GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const;
  331. bool HaveBuildTreeRPATH(const std::string& config) const;
  332. /** Full path with trailing slash to the top-level directory
  333. holding object files for this target. Includes the build
  334. time config name placeholder if needed for the generator. */
  335. std::string ObjectDirectory;
  336. /** Full path with trailing slash to the top-level directory
  337. holding object files for the given configuration. */
  338. std::string GetObjectDirectory(std::string const& config) const;
  339. void GetAppleArchs(const std::string& config,
  340. std::vector<std::string>& archVec) const;
  341. void AddCUDAArchitectureFlags(std::string& flags) const;
  342. void AddCUDAToolkitFlags(std::string& flags) const;
  343. std::string GetFeatureSpecificLinkRuleVariable(
  344. std::string const& var, std::string const& lang,
  345. std::string const& config) const;
  346. /** Return the rule variable used to create this type of target. */
  347. std::string GetCreateRuleVariable(std::string const& lang,
  348. std::string const& config) const;
  349. /** Get the include directories for this target. */
  350. std::vector<BT<std::string>> GetIncludeDirectories(
  351. const std::string& config, const std::string& lang) const;
  352. void GetCompileOptions(std::vector<std::string>& result,
  353. const std::string& config,
  354. const std::string& language) const;
  355. std::vector<BT<std::string>> GetCompileOptions(
  356. std::string const& config, std::string const& language) const;
  357. void GetCompileFeatures(std::vector<std::string>& features,
  358. const std::string& config) const;
  359. std::vector<BT<std::string>> GetCompileFeatures(
  360. std::string const& config) const;
  361. void GetCompileDefinitions(std::vector<std::string>& result,
  362. const std::string& config,
  363. const std::string& language) const;
  364. std::vector<BT<std::string>> GetCompileDefinitions(
  365. std::string const& config, std::string const& language) const;
  366. void GetLinkOptions(std::vector<std::string>& result,
  367. const std::string& config,
  368. const std::string& language) const;
  369. std::vector<BT<std::string>> GetLinkOptions(
  370. std::string const& config, std::string const& language) const;
  371. void GetStaticLibraryLinkOptions(std::vector<std::string>& result,
  372. const std::string& config,
  373. const std::string& language) const;
  374. std::vector<BT<std::string>> GetStaticLibraryLinkOptions(
  375. std::string const& config, std::string const& language) const;
  376. void GetLinkDirectories(std::vector<std::string>& result,
  377. const std::string& config,
  378. const std::string& language) const;
  379. std::vector<BT<std::string>> GetLinkDirectories(
  380. std::string const& config, std::string const& language) const;
  381. void GetLinkDepends(std::vector<std::string>& result,
  382. const std::string& config,
  383. const std::string& language) const;
  384. std::vector<BT<std::string>> GetLinkDepends(
  385. std::string const& config, std::string const& language) const;
  386. std::vector<BT<std::string>> GetPrecompileHeaders(
  387. const std::string& config, const std::string& language) const;
  388. std::string GetPchHeader(const std::string& config,
  389. const std::string& language,
  390. const std::string& arch = std::string()) const;
  391. std::string GetPchSource(const std::string& config,
  392. const std::string& language,
  393. const std::string& arch = std::string()) const;
  394. std::string GetPchFileObject(const std::string& config,
  395. const std::string& language,
  396. const std::string& arch = std::string());
  397. std::string GetPchFile(const std::string& config,
  398. const std::string& language,
  399. const std::string& arch = std::string());
  400. std::string GetPchCreateCompileOptions(
  401. const std::string& config, const std::string& language,
  402. const std::string& arch = std::string());
  403. std::string GetPchUseCompileOptions(const std::string& config,
  404. const std::string& language,
  405. const std::string& arch = std::string());
  406. void AddSourceFileToUnityBatch(const std::string& sourceFilename);
  407. bool IsSourceFilePartOfUnityBatch(const std::string& sourceFilename) const;
  408. bool IsSystemIncludeDirectory(const std::string& dir,
  409. const std::string& config,
  410. const std::string& language) const;
  411. /** Add the target output files to the global generator manifest. */
  412. void ComputeTargetManifest(const std::string& config) const;
  413. bool ComputeCompileFeatures(std::string const& config) const;
  414. /**
  415. * Trace through the source files in this target and add al source files
  416. * that they depend on, used by all generators
  417. */
  418. void TraceDependencies();
  419. /** Get the directory in which this target will be built. If the
  420. configuration name is given then the generator will add its
  421. subdirectory for that configuration. Otherwise just the canonical
  422. output directory is given. */
  423. std::string GetDirectory(const std::string& config,
  424. cmStateEnums::ArtifactType artifact =
  425. cmStateEnums::RuntimeBinaryArtifact) const;
  426. /** Get the directory in which to place the target compiler .pdb file.
  427. If the configuration name is given then the generator will add its
  428. subdirectory for that configuration. Otherwise just the canonical
  429. compiler pdb output directory is given. */
  430. std::string GetCompilePDBDirectory(const std::string& config) const;
  431. /** Get sources that must be built before the given source. */
  432. std::vector<cmSourceFile*> const* GetSourceDepends(
  433. cmSourceFile const* sf) const;
  434. /** Return whether this target uses the default value for its output
  435. directory. */
  436. bool UsesDefaultOutputDir(const std::string& config,
  437. cmStateEnums::ArtifactType artifact) const;
  438. // Cache target output paths for each configuration.
  439. struct OutputInfo
  440. {
  441. std::string OutDir;
  442. std::string ImpDir;
  443. std::string PdbDir;
  444. bool empty() const
  445. {
  446. return OutDir.empty() && ImpDir.empty() && PdbDir.empty();
  447. }
  448. };
  449. OutputInfo const* GetOutputInfo(const std::string& config) const;
  450. // Get the target PDB base name.
  451. std::string GetPDBOutputName(const std::string& config) const;
  452. /** Get the name of the pdb file for the target. */
  453. std::string GetPDBName(const std::string& config) const;
  454. /** Whether this library has soname enabled and platform supports it. */
  455. bool HasSOName(const std::string& config) const;
  456. struct CompileInfo
  457. {
  458. std::string CompilePdbDir;
  459. };
  460. CompileInfo const* GetCompileInfo(const std::string& config) const;
  461. using CompileInfoMapType = std::map<std::string, CompileInfo>;
  462. mutable CompileInfoMapType CompileInfoMap;
  463. bool IsNullImpliedByLinkLibraries(const std::string& p) const;
  464. /** Get the name of the compiler pdb file for the target. */
  465. std::string GetCompilePDBName(const std::string& config) const;
  466. /** Get the path for the MSVC /Fd option for this target. */
  467. std::string GetCompilePDBPath(const std::string& config) const;
  468. // Get the target base name.
  469. std::string GetOutputName(const std::string& config,
  470. cmStateEnums::ArtifactType artifact) const;
  471. /** Get target file prefix */
  472. std::string GetFilePrefix(const std::string& config,
  473. cmStateEnums::ArtifactType artifact =
  474. cmStateEnums::RuntimeBinaryArtifact) const;
  475. /** Get target file prefix */
  476. std::string GetFileSuffix(const std::string& config,
  477. cmStateEnums::ArtifactType artifact =
  478. cmStateEnums::RuntimeBinaryArtifact) const;
  479. /** Get target file postfix */
  480. std::string GetFilePostfix(const std::string& config) const;
  481. /** Get framework multi-config-specific postfix */
  482. std::string GetFrameworkMultiConfigPostfix(const std::string& config) const;
  483. /** Clears cached meta data for local and external source files.
  484. * The meta data will be recomputed on demand.
  485. */
  486. void ClearSourcesCache();
  487. void AddSource(const std::string& src, bool before = false);
  488. void AddTracedSources(std::vector<std::string> const& srcs);
  489. /**
  490. * Adds an entry to the INCLUDE_DIRECTORIES list.
  491. * If before is true the entry is pushed at the front.
  492. */
  493. void AddIncludeDirectory(const std::string& src, bool before = false);
  494. /**
  495. * Flags for a given source file as used in this target. Typically assigned
  496. * via SET_TARGET_PROPERTIES when the property is a list of source files.
  497. */
  498. enum SourceFileType
  499. {
  500. SourceFileTypeNormal,
  501. SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
  502. SourceFileTypePublicHeader, // is in "PUBLIC_HEADER" target property
  503. SourceFileTypeResource, // is in "RESOURCE" target property *or*
  504. // has MACOSX_PACKAGE_LOCATION=="Resources"
  505. SourceFileTypeDeepResource, // MACOSX_PACKAGE_LOCATION starts with
  506. // "Resources/"
  507. SourceFileTypeMacContent // has MACOSX_PACKAGE_LOCATION!="Resources[/]"
  508. };
  509. struct SourceFileFlags
  510. {
  511. SourceFileType Type = SourceFileTypeNormal;
  512. const char* MacFolder = nullptr; // location inside Mac content folders
  513. };
  514. void GetAutoUicOptions(std::vector<std::string>& result,
  515. const std::string& config) const;
  516. struct Names
  517. {
  518. std::string Base;
  519. std::string Output;
  520. std::string Real;
  521. std::string ImportLibrary;
  522. std::string PDB;
  523. std::string SharedObject;
  524. };
  525. /** Get the names of the executable needed to generate a build rule
  526. that takes into account executable version numbers. This should
  527. be called only on an executable target. */
  528. Names GetExecutableNames(const std::string& config) const;
  529. /** Get the names of the library needed to generate a build rule
  530. that takes into account shared library version numbers. This
  531. should be called only on a library target. */
  532. Names GetLibraryNames(const std::string& config) const;
  533. /**
  534. * Compute whether this target must be relinked before installing.
  535. */
  536. bool NeedRelinkBeforeInstall(const std::string& config) const;
  537. /** Return true if builtin chrpath will work for this target */
  538. bool IsChrpathUsed(const std::string& config) const;
  539. /** Get the directory in which this targets .pdb files will be placed.
  540. If the configuration name is given then the generator will add its
  541. subdirectory for that configuration. Otherwise just the canonical
  542. pdb output directory is given. */
  543. std::string GetPDBDirectory(const std::string& config) const;
  544. //! Return the preferred linker language for this target
  545. std::string GetLinkerLanguage(const std::string& config) const;
  546. /** Does this target have a GNU implib to convert to MS format? */
  547. bool HasImplibGNUtoMS(std::string const& config) const;
  548. /** Convert the given GNU import library name (.dll.a) to a name with a new
  549. extension (.lib or ${CMAKE_IMPORT_LIBRARY_SUFFIX}). */
  550. bool GetImplibGNUtoMS(std::string const& config, std::string const& gnuName,
  551. std::string& out, const char* newExt = nullptr) const;
  552. bool IsExecutableWithExports() const;
  553. /** Return whether or not the target has a DLL import library. */
  554. bool HasImportLibrary(std::string const& config) const;
  555. /** Get a build-tree directory in which to place target support files. */
  556. std::string GetSupportDirectory() const;
  557. /** Return whether this target may be used to link another target. */
  558. bool IsLinkable() const;
  559. /** Return whether this target is a shared library Framework on
  560. Apple. */
  561. bool IsFrameworkOnApple() const;
  562. /** Return whether this target is an executable Bundle on Apple. */
  563. bool IsAppBundleOnApple() const;
  564. /** Return whether this target is a XCTest on Apple. */
  565. bool IsXCTestOnApple() const;
  566. /** Return whether this target is a CFBundle (plugin) on Apple. */
  567. bool IsCFBundleOnApple() const;
  568. /** Assembly types. The order of the values of this enum is relevant
  569. because of smaller/larger comparison operations! */
  570. enum ManagedType
  571. {
  572. Undefined = 0, // target is no lib or executable
  573. Native, // target compiles to unmanaged binary.
  574. Mixed, // target compiles to mixed (managed and unmanaged) binary.
  575. Managed // target compiles to managed binary.
  576. };
  577. /** Return the type of assembly this target compiles to. */
  578. ManagedType GetManagedType(const std::string& config) const;
  579. struct SourceFileFlags GetTargetSourceFileFlags(
  580. const cmSourceFile* sf) const;
  581. void ReportPropertyOrigin(const std::string& p, const std::string& result,
  582. const std::string& report,
  583. const std::string& compatibilityType) const;
  584. class TargetPropertyEntry;
  585. std::string EvaluateInterfaceProperty(
  586. std::string const& prop, cmGeneratorExpressionContext* context,
  587. cmGeneratorExpressionDAGChecker* dagCheckerParent,
  588. bool usage_requirements_only = true) const;
  589. bool HaveInstallTreeRPATH(const std::string& config) const;
  590. bool GetBuildRPATH(const std::string& config, std::string& rpath) const;
  591. bool GetInstallRPATH(const std::string& config, std::string& rpath) const;
  592. /** Whether this library has \@rpath and platform supports it. */
  593. bool HasMacOSXRpathInstallNameDir(const std::string& config) const;
  594. /** Whether this library defaults to \@rpath. */
  595. bool MacOSXRpathInstallNameDirDefault() const;
  596. enum InstallNameType
  597. {
  598. INSTALL_NAME_FOR_BUILD,
  599. INSTALL_NAME_FOR_INSTALL
  600. };
  601. /** Whether to use INSTALL_NAME_DIR. */
  602. bool MacOSXUseInstallNameDir() const;
  603. /** Whether to generate an install_name. */
  604. bool CanGenerateInstallNameDir(InstallNameType t) const;
  605. /** Test for special case of a third-party shared library that has
  606. no soname at all. */
  607. bool IsImportedSharedLibWithoutSOName(const std::string& config) const;
  608. std::string ImportedGetLocation(const std::string& config) const;
  609. /** Get the target major and minor version numbers interpreted from
  610. the VERSION property. Version 0 is returned if the property is
  611. not set or cannot be parsed. */
  612. void GetTargetVersion(int& major, int& minor) const;
  613. /** Get the target major, minor, and patch version numbers
  614. interpreted from the given property. Version 0
  615. is returned if the property is not set or cannot be parsed. */
  616. void GetTargetVersion(std::string const& property, int& major, int& minor,
  617. int& patch) const;
  618. /** Get the target major, minor, and patch version numbers
  619. interpreted from the given property and if empty use the
  620. fallback property. Version 0 is returned if the property is
  621. not set or cannot be parsed. */
  622. void GetTargetVersionFallback(const std::string& property,
  623. const std::string& fallback_property,
  624. int& major, int& minor, int& patch) const;
  625. std::string GetRuntimeLinkLibrary(std::string const& lang,
  626. std::string const& config) const;
  627. std::string GetFortranModuleDirectory(std::string const& working_dir) const;
  628. const std::string& GetSourcesProperty() const;
  629. private:
  630. void AddSourceCommon(const std::string& src, bool before = false);
  631. std::string CreateFortranModuleDirectory(
  632. std::string const& working_dir) const;
  633. mutable bool FortranModuleDirectoryCreated;
  634. mutable std::string FortranModuleDirectory;
  635. friend class cmTargetTraceDependencies;
  636. struct SourceEntry
  637. {
  638. std::vector<cmSourceFile*> Depends;
  639. };
  640. using SourceEntriesType = std::map<cmSourceFile const*, SourceEntry>;
  641. SourceEntriesType SourceDepends;
  642. mutable std::set<std::string> VisitedConfigsForObjects;
  643. mutable std::map<cmSourceFile const*, std::string> Objects;
  644. std::set<cmSourceFile const*> ExplicitObjectName;
  645. mutable std::map<std::string, std::vector<std::string>> SystemIncludesCache;
  646. mutable std::string ExportMacro;
  647. void ConstructSourceFileFlags() const;
  648. mutable bool SourceFileFlagsConstructed;
  649. mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  650. mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
  651. bool NeedImportLibraryName(std::string const& config) const;
  652. const char* GetFilePrefixInternal(std::string const& config,
  653. cmStateEnums::ArtifactType artifact,
  654. const std::string& language = "") const;
  655. const char* GetFileSuffixInternal(std::string const& config,
  656. cmStateEnums::ArtifactType artifact,
  657. const std::string& language = "") const;
  658. std::string GetFullNameInternal(const std::string& config,
  659. cmStateEnums::ArtifactType artifact) const;
  660. void GetFullNameInternal(const std::string& config,
  661. cmStateEnums::ArtifactType artifact,
  662. std::string& outPrefix, std::string& outBase,
  663. std::string& outSuffix) const;
  664. mutable std::string LinkerLanguage;
  665. using LinkClosureMapType = std::map<std::string, LinkClosure>;
  666. mutable LinkClosureMapType LinkClosureMap;
  667. bool DeviceLink = false;
  668. // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type.
  669. const char* GetOutputTargetType(cmStateEnums::ArtifactType artifact) const;
  670. void ComputeVersionedName(std::string& vName, std::string const& prefix,
  671. std::string const& base, std::string const& suffix,
  672. std::string const& name,
  673. const char* version) const;
  674. struct CompatibleInterfacesBase
  675. {
  676. std::set<std::string> PropsBool;
  677. std::set<std::string> PropsString;
  678. std::set<std::string> PropsNumberMax;
  679. std::set<std::string> PropsNumberMin;
  680. };
  681. CompatibleInterfacesBase const& GetCompatibleInterfaces(
  682. std::string const& config) const;
  683. struct CompatibleInterfaces : public CompatibleInterfacesBase
  684. {
  685. bool Done = false;
  686. };
  687. mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
  688. using cmTargetLinkInformationMap =
  689. std::map<std::string, std::unique_ptr<cmComputeLinkInformation>>;
  690. mutable cmTargetLinkInformationMap LinkInformation;
  691. void CheckPropertyCompatibility(cmComputeLinkInformation& info,
  692. const std::string& config) const;
  693. void ComputeLinkClosure(const std::string& config, LinkClosure& lc) const;
  694. bool ComputeLinkClosure(const std::string& config, LinkClosure& lc,
  695. bool secondPass) const;
  696. struct LinkImplClosure : public std::vector<cmGeneratorTarget const*>
  697. {
  698. bool Done = false;
  699. };
  700. mutable std::map<std::string, LinkImplClosure> LinkImplClosureMap;
  701. using LinkInterfaceMapType = std::map<std::string, cmHeadToLinkInterfaceMap>;
  702. mutable LinkInterfaceMapType LinkInterfaceMap;
  703. mutable LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap;
  704. cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceMap(
  705. std::string const& config) const;
  706. cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap(
  707. std::string const& config) const;
  708. std::string GetLinkInterfaceDependentStringAsBoolProperty(
  709. const std::string& p, const std::string& config) const;
  710. friend class cmTargetCollectLinkLanguages;
  711. cmLinkInterface const* GetLinkInterface(const std::string& config,
  712. const cmGeneratorTarget* headTarget,
  713. bool secondPass) const;
  714. void ComputeLinkInterface(const std::string& config,
  715. cmOptionalLinkInterface& iface,
  716. const cmGeneratorTarget* head,
  717. bool secondPass) const;
  718. cmLinkImplementation const* GetLinkImplementation(const std::string& config,
  719. bool secondPass) const;
  720. // Cache import information from properties for each configuration.
  721. struct ImportInfo
  722. {
  723. bool NoSOName = false;
  724. ManagedType Managed = Native;
  725. unsigned int Multiplicity = 0;
  726. std::string Location;
  727. std::string SOName;
  728. std::string ImportLibrary;
  729. std::string LibName;
  730. std::string Languages;
  731. std::string Libraries;
  732. std::string LibrariesProp;
  733. std::string SharedDeps;
  734. };
  735. using ImportInfoMapType = std::map<std::string, ImportInfo>;
  736. mutable ImportInfoMapType ImportInfoMap;
  737. void ComputeImportInfo(std::string const& desired_config,
  738. ImportInfo& info) const;
  739. ImportInfo const* GetImportInfo(const std::string& config) const;
  740. /** Strip off leading and trailing whitespace from an item named in
  741. the link dependencies of this target. */
  742. std::string CheckCMP0004(std::string const& item) const;
  743. cmLinkInterface const* GetImportLinkInterface(const std::string& config,
  744. const cmGeneratorTarget* head,
  745. bool usage_requirements_only,
  746. bool secondPass = false) const;
  747. using KindedSourcesMapType = std::map<std::string, KindedSources>;
  748. mutable KindedSourcesMapType KindedSourcesMap;
  749. void ComputeKindedSources(KindedSources& files,
  750. std::string const& config) const;
  751. mutable std::vector<AllConfigSource> AllConfigSources;
  752. void ComputeAllConfigSources() const;
  753. mutable std::unordered_map<std::string, bool> MaybeInterfacePropertyExists;
  754. bool MaybeHaveInterfaceProperty(std::string const& prop,
  755. cmGeneratorExpressionContext* context,
  756. bool usage_requirements_only) const;
  757. using TargetPropertyEntryVector =
  758. std::vector<std::unique_ptr<TargetPropertyEntry>>;
  759. TargetPropertyEntryVector IncludeDirectoriesEntries;
  760. TargetPropertyEntryVector CompileOptionsEntries;
  761. TargetPropertyEntryVector CompileFeaturesEntries;
  762. TargetPropertyEntryVector CompileDefinitionsEntries;
  763. TargetPropertyEntryVector LinkOptionsEntries;
  764. TargetPropertyEntryVector LinkDirectoriesEntries;
  765. TargetPropertyEntryVector PrecompileHeadersEntries;
  766. TargetPropertyEntryVector SourceEntries;
  767. mutable std::set<std::string> LinkImplicitNullProperties;
  768. mutable std::map<std::string, std::string> PchHeaders;
  769. mutable std::map<std::string, std::string> PchSources;
  770. mutable std::map<std::string, std::string> PchObjectFiles;
  771. mutable std::map<std::string, std::string> PchFiles;
  772. mutable std::map<std::string, std::string> PchCreateCompileOptions;
  773. mutable std::map<std::string, std::string> PchUseCompileOptions;
  774. std::unordered_set<std::string> UnityBatchedSourceFiles;
  775. bool IsLinkLookupScope(std::string const& n,
  776. cmLocalGenerator const*& lg) const;
  777. void ExpandLinkItems(std::string const& prop, std::string const& value,
  778. std::string const& config,
  779. const cmGeneratorTarget* headTarget,
  780. bool usage_requirements_only,
  781. std::vector<cmLinkItem>& items,
  782. bool& hadHeadSensitiveCondition,
  783. bool& hadContextSensitiveCondition,
  784. bool& hadLinkLanguageSensitiveCondition) const;
  785. void LookupLinkItems(std::vector<std::string> const& names,
  786. cmListFileBacktrace const& bt,
  787. std::vector<cmLinkItem>& items) const;
  788. std::vector<BT<std::string>> GetSourceFilePaths(
  789. std::string const& config) const;
  790. std::vector<BT<cmSourceFile*>> GetSourceFilesWithoutObjectLibraries(
  791. std::string const& config) const;
  792. void GetSourceFilesWithoutObjectLibraries(std::vector<cmSourceFile*>& files,
  793. const std::string& config) const;
  794. struct HeadToLinkImplementationMap
  795. : public std::map<cmGeneratorTarget const*, cmOptionalLinkImplementation>
  796. {
  797. };
  798. using LinkImplMapType = std::map<std::string, HeadToLinkImplementationMap>;
  799. mutable LinkImplMapType LinkImplMap;
  800. cmLinkImplementationLibraries const* GetLinkImplementationLibrariesInternal(
  801. const std::string& config, const cmGeneratorTarget* head) const;
  802. bool ComputeOutputDir(const std::string& config,
  803. cmStateEnums::ArtifactType artifact,
  804. std::string& out) const;
  805. using OutputInfoMapType = std::map<std::string, OutputInfo>;
  806. mutable OutputInfoMapType OutputInfoMap;
  807. using ModuleDefinitionInfoMapType =
  808. std::map<std::string, ModuleDefinitionInfo>;
  809. mutable ModuleDefinitionInfoMapType ModuleDefinitionInfoMap;
  810. void ComputeModuleDefinitionInfo(std::string const& config,
  811. ModuleDefinitionInfo& info) const;
  812. using OutputNameKey = std::pair<std::string, cmStateEnums::ArtifactType>;
  813. using OutputNameMapType = std::map<OutputNameKey, std::string>;
  814. mutable OutputNameMapType OutputNameMap;
  815. mutable std::set<cmLinkItem> UtilityItems;
  816. cmPolicies::PolicyMap PolicyMap;
  817. mutable bool PolicyWarnedCMP0022;
  818. mutable bool PolicyReportedCMP0069;
  819. mutable bool DebugIncludesDone;
  820. mutable bool DebugCompileOptionsDone;
  821. mutable bool DebugCompileFeaturesDone;
  822. mutable bool DebugCompileDefinitionsDone;
  823. mutable bool DebugLinkOptionsDone;
  824. mutable bool DebugLinkDirectoriesDone;
  825. mutable bool DebugPrecompileHeadersDone;
  826. mutable bool DebugSourcesDone;
  827. mutable bool LinkImplementationLanguageIsContextDependent;
  828. mutable bool UtilityItemsDone;
  829. bool ComputePDBOutputDir(const std::string& kind, const std::string& config,
  830. std::string& out) const;
  831. ManagedType CheckManagedType(std::string const& propval) const;
  832. bool GetRPATH(const std::string& config, const std::string& prop,
  833. std::string& rpath) const;
  834. public:
  835. const std::vector<const cmGeneratorTarget*>& GetLinkImplementationClosure(
  836. const std::string& config) const;
  837. mutable std::map<std::string, std::string> MaxLanguageStandards;
  838. std::map<std::string, std::string> const& GetMaxLanguageStandards() const
  839. {
  840. return this->MaxLanguageStandards;
  841. }
  842. struct StrictTargetComparison
  843. {
  844. bool operator()(cmGeneratorTarget const* t1,
  845. cmGeneratorTarget const* t2) const;
  846. };
  847. };
  848. #endif