cmLocalUnixMakefileGenerator3.h 11 KB

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