cmGeneratorTarget.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. /** Get the soname of the target. Allowed only for a shared library. */
  98. std::string GetSOName(const std::string& config) const;
  99. void GetFullNameComponents(std::string& prefix,
  100. std::string& base, std::string& suffix,
  101. const std::string& config="",
  102. bool implib = false) const;
  103. cmTarget* Target;
  104. cmMakefile* Makefile;
  105. cmLocalGenerator* LocalGenerator;
  106. cmGlobalGenerator const* GlobalGenerator;
  107. std::string GetModuleDefinitionFile(const std::string& config) const;
  108. /** Full path with trailing slash to the top-level directory
  109. holding object files for this target. Includes the build
  110. time config name placeholder if needed for the generator. */
  111. std::string ObjectDirectory;
  112. void UseObjectLibraries(std::vector<std::string>& objs,
  113. const std::string& config) const;
  114. void GetAppleArchs(const std::string& config,
  115. std::vector<std::string>& archVec) const;
  116. /** Return the rule variable used to create this type of target. */
  117. std::string GetCreateRuleVariable(std::string const& lang,
  118. std::string const& config) const;
  119. /** Get the include directories for this target. */
  120. std::vector<std::string> GetIncludeDirectories(
  121. const std::string& config, const std::string& lang) const;
  122. bool IsSystemIncludeDirectory(const std::string& dir,
  123. const std::string& config) const;
  124. /** Add the target output files to the global generator manifest. */
  125. void GenerateTargetManifest(const std::string& config) const;
  126. /**
  127. * Trace through the source files in this target and add al source files
  128. * that they depend on, used by all generators
  129. */
  130. void TraceDependencies();
  131. /** Get sources that must be built before the given source. */
  132. std::vector<cmSourceFile*> const*
  133. GetSourceDepends(cmSourceFile const* sf) const;
  134. /** Get the name of the pdb file for the target. */
  135. std::string GetPDBName(const std::string& config="") const;
  136. /** Whether this library has soname enabled and platform supports it. */
  137. bool HasSOName(const std::string& config) const;
  138. /** Get the name of the compiler pdb file for the target. */
  139. std::string GetCompilePDBName(const std::string& config="") const;
  140. /** Get the path for the MSVC /Fd option for this target. */
  141. std::string GetCompilePDBPath(const std::string& config="") const;
  142. /**
  143. * Flags for a given source file as used in this target. Typically assigned
  144. * via SET_TARGET_PROPERTIES when the property is a list of source files.
  145. */
  146. enum SourceFileType
  147. {
  148. SourceFileTypeNormal,
  149. SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
  150. SourceFileTypePublicHeader, // is in "PUBLIC_HEADER" target property
  151. SourceFileTypeResource, // is in "RESOURCE" target property *or*
  152. // has MACOSX_PACKAGE_LOCATION=="Resources"
  153. SourceFileTypeMacContent // has MACOSX_PACKAGE_LOCATION!="Resources"
  154. };
  155. struct SourceFileFlags
  156. {
  157. SourceFileFlags(): Type(SourceFileTypeNormal), MacFolder(0) {}
  158. SourceFileFlags(SourceFileFlags const& r):
  159. Type(r.Type), MacFolder(r.MacFolder) {}
  160. SourceFileType Type;
  161. const char* MacFolder; // location inside Mac content folders
  162. };
  163. void GetAutoUicOptions(std::vector<std::string> &result,
  164. const std::string& config) const;
  165. /** Get the names of the executable needed to generate a build rule
  166. that takes into account executable version numbers. This should
  167. be called only on an executable target. */
  168. void GetExecutableNames(std::string& name, std::string& realName,
  169. std::string& impName, std::string& pdbName,
  170. const std::string& config) const;
  171. /** Get the names of the library needed to generate a build rule
  172. that takes into account shared library version numbers. This
  173. should be called only on a library target. */
  174. void GetLibraryNames(std::string& name, std::string& soName,
  175. std::string& realName, std::string& impName,
  176. std::string& pdbName, const std::string& config) const;
  177. /**
  178. * Compute whether this target must be relinked before installing.
  179. */
  180. bool NeedRelinkBeforeInstall(const std::string& config) const;
  181. /** Return true if builtin chrpath will work for this target */
  182. bool IsChrpathUsed(const std::string& config) const;
  183. struct SourceFileFlags
  184. GetTargetSourceFileFlags(const cmSourceFile* sf) const;
  185. struct ResxData {
  186. mutable std::set<std::string> ExpectedResxHeaders;
  187. mutable std::vector<cmSourceFile const*> ResxSources;
  188. };
  189. struct XamlData {
  190. std::set<std::string> ExpectedXamlHeaders;
  191. std::set<std::string> ExpectedXamlSources;
  192. std::vector<cmSourceFile const*> XamlSources;
  193. };
  194. void ReportPropertyOrigin(const std::string &p,
  195. const std::string &result,
  196. const std::string &report,
  197. const std::string &compatibilityType) const;
  198. private:
  199. friend class cmTargetTraceDependencies;
  200. struct SourceEntry { std::vector<cmSourceFile*> Depends; };
  201. typedef std::map<cmSourceFile const*, SourceEntry> SourceEntriesType;
  202. SourceEntriesType SourceEntries;
  203. mutable std::map<cmSourceFile const*, std::string> Objects;
  204. std::set<cmSourceFile const*> ExplicitObjectName;
  205. mutable std::map<std::string, std::vector<std::string> > SystemIncludesCache;
  206. void ConstructSourceFileFlags() const;
  207. mutable bool SourceFileFlagsConstructed;
  208. mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  209. mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
  210. struct CompatibleInterfacesBase
  211. {
  212. std::set<std::string> PropsBool;
  213. std::set<std::string> PropsString;
  214. std::set<std::string> PropsNumberMax;
  215. std::set<std::string> PropsNumberMin;
  216. };
  217. CompatibleInterfacesBase const&
  218. GetCompatibleInterfaces(std::string const& config) const;
  219. struct CompatibleInterfaces: public CompatibleInterfacesBase
  220. {
  221. CompatibleInterfaces(): Done(false) {}
  222. bool Done;
  223. };
  224. mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
  225. typedef std::map<std::string, cmComputeLinkInformation*>
  226. cmTargetLinkInformationMap;
  227. mutable cmTargetLinkInformationMap LinkInformation;
  228. void CheckPropertyCompatibility(cmComputeLinkInformation *info,
  229. const std::string& config) const;
  230. cmGeneratorTarget(cmGeneratorTarget const&);
  231. void operator=(cmGeneratorTarget const&);
  232. struct LinkImplClosure: public std::vector<cmTarget const*>
  233. {
  234. LinkImplClosure(): Done(false) {}
  235. bool Done;
  236. };
  237. mutable std::map<std::string, LinkImplClosure> LinkImplClosureMap;
  238. public:
  239. std::vector<cmTarget const*> const&
  240. GetLinkImplementationClosure(const std::string& config) const;
  241. };
  242. struct cmStrictTargetComparison {
  243. bool operator()(cmTarget const* t1, cmTarget const* t2) const;
  244. };
  245. typedef std::map<cmTarget const*,
  246. cmGeneratorTarget*,
  247. cmStrictTargetComparison> cmGeneratorTargetsType;
  248. #endif