cmTarget.h 28 KB

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