cmLocalUnixMakefileGenerator3.h 11 KB

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