cmTarget.h 29 KB

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