cmLocalUnixMakefileGenerator3.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 bring dependencies up to date
  162. for a target. */
  163. virtual bool UpdateDependencies(const char* tgtInfo,
  164. bool verbose, bool color);
  165. /** Called from command-line hook to clear dependencies. */
  166. virtual void ClearDependencies(cmMakefile* mf, bool verbose);
  167. /** write some extra rules such as make test etc */
  168. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  169. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  170. std::string GetRelativeTargetDirectory(cmTarget& target);
  171. // File pairs for implicit dependency scanning. The key of the map
  172. // is the depender and the value is the explicit dependee.
  173. struct ImplicitDependFileMap: public std::map<cmStdString, cmStdString> {};
  174. struct ImplicitDependLanguageMap:
  175. public std::map<cmStdString, ImplicitDependFileMap> {};
  176. struct ImplicitDependTargetMap:
  177. public std::map<cmStdString, ImplicitDependLanguageMap> {};
  178. ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
  179. void AddImplicitDepends(cmTarget const& tgt, const char* lang,
  180. const char* obj, const char* src);
  181. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  182. cmTarget& target);
  183. // write the target rules for the local Makefile into the stream
  184. void WriteLocalAllRules(std::ostream& ruleFileStream);
  185. struct LocalObjectEntry
  186. {
  187. cmTarget* Target;
  188. std::string Language;
  189. LocalObjectEntry(): Target(0), Language() {}
  190. LocalObjectEntry(cmTarget* t, const char* lang):
  191. Target(t), Language(lang) {}
  192. };
  193. class LocalObjectInfo: public std::vector<LocalObjectEntry> {};
  194. std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
  195. { return this->LocalObjectFiles;}
  196. std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
  197. // return info about progress actions
  198. unsigned long GetNumberOfProgressActions();
  199. unsigned long GetNumberOfProgressActionsForTarget(const char *);
  200. /** Get whether to create rules to generate preprocessed and
  201. assembly sources. This could be converted to a variable lookup
  202. later. */
  203. bool GetCreatePreprocessedSourceRules()
  204. {
  205. return !this->SkipPreprocessedSourceRules;
  206. }
  207. bool GetCreateAssemblySourceRules()
  208. {
  209. return !this->SkipAssemblySourceRules;
  210. }
  211. // Get the directories into which the .o files will go for this target
  212. void GetTargetObjectFileDirectories(cmTarget* target,
  213. std::vector<std::string>& dirs);
  214. protected:
  215. void WriteLocalMakefile();
  216. // write the target rules for the local Makefile into the stream
  217. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  218. std::set<cmStdString> &emitted);
  219. // this method Writes the Directory informaiton files
  220. void WriteDirectoryInformationFile();
  221. // write the depend info
  222. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  223. // write the local help rule
  224. void WriteHelpRule(std::ostream& ruleFileStream);
  225. // this converts a file name that is relative to the StartOuputDirectory
  226. // into a full path
  227. std::string ConvertToFullPath(const std::string& localPath);
  228. void WriteConvenienceRule(std::ostream& ruleFileStream,
  229. const char* realTarget,
  230. const char* helpTarget);
  231. void WriteTargetDependRule(std::ostream& ruleFileStream,
  232. cmTarget& target);
  233. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  234. cmTarget& target,
  235. const std::vector<std::string>& files);
  236. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  237. cmTarget& target,
  238. const std::vector<std::string>& objects);
  239. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  240. const char* comment, const char* output,
  241. LocalObjectInfo const& targets);
  242. std::string GetObjectFileName(cmTarget& target,
  243. const cmSourceFile& source,
  244. std::string* nameWithoutTargetDir = 0);
  245. void AppendRuleDepend(std::vector<std::string>& depends,
  246. const char* ruleFileName);
  247. void AppendCustomDepends(std::vector<std::string>& depends,
  248. const std::vector<cmCustomCommand>& ccs);
  249. void AppendCustomDepend(std::vector<std::string>& depends,
  250. const cmCustomCommand& cc);
  251. void AppendCustomCommands(std::vector<std::string>& commands,
  252. const std::vector<cmCustomCommand>& ccs);
  253. void AppendCustomCommand(std::vector<std::string>& commands,
  254. const cmCustomCommand& cc,
  255. bool echo_comment=false);
  256. void AppendCleanCommand(std::vector<std::string>& commands,
  257. const std::vector<std::string>& files,
  258. cmTarget& target, const char* filename =0);
  259. std::map<cmStdString, std::vector<int> > ProgressFiles;
  260. // Helper methods for dependeny updates.
  261. bool ScanDependencies(const char* targetDir);
  262. void CheckMultipleOutputs(bool verbose);
  263. private:
  264. friend class cmMakefileTargetGenerator;
  265. friend class cmMakefileExecutableTargetGenerator;
  266. friend class cmMakefileLibraryTargetGenerator;
  267. friend class cmMakefileUtilityTargetGenerator;
  268. friend class cmGlobalUnixMakefileGenerator3;
  269. ImplicitDependTargetMap ImplicitDepends;
  270. //==========================================================================
  271. // Configuration settings.
  272. int MakefileVariableSize;
  273. std::string IncludeDirective;
  274. std::string MakeSilentFlag;
  275. std::string ConfigurationName;
  276. std::string NativeEchoCommand;
  277. bool NativeEchoWindows;
  278. bool DefineWindowsNULL;
  279. bool UnixCD;
  280. bool PassMakeflags;
  281. bool SilentNoColon;
  282. bool MakeCommandEscapeTargetTwice;
  283. bool BorlandMakeCurlyHack;
  284. //==========================================================================
  285. std::string HomeRelativeOutputPath;
  286. /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
  287. beginning of generation to avoid many duplicate lookups. */
  288. bool ColorMakefile;
  289. /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
  290. CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
  291. avoid many duplicate lookups. */
  292. bool SkipPreprocessedSourceRules;
  293. bool SkipAssemblySourceRules;
  294. std::map<cmStdString, LocalObjectInfo> LocalObjectFiles;
  295. std::vector<cmStdString> LocalHelp;
  296. /* does the work for each target */
  297. std::vector<cmMakefileTargetGenerator *> TargetGenerators;
  298. std::map<cmStdString, cmStdString> MakeVariableMap;
  299. std::map<cmStdString, cmStdString> ShortMakeVariableMap;
  300. };
  301. #endif