cmLocalUnixMakefileGenerator3.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmLocalUnixMakefileGenerator3_h
  14. #define cmLocalUnixMakefileGenerator3_h
  15. #include "cmLocalGenerator.h"
  16. class cmCustomCommand;
  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();
  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 char* 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. // write the progress variables used by the makefiles
  56. void WriteProgressVariables(unsigned long total, unsigned long &current);
  57. void WriteAllProgressVariable();
  58. /**
  59. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  60. * that do not use environment variables.
  61. *
  62. */
  63. void SetPassMakeflags(bool s){this->PassMakeflags = s;}
  64. bool GetPassMakeflags() { return this->PassMakeflags; }
  65. /**
  66. * Set the flag used to keep the make program silent.
  67. */
  68. void SetMakeSilentFlag(const char* s) { this->MakeSilentFlag = s; }
  69. std::string &GetMakeSilentFlag() { return this->MakeSilentFlag; }
  70. /**
  71. * Set to true if the shell being used is the windows shell.
  72. * This controls if statements in the makefile and the SHELL variable.
  73. * The default is false.
  74. */
  75. void SetWindowsShell(bool v) {this->WindowsShell = v;}
  76. /**
  77. * Set to true if the make tool being used is Watcom WMake.
  78. */
  79. void SetWatcomWMake(bool v) {this->WatcomWMake = v;}
  80. /**
  81. * Set to true if the make tool being used is MinGW Make.
  82. */
  83. void SetMinGWMake(bool v) {this->MinGWMake = v;}
  84. /**
  85. * Set to true if the shell being used is the MSYS shell.
  86. * This controls if statements in the makefile and the SHELL variable.
  87. * The default is false.
  88. */
  89. void SetMSYSShell(bool v) {this->MSYSShell = v;}
  90. /**
  91. * If set to true, then NULL is set to nil for non Windows_NT.
  92. * This uses make syntax used by nmake and borland.
  93. * The default is false.
  94. */
  95. void SetDefineWindowsNULL(bool v) {this->DefineWindowsNULL = v;}
  96. /**
  97. * If set to true, cd dir && command is used to
  98. * run commands in a different directory.
  99. */
  100. void SetUnixCD(bool v) {this->UnixCD = v;}
  101. /**
  102. * Set Support Verbose Variable. If true, then .SILENT will
  103. * be not end with : i.e. .SILENT: or .SILENT
  104. */
  105. void SetSilentNoColon(bool v) {this->SilentNoColon = v;}
  106. /**
  107. * Set the command to use for native make shell echo. The value
  108. * should include all parts of the command up to the beginning of
  109. * the message (including a whitespace separator).
  110. */
  111. void SetNativeEchoCommand(const char* cmd, bool isWindows)
  112. { this->NativeEchoCommand = cmd; this->NativeEchoWindows = isWindows; }
  113. /**
  114. * Set the string used to include one makefile into another default
  115. * is include.
  116. */
  117. void SetIncludeDirective(const char* s) { this->IncludeDirective = s; }
  118. const char *GetIncludeDirective() { return this->IncludeDirective.c_str(); }
  119. /**
  120. * Set max makefile variable size, default is 0 which means unlimited.
  121. */
  122. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  123. /**
  124. * If ignore lib prefix is true, then do not strip lib from the name
  125. * of a library.
  126. */
  127. void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
  128. /**
  129. * Set whether passing a make target on a command line requires an
  130. * extra level of escapes.
  131. */
  132. void SetMakeCommandEscapeTargetTwice(bool b)
  133. { this->MakeCommandEscapeTargetTwice = b; }
  134. /**
  135. * Set whether the Borland curly brace command line hack should be
  136. * applied.
  137. */
  138. void SetBorlandMakeCurlyHack(bool b)
  139. { this->BorlandMakeCurlyHack = b; }
  140. // used in writing out Cmake files such as WriteDirectoryInformation
  141. static void WriteCMakeArgument(std::ostream& os, const char* s);
  142. /** creates the common disclainer text at the top of each makefile */
  143. void WriteDisclaimer(std::ostream& os);
  144. // write a comment line #====... in the stream
  145. void WriteDivider(std::ostream& os);
  146. /** used to create a recursive make call */
  147. std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
  148. // append flags to a string
  149. virtual void AppendFlags(std::string& flags, const char* newFlags);
  150. // append an echo command
  151. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  152. EchoGenerate, EchoGlobal };
  153. void AppendEcho(std::vector<std::string>& commands, const char* text,
  154. EchoColor color = EchoNormal);
  155. virtual std::string GetTargetDirectory(cmTarget const& target) const;
  156. // create a command that cds to the start dir then runs the commands
  157. void CreateCDCommand(std::vector<std::string>& commands,
  158. const char *targetDir, const char *returnDir);
  159. static std::string ConvertToQuotedOutputPath(const char* p);
  160. std::string CreateMakeVariable(const char* sin, const char* s2in);
  161. /** Called from command-line hook to scan dependencies. */
  162. virtual bool ScanDependencies(const char* tgtInfo);
  163. /** Called from command-line hook to check dependencies. */
  164. virtual void CheckDependencies(cmMakefile* mf, bool verbose,
  165. bool clear);
  166. /** write some extra rules such as make test etc */
  167. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  168. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  169. std::string GetRelativeTargetDirectory(cmTarget& target);
  170. // List the files for which to check dependency integrity. Each
  171. // language has its own list because integrity may be checked
  172. // differently.
  173. struct IntegrityCheckSet: public std::set<cmSourceFile *> {};
  174. struct IntegrityCheckSetMap: public std::map<cmStdString, IntegrityCheckSet>
  175. {};
  176. std::map<cmStdString, IntegrityCheckSetMap> &GetIntegrityCheckSet()
  177. { return this->CheckDependFiles;}
  178. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  179. cmTarget& target);
  180. // write the target rules for the local Makefile into the stream
  181. void WriteLocalAllRules(std::ostream& ruleFileStream);
  182. struct LocalObjectEntry
  183. {
  184. cmTarget* Target;
  185. std::string Language;
  186. LocalObjectEntry(): Target(0), Language() {}
  187. LocalObjectEntry(cmTarget* t, const char* lang):
  188. Target(t), Language(lang) {}
  189. };
  190. class LocalObjectInfo: public std::vector<LocalObjectEntry> {};
  191. std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
  192. { return this->LocalObjectFiles;}
  193. std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
  194. // return info about progress actions
  195. unsigned long GetNumberOfProgressActions();
  196. unsigned long GetNumberOfProgressActionsForTarget(const char *);
  197. /** Get whether to create rules to generate preprocessed and
  198. assembly sources. This could be converted to a variable lookup
  199. later. */
  200. bool GetCreatePreprocessedSourceRules()
  201. {
  202. return !this->SkipPreprocessedSourceRules;
  203. }
  204. bool GetCreateAssemblySourceRules()
  205. {
  206. return !this->SkipAssemblySourceRules;
  207. }
  208. // Get the directories into which the .o files will go for this target
  209. void GetTargetObjectFileDirectories(cmTarget* target,
  210. std::vector<std::string>& dirs);
  211. protected:
  212. void WriteLocalMakefile();
  213. // write the target rules for the local Makefile into the stream
  214. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  215. std::set<cmStdString> &emitted);
  216. // this method Writes the Directory informaiton files
  217. void WriteDirectoryInformationFile();
  218. // write the depend info
  219. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  220. // write the local help rule
  221. void WriteHelpRule(std::ostream& ruleFileStream);
  222. // this converts a file name that is relative to the StartOuputDirectory
  223. // into a full path
  224. std::string ConvertToFullPath(const std::string& localPath);
  225. void WriteConvenienceRule(std::ostream& ruleFileStream,
  226. const char* realTarget,
  227. const char* helpTarget);
  228. void WriteTargetDependRule(std::ostream& ruleFileStream,
  229. cmTarget& target);
  230. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  231. cmTarget& target,
  232. const std::vector<std::string>& files);
  233. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  234. cmTarget& target,
  235. const std::vector<std::string>& objects);
  236. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  237. const char* comment, const char* output,
  238. LocalObjectInfo const& targets);
  239. std::string GetObjectFileName(cmTarget& target,
  240. const cmSourceFile& source,
  241. std::string* nameWithoutTargetDir = 0);
  242. void AppendRuleDepend(std::vector<std::string>& depends,
  243. const char* ruleFileName);
  244. void AppendCustomDepends(std::vector<std::string>& depends,
  245. const std::vector<cmCustomCommand>& ccs);
  246. void AppendCustomDepend(std::vector<std::string>& depends,
  247. const cmCustomCommand& cc);
  248. void AppendCustomCommands(std::vector<std::string>& commands,
  249. const std::vector<cmCustomCommand>& ccs);
  250. void AppendCustomCommand(std::vector<std::string>& commands,
  251. const cmCustomCommand& cc);
  252. void AppendCleanCommand(std::vector<std::string>& commands,
  253. const std::vector<std::string>& files,
  254. cmTarget& target, const char* filename =0);
  255. std::map<cmStdString, std::vector<int> > ProgressFiles;
  256. private:
  257. friend class cmMakefileTargetGenerator;
  258. friend class cmMakefileExecutableTargetGenerator;
  259. friend class cmMakefileLibraryTargetGenerator;
  260. friend class cmMakefileUtilityTargetGenerator;
  261. friend class cmGlobalUnixMakefileGenerator3;
  262. std::map<cmStdString, IntegrityCheckSetMap> CheckDependFiles;
  263. //==========================================================================
  264. // Configuration settings.
  265. int MakefileVariableSize;
  266. std::string IncludeDirective;
  267. std::string MakeSilentFlag;
  268. std::string ConfigurationName;
  269. std::string NativeEchoCommand;
  270. bool NativeEchoWindows;
  271. bool DefineWindowsNULL;
  272. bool UnixCD;
  273. bool PassMakeflags;
  274. bool SilentNoColon;
  275. bool MakeCommandEscapeTargetTwice;
  276. bool BorlandMakeCurlyHack;
  277. //==========================================================================
  278. std::string HomeRelativeOutputPath;
  279. /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
  280. beginning of generation to avoid many duplicate lookups. */
  281. bool ColorMakefile;
  282. /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
  283. CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
  284. avoid many duplicate lookups. */
  285. bool SkipPreprocessedSourceRules;
  286. bool SkipAssemblySourceRules;
  287. std::map<cmStdString, LocalObjectInfo> LocalObjectFiles;
  288. std::vector<cmStdString> LocalHelp;
  289. /* does the work for each target */
  290. std::vector<cmMakefileTargetGenerator *> TargetGenerators;
  291. std::map<cmStdString, cmStdString> MakeVariableMap;
  292. std::map<cmStdString, cmStdString> ShortMakeVariableMap;
  293. };
  294. #endif