cmLocalUnixMakefileGenerator3.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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 cmLocalUnixMakefileGenerator3_h
  11. #define cmLocalUnixMakefileGenerator3_h
  12. #include "cmLocalGenerator.h"
  13. // for cmDepends::DependencyVector
  14. #include "cmDepends.h"
  15. class cmCustomCommand;
  16. class cmCustomCommandGenerator;
  17. class cmDependInformation;
  18. class cmDepends;
  19. class cmMakefileTargetGenerator;
  20. class cmTarget;
  21. class cmSourceFile;
  22. /** \class cmLocalUnixMakefileGenerator3
  23. * \brief Write a LocalUnix makefiles.
  24. *
  25. * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
  26. * member Makefile.
  27. */
  28. class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator
  29. {
  30. public:
  31. cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg,
  32. cmLocalGenerator* parent);
  33. virtual ~cmLocalUnixMakefileGenerator3();
  34. /**
  35. * Process the CMakeLists files for this directory to fill in the
  36. * Makefile ivar
  37. */
  38. virtual void Configure();
  39. /**
  40. * Generate the makefile for this directory.
  41. */
  42. virtual void Generate();
  43. // this returns the relative path between the HomeOutputDirectory and this
  44. // local generators StartOutputDirectory
  45. const std::string &GetHomeRelativeOutputPath();
  46. // Write out a make rule
  47. void WriteMakeRule(std::ostream& os,
  48. const char* comment,
  49. const std::string& target,
  50. const std::vector<std::string>& depends,
  51. const std::vector<std::string>& commands,
  52. bool symbolic,
  53. bool in_help = false);
  54. // write the main variables used by the makefiles
  55. void WriteMakeVariables(std::ostream& makefileStream);
  56. /**
  57. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  58. * that do not use environment variables.
  59. *
  60. */
  61. void SetPassMakeflags(bool s){this->PassMakeflags = s;}
  62. bool GetPassMakeflags() { return this->PassMakeflags; }
  63. /**
  64. * Set the flag used to keep the make program silent.
  65. */
  66. void SetMakeSilentFlag(const std::string& s) { this->MakeSilentFlag = s; }
  67. std::string &GetMakeSilentFlag() { return this->MakeSilentFlag; }
  68. /**
  69. * If set to true, then NULL is set to nil for non Windows_NT.
  70. * This uses make syntax used by nmake and borland.
  71. * The default is false.
  72. */
  73. void SetDefineWindowsNULL(bool v) {this->DefineWindowsNULL = v;}
  74. /**
  75. * If set to true, cd dir && command is used to
  76. * run commands in a different directory.
  77. */
  78. void SetUnixCD(bool v) {this->UnixCD = v;}
  79. /**
  80. * Set the string used to include one makefile into another default
  81. * is include.
  82. */
  83. void SetIncludeDirective(const std::string& s)
  84. { this->IncludeDirective = s; }
  85. const std::string& GetIncludeDirective() { return this->IncludeDirective; }
  86. /**
  87. * Set max makefile variable size, default is 0 which means unlimited.
  88. */
  89. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  90. /**
  91. * If ignore lib prefix is true, then do not strip lib from the name
  92. * of a library.
  93. */
  94. void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
  95. /**
  96. * Set whether passing a make target on a command line requires an
  97. * extra level of escapes.
  98. */
  99. void SetMakeCommandEscapeTargetTwice(bool b)
  100. { this->MakeCommandEscapeTargetTwice = b; }
  101. /**
  102. * Set whether the Borland curly brace command line hack should be
  103. * applied.
  104. */
  105. void SetBorlandMakeCurlyHack(bool b)
  106. { this->BorlandMakeCurlyHack = b; }
  107. // used in writing out Cmake files such as WriteDirectoryInformation
  108. static void WriteCMakeArgument(std::ostream& os, const char* s);
  109. /** creates the common disclaimer text at the top of each makefile */
  110. void WriteDisclaimer(std::ostream& os);
  111. // write a comment line #====... in the stream
  112. void WriteDivider(std::ostream& os);
  113. /** used to create a recursive make call */
  114. std::string GetRecursiveMakeCall(const char *makefile,
  115. const std::string& tgt);
  116. // append flags to a string
  117. virtual void AppendFlags(std::string& flags, const std::string& newFlags);
  118. virtual void AppendFlags(std::string& flags, const char* newFlags);
  119. // append an echo command
  120. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  121. EchoGenerate, EchoGlobal };
  122. struct EchoProgress { std::string Dir; std::string Arg; };
  123. void AppendEcho(std::vector<std::string>& commands, std::string const& text,
  124. EchoColor color = EchoNormal, EchoProgress const* = 0);
  125. /** Get whether the makefile is to have color. */
  126. bool GetColorMakefile() const { return this->ColorMakefile; }
  127. virtual std::string GetTargetDirectory(cmTarget const& target) const;
  128. // create a command that cds to the start dir then runs the commands
  129. void CreateCDCommand(std::vector<std::string>& commands,
  130. const char *targetDir,
  131. cmLocalGenerator::RelativeRoot returnDir);
  132. static std::string ConvertToQuotedOutputPath(const char* p,
  133. bool useWatcomQuote);
  134. std::string CreateMakeVariable(const std::string& sin,
  135. const std::string& s2in);
  136. /** Called from command-line hook to bring dependencies up to date
  137. for a target. */
  138. virtual bool UpdateDependencies(const char* tgtInfo,
  139. bool verbose, bool color);
  140. /** Called from command-line hook to clear dependencies. */
  141. virtual void ClearDependencies(cmMakefile* mf, bool verbose);
  142. /** write some extra rules such as make test etc */
  143. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  144. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  145. std::string GetRelativeTargetDirectory(cmTarget const& target);
  146. // File pairs for implicit dependency scanning. The key of the map
  147. // is the depender and the value is the explicit dependee.
  148. struct ImplicitDependFileMap:
  149. public std::map<std::string, cmDepends::DependencyVector> {};
  150. struct ImplicitDependLanguageMap:
  151. public std::map<std::string, ImplicitDependFileMap> {};
  152. struct ImplicitDependTargetMap:
  153. public std::map<std::string, ImplicitDependLanguageMap> {};
  154. ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
  155. void AddImplicitDepends(cmTarget const& tgt, const std::string& lang,
  156. const char* obj, const char* src);
  157. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  158. cmTarget& target);
  159. // write the target rules for the local Makefile into the stream
  160. void WriteLocalAllRules(std::ostream& ruleFileStream);
  161. std::vector<std::string> const& GetLocalHelp() { return this->LocalHelp; }
  162. /** Get whether to create rules to generate preprocessed and
  163. assembly sources. This could be converted to a variable lookup
  164. later. */
  165. bool GetCreatePreprocessedSourceRules()
  166. {
  167. return !this->SkipPreprocessedSourceRules;
  168. }
  169. bool GetCreateAssemblySourceRules()
  170. {
  171. return !this->SkipAssemblySourceRules;
  172. }
  173. // Fill the vector with the target names for the object files,
  174. // preprocessed files and assembly files. Currently only used by the
  175. // Eclipse generator.
  176. void GetIndividualFileTargets(std::vector<std::string>& targets);
  177. protected:
  178. void WriteLocalMakefile();
  179. // write the target rules for the local Makefile into the stream
  180. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  181. std::set<std::string> &emitted);
  182. // this method Writes the Directory information files
  183. void WriteDirectoryInformationFile();
  184. // write the depend info
  185. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  186. // write the local help rule
  187. void WriteHelpRule(std::ostream& ruleFileStream);
  188. // this converts a file name that is relative to the StartOuputDirectory
  189. // into a full path
  190. std::string ConvertToFullPath(const std::string& localPath);
  191. void WriteConvenienceRule(std::ostream& ruleFileStream,
  192. const std::string& realTarget,
  193. const std::string& helpTarget);
  194. void WriteTargetDependRule(std::ostream& ruleFileStream,
  195. cmTarget& target);
  196. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  197. cmTarget& target,
  198. const std::vector<std::string>& files);
  199. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  200. cmTarget& target,
  201. const std::vector<std::string>& objects);
  202. void AppendRuleDepend(std::vector<std::string>& depends,
  203. const char* ruleFileName);
  204. void AppendRuleDepends(std::vector<std::string>& depends,
  205. std::vector<std::string> const& ruleFiles);
  206. void AppendCustomDepends(std::vector<std::string>& depends,
  207. const std::vector<cmCustomCommand>& ccs);
  208. void AppendCustomDepend(std::vector<std::string>& depends,
  209. cmCustomCommandGenerator const& cc);
  210. void AppendCustomCommands(std::vector<std::string>& commands,
  211. const std::vector<cmCustomCommand>& ccs,
  212. cmTarget* target,
  213. cmLocalGenerator::RelativeRoot relative =
  214. cmLocalGenerator::HOME_OUTPUT);
  215. void AppendCustomCommand(std::vector<std::string>& commands,
  216. cmCustomCommandGenerator const& ccg,
  217. cmTarget* target,
  218. bool echo_comment=false,
  219. cmLocalGenerator::RelativeRoot relative =
  220. cmLocalGenerator::HOME_OUTPUT,
  221. std::ostream* content = 0);
  222. void AppendCleanCommand(std::vector<std::string>& commands,
  223. const std::vector<std::string>& files,
  224. cmTarget& target, const char* filename =0);
  225. // Helper methods for dependeny updates.
  226. bool ScanDependencies(const char* targetDir,
  227. std::map<std::string, cmDepends::DependencyVector>& validDeps);
  228. void CheckMultipleOutputs(bool verbose);
  229. private:
  230. std::string ConvertShellCommand(std::string const& cmd, RelativeRoot root);
  231. std::string MakeLauncher(cmCustomCommandGenerator const& ccg,
  232. cmTarget* target, RelativeRoot relative);
  233. virtual void ComputeObjectFilenames(
  234. std::map<cmSourceFile const*, std::string>& mapping,
  235. cmGeneratorTarget const* gt = 0);
  236. friend class cmMakefileTargetGenerator;
  237. friend class cmMakefileExecutableTargetGenerator;
  238. friend class cmMakefileLibraryTargetGenerator;
  239. friend class cmMakefileUtilityTargetGenerator;
  240. friend class cmGlobalUnixMakefileGenerator3;
  241. ImplicitDependTargetMap ImplicitDepends;
  242. //==========================================================================
  243. // Configuration settings.
  244. int MakefileVariableSize;
  245. std::string IncludeDirective;
  246. std::string MakeSilentFlag;
  247. std::string ConfigurationName;
  248. bool DefineWindowsNULL;
  249. bool UnixCD;
  250. bool PassMakeflags;
  251. bool MakeCommandEscapeTargetTwice;
  252. bool BorlandMakeCurlyHack;
  253. //==========================================================================
  254. std::string HomeRelativeOutputPath;
  255. /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
  256. beginning of generation to avoid many duplicate lookups. */
  257. bool ColorMakefile;
  258. /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
  259. CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
  260. avoid many duplicate lookups. */
  261. bool SkipPreprocessedSourceRules;
  262. bool SkipAssemblySourceRules;
  263. struct LocalObjectEntry
  264. {
  265. cmTarget* Target;
  266. std::string Language;
  267. LocalObjectEntry(): Target(0), Language() {}
  268. LocalObjectEntry(cmTarget* t, const std::string& lang):
  269. Target(t), Language(lang) {}
  270. };
  271. struct LocalObjectInfo: public std::vector<LocalObjectEntry>
  272. {
  273. bool HasSourceExtension;
  274. bool HasPreprocessRule;
  275. bool HasAssembleRule;
  276. LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
  277. HasAssembleRule(false) {}
  278. };
  279. void GetLocalObjectFiles(
  280. std::map<std::string, LocalObjectInfo> &localObjectFiles);
  281. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  282. const char* comment, const char* output,
  283. LocalObjectInfo const& info);
  284. std::vector<std::string> LocalHelp;
  285. /* does the work for each target */
  286. std::map<std::string, std::string> MakeVariableMap;
  287. std::map<std::string, std::string> ShortMakeVariableMap;
  288. };
  289. #endif