cmLocalUnixMakefileGenerator3.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 "cmLocalGenerator.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 cmLocalGenerator
  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. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  120. cmTarget& target);
  121. // write the target rules for the local Makefile into the stream
  122. void WriteLocalAllRules(std::ostream& ruleFileStream);
  123. std::vector<std::string> const& GetLocalHelp() { return this->LocalHelp; }
  124. /** Get whether to create rules to generate preprocessed and
  125. assembly sources. This could be converted to a variable lookup
  126. later. */
  127. bool GetCreatePreprocessedSourceRules()
  128. {
  129. return !this->SkipPreprocessedSourceRules;
  130. }
  131. bool GetCreateAssemblySourceRules()
  132. {
  133. return !this->SkipAssemblySourceRules;
  134. }
  135. // Fill the vector with the target names for the object files,
  136. // preprocessed files and assembly files. Currently only used by the
  137. // Eclipse generator.
  138. void GetIndividualFileTargets(std::vector<std::string>& targets);
  139. protected:
  140. void WriteLocalMakefile();
  141. // write the target rules for the local Makefile into the stream
  142. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  143. std::set<std::string> &emitted);
  144. // this method Writes the Directory information files
  145. void WriteDirectoryInformationFile();
  146. // write the depend info
  147. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  148. // write the local help rule
  149. void WriteHelpRule(std::ostream& ruleFileStream);
  150. // this converts a file name that is relative to the StartOuputDirectory
  151. // into a full path
  152. std::string ConvertToFullPath(const std::string& localPath);
  153. void WriteConvenienceRule(std::ostream& ruleFileStream,
  154. const std::string& realTarget,
  155. const std::string& helpTarget);
  156. void WriteTargetDependRule(std::ostream& ruleFileStream,
  157. cmTarget& target);
  158. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  159. cmTarget& target,
  160. const std::vector<std::string>& files);
  161. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  162. cmTarget& target,
  163. const std::vector<std::string>& objects);
  164. void AppendRuleDepend(std::vector<std::string>& depends,
  165. const char* ruleFileName);
  166. void AppendRuleDepends(std::vector<std::string>& depends,
  167. std::vector<std::string> const& ruleFiles);
  168. void AppendCustomDepends(std::vector<std::string>& depends,
  169. const std::vector<cmCustomCommand>& ccs);
  170. void AppendCustomDepend(std::vector<std::string>& depends,
  171. cmCustomCommandGenerator const& cc);
  172. void AppendCustomCommands(std::vector<std::string>& commands,
  173. const std::vector<cmCustomCommand>& ccs,
  174. cmTarget* target,
  175. cmLocalGenerator::RelativeRoot relative =
  176. cmLocalGenerator::HOME_OUTPUT);
  177. void AppendCustomCommand(std::vector<std::string>& commands,
  178. cmCustomCommandGenerator const& ccg,
  179. cmTarget* target,
  180. bool echo_comment=false,
  181. cmLocalGenerator::RelativeRoot relative =
  182. cmLocalGenerator::HOME_OUTPUT,
  183. std::ostream* content = 0);
  184. void AppendCleanCommand(std::vector<std::string>& commands,
  185. const std::vector<std::string>& files,
  186. cmTarget& target, const char* filename =0);
  187. // Helper methods for dependeny updates.
  188. bool ScanDependencies(const char* targetDir,
  189. std::map<std::string, cmDepends::DependencyVector>& validDeps);
  190. void CheckMultipleOutputs(bool verbose);
  191. private:
  192. std::string ConvertShellCommand(std::string const& cmd, RelativeRoot root);
  193. std::string MakeLauncher(cmCustomCommandGenerator const& ccg,
  194. cmTarget* target, RelativeRoot relative);
  195. virtual void ComputeObjectFilenames(
  196. std::map<cmSourceFile const*, std::string>& mapping,
  197. cmGeneratorTarget const* gt = 0);
  198. friend class cmMakefileTargetGenerator;
  199. friend class cmMakefileExecutableTargetGenerator;
  200. friend class cmMakefileLibraryTargetGenerator;
  201. friend class cmMakefileUtilityTargetGenerator;
  202. friend class cmGlobalUnixMakefileGenerator3;
  203. ImplicitDependTargetMap ImplicitDepends;
  204. std::string ConfigurationName;
  205. std::string HomeRelativeOutputPath;
  206. struct LocalObjectEntry
  207. {
  208. cmTarget* Target;
  209. std::string Language;
  210. LocalObjectEntry(): Target(0), Language() {}
  211. LocalObjectEntry(cmTarget* t, const std::string& lang):
  212. Target(t), Language(lang) {}
  213. };
  214. struct LocalObjectInfo: public std::vector<LocalObjectEntry>
  215. {
  216. bool HasSourceExtension;
  217. bool HasPreprocessRule;
  218. bool HasAssembleRule;
  219. LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
  220. HasAssembleRule(false) {}
  221. };
  222. void GetLocalObjectFiles(
  223. std::map<std::string, LocalObjectInfo> &localObjectFiles);
  224. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  225. const char* comment, const char* output,
  226. LocalObjectInfo const& info);
  227. std::vector<std::string> LocalHelp;
  228. /* does the work for each target */
  229. std::map<std::string, std::string> MakeVariableMap;
  230. std::map<std::string, std::string> ShortMakeVariableMap;
  231. int MakefileVariableSize;
  232. bool MakeCommandEscapeTargetTwice;
  233. bool BorlandMakeCurlyHack;
  234. bool ColorMakefile;
  235. bool SkipPreprocessedSourceRules;
  236. bool SkipAssemblySourceRules;
  237. };
  238. #endif