cmLocalUnixMakefileGenerator3.h 12 KB

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