cmLocalUnixMakefileGenerator3.h 12 KB

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