cmLocalUnixMakefileGenerator3.h 10.0 KB

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