cmLocalUnixMakefileGenerator3.h 11 KB

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