cmLocalUnixMakefileGenerator3.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 cmMakeDepend;
  20. class cmMakefileTargetGenerator;
  21. class cmTarget;
  22. class cmSourceFile;
  23. /** \class cmLocalUnixMakefileGenerator3
  24. * \brief Write a LocalUnix makefiles.
  25. *
  26. * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
  27. * member Makefile.
  28. */
  29. class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator
  30. {
  31. public:
  32. cmLocalUnixMakefileGenerator3();
  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 char* 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. // write the progress variables used by the makefiles
  57. void WriteProgressVariables(unsigned long total, unsigned long &current);
  58. void WriteAllProgressVariable();
  59. /**
  60. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  61. * that do not use environment variables.
  62. *
  63. */
  64. void SetPassMakeflags(bool s){this->PassMakeflags = s;}
  65. bool GetPassMakeflags() { return this->PassMakeflags; }
  66. /**
  67. * Set the flag used to keep the make program silent.
  68. */
  69. void SetMakeSilentFlag(const char* s) { this->MakeSilentFlag = s; }
  70. std::string &GetMakeSilentFlag() { return this->MakeSilentFlag; }
  71. /**
  72. * Set to true if the shell being used is the windows shell.
  73. * This controls if statements in the makefile and the SHELL variable.
  74. * The default is false.
  75. */
  76. void SetWindowsShell(bool v) {this->WindowsShell = v;}
  77. /**
  78. * Set to true if the make tool being used is Watcom WMake.
  79. */
  80. void SetWatcomWMake(bool v) {this->WatcomWMake = v;}
  81. /**
  82. * Set to true if the make tool being used is MinGW Make.
  83. */
  84. void SetMinGWMake(bool v) {this->MinGWMake = 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 Support Verbose Variable. If true, then .SILENT will
  104. * be not end with : i.e. .SILENT: or .SILENT
  105. */
  106. void SetSilentNoColon(bool v) {this->SilentNoColon = v;}
  107. /**
  108. * If set to true, the CMake variable CMAKE_VERBOSE_MAKEFILES doesn't have
  109. * anymore. Set it to true when writing a generator where short output
  110. * doesn't make sense, e.g. because the full output is parsed by an
  111. * IDE/editor.
  112. */
  113. void SetForceVerboseMakefiles(bool enable)
  114. {this->ForceVerboseMakefiles=enable;}
  115. /**
  116. * Set the command to use for native make shell echo. The value
  117. * should include all parts of the command up to the beginning of
  118. * the message (including a whitespace separator).
  119. */
  120. void SetNativeEchoCommand(const char* cmd, bool isWindows)
  121. { this->NativeEchoCommand = cmd; this->NativeEchoWindows = isWindows; }
  122. /**
  123. * Set the string used to include one makefile into another default
  124. * is include.
  125. */
  126. void SetIncludeDirective(const char* s) { this->IncludeDirective = s; }
  127. const char *GetIncludeDirective() { return this->IncludeDirective.c_str(); }
  128. /**
  129. * Set max makefile variable size, default is 0 which means unlimited.
  130. */
  131. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  132. /**
  133. * If ignore lib prefix is true, then do not strip lib from the name
  134. * of a library.
  135. */
  136. void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
  137. /**
  138. * Set whether passing a make target on a command line requires an
  139. * extra level of escapes.
  140. */
  141. void SetMakeCommandEscapeTargetTwice(bool b)
  142. { this->MakeCommandEscapeTargetTwice = b; }
  143. /**
  144. * Set whether the Borland curly brace command line hack should be
  145. * applied.
  146. */
  147. void SetBorlandMakeCurlyHack(bool b)
  148. { this->BorlandMakeCurlyHack = b; }
  149. // used in writing out Cmake files such as WriteDirectoryInformation
  150. static void WriteCMakeArgument(std::ostream& os, const char* s);
  151. /** creates the common disclainer text at the top of each makefile */
  152. void WriteDisclaimer(std::ostream& os);
  153. // write a comment line #====... in the stream
  154. void WriteDivider(std::ostream& os);
  155. /** used to create a recursive make call */
  156. std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
  157. // append flags to a string
  158. virtual void AppendFlags(std::string& flags, const char* newFlags);
  159. // append an echo command
  160. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  161. EchoGenerate, EchoGlobal };
  162. void AppendEcho(std::vector<std::string>& commands, const char* text,
  163. EchoColor color = EchoNormal);
  164. static std::string GetTargetDirectory(cmTarget& target);
  165. // create a command that cds to the start dir then runs the commands
  166. void CreateCDCommand(std::vector<std::string>& commands,
  167. const char *targetDir, const char *returnDir);
  168. static std::string ConvertToQuotedOutputPath(const char* p);
  169. std::string CreateMakeVariable(const char* sin, const char* s2in);
  170. /** Called from command-line hook to scan dependencies. */
  171. virtual bool ScanDependencies(const char* tgtInfo);
  172. /** Called from command-line hook to check dependencies. */
  173. virtual void CheckDependencies(cmMakefile* mf, bool verbose,
  174. bool clear);
  175. /** write some extra rules such as make test etc */
  176. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  177. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  178. std::string GetRelativeTargetDirectory(cmTarget& target);
  179. // List the files for which to check dependency integrity. Each
  180. // language has its own list because integrity may be checked
  181. // differently.
  182. struct IntegrityCheckSet: public std::set<cmSourceFile *> {};
  183. struct IntegrityCheckSetMap: public std::map<cmStdString, IntegrityCheckSet>
  184. {};
  185. std::map<cmStdString, IntegrityCheckSetMap> &GetIntegrityCheckSet()
  186. { return this->CheckDependFiles;}
  187. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  188. cmTarget& target);
  189. // write the target rules for the local Makefile into the stream
  190. void WriteLocalAllRules(std::ostream& ruleFileStream);
  191. struct LocalObjectEntry
  192. {
  193. cmTarget* Target;
  194. std::string Language;
  195. LocalObjectEntry(): Target(0), Language() {}
  196. LocalObjectEntry(cmTarget* t, const char* lang):
  197. Target(t), Language(lang) {}
  198. };
  199. class LocalObjectInfo: public std::vector<LocalObjectEntry> {};
  200. std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
  201. { return this->LocalObjectFiles;}
  202. std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
  203. // return info about progress actions
  204. unsigned long GetNumberOfProgressActions();
  205. unsigned long GetNumberOfProgressActionsForTarget(const char *);
  206. /** Get whether to create rules to generate preprocessed and
  207. assembly sources. This could be converted to a variable lookup
  208. later. */
  209. bool GetCreatePreprocessedSourceRules()
  210. {
  211. return !this->SkipPreprocessedSourceRules;
  212. }
  213. bool GetCreateAssemblySourceRules()
  214. {
  215. return !this->SkipAssemblySourceRules;
  216. }
  217. // Get the directories into which the .o files will go for this target
  218. void GetTargetObjectFileDirectories(cmTarget* target,
  219. std::vector<std::string>& dirs);
  220. protected:
  221. void WriteLocalMakefile();
  222. // write the target rules for the local Makefile into the stream
  223. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  224. std::set<cmStdString> &emitted);
  225. // this method Writes the Directory informaiton files
  226. void WriteDirectoryInformationFile();
  227. // write the depend info
  228. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  229. // write the local help rule
  230. void WriteHelpRule(std::ostream& ruleFileStream);
  231. // this converts a file name that is relative to the StartOuputDirectory
  232. // into a full path
  233. std::string ConvertToFullPath(const std::string& localPath);
  234. void WriteConvenienceRule(std::ostream& ruleFileStream,
  235. const char* realTarget,
  236. const char* helpTarget);
  237. void WriteTargetDependRule(std::ostream& ruleFileStream,
  238. cmTarget& target);
  239. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  240. cmTarget& target,
  241. const std::vector<std::string>& files);
  242. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  243. cmTarget& target,
  244. const std::vector<std::string>& objects);
  245. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  246. const char* comment, const char* output,
  247. LocalObjectInfo const& targets);
  248. std::string GetObjectFileName(cmTarget& target,
  249. const cmSourceFile& source,
  250. std::string* nameWithoutTargetDir = 0);
  251. void AppendRuleDepend(std::vector<std::string>& depends,
  252. const char* ruleFileName);
  253. void AppendCustomDepends(std::vector<std::string>& depends,
  254. const std::vector<cmCustomCommand>& ccs);
  255. void AppendCustomDepend(std::vector<std::string>& depends,
  256. const cmCustomCommand& cc);
  257. void AppendCustomCommands(std::vector<std::string>& commands,
  258. const std::vector<cmCustomCommand>& ccs);
  259. void AppendCustomCommand(std::vector<std::string>& commands,
  260. const cmCustomCommand& cc);
  261. void AppendCleanCommand(std::vector<std::string>& commands,
  262. const std::vector<std::string>& files,
  263. cmTarget& target, const char* filename =0);
  264. bool ForceVerboseMakefiles;
  265. std::map<cmStdString, std::vector<int> > ProgressFiles;
  266. private:
  267. friend class cmMakefileTargetGenerator;
  268. friend class cmMakefileExecutableTargetGenerator;
  269. friend class cmMakefileLibraryTargetGenerator;
  270. friend class cmMakefileUtilityTargetGenerator;
  271. friend class cmGlobalUnixMakefileGenerator3;
  272. std::map<cmStdString, IntegrityCheckSetMap> CheckDependFiles;
  273. //==========================================================================
  274. // Configuration settings.
  275. int MakefileVariableSize;
  276. std::string IncludeDirective;
  277. std::string MakeSilentFlag;
  278. std::string ConfigurationName;
  279. std::string NativeEchoCommand;
  280. bool NativeEchoWindows;
  281. bool DefineWindowsNULL;
  282. bool UnixCD;
  283. bool PassMakeflags;
  284. bool SilentNoColon;
  285. bool MakeCommandEscapeTargetTwice;
  286. bool BorlandMakeCurlyHack;
  287. //==========================================================================
  288. std::string HomeRelativeOutputPath;
  289. /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
  290. beginning of generation to avoid many duplicate lookups. */
  291. bool ColorMakefile;
  292. /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
  293. CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
  294. avoid many duplicate lookups. */
  295. bool SkipPreprocessedSourceRules;
  296. bool SkipAssemblySourceRules;
  297. std::map<cmStdString, LocalObjectInfo> LocalObjectFiles;
  298. std::vector<cmStdString> LocalHelp;
  299. /* does the work for each target */
  300. std::vector<cmMakefileTargetGenerator *> TargetGenerators;
  301. std::map<cmStdString, cmStdString> MakeVariableMap;
  302. std::map<cmStdString, cmStdString> ShortMakeVariableMap;
  303. };
  304. #endif