cmLocalUnixMakefileGenerator3.h 12 KB

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