cmLocalUnixMakefileGenerator3.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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 make tool being used is NMake.
  86. */
  87. void SetNMake(bool v) {this->NMake = v;}
  88. /**
  89. * Set to true if the shell being used is the MSYS shell.
  90. * This controls if statements in the makefile and the SHELL variable.
  91. * The default is false.
  92. */
  93. void SetMSYSShell(bool v) {this->MSYSShell = v;}
  94. /**
  95. * If set to true, then NULL is set to nil for non Windows_NT.
  96. * This uses make syntax used by nmake and borland.
  97. * The default is false.
  98. */
  99. void SetDefineWindowsNULL(bool v) {this->DefineWindowsNULL = v;}
  100. /**
  101. * If set to true, cd dir && command is used to
  102. * run commands in a different directory.
  103. */
  104. void SetUnixCD(bool v) {this->UnixCD = v;}
  105. /**
  106. * Set Support Verbose Variable. If true, then .SILENT will
  107. * be not end with : i.e. .SILENT: or .SILENT
  108. */
  109. void SetSilentNoColon(bool v) {this->SilentNoColon = v;}
  110. /**
  111. * Set the command to use for native make shell echo. The value
  112. * should include all parts of the command up to the beginning of
  113. * the message (including a whitespace separator).
  114. */
  115. void SetNativeEchoCommand(const char* cmd, bool isWindows)
  116. { this->NativeEchoCommand = cmd; this->NativeEchoWindows = isWindows; }
  117. /**
  118. * Set the string used to include one makefile into another default
  119. * is include.
  120. */
  121. void SetIncludeDirective(const char* s) { this->IncludeDirective = s; }
  122. const char *GetIncludeDirective() { return this->IncludeDirective.c_str(); }
  123. /**
  124. * Set max makefile variable size, default is 0 which means unlimited.
  125. */
  126. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  127. /**
  128. * If ignore lib prefix is true, then do not strip lib from the name
  129. * of a library.
  130. */
  131. void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
  132. /**
  133. * Set whether passing a make target on a command line requires an
  134. * extra level of escapes.
  135. */
  136. void SetMakeCommandEscapeTargetTwice(bool b)
  137. { this->MakeCommandEscapeTargetTwice = b; }
  138. /**
  139. * Set whether the Borland curly brace command line hack should be
  140. * applied.
  141. */
  142. void SetBorlandMakeCurlyHack(bool b)
  143. { this->BorlandMakeCurlyHack = b; }
  144. // used in writing out Cmake files such as WriteDirectoryInformation
  145. static void WriteCMakeArgument(std::ostream& os, const char* s);
  146. /** creates the common disclainer text at the top of each makefile */
  147. void WriteDisclaimer(std::ostream& os);
  148. // write a comment line #====... in the stream
  149. void WriteDivider(std::ostream& os);
  150. /** used to create a recursive make call */
  151. std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
  152. // append flags to a string
  153. virtual void AppendFlags(std::string& flags, const char* newFlags);
  154. // append an echo command
  155. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  156. EchoGenerate, EchoGlobal };
  157. void AppendEcho(std::vector<std::string>& commands, const char* text,
  158. EchoColor color = EchoNormal);
  159. virtual std::string GetTargetDirectory(cmTarget const& target) const;
  160. // create a command that cds to the start dir then runs the commands
  161. void CreateCDCommand(std::vector<std::string>& commands,
  162. const char *targetDir,
  163. cmLocalGenerator::RelativeRoot returnDir);
  164. static std::string ConvertToQuotedOutputPath(const char* p);
  165. std::string CreateMakeVariable(const char* sin, const char* s2in);
  166. /** Called from command-line hook to bring dependencies up to date
  167. for a target. */
  168. virtual bool UpdateDependencies(const char* tgtInfo,
  169. bool verbose, bool color);
  170. /** Called from command-line hook to clear dependencies. */
  171. virtual void ClearDependencies(cmMakefile* mf, bool verbose);
  172. /** write some extra rules such as make test etc */
  173. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  174. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  175. std::string GetRelativeTargetDirectory(cmTarget const& target);
  176. // File pairs for implicit dependency scanning. The key of the map
  177. // is the depender and the value is the explicit dependee.
  178. struct ImplicitDependFileMap: public std::map<cmStdString, cmStdString> {};
  179. struct ImplicitDependLanguageMap:
  180. public std::map<cmStdString, ImplicitDependFileMap> {};
  181. struct ImplicitDependTargetMap:
  182. public std::map<cmStdString, ImplicitDependLanguageMap> {};
  183. ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
  184. void AddImplicitDepends(cmTarget const& tgt, const char* lang,
  185. const char* obj, const char* src);
  186. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  187. cmTarget& target);
  188. // write the target rules for the local Makefile into the stream
  189. void WriteLocalAllRules(std::ostream& ruleFileStream);
  190. struct LocalObjectEntry
  191. {
  192. cmTarget* Target;
  193. std::string Language;
  194. LocalObjectEntry(): Target(0), Language() {}
  195. LocalObjectEntry(cmTarget* t, const char* lang):
  196. Target(t), Language(lang) {}
  197. };
  198. struct LocalObjectInfo: public std::vector<LocalObjectEntry>
  199. {
  200. bool HasSourceExtension;
  201. };
  202. std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
  203. { return this->LocalObjectFiles;}
  204. std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
  205. // return info about progress actions
  206. unsigned long GetNumberOfProgressActions();
  207. unsigned long GetNumberOfProgressActionsForTarget(const char *);
  208. /** Get whether to create rules to generate preprocessed and
  209. assembly sources. This could be converted to a variable lookup
  210. later. */
  211. bool GetCreatePreprocessedSourceRules()
  212. {
  213. return !this->SkipPreprocessedSourceRules;
  214. }
  215. bool GetCreateAssemblySourceRules()
  216. {
  217. return !this->SkipAssemblySourceRules;
  218. }
  219. // Get the directories into which the .o files will go for this target
  220. void GetTargetObjectFileDirectories(cmTarget* target,
  221. std::vector<std::string>& dirs);
  222. protected:
  223. void WriteLocalMakefile();
  224. // write the target rules for the local Makefile into the stream
  225. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  226. std::set<cmStdString> &emitted);
  227. // this method Writes the Directory informaiton files
  228. void WriteDirectoryInformationFile();
  229. // write the depend info
  230. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  231. // write the local help rule
  232. void WriteHelpRule(std::ostream& ruleFileStream);
  233. // this converts a file name that is relative to the StartOuputDirectory
  234. // into a full path
  235. std::string ConvertToFullPath(const std::string& localPath);
  236. void WriteConvenienceRule(std::ostream& ruleFileStream,
  237. const char* realTarget,
  238. const char* helpTarget);
  239. void WriteTargetDependRule(std::ostream& ruleFileStream,
  240. cmTarget& target);
  241. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  242. cmTarget& target,
  243. const std::vector<std::string>& files);
  244. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  245. cmTarget& target,
  246. const std::vector<std::string>& objects);
  247. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  248. const char* comment, const char* output,
  249. LocalObjectInfo const& info);
  250. std::string GetObjectFileName(cmTarget& target,
  251. const cmSourceFile& source,
  252. std::string* nameWithoutTargetDir = 0,
  253. bool* hasSourceExtension = 0);
  254. void AppendRuleDepend(std::vector<std::string>& depends,
  255. const char* ruleFileName);
  256. void AppendCustomDepends(std::vector<std::string>& depends,
  257. const std::vector<cmCustomCommand>& ccs);
  258. void AppendCustomDepend(std::vector<std::string>& depends,
  259. const cmCustomCommand& cc);
  260. void AppendCustomCommands(std::vector<std::string>& commands,
  261. const std::vector<cmCustomCommand>& ccs,
  262. cmLocalGenerator::RelativeRoot relative =
  263. cmLocalGenerator::HOME_OUTPUT);
  264. void AppendCustomCommand(std::vector<std::string>& commands,
  265. const cmCustomCommand& cc,
  266. bool echo_comment=false,
  267. cmLocalGenerator::RelativeRoot relative =
  268. cmLocalGenerator::HOME_OUTPUT);
  269. void AppendCleanCommand(std::vector<std::string>& commands,
  270. const std::vector<std::string>& files,
  271. cmTarget& target, const char* filename =0);
  272. std::map<cmStdString, std::vector<int> > ProgressFiles;
  273. // Helper methods for dependeny updates.
  274. bool ScanDependencies(const char* targetDir);
  275. void CheckMultipleOutputs(bool verbose);
  276. private:
  277. friend class cmMakefileTargetGenerator;
  278. friend class cmMakefileExecutableTargetGenerator;
  279. friend class cmMakefileLibraryTargetGenerator;
  280. friend class cmMakefileUtilityTargetGenerator;
  281. friend class cmGlobalUnixMakefileGenerator3;
  282. ImplicitDependTargetMap ImplicitDepends;
  283. //==========================================================================
  284. // Configuration settings.
  285. int MakefileVariableSize;
  286. std::string IncludeDirective;
  287. std::string MakeSilentFlag;
  288. std::string ConfigurationName;
  289. std::string NativeEchoCommand;
  290. bool NativeEchoWindows;
  291. bool DefineWindowsNULL;
  292. bool UnixCD;
  293. bool PassMakeflags;
  294. bool SilentNoColon;
  295. bool MakeCommandEscapeTargetTwice;
  296. bool BorlandMakeCurlyHack;
  297. //==========================================================================
  298. std::string HomeRelativeOutputPath;
  299. /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
  300. beginning of generation to avoid many duplicate lookups. */
  301. bool ColorMakefile;
  302. /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
  303. CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
  304. avoid many duplicate lookups. */
  305. bool SkipPreprocessedSourceRules;
  306. bool SkipAssemblySourceRules;
  307. std::map<cmStdString, LocalObjectInfo> LocalObjectFiles;
  308. std::vector<cmStdString> LocalHelp;
  309. /* does the work for each target */
  310. std::vector<cmMakefileTargetGenerator *> TargetGenerators;
  311. std::map<cmStdString, cmStdString> MakeVariableMap;
  312. std::map<cmStdString, cmStdString> ShortMakeVariableMap;
  313. };
  314. #endif