cmLocalGenerator.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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 cmLocalGenerator_h
  11. #define cmLocalGenerator_h
  12. #include "cmStandardIncludes.h"
  13. #include "cmState.h"
  14. #include "cmake.h"
  15. #include "cmOutputConverter.h"
  16. class cmMakefile;
  17. class cmGlobalGenerator;
  18. class cmGeneratorTarget;
  19. class cmTargetManifest;
  20. class cmSourceFile;
  21. class cmCustomCommand;
  22. class cmCustomCommandGenerator;
  23. /** \class cmLocalGenerator
  24. * \brief Create required build files for a directory.
  25. *
  26. * Subclasses of this abstract class generate makefiles, DSP, etc for various
  27. * platforms. This class should never be constructed directly. A
  28. * GlobalGenerator will create it and invoke the appropriate commands on it.
  29. */
  30. class cmLocalGenerator : public cmOutputConverter
  31. {
  32. public:
  33. cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile);
  34. virtual ~cmLocalGenerator();
  35. /**
  36. * Generate the makefile for this directory.
  37. */
  38. virtual void Generate() {}
  39. virtual void ComputeHomeRelativeOutputPath() {}
  40. /**
  41. * Calls TraceVSDependencies() on all targets of this generator.
  42. */
  43. void TraceDependencies();
  44. virtual void AddHelperCommands() {}
  45. /**
  46. * Generate the install rules files in this directory.
  47. */
  48. void GenerateInstallRules();
  49. /**
  50. * Generate the test files for tests.
  51. */
  52. void GenerateTestFiles();
  53. /**
  54. * Generate a manifest of target files that will be built.
  55. */
  56. void ComputeTargetManifest();
  57. bool IsRootMakefile() const;
  58. ///! Get the makefile for this generator
  59. cmMakefile *GetMakefile() {
  60. return this->Makefile; }
  61. ///! Get the makefile for this generator, const version
  62. const cmMakefile *GetMakefile() const {
  63. return this->Makefile; }
  64. ///! Get the GlobalGenerator this is associated with
  65. cmGlobalGenerator *GetGlobalGenerator() {
  66. return this->GlobalGenerator; }
  67. const cmGlobalGenerator *GetGlobalGenerator() const {
  68. return this->GlobalGenerator; }
  69. cmState* GetState() const;
  70. cmState::Snapshot GetStateSnapshot() const;
  71. void AddArchitectureFlags(std::string& flags,
  72. cmGeneratorTarget const* target,
  73. const std::string&lang, const std::string& config);
  74. void AddLanguageFlags(std::string& flags, const std::string& lang,
  75. const std::string& config);
  76. void AddCMP0018Flags(std::string &flags, cmGeneratorTarget const* target,
  77. std::string const& lang, const std::string& config);
  78. void AddVisibilityPresetFlags(std::string &flags,
  79. cmGeneratorTarget const* target,
  80. const std::string& lang);
  81. void AddConfigVariableFlags(std::string& flags, const std::string& var,
  82. const std::string& config);
  83. void AddCompilerRequirementFlag(std::string &flags,
  84. cmGeneratorTarget const* target,
  85. const std::string& lang);
  86. ///! Append flags to a string.
  87. virtual void AppendFlags(std::string& flags, const std::string& newFlags);
  88. virtual void AppendFlags(std::string& flags, const char* newFlags);
  89. virtual void AppendFlagEscape(std::string& flags,
  90. const std::string& rawFlag);
  91. ///! Get the include flags for the current makefile and language
  92. std::string GetIncludeFlags(const std::vector<std::string> &includes,
  93. cmGeneratorTarget* target,
  94. const std::string& lang,
  95. bool forceFullPaths = false,
  96. bool forResponseFile = false,
  97. const std::string& config = "");
  98. const std::vector<cmGeneratorTarget*> &GetGeneratorTargets() const
  99. {
  100. return this->GeneratorTargets;
  101. }
  102. const std::vector<cmGeneratorTarget*> &GetImportedGeneratorTargets() const
  103. {
  104. return this->ImportedGeneratorTargets;
  105. }
  106. void AddGeneratorTarget(cmGeneratorTarget* gt);
  107. void AddImportedGeneratorTarget(cmGeneratorTarget* gt);
  108. void AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt);
  109. cmGeneratorTarget* FindGeneratorTarget(const std::string& name) const;
  110. cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
  111. /**
  112. * Encode a list of preprocessor definitions for the compiler
  113. * command line.
  114. */
  115. void AppendDefines(std::set<std::string>& defines,
  116. const char* defines_list);
  117. void AppendDefines(std::set<std::string>& defines,
  118. std::string defines_list)
  119. {
  120. this->AppendDefines(defines, defines_list.c_str());
  121. }
  122. void AppendDefines(std::set<std::string>& defines,
  123. const std::vector<std::string> &defines_vec);
  124. /**
  125. * Join a set of defines into a definesString with a space separator.
  126. */
  127. void JoinDefines(const std::set<std::string>& defines,
  128. std::string &definesString,
  129. const std::string& lang);
  130. /** Lookup and append options associated with a particular feature. */
  131. void AppendFeatureOptions(std::string& flags, const std::string& lang,
  132. const char* feature);
  133. const char* GetFeature(const std::string& feature,
  134. const std::string& config);
  135. /** \brief Get absolute path to dependency \a name
  136. *
  137. * Translate a dependency as given in CMake code to the name to
  138. * appear in a generated build file.
  139. * - If \a name is a utility target, returns false.
  140. * - If \a name is a CMake target, it will be transformed to the real output
  141. * location of that target for the given configuration.
  142. * - If \a name is the full path to a file, it will be returned.
  143. * - Otherwise \a name is treated as a relative path with respect to
  144. * the source directory of this generator. This should only be
  145. * used for dependencies of custom commands.
  146. */
  147. bool GetRealDependency(const std::string& name, const std::string& config,
  148. std::string& dep);
  149. virtual std::string ConvertToIncludeReference(std::string const& path,
  150. OutputFormat format = SHELL,
  151. bool forceFullPaths = false);
  152. /** Called from command-line hook to clear dependencies. */
  153. virtual void ClearDependencies(cmMakefile* /* mf */,
  154. bool /* verbose */) {}
  155. /** Called from command-line hook to update dependencies. */
  156. virtual bool UpdateDependencies(const char* /* tgtInfo */,
  157. bool /*verbose*/,
  158. bool /*color*/)
  159. { return true; }
  160. /** Get the include flags for the current makefile and language. */
  161. void GetIncludeDirectories(std::vector<std::string>& dirs,
  162. cmGeneratorTarget const* target,
  163. const std::string& lang = "C",
  164. const std::string& config = "",
  165. bool stripImplicitInclDirs = true) const;
  166. void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
  167. const std::string& lang, const std::string& config);
  168. void AddCompileDefinitions(std::set<std::string>& defines,
  169. cmGeneratorTarget const* target,
  170. const std::string& config,
  171. const std::string& lang);
  172. std::string GetProjectName() const;
  173. /** Compute the language used to compile the given source file. */
  174. std::string GetSourceFileLanguage(const cmSourceFile& source);
  175. // Fill the vector with the target names for the object files,
  176. // preprocessed files and assembly files.
  177. void GetIndividualFileTargets(std::vector<std::string>&) {}
  178. // Create a struct to hold the varibles passed into
  179. // ExpandRuleVariables
  180. struct RuleVariables
  181. {
  182. RuleVariables()
  183. {
  184. memset(this, 0, sizeof(*this));
  185. }
  186. cmGeneratorTarget* CMTarget;
  187. const char* TargetPDB;
  188. const char* TargetCompilePDB;
  189. const char* TargetVersionMajor;
  190. const char* TargetVersionMinor;
  191. const char* Language;
  192. const char* Objects;
  193. const char* Target;
  194. const char* LinkLibraries;
  195. const char* Source;
  196. const char* AssemblySource;
  197. const char* PreprocessedSource;
  198. const char* Output;
  199. const char* Object;
  200. const char* ObjectDir;
  201. const char* ObjectFileDir;
  202. const char* Flags;
  203. const char* ObjectsQuoted;
  204. const char* SONameFlag;
  205. const char* TargetSOName;
  206. const char* TargetInstallNameDir;
  207. const char* LinkFlags;
  208. const char* Manifests;
  209. const char* LanguageCompileFlags;
  210. const char* Defines;
  211. const char* Includes;
  212. const char* RuleLauncher;
  213. const char* DependencyFile;
  214. const char* FilterPrefix;
  215. };
  216. /**
  217. * Get the relative path from the generator output directory to a
  218. * per-target support directory.
  219. */
  220. virtual std::string
  221. GetTargetDirectory(cmGeneratorTarget const* target) const;
  222. /**
  223. * Get the level of backwards compatibility requested by the project
  224. * in this directory. This is the value of the CMake variable
  225. * CMAKE_BACKWARDS_COMPATIBILITY whose format is
  226. * "major.minor[.patch]". The returned integer is encoded as
  227. *
  228. * CMake_VERSION_ENCODE(major, minor, patch)
  229. *
  230. * and is monotonically increasing with the CMake version.
  231. */
  232. KWIML_INT_uint64_t GetBackwardsCompatibility();
  233. /**
  234. * Test whether compatibility is set to a given version or lower.
  235. */
  236. bool NeedBackwardsCompatibility_2_4();
  237. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
  238. cmake* GetCMakeInstance() const;
  239. const char* GetSourceDirectory() const;
  240. const char* GetBinaryDirectory() const;
  241. const char* GetCurrentBinaryDirectory() const;
  242. const char* GetCurrentSourceDirectory() const;
  243. /**
  244. * Generate a Mac OS X application bundle Info.plist file.
  245. */
  246. void GenerateAppleInfoPList(cmGeneratorTarget* target,
  247. const std::string& targetName,
  248. const char* fname);
  249. /**
  250. * Generate a Mac OS X framework Info.plist file.
  251. */
  252. void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
  253. const std::string& targetName,
  254. const char* fname);
  255. /** Construct a comment for a custom command. */
  256. std::string ConstructComment(cmCustomCommandGenerator const& ccg,
  257. const char* default_comment = "");
  258. // Compute object file names.
  259. std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  260. std::string const& dir_max,
  261. bool* hasSourceExtension = 0);
  262. /** Fill out the static linker flags for the given target. */
  263. void GetStaticLibraryFlags(std::string& flags,
  264. std::string const& config,
  265. cmGeneratorTarget* target);
  266. /** Fill out these strings for the given target. Libraries to link,
  267. * flags, and linkflags. */
  268. void GetTargetFlags(std::string& linkLibs,
  269. std::string& flags,
  270. std::string& linkFlags,
  271. std::string& frameworkPath,
  272. std::string& linkPath,
  273. cmGeneratorTarget* target,
  274. bool useWatcomQuote);
  275. virtual void ComputeObjectFilenames(
  276. std::map<cmSourceFile const*, std::string>& mapping,
  277. cmGeneratorTarget const* gt = 0);
  278. bool IsWindowsShell() const;
  279. bool IsWatcomWMake() const;
  280. bool IsMinGWMake() const;
  281. bool IsNMake() const;
  282. void IssueMessage(cmake::MessageType t, std::string const& text) const;
  283. void CreateEvaluationFileOutputs(const std::string& config);
  284. void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
  285. protected:
  286. ///! put all the libraries for a target on into the given stream
  287. void OutputLinkLibraries(std::string& linkLibraries,
  288. std::string& frameworkPath,
  289. std::string& linkPath,
  290. cmGeneratorTarget &,
  291. bool relink,
  292. bool forResponseFile,
  293. bool useWatcomQuote);
  294. // Expand rule variables in CMake of the type found in language rules
  295. void ExpandRuleVariables(std::string& string,
  296. const RuleVariables& replaceValues);
  297. // Expand rule variables in a single string
  298. std::string ExpandRuleVariable(std::string const& variable,
  299. const RuleVariables& replaceValues);
  300. const char* GetRuleLauncher(cmGeneratorTarget* target,
  301. const std::string& prop);
  302. void InsertRuleLauncher(std::string& s, cmGeneratorTarget* target,
  303. const std::string& prop);
  304. // Handle old-style install rules stored in the targets.
  305. void GenerateTargetInstallRules(
  306. std::ostream& os, const std::string& config,
  307. std::vector<std::string> const& configurationTypes);
  308. std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
  309. std::string const& dir_max);
  310. virtual std::string ConvertToLinkReference(std::string const& lib,
  311. OutputFormat format = SHELL);
  312. /** Check whether the native build system supports the given
  313. definition. Issues a warning. */
  314. virtual bool CheckDefinition(std::string const& define) const;
  315. cmMakefile *Makefile;
  316. cmState::Snapshot StateSnapshot;
  317. cmGlobalGenerator *GlobalGenerator;
  318. std::map<std::string, std::string> UniqueObjectNamesMap;
  319. std::string::size_type ObjectPathMax;
  320. std::set<std::string> ObjectMaxPathViolations;
  321. std::set<cmGeneratorTarget const*> WarnCMP0063;
  322. std::vector<cmGeneratorTarget*> GeneratorTargets;
  323. std::vector<cmGeneratorTarget*> ImportedGeneratorTargets;
  324. std::vector<cmGeneratorTarget*> OwnedImportedGeneratorTargets;
  325. std::map<std::string, std::string> AliasTargets;
  326. bool EmitUniversalBinaryFlags;
  327. // Hack for ExpandRuleVariable until object-oriented version is
  328. // committed.
  329. std::string TargetImplib;
  330. KWIML_INT_uint64_t BackwardsCompatibility;
  331. bool BackwardsCompatibilityFinal;
  332. private:
  333. void AddSharedFlags(std::string& flags, const std::string& lang,
  334. bool shared);
  335. bool GetShouldUseOldFlags(bool shared, const std::string &lang) const;
  336. void AddPositionIndependentFlags(std::string& flags, std::string const& l,
  337. int targetType);
  338. void ComputeObjectMaxPath();
  339. };
  340. #endif