cmTarget.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 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 cmTarget_h
  11. #define cmTarget_h
  12. #include "cmCustomCommand.h"
  13. #include "cmPropertyMap.h"
  14. #include "cmPolicies.h"
  15. #include "cmListFileCache.h"
  16. #include <cmsys/auto_ptr.hxx>
  17. #if defined(CMAKE_BUILD_WITH_CMAKE)
  18. #include <cmsys/hash_map.hxx>
  19. #endif
  20. #define CM_FOR_EACH_TARGET_POLICY(F) \
  21. F(CMP0003) \
  22. F(CMP0004) \
  23. F(CMP0008) \
  24. F(CMP0020) \
  25. F(CMP0021) \
  26. F(CMP0022) \
  27. F(CMP0027) \
  28. F(CMP0038) \
  29. F(CMP0041) \
  30. F(CMP0042) \
  31. F(CMP0046) \
  32. F(CMP0052)
  33. class cmake;
  34. class cmMakefile;
  35. class cmSourceFile;
  36. class cmGlobalGenerator;
  37. class cmComputeLinkInformation;
  38. class cmListFileBacktrace;
  39. class cmTarget;
  40. class cmGeneratorTarget;
  41. class cmTargetTraceDependencies;
  42. // Basic information about each link item.
  43. class cmLinkItem: public std::string
  44. {
  45. typedef std::string std_string;
  46. public:
  47. cmLinkItem(): std_string(), Target(0) {}
  48. cmLinkItem(const std_string& n,
  49. cmTarget const* t): std_string(n), Target(t) {}
  50. cmLinkItem(cmLinkItem const& r): std_string(r), Target(r.Target) {}
  51. cmTarget const* Target;
  52. };
  53. class cmLinkImplItem: public cmLinkItem
  54. {
  55. public:
  56. cmLinkImplItem(): cmLinkItem(), Backtrace(0), FromGenex(false) {}
  57. cmLinkImplItem(std::string const& n,
  58. cmTarget const* t,
  59. cmListFileBacktrace const& bt,
  60. bool fromGenex):
  61. cmLinkItem(n, t), Backtrace(bt), FromGenex(fromGenex) {}
  62. cmLinkImplItem(cmLinkImplItem const& r):
  63. cmLinkItem(r), Backtrace(r.Backtrace), FromGenex(r.FromGenex) {}
  64. cmListFileBacktrace Backtrace;
  65. bool FromGenex;
  66. };
  67. struct cmTargetLinkInformationMap:
  68. public std::map<std::string, cmComputeLinkInformation*>
  69. {
  70. typedef std::map<std::string, cmComputeLinkInformation*> derived;
  71. cmTargetLinkInformationMap() {}
  72. cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r);
  73. ~cmTargetLinkInformationMap();
  74. };
  75. class cmTargetInternals;
  76. class cmTargetInternalPointer
  77. {
  78. public:
  79. cmTargetInternalPointer();
  80. cmTargetInternalPointer(cmTargetInternalPointer const& r);
  81. ~cmTargetInternalPointer();
  82. cmTargetInternalPointer& operator=(cmTargetInternalPointer const& r);
  83. cmTargetInternals* operator->() const { return this->Pointer; }
  84. cmTargetInternals* Get() const { return this->Pointer; }
  85. private:
  86. cmTargetInternals* Pointer;
  87. };
  88. /** \class cmTarget
  89. * \brief Represent a library or executable target loaded from a makefile.
  90. *
  91. * cmTarget represents a target loaded from
  92. * a makefile.
  93. */
  94. class cmTarget
  95. {
  96. public:
  97. cmTarget();
  98. enum TargetType { EXECUTABLE, STATIC_LIBRARY,
  99. SHARED_LIBRARY, MODULE_LIBRARY,
  100. OBJECT_LIBRARY, UTILITY, GLOBAL_TARGET,
  101. INTERFACE_LIBRARY,
  102. UNKNOWN_LIBRARY};
  103. static const char* GetTargetTypeName(TargetType targetType);
  104. enum CustomCommandType { PRE_BUILD, PRE_LINK, POST_BUILD };
  105. /**
  106. * Return the type of target.
  107. */
  108. TargetType GetType() const
  109. {
  110. return this->TargetTypeValue;
  111. }
  112. /**
  113. * Set the target type
  114. */
  115. void SetType(TargetType f, const std::string& name);
  116. void MarkAsImported();
  117. ///! Set/Get the name of the target
  118. const std::string& GetName() const {return this->Name;}
  119. std::string GetExportName() const;
  120. ///! Set the cmMakefile that owns this target
  121. void SetMakefile(cmMakefile *mf);
  122. cmMakefile *GetMakefile() const { return this->Makefile;}
  123. #define DECLARE_TARGET_POLICY(POLICY) \
  124. cmPolicies::PolicyStatus GetPolicyStatus ## POLICY () const \
  125. { return this->PolicyStatus ## POLICY; }
  126. CM_FOR_EACH_TARGET_POLICY(DECLARE_TARGET_POLICY)
  127. #undef DECLARE_TARGET_POLICY
  128. /**
  129. * Get the list of the custom commands for this target
  130. */
  131. std::vector<cmCustomCommand> const &GetPreBuildCommands() const
  132. {return this->PreBuildCommands;}
  133. std::vector<cmCustomCommand> const &GetPreLinkCommands() const
  134. {return this->PreLinkCommands;}
  135. std::vector<cmCustomCommand> const &GetPostBuildCommands() const
  136. {return this->PostBuildCommands;}
  137. void AddPreBuildCommand(cmCustomCommand const &cmd)
  138. {this->PreBuildCommands.push_back(cmd);}
  139. void AddPreLinkCommand(cmCustomCommand const &cmd)
  140. {this->PreLinkCommands.push_back(cmd);}
  141. void AddPostBuildCommand(cmCustomCommand const &cmd)
  142. {this->PostBuildCommands.push_back(cmd);}
  143. /**
  144. * Get the list of the source files used by this target
  145. */
  146. void GetSourceFiles(std::vector<cmSourceFile*> &files,
  147. const std::string& config) const;
  148. bool GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const;
  149. /**
  150. * Add sources to the target.
  151. */
  152. void AddSources(std::vector<std::string> const& srcs);
  153. void AddTracedSources(std::vector<std::string> const& srcs);
  154. cmSourceFile* AddSourceCMP0049(const std::string& src);
  155. cmSourceFile* AddSource(const std::string& src);
  156. enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED};
  157. //* how we identify a library, by name and type
  158. typedef std::pair<std::string, LinkLibraryType> LibraryID;
  159. typedef std::vector<LibraryID > LinkLibraryVectorType;
  160. const LinkLibraryVectorType &GetOriginalLinkLibraries() const
  161. {return this->OriginalLinkLibraries;}
  162. /** Compute the link type to use for the given configuration. */
  163. LinkLibraryType ComputeLinkType(const std::string& config) const;
  164. /**
  165. * Clear the dependency information recorded for this target, if any.
  166. */
  167. void ClearDependencyInformation(cmMakefile& mf, const std::string& target);
  168. // Check to see if a library is a framework and treat it different on Mac
  169. bool NameResolvesToFramework(const std::string& libname) const;
  170. void AddLinkLibrary(cmMakefile& mf,
  171. const std::string& target, const std::string& lib,
  172. LinkLibraryType llt);
  173. enum TLLSignature {
  174. KeywordTLLSignature,
  175. PlainTLLSignature
  176. };
  177. bool PushTLLCommandTrace(TLLSignature signature);
  178. void GetTllSignatureTraces(std::ostringstream &s, TLLSignature sig) const;
  179. void MergeLinkLibraries( cmMakefile& mf, const std::string& selfname,
  180. const LinkLibraryVectorType& libs );
  181. const std::vector<std::string>& GetLinkDirectories() const;
  182. void AddLinkDirectory(const std::string& d);
  183. /**
  184. * Set the path where this target should be installed. This is relative to
  185. * INSTALL_PREFIX
  186. */
  187. std::string GetInstallPath() const {return this->InstallPath;}
  188. void SetInstallPath(const char *name) {this->InstallPath = name;}
  189. /**
  190. * Set the path where this target (if it has a runtime part) should be
  191. * installed. This is relative to INSTALL_PREFIX
  192. */
  193. std::string GetRuntimeInstallPath() const {return this->RuntimeInstallPath;}
  194. void SetRuntimeInstallPath(const char *name) {
  195. this->RuntimeInstallPath = name; }
  196. /**
  197. * Get/Set whether there is an install rule for this target.
  198. */
  199. bool GetHaveInstallRule() const { return this->HaveInstallRule; }
  200. void SetHaveInstallRule(bool h) { this->HaveInstallRule = h; }
  201. /** Add a utility on which this project depends. A utility is an executable
  202. * name as would be specified to the ADD_EXECUTABLE or UTILITY_SOURCE
  203. * commands. It is not a full path nor does it have an extension.
  204. */
  205. void AddUtility(const std::string& u, cmMakefile *makefile = 0);
  206. ///! Get the utilities used by this target
  207. std::set<std::string>const& GetUtilities() const { return this->Utilities; }
  208. std::set<cmLinkItem>const& GetUtilityItems() const;
  209. cmListFileBacktrace const* GetUtilityBacktrace(const std::string& u) const;
  210. /** Finalize the target at the end of the Configure step. */
  211. void FinishConfigure();
  212. ///! Set/Get a property of this target file
  213. void SetProperty(const std::string& prop, const char *value);
  214. void AppendProperty(const std::string& prop, const char* value,
  215. bool asString=false);
  216. const char *GetProperty(const std::string& prop) const;
  217. const char *GetProperty(const std::string& prop, cmMakefile* context) const;
  218. bool GetPropertyAsBool(const std::string& prop) const;
  219. void CheckProperty(const std::string& prop, cmMakefile* context) const;
  220. const char* GetFeature(const std::string& feature,
  221. const std::string& config) const;
  222. bool GetFeatureAsBool(const std::string& feature,
  223. const std::string& config) const;
  224. bool IsImported() const {return this->IsImportedTarget;}
  225. void GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const;
  226. /** The link interface specifies transitive library dependencies and
  227. other information needed by targets that link to this target. */
  228. struct LinkInterfaceLibraries
  229. {
  230. // Libraries listed in the interface.
  231. std::vector<cmLinkItem> Libraries;
  232. };
  233. struct LinkInterface: public LinkInterfaceLibraries
  234. {
  235. // Languages whose runtime libraries must be linked.
  236. std::vector<std::string> Languages;
  237. // Shared library dependencies needed for linking on some platforms.
  238. std::vector<cmLinkItem> SharedDeps;
  239. // Number of repetitions of a strongly connected component of two
  240. // or more static libraries.
  241. int Multiplicity;
  242. // Libraries listed for other configurations.
  243. // Needed only for OLD behavior of CMP0003.
  244. std::vector<cmLinkItem> WrongConfigLibraries;
  245. bool ImplementationIsInterface;
  246. LinkInterface(): Multiplicity(0), ImplementationIsInterface(false) {}
  247. };
  248. /** Get the link interface for the given configuration. Returns 0
  249. if the target cannot be linked. */
  250. LinkInterface const* GetLinkInterface(const std::string& config,
  251. cmTarget const* headTarget) const;
  252. LinkInterfaceLibraries const*
  253. GetLinkInterfaceLibraries(const std::string& config,
  254. cmTarget const* headTarget,
  255. bool usage_requirements_only) const;
  256. std::vector<cmTarget const*> const&
  257. GetLinkImplementationClosure(const std::string& config) const;
  258. struct CompatibleInterfaces
  259. {
  260. std::set<std::string> PropsBool;
  261. std::set<std::string> PropsString;
  262. std::set<std::string> PropsNumberMax;
  263. std::set<std::string> PropsNumberMin;
  264. };
  265. CompatibleInterfaces const&
  266. GetCompatibleInterfaces(std::string const& config) const;
  267. /** The link implementation specifies the direct library
  268. dependencies needed by the object files of the target. */
  269. struct LinkImplementationLibraries
  270. {
  271. // Libraries linked directly in this configuration.
  272. std::vector<cmLinkImplItem> Libraries;
  273. // Libraries linked directly in other configurations.
  274. // Needed only for OLD behavior of CMP0003.
  275. std::vector<cmLinkItem> WrongConfigLibraries;
  276. };
  277. struct LinkImplementation: public LinkImplementationLibraries
  278. {
  279. // Languages whose runtime libraries must be linked.
  280. std::vector<std::string> Languages;
  281. };
  282. LinkImplementation const*
  283. GetLinkImplementation(const std::string& config) const;
  284. LinkImplementationLibraries const*
  285. GetLinkImplementationLibraries(const std::string& config) const;
  286. /** Link information from the transitive closure of the link
  287. implementation and the interfaces of its dependencies. */
  288. struct LinkClosure
  289. {
  290. // The preferred linker language.
  291. std::string LinkerLanguage;
  292. // Languages whose runtime libraries must be linked.
  293. std::vector<std::string> Languages;
  294. };
  295. LinkClosure const* GetLinkClosure(const std::string& config) const;
  296. cmTarget const* FindTargetToLink(std::string const& name) const;
  297. /** Strip off leading and trailing whitespace from an item named in
  298. the link dependencies of this target. */
  299. std::string CheckCMP0004(std::string const& item) const;
  300. /** Get the directory in which this target will be built. If the
  301. configuration name is given then the generator will add its
  302. subdirectory for that configuration. Otherwise just the canonical
  303. output directory is given. */
  304. std::string GetDirectory(const std::string& config = "",
  305. bool implib = false) const;
  306. /** Get the directory in which this targets .pdb files will be placed.
  307. If the configuration name is given then the generator will add its
  308. subdirectory for that configuration. Otherwise just the canonical
  309. pdb output directory is given. */
  310. std::string GetPDBDirectory(const std::string& config) const;
  311. /** Get the directory in which to place the target compiler .pdb file.
  312. If the configuration name is given then the generator will add its
  313. subdirectory for that configuration. Otherwise just the canonical
  314. compiler pdb output directory is given. */
  315. std::string GetCompilePDBDirectory(const std::string& config = "") const;
  316. /** Get the location of the target in the build tree for the given
  317. configuration. */
  318. const char* GetLocation(const std::string& config) const;
  319. /** Get the location of the target in the build tree with a placeholder
  320. referencing the configuration in the native build system. This
  321. location is suitable for use as the LOCATION target property. */
  322. const char* GetLocationForBuild() const;
  323. /** Get the target major and minor version numbers interpreted from
  324. the VERSION property. Version 0 is returned if the property is
  325. not set or cannot be parsed. */
  326. void GetTargetVersion(int& major, int& minor) const;
  327. /** Get the target major, minor, and patch version numbers
  328. interpreted from the VERSION or SOVERSION property. Version 0
  329. is returned if the property is not set or cannot be parsed. */
  330. void
  331. GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const;
  332. ///! Return the preferred linker language for this target
  333. std::string GetLinkerLanguage(const std::string& config = "") const;
  334. /** Get the full name of the target according to the settings in its
  335. makefile. */
  336. std::string GetFullName(const std::string& config="",
  337. bool implib = false) const;
  338. void GetFullNameComponents(std::string& prefix,
  339. std::string& base, std::string& suffix,
  340. const std::string& config="",
  341. bool implib = false) const;
  342. /** Get the name of the pdb file for the target. */
  343. std::string GetPDBName(const std::string& config) const;
  344. /** Get the name of the compiler pdb file for the target. */
  345. std::string GetCompilePDBName(const std::string& config="") const;
  346. /** Get the path for the MSVC /Fd option for this target. */
  347. std::string GetCompilePDBPath(const std::string& config="") const;
  348. /** Whether this library has soname enabled and platform supports it. */
  349. bool HasSOName(const std::string& config) const;
  350. /** Get the soname of the target. Allowed only for a shared library. */
  351. std::string GetSOName(const std::string& config) const;
  352. /** Whether this library has \@rpath and platform supports it. */
  353. bool HasMacOSXRpathInstallNameDir(const std::string& config) const;
  354. /** Whether this library defaults to \@rpath. */
  355. bool MacOSXRpathInstallNameDirDefault() const;
  356. /** Test for special case of a third-party shared library that has
  357. no soname at all. */
  358. bool IsImportedSharedLibWithoutSOName(const std::string& config) const;
  359. /** Get the full path to the target according to the settings in its
  360. makefile and the configuration type. */
  361. std::string GetFullPath(const std::string& config="", bool implib = false,
  362. bool realname = false) const;
  363. /** Get the names of the library needed to generate a build rule
  364. that takes into account shared library version numbers. This
  365. should be called only on a library target. */
  366. void GetLibraryNames(std::string& name, std::string& soName,
  367. std::string& realName, std::string& impName,
  368. std::string& pdbName, const std::string& config) const;
  369. /** Get the names of the executable needed to generate a build rule
  370. that takes into account executable version numbers. This should
  371. be called only on an executable target. */
  372. void GetExecutableNames(std::string& name, std::string& realName,
  373. std::string& impName,
  374. std::string& pdbName,
  375. const std::string& config) const;
  376. /** Does this target have a GNU implib to convert to MS format? */
  377. bool HasImplibGNUtoMS() const;
  378. /** Convert the given GNU import library name (.dll.a) to a name with a new
  379. extension (.lib or ${CMAKE_IMPORT_LIBRARY_SUFFIX}). */
  380. bool GetImplibGNUtoMS(std::string const& gnuName, std::string& out,
  381. const char* newExt = 0) const;
  382. /**
  383. * Compute whether this target must be relinked before installing.
  384. */
  385. bool NeedRelinkBeforeInstall(const std::string& config) const;
  386. bool HaveBuildTreeRPATH(const std::string& config) const;
  387. bool HaveInstallTreeRPATH() const;
  388. /** Return true if builtin chrpath will work for this target */
  389. bool IsChrpathUsed(const std::string& config) const;
  390. /** Return the install name directory for the target in the
  391. * build tree. For example: "\@rpath/", "\@loader_path/",
  392. * or "/full/path/to/library". */
  393. std::string GetInstallNameDirForBuildTree(const std::string& config) const;
  394. /** Return the install name directory for the target in the
  395. * install tree. For example: "\@rpath/" or "\@loader_path/". */
  396. std::string GetInstallNameDirForInstallTree() const;
  397. cmComputeLinkInformation*
  398. GetLinkInformation(const std::string& config) const;
  399. // Get the properties
  400. cmPropertyMap &GetProperties() const { return this->Properties; }
  401. bool GetMappedConfig(std::string const& desired_config,
  402. const char** loc,
  403. const char** imp,
  404. std::string& suffix) const;
  405. // Define the properties
  406. static void DefineProperties(cmake *cm);
  407. /** Get the macro to define when building sources in this target.
  408. If no macro should be defined null is returned. */
  409. const char* GetExportMacro() const;
  410. void GetCompileDefinitions(std::vector<std::string> &result,
  411. const std::string& config,
  412. const std::string& language) const;
  413. // Compute the set of languages compiled by the target. This is
  414. // computed every time it is called because the languages can change
  415. // when source file properties are changed and we do not have enough
  416. // information to forward these property changes to the targets
  417. // until we have per-target object file properties.
  418. void GetLanguages(std::set<std::string>& languages,
  419. std::string const& config) const;
  420. /** Return whether this target is an executable with symbol exports
  421. enabled. */
  422. bool IsExecutableWithExports() const;
  423. /** Return whether this target may be used to link another target. */
  424. bool IsLinkable() const;
  425. /** Return whether or not the target is for a DLL platform. */
  426. bool IsDLLPlatform() const { return this->DLLPlatform; }
  427. /** Return whether or not the target has a DLL import library. */
  428. bool HasImportLibrary() const;
  429. /** Return whether this target is a shared library Framework on
  430. Apple. */
  431. bool IsFrameworkOnApple() const;
  432. /** Return whether this target is a CFBundle (plugin) on Apple. */
  433. bool IsCFBundleOnApple() const;
  434. /** Return whether this target is an executable Bundle on Apple. */
  435. bool IsAppBundleOnApple() const;
  436. /** Return whether this target is an executable Bundle, a framework
  437. or CFBundle on Apple. */
  438. bool IsBundleOnApple() const;
  439. /** Return the framework version string. Undefined if
  440. IsFrameworkOnApple returns false. */
  441. std::string GetFrameworkVersion() const;
  442. /** Get a backtrace from the creation of the target. */
  443. cmListFileBacktrace const& GetBacktrace() const;
  444. /** Get a build-tree directory in which to place target support files. */
  445. std::string GetSupportDirectory() const;
  446. /** Return whether this target uses the default value for its output
  447. directory. */
  448. bool UsesDefaultOutputDir(const std::string& config, bool implib) const;
  449. /** @return the mac content directory for this target. */
  450. std::string GetMacContentDirectory(const std::string& config,
  451. bool implib) const;
  452. /** @return whether this target have a well defined output file name. */
  453. bool HaveWellDefinedOutputFiles() const;
  454. /** @return the Mac framework directory without the base. */
  455. std::string GetFrameworkDirectory(const std::string& config,
  456. bool rootDir) const;
  457. /** @return the Mac CFBundle directory without the base */
  458. std::string GetCFBundleDirectory(const std::string& config,
  459. bool contentOnly) const;
  460. /** @return the Mac App directory without the base */
  461. std::string GetAppBundleDirectory(const std::string& config,
  462. bool contentOnly) const;
  463. std::vector<std::string> GetIncludeDirectories(
  464. const std::string& config,
  465. const std::string& language) const;
  466. void InsertInclude(const cmValueWithOrigin &entry,
  467. bool before = false);
  468. void InsertCompileOption(const cmValueWithOrigin &entry,
  469. bool before = false);
  470. void InsertCompileDefinition(const cmValueWithOrigin &entry);
  471. void AppendBuildInterfaceIncludes();
  472. void GetCompileOptions(std::vector<std::string> &result,
  473. const std::string& config,
  474. const std::string& language) const;
  475. void GetAutoUicOptions(std::vector<std::string> &result,
  476. const std::string& config) const;
  477. void GetCompileFeatures(std::vector<std::string> &features,
  478. const std::string& config) const;
  479. bool IsNullImpliedByLinkLibraries(const std::string &p) const;
  480. bool IsLinkInterfaceDependentBoolProperty(const std::string &p,
  481. const std::string& config) const;
  482. bool IsLinkInterfaceDependentStringProperty(const std::string &p,
  483. const std::string& config) const;
  484. bool IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
  485. const std::string& config) const;
  486. bool IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  487. const std::string& config) const;
  488. bool GetLinkInterfaceDependentBoolProperty(const std::string &p,
  489. const std::string& config) const;
  490. const char *GetLinkInterfaceDependentStringProperty(const std::string &p,
  491. const std::string& config) const;
  492. const char *GetLinkInterfaceDependentNumberMinProperty(const std::string &p,
  493. const std::string& config) const;
  494. const char *GetLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  495. const std::string& config) const;
  496. std::string GetDebugGeneratorExpressions(const std::string &value,
  497. cmTarget::LinkLibraryType llt) const;
  498. void AddSystemIncludeDirectories(const std::set<std::string> &incs);
  499. void AddSystemIncludeDirectories(const std::vector<std::string> &incs);
  500. std::set<std::string> const & GetSystemIncludeDirectories() const
  501. { return this->SystemIncludeDirectories; }
  502. bool LinkLanguagePropagatesToDependents() const
  503. { return this->TargetTypeValue == STATIC_LIBRARY; }
  504. void ReportPropertyOrigin(const std::string &p,
  505. const std::string &result,
  506. const std::string &report,
  507. const std::string &compatibilityType) const;
  508. std::map<std::string, std::string> const&
  509. GetMaxLanguageStandards() const
  510. {
  511. return this->MaxLanguageStandards;
  512. }
  513. #if defined(_WIN32) && !defined(__CYGWIN__)
  514. const LinkLibraryVectorType &GetLinkLibrariesForVS6() const {
  515. return this->LinkLibrariesForVS6;}
  516. #endif
  517. private:
  518. bool HandleLocationPropertyPolicy(cmMakefile* context) const;
  519. // The set of include directories that are marked as system include
  520. // directories.
  521. std::set<std::string> SystemIncludeDirectories;
  522. std::vector<std::pair<TLLSignature, cmListFileBacktrace> > TLLCommands;
  523. #if defined(_WIN32) && !defined(__CYGWIN__)
  524. /**
  525. * A list of direct dependencies. Use in conjunction with DependencyMap.
  526. */
  527. typedef std::vector< LibraryID > DependencyList;
  528. /**
  529. * This map holds the dependency graph. map[x] returns a set of
  530. * direct dependencies of x. Note that the direct depenencies are
  531. * ordered. This is necessary to handle direct dependencies that
  532. * themselves have no dependency information.
  533. */
  534. typedef std::map< LibraryID, DependencyList > DependencyMap;
  535. /**
  536. * Inserts \a dep at the end of the dependency list of \a lib.
  537. */
  538. void InsertDependencyForVS6( DependencyMap& depMap,
  539. const LibraryID& lib,
  540. const LibraryID& dep);
  541. /*
  542. * Deletes \a dep from the dependency list of \a lib.
  543. */
  544. void DeleteDependencyForVS6( DependencyMap& depMap,
  545. const LibraryID& lib,
  546. const LibraryID& dep);
  547. /**
  548. * Emits the library \a lib and all its dependencies into link_line.
  549. * \a emitted keeps track of the libraries that have been emitted to
  550. * avoid duplicates--it is more efficient than searching
  551. * link_line. \a visited is used detect cycles. Note that \a
  552. * link_line is in reverse order, in that the dependencies of a
  553. * library are listed before the library itself.
  554. */
  555. void EmitForVS6( const LibraryID lib,
  556. const DependencyMap& dep_map,
  557. std::set<LibraryID>& emitted,
  558. std::set<LibraryID>& visited,
  559. DependencyList& link_line);
  560. /**
  561. * Finds the dependencies for \a lib and inserts them into \a
  562. * dep_map.
  563. */
  564. void GatherDependenciesForVS6( const cmMakefile& mf,
  565. const LibraryID& lib,
  566. DependencyMap& dep_map);
  567. void AnalyzeLibDependenciesForVS6( const cmMakefile& mf );
  568. #endif
  569. const char* GetSuffixVariableInternal(bool implib) const;
  570. const char* GetPrefixVariableInternal(bool implib) const;
  571. std::string GetFullNameInternal(const std::string& config,
  572. bool implib) const;
  573. void GetFullNameInternal(const std::string& config, bool implib,
  574. std::string& outPrefix, std::string& outBase,
  575. std::string& outSuffix) const;
  576. // Use a makefile variable to set a default for the given property.
  577. // If the variable is not defined use the given default instead.
  578. void SetPropertyDefault(const std::string& property,
  579. const char* default_value);
  580. // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type.
  581. const char* GetOutputTargetType(bool implib) const;
  582. // Get the target base name.
  583. std::string GetOutputName(const std::string& config, bool implib) const;
  584. std::string GetFullNameImported(const std::string& config,
  585. bool implib) const;
  586. std::string ImportedGetFullPath(const std::string& config,
  587. bool implib) const;
  588. std::string NormalGetFullPath(const std::string& config, bool implib,
  589. bool realname) const;
  590. /** Get the real name of the target. Allowed only for non-imported
  591. targets. When a library or executable file is versioned this is
  592. the full versioned name. If the target is not versioned this is
  593. the same as GetFullName. */
  594. std::string NormalGetRealName(const std::string& config) const;
  595. /** Append to @a base the mac content directory and return it. */
  596. std::string BuildMacContentDirectory(const std::string& base,
  597. const std::string& config,
  598. bool contentOnly) const;
  599. void GetSourceFiles(std::vector<std::string> &files,
  600. const std::string& config) const;
  601. private:
  602. std::string Name;
  603. std::vector<cmCustomCommand> PreBuildCommands;
  604. std::vector<cmCustomCommand> PreLinkCommands;
  605. std::vector<cmCustomCommand> PostBuildCommands;
  606. TargetType TargetTypeValue;
  607. LinkLibraryVectorType PrevLinkedLibraries;
  608. #if defined(_WIN32) && !defined(__CYGWIN__)
  609. LinkLibraryVectorType LinkLibrariesForVS6;
  610. bool LinkLibrariesForVS6Analyzed;
  611. #endif
  612. std::vector<std::string> LinkDirectories;
  613. std::set<std::string> LinkDirectoriesEmmitted;
  614. bool HaveInstallRule;
  615. std::string InstallPath;
  616. std::string RuntimeInstallPath;
  617. mutable std::string ExportMacro;
  618. std::set<std::string> Utilities;
  619. std::map<std::string, cmListFileBacktrace> UtilityBacktraces;
  620. bool RecordDependencies;
  621. mutable cmPropertyMap Properties;
  622. LinkLibraryVectorType OriginalLinkLibraries;
  623. bool DLLPlatform;
  624. bool IsAndroid;
  625. bool IsApple;
  626. bool IsImportedTarget;
  627. mutable bool DebugIncludesDone;
  628. mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
  629. mutable bool DebugCompileOptionsDone;
  630. mutable bool DebugCompileDefinitionsDone;
  631. mutable bool DebugSourcesDone;
  632. mutable bool DebugCompileFeaturesDone;
  633. mutable std::set<std::string> LinkImplicitNullProperties;
  634. mutable std::map<std::string, std::string> MaxLanguageStandards;
  635. bool BuildInterfaceIncludesAppended;
  636. // Cache target output paths for each configuration.
  637. struct OutputInfo;
  638. OutputInfo const* GetOutputInfo(const std::string& config) const;
  639. bool
  640. ComputeOutputDir(const std::string& config,
  641. bool implib, std::string& out) const;
  642. bool ComputePDBOutputDir(const std::string& kind, const std::string& config,
  643. std::string& out) const;
  644. // Cache import information from properties for each configuration.
  645. struct ImportInfo;
  646. ImportInfo const* GetImportInfo(const std::string& config) const;
  647. void ComputeImportInfo(std::string const& desired_config,
  648. ImportInfo& info) const;
  649. // Cache target compile paths for each configuration.
  650. struct CompileInfo;
  651. CompileInfo const* GetCompileInfo(const std::string& config) const;
  652. mutable cmTargetLinkInformationMap LinkInformation;
  653. void CheckPropertyCompatibility(cmComputeLinkInformation *info,
  654. const std::string& config) const;
  655. LinkInterface const*
  656. GetImportLinkInterface(const std::string& config, cmTarget const* head,
  657. bool usage_requirements_only) const;
  658. LinkImplementationLibraries const*
  659. GetLinkImplementationLibrariesInternal(const std::string& config,
  660. cmTarget const* head) const;
  661. void ComputeLinkClosure(const std::string& config, LinkClosure& lc) const;
  662. void ExpandLinkItems(std::string const& prop, std::string const& value,
  663. std::string const& config, cmTarget const* headTarget,
  664. bool usage_requirements_only,
  665. std::vector<cmLinkItem>& items,
  666. bool& hadHeadSensitiveCondition) const;
  667. void LookupLinkItems(std::vector<std::string> const& names,
  668. std::vector<cmLinkItem>& items) const;
  669. std::string ProcessSourceItemCMP0049(const std::string& s);
  670. void ClearLinkMaps();
  671. void MaybeInvalidatePropertyCache(const std::string& prop);
  672. void ProcessSourceExpression(std::string const& expr);
  673. // The cmMakefile instance that owns this target. This should
  674. // always be set.
  675. cmMakefile* Makefile;
  676. // Policy status recorded when target was created.
  677. #define TARGET_POLICY_MEMBER(POLICY) \
  678. cmPolicies::PolicyStatus PolicyStatus ## POLICY;
  679. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_MEMBER)
  680. #undef TARGET_POLICY_MEMBER
  681. // Internal representation details.
  682. friend class cmTargetInternals;
  683. friend class cmGeneratorTarget;
  684. friend class cmTargetTraceDependencies;
  685. cmTargetInternalPointer Internal;
  686. void ComputeVersionedName(std::string& vName,
  687. std::string const& prefix,
  688. std::string const& base,
  689. std::string const& suffix,
  690. std::string const& name,
  691. const char* version) const;
  692. mutable bool LinkImplementationLanguageIsContextDependent;
  693. };
  694. #ifdef CMAKE_BUILD_WITH_CMAKE
  695. typedef cmsys::hash_map<std::string,cmTarget> cmTargets;
  696. #else
  697. typedef std::map<std::string,cmTarget> cmTargets;
  698. #endif
  699. class cmTargetSet: public std::set<std::string> {};
  700. class cmTargetManifest: public std::map<std::string, cmTargetSet> {};
  701. #endif