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 cmDepends;
  18. class cmMakefileTargetGenerator;
  19. class cmTarget;
  20. class cmSourceFile;
  21. /** \class cmLocalUnixMakefileGenerator3
  22. * \brief Write a LocalUnix makefiles.
  23. *
  24. * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
  25. * member Makefile.
  26. */
  27. class cmLocalUnixMakefileGenerator3 : public cmLocalCommonGenerator
  28. {
  29. public:
  30. cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg, cmMakefile* mf);
  31. virtual ~cmLocalUnixMakefileGenerator3();
  32. virtual void ComputeHomeRelativeOutputPath();
  33. /**
  34. * Generate the makefile for this directory.
  35. */
  36. virtual void Generate();
  37. // this returns the relative path between the HomeOutputDirectory and this
  38. // local generators StartOutputDirectory
  39. const std::string &GetHomeRelativeOutputPath();
  40. // Write out a make rule
  41. void WriteMakeRule(std::ostream& os,
  42. const char* comment,
  43. const std::string& target,
  44. const std::vector<std::string>& depends,
  45. const std::vector<std::string>& commands,
  46. bool symbolic,
  47. bool in_help = false);
  48. // write the main variables used by the makefiles
  49. void WriteMakeVariables(std::ostream& makefileStream);
  50. /**
  51. * Set max makefile variable size, default is 0 which means unlimited.
  52. */
  53. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  54. /**
  55. * Set whether passing a make target on a command line requires an
  56. * extra level of escapes.
  57. */
  58. void SetMakeCommandEscapeTargetTwice(bool b)
  59. { this->MakeCommandEscapeTargetTwice = b; }
  60. /**
  61. * Set whether the Borland curly brace command line hack should be
  62. * applied.
  63. */
  64. void SetBorlandMakeCurlyHack(bool b)
  65. { this->BorlandMakeCurlyHack = b; }
  66. // used in writing out Cmake files such as WriteDirectoryInformation
  67. static void WriteCMakeArgument(std::ostream& os, const char* s);
  68. /** creates the common disclaimer text at the top of each makefile */
  69. void WriteDisclaimer(std::ostream& os);
  70. // write a comment line #====... in the stream
  71. void WriteDivider(std::ostream& os);
  72. /** used to create a recursive make call */
  73. std::string GetRecursiveMakeCall(const char *makefile,
  74. const std::string& tgt);
  75. // append flags to a string
  76. virtual void AppendFlags(std::string& flags, const std::string& newFlags);
  77. virtual void AppendFlags(std::string& flags, const char* newFlags);
  78. // append an echo command
  79. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  80. EchoGenerate, EchoGlobal };
  81. struct EchoProgress { std::string Dir; std::string Arg; };
  82. void AppendEcho(std::vector<std::string>& commands, std::string const& text,
  83. EchoColor color = EchoNormal, EchoProgress const* = 0);
  84. /** Get whether the makefile is to have color. */
  85. bool GetColorMakefile() const { return this->ColorMakefile; }
  86. virtual
  87. std::string GetTargetDirectory(cmGeneratorTarget 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,
  144. cmGeneratorTarget *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. cmGeneratorTarget* target,
  172. cmLocalGenerator::RelativeRoot relative =
  173. cmLocalGenerator::HOME_OUTPUT);
  174. void AppendCustomCommand(std::vector<std::string>& commands,
  175. cmCustomCommandGenerator const& ccg,
  176. cmGeneratorTarget* 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. cmGeneratorTarget* 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. cmGeneratorTarget* 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. cmGeneratorTarget* Target;
  205. std::string Language;
  206. LocalObjectEntry(): Target(0), Language() {}
  207. LocalObjectEntry(cmGeneratorTarget* 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