cmTarget.h 31 KB

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