cmLocalUnixMakefileGenerator3.h 11 KB

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