cmLocalUnixMakefileGenerator3.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. ~cmLocalUnixMakefileGenerator3() CM_OVERRIDE;
  31. void ComputeHomeRelativeOutputPath() CM_OVERRIDE;
  32. /**
  33. * Generate the makefile for this directory.
  34. */
  35. void Generate() CM_OVERRIDE;
  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. void AppendFlags(std::string& flags,
  75. const std::string& newFlags) CM_OVERRIDE;
  76. void AppendFlags(std::string& flags, const char* newFlags) CM_OVERRIDE;
  77. // append an echo command
  78. enum EchoColor
  79. {
  80. EchoNormal,
  81. EchoDepend,
  82. EchoBuild,
  83. EchoLink,
  84. EchoGenerate,
  85. EchoGlobal
  86. };
  87. struct EchoProgress
  88. {
  89. std::string Dir;
  90. std::string Arg;
  91. };
  92. void AppendEcho(std::vector<std::string>& commands, std::string const& text,
  93. EchoColor color = EchoNormal,
  94. EchoProgress const* = CM_NULLPTR);
  95. /** Get whether the makefile is to have color. */
  96. bool GetColorMakefile() const { return this->ColorMakefile; }
  97. std::string GetTargetDirectory(cmGeneratorTarget const* target) const
  98. CM_OVERRIDE;
  99. // create a command that cds to the start dir then runs the commands
  100. void CreateCDCommand(std::vector<std::string>& commands,
  101. const char* targetDir, std::string const& relDir);
  102. static std::string ConvertToQuotedOutputPath(const char* p,
  103. bool useWatcomQuote);
  104. std::string CreateMakeVariable(const std::string& sin,
  105. const std::string& s2in);
  106. /** Called from command-line hook to bring dependencies up to date
  107. for a target. */
  108. bool UpdateDependencies(const char* tgtInfo, bool verbose,
  109. bool color) CM_OVERRIDE;
  110. /** Called from command-line hook to clear dependencies. */
  111. void ClearDependencies(cmMakefile* mf, bool verbose) CM_OVERRIDE;
  112. /** write some extra rules such as make test etc */
  113. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  114. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  115. std::string GetRelativeTargetDirectory(cmGeneratorTarget* target);
  116. // File pairs for implicit dependency scanning. The key of the map
  117. // is the depender and the value is the explicit dependee.
  118. struct ImplicitDependFileMap
  119. : public std::map<std::string, cmDepends::DependencyVector>
  120. {
  121. };
  122. struct ImplicitDependLanguageMap
  123. : public std::map<std::string, ImplicitDependFileMap>
  124. {
  125. };
  126. struct ImplicitDependTargetMap
  127. : public std::map<std::string, ImplicitDependLanguageMap>
  128. {
  129. };
  130. ImplicitDependLanguageMap const& GetImplicitDepends(
  131. cmGeneratorTarget const* tgt);
  132. void AddImplicitDepends(cmGeneratorTarget const* tgt,
  133. const std::string& lang, const char* obj,
  134. const char* src);
  135. // write the target rules for the local Makefile into the stream
  136. void WriteLocalAllRules(std::ostream& ruleFileStream);
  137. std::vector<std::string> const& GetLocalHelp() { return this->LocalHelp; }
  138. /** Get whether to create rules to generate preprocessed and
  139. assembly sources. This could be converted to a variable lookup
  140. later. */
  141. bool GetCreatePreprocessedSourceRules()
  142. {
  143. return !this->SkipPreprocessedSourceRules;
  144. }
  145. bool GetCreateAssemblySourceRules()
  146. {
  147. return !this->SkipAssemblySourceRules;
  148. }
  149. // Fill the vector with the target names for the object files,
  150. // preprocessed files and assembly files. Currently only used by the
  151. // Eclipse generator.
  152. void GetIndividualFileTargets(std::vector<std::string>& targets);
  153. protected:
  154. void WriteLocalMakefile();
  155. // write the target rules for the local Makefile into the stream
  156. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  157. std::set<std::string>& emitted);
  158. // this method Writes the Directory information files
  159. void WriteDirectoryInformationFile();
  160. // write the depend info
  161. void WriteDependLanguageInfo(std::ostream& cmakefileStream,
  162. cmGeneratorTarget* tgt);
  163. // write the local help rule
  164. void WriteHelpRule(std::ostream& ruleFileStream);
  165. // this converts a file name that is relative to the StartOuputDirectory
  166. // into a full path
  167. std::string ConvertToFullPath(const std::string& localPath);
  168. void WriteConvenienceRule(std::ostream& ruleFileStream,
  169. const std::string& realTarget,
  170. const std::string& helpTarget);
  171. void WriteTargetDependRule(std::ostream& ruleFileStream,
  172. cmGeneratorTarget* target);
  173. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  174. cmGeneratorTarget* target,
  175. const std::vector<std::string>& files);
  176. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  177. cmGeneratorTarget* target,
  178. const std::vector<std::string>& objects);
  179. void AppendRuleDepend(std::vector<std::string>& depends,
  180. const char* ruleFileName);
  181. void AppendRuleDepends(std::vector<std::string>& depends,
  182. std::vector<std::string> const& ruleFiles);
  183. void AppendCustomDepends(std::vector<std::string>& depends,
  184. const std::vector<cmCustomCommand>& ccs);
  185. void AppendCustomDepend(std::vector<std::string>& depends,
  186. cmCustomCommandGenerator const& cc);
  187. void AppendCustomCommands(std::vector<std::string>& commands,
  188. const std::vector<cmCustomCommand>& ccs,
  189. cmGeneratorTarget* target,
  190. std::string const& relative);
  191. void AppendCustomCommand(std::vector<std::string>& commands,
  192. cmCustomCommandGenerator const& ccg,
  193. cmGeneratorTarget* target,
  194. std::string const& relative,
  195. bool echo_comment = false,
  196. std::ostream* content = CM_NULLPTR);
  197. void AppendCleanCommand(std::vector<std::string>& commands,
  198. const std::vector<std::string>& files,
  199. cmGeneratorTarget* target,
  200. const char* filename = CM_NULLPTR);
  201. // Helper methods for dependeny updates.
  202. bool ScanDependencies(
  203. const char* targetDir,
  204. std::map<std::string, cmDepends::DependencyVector>& validDeps);
  205. void CheckMultipleOutputs(bool verbose);
  206. private:
  207. std::string MaybeConvertWatcomShellCommand(std::string const& cmd);
  208. void ComputeObjectFilenames(
  209. std::map<cmSourceFile const*, std::string>& mapping,
  210. cmGeneratorTarget const* gt = CM_NULLPTR) CM_OVERRIDE;
  211. friend class cmMakefileTargetGenerator;
  212. friend class cmMakefileExecutableTargetGenerator;
  213. friend class cmMakefileLibraryTargetGenerator;
  214. friend class cmMakefileUtilityTargetGenerator;
  215. friend class cmGlobalUnixMakefileGenerator3;
  216. ImplicitDependTargetMap ImplicitDepends;
  217. std::string HomeRelativeOutputPath;
  218. struct LocalObjectEntry
  219. {
  220. cmGeneratorTarget* Target;
  221. std::string Language;
  222. LocalObjectEntry()
  223. : Target(CM_NULLPTR)
  224. , Language()
  225. {
  226. }
  227. LocalObjectEntry(cmGeneratorTarget* t, const std::string& lang)
  228. : Target(t)
  229. , Language(lang)
  230. {
  231. }
  232. };
  233. struct LocalObjectInfo : public std::vector<LocalObjectEntry>
  234. {
  235. bool HasSourceExtension;
  236. bool HasPreprocessRule;
  237. bool HasAssembleRule;
  238. LocalObjectInfo()
  239. : HasSourceExtension(false)
  240. , HasPreprocessRule(false)
  241. , HasAssembleRule(false)
  242. {
  243. }
  244. };
  245. void GetLocalObjectFiles(
  246. std::map<std::string, LocalObjectInfo>& localObjectFiles);
  247. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  248. const char* comment, const char* output,
  249. LocalObjectInfo const& info);
  250. std::vector<std::string> LocalHelp;
  251. /* does the work for each target */
  252. std::map<std::string, std::string> MakeVariableMap;
  253. std::map<std::string, std::string> ShortMakeVariableMap;
  254. int MakefileVariableSize;
  255. bool MakeCommandEscapeTargetTwice;
  256. bool BorlandMakeCurlyHack;
  257. bool ColorMakefile;
  258. bool SkipPreprocessedSourceRules;
  259. bool SkipAssemblySourceRules;
  260. };
  261. #endif