cmLocalUnixMakefileGenerator3.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. // write the main variables used by the makefiles
  54. void WriteMakeVariables(std::ostream& makefileStream);
  55. /**
  56. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  57. * that do not use environment variables.
  58. *
  59. */
  60. void SetPassMakeflags(bool s){this->PassMakeflags = s;}
  61. bool GetPassMakeflags() { return this->PassMakeflags; }
  62. /**
  63. * Set the flag used to keep the make program silent.
  64. */
  65. void SetMakeSilentFlag(const char* s) { this->MakeSilentFlag = s; }
  66. std::string &GetMakeSilentFlag() { return this->MakeSilentFlag; }
  67. /** Set whether the echo command needs its argument quoted. */
  68. void SetEchoNeedsQuote(bool b) { this->EchoNeedsQuote = b; }
  69. /**
  70. * Set to true if the shell being used is the windows shell.
  71. * This controls if statements in the makefile and the SHELL variable.
  72. * The default is false.
  73. */
  74. void SetWindowsShell(bool v) {this->WindowsShell = v;}
  75. /**
  76. * If set to true, then NULL is set to nil for non Windows_NT.
  77. * This uses make syntax used by nmake and borland.
  78. * The default is false.
  79. */
  80. void SetDefineWindowsNULL(bool v) {this->DefineWindowsNULL = v;}
  81. /**
  82. * If set to true, cd dir && command is used to
  83. * run commands in a different directory.
  84. */
  85. void SetUnixCD(bool v) {this->UnixCD = v;}
  86. /**
  87. * Set Support Verbose Variable. If true, then .SILENT will
  88. * be not end with : i.e. .SILENT: or .SILENT
  89. */
  90. void SetSilentNoColon(bool v) {this->SilentNoColon = v;}
  91. /**
  92. * Set the string used to include one makefile into another default
  93. * is include.
  94. */
  95. void SetIncludeDirective(const char* s) { this->IncludeDirective = s; }
  96. const char *GetIncludeDirective() { return this->IncludeDirective.c_str(); }
  97. /**
  98. * Set max makefile variable size, default is 0 which means unlimited.
  99. */
  100. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  101. /**
  102. * If ignore lib prefix is true, then do not strip lib from the name
  103. * of a library.
  104. */
  105. void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
  106. // used in writing out Cmake files such as WriteDirectoryInformation
  107. static void WriteCMakeArgument(std::ostream& os, const char* s);
  108. /** creates the common disclainer text at the top of each makefile */
  109. void WriteDisclaimer(std::ostream& os);
  110. // write a comment line #====... in the stream
  111. void WriteDivider(std::ostream& os);
  112. /** used to create a recursive make call */
  113. std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
  114. // append an echo command
  115. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  116. EchoGenerate, EchoGlobal };
  117. void AppendEcho(std::vector<std::string>& commands, const char* text,
  118. EchoColor color = EchoNormal);
  119. static std::string GetTargetDirectory(cmTarget& target);
  120. // create a command that cds to the start dir then runs the commands
  121. void CreateCDCommand(std::vector<std::string>& commands,
  122. const char *targetDir, const char *returnDir);
  123. static std::string ConvertToQuotedOutputPath(const char* p);
  124. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  125. std::string CreateMakeVariable(const char* sin, const char* s2in);
  126. // cleanup the name of a potential target
  127. std::string ConvertToMakeTarget(const char* tgt);
  128. const char* GetSourceFileLanguage(const cmSourceFile& source);
  129. /** Called from command-line hook to scan dependencies. */
  130. virtual bool ScanDependencies(std::vector<std::string> const& args);
  131. /** Called from command-line hook to check dependencies. */
  132. virtual void CheckDependencies(cmMakefile* mf, bool verbose,
  133. bool clear);
  134. /** write some extra rules such as make test etc */
  135. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  136. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  137. std::string GetRelativeTargetDirectory(cmTarget& target);
  138. // List the files for which to check dependency integrity. Each
  139. // language has its own list because integrity may be checked
  140. // differently.
  141. struct IntegrityCheckSet: public std::set<cmSourceFile *> {};
  142. struct IntegrityCheckSetMap: public std::map<cmStdString, IntegrityCheckSet>
  143. {};
  144. std::map<cmStdString, IntegrityCheckSetMap> &GetIntegrityCheckSet()
  145. { return this->CheckDependFiles;}
  146. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  147. cmTarget& target);
  148. // write the target rules for the local Makefile into the stream
  149. void WriteLocalAllRules(std::ostream& ruleFileStream);
  150. std::map<cmStdString,std::vector<cmTarget *> > GetLocalObjectFiles()
  151. { return this->LocalObjectFiles;}
  152. protected:
  153. // these two methods just compute reasonable values for LibraryOutputPath
  154. // and ExecutableOutputPath
  155. void ConfigureOutputPaths();
  156. void FormatOutputPath(std::string& path, const char* name);
  157. void WriteLocalMakefile();
  158. // write the target rules for the local Makefile into the stream
  159. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  160. std::set<cmStdString> &emitted);
  161. // this method Writes the Directory informaiton files
  162. void WriteDirectoryInformationFile();
  163. // write the depend info
  164. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  165. // write the local help rule
  166. void WriteHelpRule(std::ostream& ruleFileStream);
  167. // this converts a file name that is relative to the StartOuputDirectory
  168. // into a full path
  169. std::string ConvertToFullPath(const std::string& localPath);
  170. void WriteConvenienceRule(std::ostream& ruleFileStream,
  171. const char* realTarget,
  172. const char* helpTarget);
  173. void WriteTargetDependRule(std::ostream& ruleFileStream,
  174. cmTarget& target);
  175. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  176. cmTarget& target,
  177. const std::vector<std::string>& files);
  178. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  179. cmTarget& target,
  180. const std::vector<std::string>& objects);
  181. std::string GetObjectFileName(cmTarget& target,
  182. const cmSourceFile& source,
  183. std::string* nameWithoutTargetDir = 0);
  184. void AppendRuleDepend(std::vector<std::string>& depends,
  185. const char* ruleFileName);
  186. void AppendCustomDepends(std::vector<std::string>& depends,
  187. const std::vector<cmCustomCommand>& ccs);
  188. void AppendCustomDepend(std::vector<std::string>& depends,
  189. const cmCustomCommand& cc);
  190. void AppendCustomCommands(std::vector<std::string>& commands,
  191. const std::vector<cmCustomCommand>& ccs);
  192. void AppendCustomCommand(std::vector<std::string>& commands,
  193. const cmCustomCommand& cc);
  194. void AppendCleanCommand(std::vector<std::string>& commands,
  195. const std::vector<std::string>& files,
  196. cmTarget& target, const char* filename =0);
  197. bool ForceVerboseMakefiles;
  198. private:
  199. friend class cmMakefileTargetGenerator;
  200. friend class cmMakefileExecutableTargetGenerator;
  201. friend class cmMakefileLibraryTargetGenerator;
  202. friend class cmMakefileUtilityTargetGenerator;
  203. std::map<cmStdString, IntegrityCheckSetMap> CheckDependFiles;
  204. //==========================================================================
  205. // Configuration settings.
  206. int MakefileVariableSize;
  207. std::string IncludeDirective;
  208. std::string MakeSilentFlag;
  209. std::string ExecutableOutputPath;
  210. std::string LibraryOutputPath;
  211. std::string ConfigurationName;
  212. bool DefineWindowsNULL;
  213. bool UnixCD;
  214. bool PassMakeflags;
  215. bool SilentNoColon;
  216. // Flag for whether echo command needs quotes.
  217. bool EchoNeedsQuote;
  218. //==========================================================================
  219. std::string HomeRelativeOutputPath;
  220. std::map<cmStdString,std::vector<cmTarget *> > LocalObjectFiles;
  221. /* does the work for each target */
  222. std::vector<cmMakefileTargetGenerator *> TargetGenerators;
  223. std::map<cmStdString, cmStdString> MakeVariableMap;
  224. std::map<cmStdString, cmStdString> ShortMakeVariableMap;
  225. std::map<cmStdString, cmStdString> UniqueObjectNamesMap;
  226. };
  227. #endif