cmGeneratorTarget.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmGeneratorTarget_h
  11. #define cmGeneratorTarget_h
  12. #include "cmStandardIncludes.h"
  13. class cmCustomCommand;
  14. class cmGlobalGenerator;
  15. class cmLocalGenerator;
  16. class cmMakefile;
  17. class cmSourceFile;
  18. class cmTarget;
  19. class cmComputeLinkInformation;
  20. class cmGeneratorTarget
  21. {
  22. public:
  23. cmGeneratorTarget(cmTarget*, cmLocalGenerator* lg);
  24. ~cmGeneratorTarget();
  25. cmLocalGenerator* GetLocalGenerator() const;
  26. bool IsImported() const;
  27. const char *GetLocation(const std::string& config) const;
  28. /** Get the location of the target in the build tree with a placeholder
  29. referencing the configuration in the native build system. This
  30. location is suitable for use as the LOCATION target property. */
  31. const char* GetLocationForBuild() const;
  32. cmComputeLinkInformation*
  33. GetLinkInformation(const std::string& config) const;
  34. int GetType() const;
  35. std::string GetName() const;
  36. const char *GetProperty(const std::string& prop) const;
  37. bool GetPropertyAsBool(const std::string& prop) const;
  38. void GetSourceFiles(std::vector<cmSourceFile*>& files,
  39. const std::string& config) const;
  40. void GetObjectSources(std::vector<cmSourceFile const*> &,
  41. const std::string& config) const;
  42. const std::string& GetObjectName(cmSourceFile const* file);
  43. bool HasExplicitObjectName(cmSourceFile const* file) const;
  44. void AddExplicitObjectName(cmSourceFile const* sf);
  45. void GetResxSources(std::vector<cmSourceFile const*>&,
  46. const std::string& config) const;
  47. void GetIDLSources(std::vector<cmSourceFile const*>&,
  48. const std::string& config) const;
  49. void GetExternalObjects(std::vector<cmSourceFile const*>&,
  50. const std::string& config) const;
  51. void GetHeaderSources(std::vector<cmSourceFile const*>&,
  52. const std::string& config) const;
  53. void GetExtraSources(std::vector<cmSourceFile const*>&,
  54. const std::string& config) const;
  55. void GetCustomCommands(std::vector<cmSourceFile const*>&,
  56. const std::string& config) const;
  57. void GetExpectedResxHeaders(std::set<std::string>&,
  58. const std::string& config) const;
  59. void GetAppManifest(std::vector<cmSourceFile const*>&,
  60. const std::string& config) const;
  61. void GetCertificates(std::vector<cmSourceFile const*>&,
  62. const std::string& config) const;
  63. void GetXamlSources(std::vector<cmSourceFile const*>&,
  64. const std::string& config) const;
  65. void GetExpectedXamlHeaders(std::set<std::string>&,
  66. const std::string& config) const;
  67. void GetExpectedXamlSources(std::set<std::string>&,
  68. const std::string& config) const;
  69. void ComputeObjectMapping();
  70. const char* GetFeature(const std::string& feature,
  71. const std::string& config) const;
  72. bool GetFeatureAsBool(const std::string& feature,
  73. const std::string& config) const;
  74. bool IsLinkInterfaceDependentBoolProperty(const std::string &p,
  75. const std::string& config) const;
  76. bool IsLinkInterfaceDependentStringProperty(const std::string &p,
  77. const std::string& config) const;
  78. bool IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
  79. const std::string& config) const;
  80. bool IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  81. const std::string& config) const;
  82. bool GetLinkInterfaceDependentBoolProperty(const std::string &p,
  83. const std::string& config) const;
  84. const char *GetLinkInterfaceDependentStringProperty(const std::string &p,
  85. const std::string& config) const;
  86. const char *GetLinkInterfaceDependentNumberMinProperty(const std::string &p,
  87. const std::string& config) const;
  88. const char *GetLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  89. const std::string& config) const;
  90. /** Get the full path to the target according to the settings in its
  91. makefile and the configuration type. */
  92. std::string GetFullPath(const std::string& config="", bool implib = false,
  93. bool realname = false) const;
  94. std::string NormalGetFullPath(const std::string& config, bool implib,
  95. bool realname) const;
  96. std::string NormalGetRealName(const std::string& config) const;
  97. /** @return the Mac App directory without the base */
  98. std::string GetAppBundleDirectory(const std::string& config,
  99. bool contentOnly) const;
  100. /** Get the full name of the target according to the settings in its
  101. makefile. */
  102. std::string GetFullName(const std::string& config="",
  103. bool implib = false) const;
  104. /** Return the install name directory for the target in the
  105. * build tree. For example: "\@rpath/", "\@loader_path/",
  106. * or "/full/path/to/library". */
  107. std::string GetInstallNameDirForBuildTree(const std::string& config) const;
  108. /** Return the install name directory for the target in the
  109. * install tree. For example: "\@rpath/" or "\@loader_path/". */
  110. std::string GetInstallNameDirForInstallTree() const;
  111. /** Get the soname of the target. Allowed only for a shared library. */
  112. std::string GetSOName(const std::string& config) const;
  113. void GetFullNameComponents(std::string& prefix,
  114. std::string& base, std::string& suffix,
  115. const std::string& config="",
  116. bool implib = false) const;
  117. /** Append to @a base the mac content directory and return it. */
  118. std::string BuildMacContentDirectory(const std::string& base,
  119. const std::string& config = "",
  120. bool contentOnly = true) const;
  121. /** @return the mac content directory for this target. */
  122. std::string GetMacContentDirectory(const std::string& config = 0,
  123. bool implib = false) const;
  124. cmTarget* Target;
  125. cmMakefile* Makefile;
  126. cmLocalGenerator* LocalGenerator;
  127. cmGlobalGenerator const* GlobalGenerator;
  128. std::string GetModuleDefinitionFile(const std::string& config) const;
  129. /** Full path with trailing slash to the top-level directory
  130. holding object files for this target. Includes the build
  131. time config name placeholder if needed for the generator. */
  132. std::string ObjectDirectory;
  133. void UseObjectLibraries(std::vector<std::string>& objs,
  134. const std::string& config) const;
  135. void GetAppleArchs(const std::string& config,
  136. std::vector<std::string>& archVec) const;
  137. /** Return the rule variable used to create this type of target. */
  138. std::string GetCreateRuleVariable(std::string const& lang,
  139. std::string const& config) const;
  140. /** Get the include directories for this target. */
  141. std::vector<std::string> GetIncludeDirectories(
  142. const std::string& config, const std::string& lang) const;
  143. bool IsSystemIncludeDirectory(const std::string& dir,
  144. const std::string& config) const;
  145. /** Add the target output files to the global generator manifest. */
  146. void GenerateTargetManifest(const std::string& config) const;
  147. /**
  148. * Trace through the source files in this target and add al source files
  149. * that they depend on, used by all generators
  150. */
  151. void TraceDependencies();
  152. /** Get sources that must be built before the given source. */
  153. std::vector<cmSourceFile*> const*
  154. GetSourceDepends(cmSourceFile const* sf) const;
  155. /** Get the name of the pdb file for the target. */
  156. std::string GetPDBName(const std::string& config="") const;
  157. /** Whether this library has soname enabled and platform supports it. */
  158. bool HasSOName(const std::string& config) const;
  159. /** Get the name of the compiler pdb file for the target. */
  160. std::string GetCompilePDBName(const std::string& config="") const;
  161. /** Get the path for the MSVC /Fd option for this target. */
  162. std::string GetCompilePDBPath(const std::string& config="") const;
  163. /**
  164. * Flags for a given source file as used in this target. Typically assigned
  165. * via SET_TARGET_PROPERTIES when the property is a list of source files.
  166. */
  167. enum SourceFileType
  168. {
  169. SourceFileTypeNormal,
  170. SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
  171. SourceFileTypePublicHeader, // is in "PUBLIC_HEADER" target property
  172. SourceFileTypeResource, // is in "RESOURCE" target property *or*
  173. // has MACOSX_PACKAGE_LOCATION=="Resources"
  174. SourceFileTypeMacContent // has MACOSX_PACKAGE_LOCATION!="Resources"
  175. };
  176. struct SourceFileFlags
  177. {
  178. SourceFileFlags(): Type(SourceFileTypeNormal), MacFolder(0) {}
  179. SourceFileFlags(SourceFileFlags const& r):
  180. Type(r.Type), MacFolder(r.MacFolder) {}
  181. SourceFileType Type;
  182. const char* MacFolder; // location inside Mac content folders
  183. };
  184. void GetAutoUicOptions(std::vector<std::string> &result,
  185. const std::string& config) const;
  186. /** Get the names of the executable needed to generate a build rule
  187. that takes into account executable version numbers. This should
  188. be called only on an executable target. */
  189. void GetExecutableNames(std::string& name, std::string& realName,
  190. std::string& impName, std::string& pdbName,
  191. const std::string& config) const;
  192. /** Get the names of the library needed to generate a build rule
  193. that takes into account shared library version numbers. This
  194. should be called only on a library target. */
  195. void GetLibraryNames(std::string& name, std::string& soName,
  196. std::string& realName, std::string& impName,
  197. std::string& pdbName, const std::string& config) const;
  198. /**
  199. * Compute whether this target must be relinked before installing.
  200. */
  201. bool NeedRelinkBeforeInstall(const std::string& config) const;
  202. /** Return true if builtin chrpath will work for this target */
  203. bool IsChrpathUsed(const std::string& config) const;
  204. struct SourceFileFlags
  205. GetTargetSourceFileFlags(const cmSourceFile* sf) const;
  206. struct ResxData {
  207. mutable std::set<std::string> ExpectedResxHeaders;
  208. mutable std::vector<cmSourceFile const*> ResxSources;
  209. };
  210. struct XamlData {
  211. std::set<std::string> ExpectedXamlHeaders;
  212. std::set<std::string> ExpectedXamlSources;
  213. std::vector<cmSourceFile const*> XamlSources;
  214. };
  215. void ReportPropertyOrigin(const std::string &p,
  216. const std::string &result,
  217. const std::string &report,
  218. const std::string &compatibilityType) const;
  219. private:
  220. friend class cmTargetTraceDependencies;
  221. struct SourceEntry { std::vector<cmSourceFile*> Depends; };
  222. typedef std::map<cmSourceFile const*, SourceEntry> SourceEntriesType;
  223. SourceEntriesType SourceEntries;
  224. mutable std::map<cmSourceFile const*, std::string> Objects;
  225. std::set<cmSourceFile const*> ExplicitObjectName;
  226. mutable std::map<std::string, std::vector<std::string> > SystemIncludesCache;
  227. void ConstructSourceFileFlags() const;
  228. mutable bool SourceFileFlagsConstructed;
  229. mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  230. mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
  231. std::string GetFullNameInternal(const std::string& config,
  232. bool implib) const;
  233. void GetFullNameInternal(const std::string& config, bool implib,
  234. std::string& outPrefix, std::string& outBase,
  235. std::string& outSuffix) const;
  236. struct CompatibleInterfacesBase
  237. {
  238. std::set<std::string> PropsBool;
  239. std::set<std::string> PropsString;
  240. std::set<std::string> PropsNumberMax;
  241. std::set<std::string> PropsNumberMin;
  242. };
  243. CompatibleInterfacesBase const&
  244. GetCompatibleInterfaces(std::string const& config) const;
  245. struct CompatibleInterfaces: public CompatibleInterfacesBase
  246. {
  247. CompatibleInterfaces(): Done(false) {}
  248. bool Done;
  249. };
  250. mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
  251. typedef std::map<std::string, cmComputeLinkInformation*>
  252. cmTargetLinkInformationMap;
  253. mutable cmTargetLinkInformationMap LinkInformation;
  254. void CheckPropertyCompatibility(cmComputeLinkInformation *info,
  255. const std::string& config) const;
  256. cmGeneratorTarget(cmGeneratorTarget const&);
  257. void operator=(cmGeneratorTarget const&);
  258. struct LinkImplClosure: public std::vector<cmTarget const*>
  259. {
  260. LinkImplClosure(): Done(false) {}
  261. bool Done;
  262. };
  263. mutable std::map<std::string, LinkImplClosure> LinkImplClosureMap;
  264. public:
  265. std::vector<cmTarget const*> const&
  266. GetLinkImplementationClosure(const std::string& config) const;
  267. };
  268. struct cmStrictTargetComparison {
  269. bool operator()(cmTarget const* t1, cmTarget const* t2) const;
  270. };
  271. typedef std::map<cmTarget const*,
  272. cmGeneratorTarget*,
  273. cmStrictTargetComparison> cmGeneratorTargetsType;
  274. #endif