cmLocalUnixMakefileGenerator3.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. /** Set whether the echo command needs its argument quoted. */
  72. void SetEchoNeedsQuote(bool b) { this->EchoNeedsQuote = b; }
  73. /**
  74. * Set to true if the shell being used is the windows shell.
  75. * This controls if statements in the makefile and the SHELL variable.
  76. * The default is false.
  77. */
  78. void SetWindowsShell(bool v) {this->WindowsShell = v;}
  79. /**
  80. * Set to true if the shell being used is the MSYS shell.
  81. * This controls if statements in the makefile and the SHELL variable.
  82. * The default is false.
  83. */
  84. void SetMSYSShell(bool v) {this->MSYSShell = v;}
  85. /**
  86. * If set to true, then NULL is set to nil for non Windows_NT.
  87. * This uses make syntax used by nmake and borland.
  88. * The default is false.
  89. */
  90. void SetDefineWindowsNULL(bool v) {this->DefineWindowsNULL = v;}
  91. /**
  92. * If set to true, cd dir && command is used to
  93. * run commands in a different directory.
  94. */
  95. void SetUnixCD(bool v) {this->UnixCD = v;}
  96. /**
  97. * Set Support Verbose Variable. If true, then .SILENT will
  98. * be not end with : i.e. .SILENT: or .SILENT
  99. */
  100. void SetSilentNoColon(bool v) {this->SilentNoColon = v;}
  101. /**
  102. * Set the string used to include one makefile into another default
  103. * is include.
  104. */
  105. void SetIncludeDirective(const char* s) { this->IncludeDirective = s; }
  106. const char *GetIncludeDirective() { return this->IncludeDirective.c_str(); }
  107. /**
  108. * Set max makefile variable size, default is 0 which means unlimited.
  109. */
  110. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  111. /**
  112. * If ignore lib prefix is true, then do not strip lib from the name
  113. * of a library.
  114. */
  115. void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
  116. // used in writing out Cmake files such as WriteDirectoryInformation
  117. static void WriteCMakeArgument(std::ostream& os, const char* s);
  118. /** creates the common disclainer text at the top of each makefile */
  119. void WriteDisclaimer(std::ostream& os);
  120. // write a comment line #====... in the stream
  121. void WriteDivider(std::ostream& os);
  122. /** used to create a recursive make call */
  123. std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
  124. // append an echo command
  125. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  126. EchoGenerate, EchoGlobal };
  127. void AppendEcho(std::vector<std::string>& commands, const char* text,
  128. EchoColor color = EchoNormal);
  129. static std::string GetTargetDirectory(cmTarget& target);
  130. // create a command that cds to the start dir then runs the commands
  131. void CreateCDCommand(std::vector<std::string>& commands,
  132. const char *targetDir, const char *returnDir);
  133. static std::string ConvertToQuotedOutputPath(const char* p);
  134. std::string CreateMakeVariable(const char* sin, const char* s2in);
  135. // cleanup the name of a potential target
  136. std::string ConvertToMakeTarget(const char* tgt);
  137. /** Called from command-line hook to scan dependencies. */
  138. virtual bool ScanDependencies(const char* tgtInfo);
  139. /** Called from command-line hook to check dependencies. */
  140. virtual void CheckDependencies(cmMakefile* mf, bool verbose,
  141. bool clear);
  142. /** write some extra rules such as make test etc */
  143. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  144. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  145. std::string GetRelativeTargetDirectory(cmTarget& target);
  146. // List the files for which to check dependency integrity. Each
  147. // language has its own list because integrity may be checked
  148. // differently.
  149. struct IntegrityCheckSet: public std::set<cmSourceFile *> {};
  150. struct IntegrityCheckSetMap: public std::map<cmStdString, IntegrityCheckSet>
  151. {};
  152. std::map<cmStdString, IntegrityCheckSetMap> &GetIntegrityCheckSet()
  153. { return this->CheckDependFiles;}
  154. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  155. cmTarget& target);
  156. // write the target rules for the local Makefile into the stream
  157. void WriteLocalAllRules(std::ostream& ruleFileStream);
  158. struct LocalObjectEntry
  159. {
  160. cmTarget* Target;
  161. std::string Language;
  162. LocalObjectEntry(): Target(0), Language() {}
  163. LocalObjectEntry(cmTarget* t, const char* lang):
  164. Target(t), Language(lang) {}
  165. };
  166. class LocalObjectInfo: public std::vector<LocalObjectEntry> {};
  167. std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
  168. { return this->LocalObjectFiles;}
  169. std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
  170. // return info about progress actions
  171. unsigned long GetNumberOfProgressActions();
  172. unsigned long GetNumberOfProgressActionsForTarget(const char *);
  173. /** Get whether to create rules to generate preprocessed and
  174. assembly sources. This could be converted to a variable lookup
  175. later. */
  176. bool GetCreatePreprocessedSourceRules()
  177. {
  178. return !this->SkipPreprocessedSourceRules;
  179. }
  180. bool GetCreateAssemblySourceRules()
  181. {
  182. return !this->SkipAssemblySourceRules;
  183. }
  184. protected:
  185. // these two methods just compute reasonable values for LibraryOutputPath
  186. // and ExecutableOutputPath
  187. void ConfigureOutputPaths();
  188. void FormatOutputPath(std::string& path, const char* name);
  189. void WriteLocalMakefile();
  190. // write the target rules for the local Makefile into the stream
  191. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  192. std::set<cmStdString> &emitted);
  193. // this method Writes the Directory informaiton files
  194. void WriteDirectoryInformationFile();
  195. // write the depend info
  196. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  197. // write the local help rule
  198. void WriteHelpRule(std::ostream& ruleFileStream);
  199. // this converts a file name that is relative to the StartOuputDirectory
  200. // into a full path
  201. std::string ConvertToFullPath(const std::string& localPath);
  202. void WriteConvenienceRule(std::ostream& ruleFileStream,
  203. const char* realTarget,
  204. const char* helpTarget);
  205. void WriteTargetDependRule(std::ostream& ruleFileStream,
  206. cmTarget& target);
  207. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  208. cmTarget& target,
  209. const std::vector<std::string>& files);
  210. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  211. cmTarget& target,
  212. const std::vector<std::string>& objects);
  213. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  214. const char* comment, const char* output,
  215. LocalObjectInfo const& targets);
  216. std::string GetObjectFileName(cmTarget& target,
  217. const cmSourceFile& source,
  218. std::string* nameWithoutTargetDir = 0);
  219. void AppendRuleDepend(std::vector<std::string>& depends,
  220. const char* ruleFileName);
  221. void AppendCustomDepends(std::vector<std::string>& depends,
  222. const std::vector<cmCustomCommand>& ccs);
  223. void AppendCustomDepend(std::vector<std::string>& depends,
  224. const cmCustomCommand& cc);
  225. void AppendCustomCommands(std::vector<std::string>& commands,
  226. const std::vector<cmCustomCommand>& ccs);
  227. void AppendCustomCommand(std::vector<std::string>& commands,
  228. const cmCustomCommand& cc);
  229. void AppendCleanCommand(std::vector<std::string>& commands,
  230. const std::vector<std::string>& files,
  231. cmTarget& target, const char* filename =0);
  232. bool ForceVerboseMakefiles;
  233. std::map<cmStdString, std::vector<int> > ProgressFiles;
  234. private:
  235. friend class cmMakefileTargetGenerator;
  236. friend class cmMakefileExecutableTargetGenerator;
  237. friend class cmMakefileLibraryTargetGenerator;
  238. friend class cmMakefileUtilityTargetGenerator;
  239. friend class cmGlobalUnixMakefileGenerator3;
  240. std::map<cmStdString, IntegrityCheckSetMap> CheckDependFiles;
  241. //==========================================================================
  242. // Configuration settings.
  243. int MakefileVariableSize;
  244. std::string IncludeDirective;
  245. std::string MakeSilentFlag;
  246. std::string ExecutableOutputPath;
  247. std::string LibraryOutputPath;
  248. std::string ConfigurationName;
  249. bool DefineWindowsNULL;
  250. bool UnixCD;
  251. bool PassMakeflags;
  252. bool SilentNoColon;
  253. // Flag for whether echo command needs quotes.
  254. bool EchoNeedsQuote;
  255. //==========================================================================
  256. std::string HomeRelativeOutputPath;
  257. /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
  258. beginning of generation to avoid many duplicate lookups. */
  259. bool ColorMakefile;
  260. /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
  261. CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
  262. avoid many duplicate lookups. */
  263. bool SkipPreprocessedSourceRules;
  264. bool SkipAssemblySourceRules;
  265. std::map<cmStdString, LocalObjectInfo> LocalObjectFiles;
  266. std::vector<cmStdString> LocalHelp;
  267. /* does the work for each target */
  268. std::vector<cmMakefileTargetGenerator *> TargetGenerators;
  269. std::map<cmStdString, cmStdString> MakeVariableMap;
  270. std::map<cmStdString, cmStdString> ShortMakeVariableMap;
  271. };
  272. #endif