cmLocalUnixMakefileGenerator3.h 14 KB

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