cmLocalUnixMakefileGenerator3.h 12 KB

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