cmLocalUnixMakefileGenerator3.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmLocalUnixMakefileGenerator3_h
  11. #define cmLocalUnixMakefileGenerator3_h
  12. #include "cmLocalCommonGenerator.h"
  13. // for cmDepends::DependencyVector
  14. #include "cmDepends.h"
  15. class cmCustomCommand;
  16. class cmCustomCommandGenerator;
  17. class cmDepends;
  18. class cmMakefileTargetGenerator;
  19. class cmSourceFile;
  20. /** \class cmLocalUnixMakefileGenerator3
  21. * \brief Write a LocalUnix makefiles.
  22. *
  23. * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
  24. * member Makefile.
  25. */
  26. class cmLocalUnixMakefileGenerator3 : public cmLocalCommonGenerator
  27. {
  28. public:
  29. cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg, cmMakefile* mf);
  30. virtual ~cmLocalUnixMakefileGenerator3();
  31. virtual void ComputeHomeRelativeOutputPath();
  32. /**
  33. * Generate the makefile for this directory.
  34. */
  35. virtual void Generate();
  36. // this returns the relative path between the HomeOutputDirectory and this
  37. // local generators StartOutputDirectory
  38. const std::string& GetHomeRelativeOutputPath();
  39. // Write out a make rule
  40. void WriteMakeRule(std::ostream& os, const char* comment,
  41. const std::string& target,
  42. const std::vector<std::string>& depends,
  43. const std::vector<std::string>& commands, bool symbolic,
  44. bool in_help = false);
  45. // write the main variables used by the makefiles
  46. void WriteMakeVariables(std::ostream& makefileStream);
  47. /**
  48. * Set max makefile variable size, default is 0 which means unlimited.
  49. */
  50. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  51. /**
  52. * Set whether passing a make target on a command line requires an
  53. * extra level of escapes.
  54. */
  55. void SetMakeCommandEscapeTargetTwice(bool b)
  56. {
  57. this->MakeCommandEscapeTargetTwice = b;
  58. }
  59. /**
  60. * Set whether the Borland curly brace command line hack should be
  61. * applied.
  62. */
  63. void SetBorlandMakeCurlyHack(bool b) { this->BorlandMakeCurlyHack = b; }
  64. // used in writing out Cmake files such as WriteDirectoryInformation
  65. static void WriteCMakeArgument(std::ostream& os, const char* s);
  66. /** creates the common disclaimer text at the top of each makefile */
  67. void WriteDisclaimer(std::ostream& os);
  68. // write a comment line #====... in the stream
  69. void WriteDivider(std::ostream& os);
  70. /** used to create a recursive make call */
  71. std::string GetRecursiveMakeCall(const char* makefile,
  72. const std::string& tgt);
  73. // append flags to a string
  74. virtual void AppendFlags(std::string& flags, const std::string& newFlags);
  75. virtual void AppendFlags(std::string& flags, const char* newFlags);
  76. // append an echo command
  77. enum EchoColor
  78. {
  79. EchoNormal,
  80. EchoDepend,
  81. EchoBuild,
  82. EchoLink,
  83. EchoGenerate,
  84. EchoGlobal
  85. };
  86. struct EchoProgress
  87. {
  88. std::string Dir;
  89. std::string Arg;
  90. };
  91. void AppendEcho(std::vector<std::string>& commands, std::string const& text,
  92. EchoColor color = EchoNormal, EchoProgress const* = 0);
  93. /** Get whether the makefile is to have color. */
  94. bool GetColorMakefile() const { return this->ColorMakefile; }
  95. virtual std::string GetTargetDirectory(
  96. cmGeneratorTarget const* target) const;
  97. // create a command that cds to the start dir then runs the commands
  98. void CreateCDCommand(std::vector<std::string>& commands,
  99. const char* targetDir,
  100. cmOutputConverter::RelativeRoot returnDir);
  101. static std::string ConvertToQuotedOutputPath(const char* p,
  102. bool useWatcomQuote);
  103. std::string CreateMakeVariable(const std::string& sin,
  104. const std::string& s2in);
  105. /** Called from command-line hook to bring dependencies up to date
  106. for a target. */
  107. virtual bool UpdateDependencies(const char* tgtInfo, bool verbose,
  108. bool color);
  109. /** Called from command-line hook to clear dependencies. */
  110. virtual void ClearDependencies(cmMakefile* mf, bool verbose);
  111. /** write some extra rules such as make test etc */
  112. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  113. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  114. std::string GetRelativeTargetDirectory(cmGeneratorTarget* target);
  115. // File pairs for implicit dependency scanning. The key of the map
  116. // is the depender and the value is the explicit dependee.
  117. struct ImplicitDependFileMap
  118. : public std::map<std::string, cmDepends::DependencyVector>
  119. {
  120. };
  121. struct ImplicitDependLanguageMap
  122. : public std::map<std::string, ImplicitDependFileMap>
  123. {
  124. };
  125. struct ImplicitDependTargetMap
  126. : public std::map<std::string, ImplicitDependLanguageMap>
  127. {
  128. };
  129. ImplicitDependLanguageMap const& GetImplicitDepends(
  130. cmGeneratorTarget const* tgt);
  131. void AddImplicitDepends(cmGeneratorTarget const* tgt,
  132. const std::string& lang, const char* obj,
  133. const char* src);
  134. // write the target rules for the local Makefile into the stream
  135. void WriteLocalAllRules(std::ostream& ruleFileStream);
  136. std::vector<std::string> const& GetLocalHelp() { return this->LocalHelp; }
  137. /** Get whether to create rules to generate preprocessed and
  138. assembly sources. This could be converted to a variable lookup
  139. later. */
  140. bool GetCreatePreprocessedSourceRules()
  141. {
  142. return !this->SkipPreprocessedSourceRules;
  143. }
  144. bool GetCreateAssemblySourceRules()
  145. {
  146. return !this->SkipAssemblySourceRules;
  147. }
  148. // Fill the vector with the target names for the object files,
  149. // preprocessed files and assembly files. Currently only used by the
  150. // Eclipse generator.
  151. void GetIndividualFileTargets(std::vector<std::string>& targets);
  152. protected:
  153. void WriteLocalMakefile();
  154. // write the target rules for the local Makefile into the stream
  155. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  156. std::set<std::string>& emitted);
  157. // this method Writes the Directory information files
  158. void WriteDirectoryInformationFile();
  159. // write the depend info
  160. void WriteDependLanguageInfo(std::ostream& cmakefileStream,
  161. cmGeneratorTarget* tgt);
  162. // write the local help rule
  163. void WriteHelpRule(std::ostream& ruleFileStream);
  164. // this converts a file name that is relative to the StartOuputDirectory
  165. // into a full path
  166. std::string ConvertToFullPath(const std::string& localPath);
  167. void WriteConvenienceRule(std::ostream& ruleFileStream,
  168. const std::string& realTarget,
  169. const std::string& helpTarget);
  170. void WriteTargetDependRule(std::ostream& ruleFileStream,
  171. cmGeneratorTarget* target);
  172. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  173. cmGeneratorTarget* target,
  174. const std::vector<std::string>& files);
  175. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  176. cmGeneratorTarget* target,
  177. const std::vector<std::string>& objects);
  178. void AppendRuleDepend(std::vector<std::string>& depends,
  179. const char* ruleFileName);
  180. void AppendRuleDepends(std::vector<std::string>& depends,
  181. std::vector<std::string> const& ruleFiles);
  182. void AppendCustomDepends(std::vector<std::string>& depends,
  183. const std::vector<cmCustomCommand>& ccs);
  184. void AppendCustomDepend(std::vector<std::string>& depends,
  185. cmCustomCommandGenerator const& cc);
  186. void AppendCustomCommands(
  187. std::vector<std::string>& commands,
  188. const std::vector<cmCustomCommand>& ccs, cmGeneratorTarget* target,
  189. cmOutputConverter::RelativeRoot relative = cmOutputConverter::HOME_OUTPUT);
  190. void AppendCustomCommand(
  191. std::vector<std::string>& commands, cmCustomCommandGenerator const& ccg,
  192. cmGeneratorTarget* target, bool echo_comment = false,
  193. cmOutputConverter::RelativeRoot relative = cmOutputConverter::HOME_OUTPUT,
  194. std::ostream* content = 0);
  195. void AppendCleanCommand(std::vector<std::string>& commands,
  196. const std::vector<std::string>& files,
  197. cmGeneratorTarget* target, const char* filename = 0);
  198. // Helper methods for dependeny updates.
  199. bool ScanDependencies(
  200. const char* targetDir,
  201. std::map<std::string, cmDepends::DependencyVector>& validDeps);
  202. void CheckMultipleOutputs(bool verbose);
  203. private:
  204. std::string ConvertShellCommand(std::string const& cmd,
  205. cmOutputConverter::RelativeRoot root);
  206. std::string MakeLauncher(cmCustomCommandGenerator const& ccg,
  207. cmGeneratorTarget* target,
  208. cmOutputConverter::RelativeRoot relative);
  209. virtual void ComputeObjectFilenames(
  210. std::map<cmSourceFile const*, std::string>& mapping,
  211. cmGeneratorTarget const* gt = 0);
  212. friend class cmMakefileTargetGenerator;
  213. friend class cmMakefileExecutableTargetGenerator;
  214. friend class cmMakefileLibraryTargetGenerator;
  215. friend class cmMakefileUtilityTargetGenerator;
  216. friend class cmGlobalUnixMakefileGenerator3;
  217. ImplicitDependTargetMap ImplicitDepends;
  218. std::string HomeRelativeOutputPath;
  219. struct LocalObjectEntry
  220. {
  221. cmGeneratorTarget* Target;
  222. std::string Language;
  223. LocalObjectEntry()
  224. : Target(0)
  225. , Language()
  226. {
  227. }
  228. LocalObjectEntry(cmGeneratorTarget* t, const std::string& lang)
  229. : Target(t)
  230. , Language(lang)
  231. {
  232. }
  233. };
  234. struct LocalObjectInfo : public std::vector<LocalObjectEntry>
  235. {
  236. bool HasSourceExtension;
  237. bool HasPreprocessRule;
  238. bool HasAssembleRule;
  239. LocalObjectInfo()
  240. : HasSourceExtension(false)
  241. , HasPreprocessRule(false)
  242. , HasAssembleRule(false)
  243. {
  244. }
  245. };
  246. void GetLocalObjectFiles(
  247. std::map<std::string, LocalObjectInfo>& localObjectFiles);
  248. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  249. const char* comment, const char* output,
  250. LocalObjectInfo const& info);
  251. std::vector<std::string> LocalHelp;
  252. /* does the work for each target */
  253. std::map<std::string, std::string> MakeVariableMap;
  254. std::map<std::string, std::string> ShortMakeVariableMap;
  255. int MakefileVariableSize;
  256. bool MakeCommandEscapeTargetTwice;
  257. bool BorlandMakeCurlyHack;
  258. bool ColorMakefile;
  259. bool SkipPreprocessedSourceRules;
  260. bool SkipAssemblySourceRules;
  261. };
  262. #endif