cmLocalUnixMakefileGenerator3.h 12 KB

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