cmGeneratorTarget.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmGeneratorTarget_h
  11. #define cmGeneratorTarget_h
  12. #include "cmLinkItem.h"
  13. class cmCustomCommand;
  14. class cmGlobalGenerator;
  15. class cmLocalGenerator;
  16. class cmMakefile;
  17. class cmSourceFile;
  18. class cmTarget;
  19. class cmComputeLinkInformation;
  20. class cmGeneratorTarget
  21. {
  22. public:
  23. cmGeneratorTarget(cmTarget*, cmLocalGenerator* lg);
  24. ~cmGeneratorTarget();
  25. cmLocalGenerator* GetLocalGenerator() const;
  26. bool IsImported() const;
  27. const char *GetLocation(const std::string& config) const;
  28. /** Get the location of the target in the build tree with a placeholder
  29. referencing the configuration in the native build system. This
  30. location is suitable for use as the LOCATION target property. */
  31. const char* GetLocationForBuild() const;
  32. cmComputeLinkInformation*
  33. GetLinkInformation(const std::string& config) const;
  34. int GetType() const;
  35. std::string GetName() const;
  36. const char *GetProperty(const std::string& prop) const;
  37. bool GetPropertyAsBool(const std::string& prop) const;
  38. void GetSourceFiles(std::vector<cmSourceFile*>& files,
  39. const std::string& config) const;
  40. void GetObjectSources(std::vector<cmSourceFile const*> &,
  41. const std::string& config) const;
  42. const std::string& GetObjectName(cmSourceFile const* file);
  43. bool HasExplicitObjectName(cmSourceFile const* file) const;
  44. void AddExplicitObjectName(cmSourceFile const* sf);
  45. void GetResxSources(std::vector<cmSourceFile const*>&,
  46. const std::string& config) const;
  47. void GetIDLSources(std::vector<cmSourceFile const*>&,
  48. const std::string& config) const;
  49. void GetExternalObjects(std::vector<cmSourceFile const*>&,
  50. const std::string& config) const;
  51. void GetHeaderSources(std::vector<cmSourceFile const*>&,
  52. const std::string& config) const;
  53. void GetExtraSources(std::vector<cmSourceFile const*>&,
  54. const std::string& config) const;
  55. void GetCustomCommands(std::vector<cmSourceFile const*>&,
  56. const std::string& config) const;
  57. void GetExpectedResxHeaders(std::set<std::string>&,
  58. const std::string& config) const;
  59. void GetAppManifest(std::vector<cmSourceFile const*>&,
  60. const std::string& config) const;
  61. void GetManifests(std::vector<cmSourceFile const*>&,
  62. const std::string& config) const;
  63. void GetCertificates(std::vector<cmSourceFile const*>&,
  64. const std::string& config) const;
  65. void GetXamlSources(std::vector<cmSourceFile const*>&,
  66. const std::string& config) const;
  67. void GetExpectedXamlHeaders(std::set<std::string>&,
  68. const std::string& config) const;
  69. void GetExpectedXamlSources(std::set<std::string>&,
  70. const std::string& config) const;
  71. void ComputeObjectMapping();
  72. const char* GetFeature(const std::string& feature,
  73. const std::string& config) const;
  74. bool GetFeatureAsBool(const std::string& feature,
  75. const std::string& config) const;
  76. bool IsLinkInterfaceDependentBoolProperty(const std::string &p,
  77. const std::string& config) const;
  78. bool IsLinkInterfaceDependentStringProperty(const std::string &p,
  79. const std::string& config) const;
  80. bool IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
  81. const std::string& config) const;
  82. bool IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  83. const std::string& config) const;
  84. bool GetLinkInterfaceDependentBoolProperty(const std::string &p,
  85. const std::string& config) const;
  86. const char *GetLinkInterfaceDependentStringProperty(const std::string &p,
  87. const std::string& config) const;
  88. const char *GetLinkInterfaceDependentNumberMinProperty(const std::string &p,
  89. const std::string& config) const;
  90. const char *GetLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  91. const std::string& config) const;
  92. cmLinkInterface const* GetLinkInterface(const std::string& config,
  93. const cmGeneratorTarget* headTarget) const;
  94. void ComputeLinkInterface(const std::string& config,
  95. cmOptionalLinkInterface& iface,
  96. const cmGeneratorTarget* head) const;
  97. cmLinkInterfaceLibraries const*
  98. GetLinkInterfaceLibraries(const std::string& config,
  99. const cmGeneratorTarget* headTarget,
  100. bool usage_requirements_only) const;
  101. void ComputeLinkInterfaceLibraries(const std::string& config,
  102. cmOptionalLinkInterface &iface,
  103. const cmGeneratorTarget* head,
  104. bool usage_requirements_only) const;
  105. /** Get the full path to the target according to the settings in its
  106. makefile and the configuration type. */
  107. std::string GetFullPath(const std::string& config="", bool implib = false,
  108. bool realname = false) const;
  109. std::string NormalGetFullPath(const std::string& config, bool implib,
  110. bool realname) const;
  111. std::string NormalGetRealName(const std::string& config) const;
  112. /** @return the Mac App directory without the base */
  113. std::string GetAppBundleDirectory(const std::string& config,
  114. bool contentOnly) const;
  115. /** Return whether this target is an executable Bundle, a framework
  116. or CFBundle on Apple. */
  117. bool IsBundleOnApple() const;
  118. /** Get the full name of the target according to the settings in its
  119. makefile. */
  120. std::string GetFullName(const std::string& config="",
  121. bool implib = false) const;
  122. /** @return the Mac framework directory without the base. */
  123. std::string GetFrameworkDirectory(const std::string& config,
  124. bool rootDir) const;
  125. /** @return the Mac CFBundle directory without the base */
  126. std::string GetCFBundleDirectory(const std::string& config,
  127. bool contentOnly) const;
  128. /** Return the install name directory for the target in the
  129. * build tree. For example: "\@rpath/", "\@loader_path/",
  130. * or "/full/path/to/library". */
  131. std::string GetInstallNameDirForBuildTree(const std::string& config) const;
  132. /** Return the install name directory for the target in the
  133. * install tree. For example: "\@rpath/" or "\@loader_path/". */
  134. std::string GetInstallNameDirForInstallTree() const;
  135. /** Get the soname of the target. Allowed only for a shared library. */
  136. std::string GetSOName(const std::string& config) const;
  137. void GetFullNameComponents(std::string& prefix,
  138. std::string& base, std::string& suffix,
  139. const std::string& config="",
  140. bool implib = false) const;
  141. /** Append to @a base the mac content directory and return it. */
  142. std::string BuildMacContentDirectory(const std::string& base,
  143. const std::string& config = "",
  144. bool contentOnly = true) const;
  145. /** @return the mac content directory for this target. */
  146. std::string GetMacContentDirectory(const std::string& config = 0,
  147. bool implib = false) const;
  148. cmTarget* Target;
  149. cmMakefile* Makefile;
  150. cmLocalGenerator* LocalGenerator;
  151. cmGlobalGenerator const* GlobalGenerator;
  152. std::string GetModuleDefinitionFile(const std::string& config) const;
  153. /** Link information from the transitive closure of the link
  154. implementation and the interfaces of its dependencies. */
  155. struct LinkClosure
  156. {
  157. // The preferred linker language.
  158. std::string LinkerLanguage;
  159. // Languages whose runtime libraries must be linked.
  160. std::vector<std::string> Languages;
  161. };
  162. LinkClosure const* GetLinkClosure(const std::string& config) const;
  163. void ComputeLinkClosure(const std::string& config, LinkClosure& lc) const;
  164. cmLinkImplementation const*
  165. GetLinkImplementation(const std::string& config) const;
  166. void ComputeLinkImplementationLanguages(const std::string& config,
  167. cmOptionalLinkImplementation& impl
  168. ) const;
  169. cmLinkImplementationLibraries const*
  170. GetLinkImplementationLibraries(const std::string& config) const;
  171. void ComputeLinkImplementationLibraries(const std::string& config,
  172. cmOptionalLinkImplementation& impl,
  173. cmTarget const* head) const;
  174. // Compute the set of languages compiled by the target. This is
  175. // computed every time it is called because the languages can change
  176. // when source file properties are changed and we do not have enough
  177. // information to forward these property changes to the targets
  178. // until we have per-target object file properties.
  179. void GetLanguages(std::set<std::string>& languages,
  180. std::string const& config) const;
  181. bool GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const;
  182. bool HaveBuildTreeRPATH(const std::string& config) const;
  183. /** Full path with trailing slash to the top-level directory
  184. holding object files for this target. Includes the build
  185. time config name placeholder if needed for the generator. */
  186. std::string ObjectDirectory;
  187. void UseObjectLibraries(std::vector<std::string>& objs,
  188. const std::string& config) const;
  189. void GetAppleArchs(const std::string& config,
  190. std::vector<std::string>& archVec) const;
  191. /** Return the rule variable used to create this type of target. */
  192. std::string GetCreateRuleVariable(std::string const& lang,
  193. std::string const& config) const;
  194. /** Get the include directories for this target. */
  195. std::vector<std::string> GetIncludeDirectories(
  196. const std::string& config, const std::string& lang) const;
  197. void GetCompileOptions(std::vector<std::string> &result,
  198. const std::string& config,
  199. const std::string& language) const;
  200. void GetCompileFeatures(std::vector<std::string> &features,
  201. const std::string& config) const;
  202. void GetCompileDefinitions(std::vector<std::string> &result,
  203. const std::string& config,
  204. const std::string& language) const;
  205. bool IsSystemIncludeDirectory(const std::string& dir,
  206. const std::string& config) const;
  207. /** Add the target output files to the global generator manifest. */
  208. void ComputeTargetManifest(const std::string& config) const;
  209. /**
  210. * Trace through the source files in this target and add al source files
  211. * that they depend on, used by all generators
  212. */
  213. void TraceDependencies();
  214. /** Get the directory in which this target will be built. If the
  215. configuration name is given then the generator will add its
  216. subdirectory for that configuration. Otherwise just the canonical
  217. output directory is given. */
  218. std::string GetDirectory(const std::string& config = "",
  219. bool implib = false) const;
  220. /** Get the directory in which to place the target compiler .pdb file.
  221. If the configuration name is given then the generator will add its
  222. subdirectory for that configuration. Otherwise just the canonical
  223. compiler pdb output directory is given. */
  224. std::string GetCompilePDBDirectory(const std::string& config = "") const;
  225. /** Get sources that must be built before the given source. */
  226. std::vector<cmSourceFile*> const*
  227. GetSourceDepends(cmSourceFile const* sf) const;
  228. /** Return whether this target uses the default value for its output
  229. directory. */
  230. bool UsesDefaultOutputDir(const std::string& config, bool implib) const;
  231. // Cache target output paths for each configuration.
  232. struct OutputInfo
  233. {
  234. std::string OutDir;
  235. std::string ImpDir;
  236. std::string PdbDir;
  237. bool empty() const
  238. { return OutDir.empty() && ImpDir.empty() && PdbDir.empty(); }
  239. };
  240. OutputInfo const* GetOutputInfo(const std::string& config) const;
  241. /** Get the name of the pdb file for the target. */
  242. std::string GetPDBName(const std::string& config="") const;
  243. /** Whether this library has soname enabled and platform supports it. */
  244. bool HasSOName(const std::string& config) const;
  245. struct CompileInfo
  246. {
  247. std::string CompilePdbDir;
  248. };
  249. CompileInfo const* GetCompileInfo(const std::string& config) const;
  250. typedef std::map<std::string, CompileInfo> CompileInfoMapType;
  251. mutable CompileInfoMapType CompileInfoMap;
  252. bool IsNullImpliedByLinkLibraries(const std::string &p) const;
  253. /** Get the name of the compiler pdb file for the target. */
  254. std::string GetCompilePDBName(const std::string& config="") const;
  255. /** Get the path for the MSVC /Fd option for this target. */
  256. std::string GetCompilePDBPath(const std::string& config="") const;
  257. // Get the target base name.
  258. std::string GetOutputName(const std::string& config, bool implib) const;
  259. void AddSource(const std::string& src);
  260. void AddTracedSources(std::vector<std::string> const& srcs);
  261. /**
  262. * Flags for a given source file as used in this target. Typically assigned
  263. * via SET_TARGET_PROPERTIES when the property is a list of source files.
  264. */
  265. enum SourceFileType
  266. {
  267. SourceFileTypeNormal,
  268. SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
  269. SourceFileTypePublicHeader, // is in "PUBLIC_HEADER" target property
  270. SourceFileTypeResource, // is in "RESOURCE" target property *or*
  271. // has MACOSX_PACKAGE_LOCATION=="Resources"
  272. SourceFileTypeMacContent // has MACOSX_PACKAGE_LOCATION!="Resources"
  273. };
  274. struct SourceFileFlags
  275. {
  276. SourceFileFlags(): Type(SourceFileTypeNormal), MacFolder(0) {}
  277. SourceFileFlags(SourceFileFlags const& r):
  278. Type(r.Type), MacFolder(r.MacFolder) {}
  279. SourceFileType Type;
  280. const char* MacFolder; // location inside Mac content folders
  281. };
  282. void GetAutoUicOptions(std::vector<std::string> &result,
  283. const std::string& config) const;
  284. /** Get the names of the executable needed to generate a build rule
  285. that takes into account executable version numbers. This should
  286. be called only on an executable target. */
  287. void GetExecutableNames(std::string& name, std::string& realName,
  288. std::string& impName, std::string& pdbName,
  289. const std::string& config) const;
  290. /** Get the names of the library needed to generate a build rule
  291. that takes into account shared library version numbers. This
  292. should be called only on a library target. */
  293. void GetLibraryNames(std::string& name, std::string& soName,
  294. std::string& realName, std::string& impName,
  295. std::string& pdbName, const std::string& config) const;
  296. /**
  297. * Compute whether this target must be relinked before installing.
  298. */
  299. bool NeedRelinkBeforeInstall(const std::string& config) const;
  300. /** Return true if builtin chrpath will work for this target */
  301. bool IsChrpathUsed(const std::string& config) const;
  302. /** Get the directory in which this targets .pdb files will be placed.
  303. If the configuration name is given then the generator will add its
  304. subdirectory for that configuration. Otherwise just the canonical
  305. pdb output directory is given. */
  306. std::string GetPDBDirectory(const std::string& config) const;
  307. ///! Return the preferred linker language for this target
  308. std::string GetLinkerLanguage(const std::string& config = "") const;
  309. struct SourceFileFlags
  310. GetTargetSourceFileFlags(const cmSourceFile* sf) const;
  311. struct ResxData {
  312. mutable std::set<std::string> ExpectedResxHeaders;
  313. mutable std::vector<cmSourceFile const*> ResxSources;
  314. };
  315. struct XamlData {
  316. std::set<std::string> ExpectedXamlHeaders;
  317. std::set<std::string> ExpectedXamlSources;
  318. std::vector<cmSourceFile const*> XamlSources;
  319. };
  320. void ReportPropertyOrigin(const std::string &p,
  321. const std::string &result,
  322. const std::string &report,
  323. const std::string &compatibilityType) const;
  324. class TargetPropertyEntry;
  325. bool HaveInstallTreeRPATH() const;
  326. /** Whether this library has \@rpath and platform supports it. */
  327. bool HasMacOSXRpathInstallNameDir(const std::string& config) const;
  328. /** Whether this library defaults to \@rpath. */
  329. bool MacOSXRpathInstallNameDirDefault() const;
  330. /** Test for special case of a third-party shared library that has
  331. no soname at all. */
  332. bool IsImportedSharedLibWithoutSOName(const std::string& config) const;
  333. private:
  334. friend class cmTargetTraceDependencies;
  335. struct SourceEntry { std::vector<cmSourceFile*> Depends; };
  336. typedef std::map<cmSourceFile const*, SourceEntry> SourceEntriesType;
  337. SourceEntriesType SourceDepends;
  338. mutable std::map<cmSourceFile const*, std::string> Objects;
  339. std::set<cmSourceFile const*> ExplicitObjectName;
  340. mutable std::map<std::string, std::vector<std::string> > SystemIncludesCache;
  341. void ConstructSourceFileFlags() const;
  342. mutable bool SourceFileFlagsConstructed;
  343. mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  344. mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
  345. std::string GetFullNameInternal(const std::string& config,
  346. bool implib) const;
  347. void GetFullNameInternal(const std::string& config, bool implib,
  348. std::string& outPrefix, std::string& outBase,
  349. std::string& outSuffix) const;
  350. typedef std::map<std::string, LinkClosure> LinkClosureMapType;
  351. mutable LinkClosureMapType LinkClosureMap;
  352. // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type.
  353. const char* GetOutputTargetType(bool implib) const;
  354. struct CompatibleInterfacesBase
  355. {
  356. std::set<std::string> PropsBool;
  357. std::set<std::string> PropsString;
  358. std::set<std::string> PropsNumberMax;
  359. std::set<std::string> PropsNumberMin;
  360. };
  361. CompatibleInterfacesBase const&
  362. GetCompatibleInterfaces(std::string const& config) const;
  363. struct CompatibleInterfaces: public CompatibleInterfacesBase
  364. {
  365. CompatibleInterfaces(): Done(false) {}
  366. bool Done;
  367. };
  368. mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
  369. typedef std::map<std::string, cmComputeLinkInformation*>
  370. cmTargetLinkInformationMap;
  371. mutable cmTargetLinkInformationMap LinkInformation;
  372. void CheckPropertyCompatibility(cmComputeLinkInformation *info,
  373. const std::string& config) const;
  374. cmGeneratorTarget(cmGeneratorTarget const&);
  375. void operator=(cmGeneratorTarget const&);
  376. struct LinkImplClosure: public std::vector<cmTarget const*>
  377. {
  378. LinkImplClosure(): Done(false) {}
  379. bool Done;
  380. };
  381. mutable std::map<std::string, LinkImplClosure> LinkImplClosureMap;
  382. typedef std::map<std::string, cmHeadToLinkInterfaceMap>
  383. LinkInterfaceMapType;
  384. mutable LinkInterfaceMapType LinkInterfaceMap;
  385. mutable LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap;
  386. cmHeadToLinkInterfaceMap&
  387. GetHeadToLinkInterfaceMap(std::string const& config) const;
  388. cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap(
  389. std::string const& config) const;
  390. cmLinkInterface const*
  391. GetImportLinkInterface(const std::string& config, cmTarget const* head,
  392. bool usage_requirements_only) const;
  393. typedef std::map<std::string, std::vector<cmSourceFile*> >
  394. SourceFilesMapType;
  395. mutable SourceFilesMapType SourceFilesMap;
  396. std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
  397. std::vector<TargetPropertyEntry*> CompileOptionsEntries;
  398. std::vector<TargetPropertyEntry*> CompileFeaturesEntries;
  399. std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
  400. std::vector<TargetPropertyEntry*> SourceEntries;
  401. mutable std::set<std::string> LinkImplicitNullProperties;
  402. void ExpandLinkItems(std::string const& prop, std::string const& value,
  403. std::string const& config, cmTarget const* headTarget,
  404. bool usage_requirements_only,
  405. std::vector<cmLinkItem>& items,
  406. bool& hadHeadSensitiveCondition) const;
  407. void LookupLinkItems(std::vector<std::string> const& names,
  408. std::vector<cmLinkItem>& items) const;
  409. void GetSourceFiles(std::vector<std::string>& files,
  410. const std::string& config) const;
  411. struct HeadToLinkImplementationMap:
  412. public std::map<cmTarget const*, cmOptionalLinkImplementation> {};
  413. typedef std::map<std::string,
  414. HeadToLinkImplementationMap> LinkImplMapType;
  415. mutable LinkImplMapType LinkImplMap;
  416. cmLinkImplementationLibraries const*
  417. GetLinkImplementationLibrariesInternal(const std::string& config,
  418. const cmGeneratorTarget* head) const;
  419. bool
  420. ComputeOutputDir(const std::string& config,
  421. bool implib, std::string& out) const;
  422. typedef std::map<std::string, OutputInfo> OutputInfoMapType;
  423. mutable OutputInfoMapType OutputInfoMap;
  424. typedef std::pair<std::string, bool> OutputNameKey;
  425. typedef std::map<OutputNameKey, std::string> OutputNameMapType;
  426. mutable OutputNameMapType OutputNameMap;
  427. mutable bool PolicyWarnedCMP0022;
  428. mutable bool DebugIncludesDone;
  429. mutable bool DebugCompileOptionsDone;
  430. mutable bool DebugCompileFeaturesDone;
  431. mutable bool DebugCompileDefinitionsDone;
  432. mutable bool DebugSourcesDone;
  433. mutable bool LinkImplementationLanguageIsContextDependent;
  434. bool ComputePDBOutputDir(const std::string& kind, const std::string& config,
  435. std::string& out) const;
  436. public:
  437. std::vector<cmTarget const*> const&
  438. GetLinkImplementationClosure(const std::string& config) const;
  439. mutable std::map<std::string, std::string> MaxLanguageStandards;
  440. std::map<std::string, std::string> const&
  441. GetMaxLanguageStandards() const
  442. {
  443. return this->MaxLanguageStandards;
  444. }
  445. };
  446. struct cmStrictTargetComparison {
  447. bool operator()(cmTarget const* t1, cmTarget const* t2) const;
  448. };
  449. typedef std::map<cmTarget const*,
  450. cmGeneratorTarget*,
  451. cmStrictTargetComparison> cmGeneratorTargetsType;
  452. #endif