cmLocalUnixMakefileGenerator3.h 14 KB

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