cmLocalUnixMakefileGenerator3.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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 char* newFlags);
  141. // append an echo command
  142. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  143. EchoGenerate, EchoGlobal };
  144. void AppendEcho(std::vector<std::string>& commands, const char* text,
  145. EchoColor color = EchoNormal);
  146. /** Get whether the makefile is to have color. */
  147. bool GetColorMakefile() const { return this->ColorMakefile; }
  148. virtual std::string GetTargetDirectory(cmTarget const& target) const;
  149. // create a command that cds to the start dir then runs the commands
  150. void CreateCDCommand(std::vector<std::string>& commands,
  151. const char *targetDir,
  152. cmLocalGenerator::RelativeRoot returnDir);
  153. static std::string ConvertToQuotedOutputPath(const char* p);
  154. std::string CreateMakeVariable(const std::string& sin,
  155. const std::string& s2in);
  156. /** Called from command-line hook to bring dependencies up to date
  157. for a target. */
  158. virtual bool UpdateDependencies(const char* tgtInfo,
  159. bool verbose, bool color);
  160. /** Called from command-line hook to clear dependencies. */
  161. virtual void ClearDependencies(cmMakefile* mf, bool verbose);
  162. /** write some extra rules such as make test etc */
  163. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  164. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  165. std::string GetRelativeTargetDirectory(cmTarget const& target);
  166. // File pairs for implicit dependency scanning. The key of the map
  167. // is the depender and the value is the explicit dependee.
  168. struct ImplicitDependFileMap:
  169. public std::map<std::string, cmDepends::DependencyVector> {};
  170. struct ImplicitDependLanguageMap:
  171. public std::map<std::string, ImplicitDependFileMap> {};
  172. struct ImplicitDependTargetMap:
  173. public std::map<std::string, ImplicitDependLanguageMap> {};
  174. ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
  175. void AddImplicitDepends(cmTarget const& tgt, const std::string& lang,
  176. const char* obj, const char* src);
  177. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  178. cmTarget& target);
  179. // write the target rules for the local Makefile into the stream
  180. void WriteLocalAllRules(std::ostream& ruleFileStream);
  181. std::vector<std::string> const& GetLocalHelp() { return this->LocalHelp; }
  182. /** Get whether to create rules to generate preprocessed and
  183. assembly sources. This could be converted to a variable lookup
  184. later. */
  185. bool GetCreatePreprocessedSourceRules()
  186. {
  187. return !this->SkipPreprocessedSourceRules;
  188. }
  189. bool GetCreateAssemblySourceRules()
  190. {
  191. return !this->SkipAssemblySourceRules;
  192. }
  193. // Fill the vector with the target names for the object files,
  194. // preprocessed files and assembly files. Currently only used by the
  195. // Eclipse generator.
  196. void GetIndividualFileTargets(std::vector<std::string>& targets);
  197. protected:
  198. void WriteLocalMakefile();
  199. // write the target rules for the local Makefile into the stream
  200. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  201. std::set<std::string> &emitted);
  202. // this method Writes the Directory information files
  203. void WriteDirectoryInformationFile();
  204. // write the depend info
  205. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  206. // write the local help rule
  207. void WriteHelpRule(std::ostream& ruleFileStream);
  208. // this converts a file name that is relative to the StartOuputDirectory
  209. // into a full path
  210. std::string ConvertToFullPath(const std::string& localPath);
  211. void WriteConvenienceRule(std::ostream& ruleFileStream,
  212. const std::string& realTarget,
  213. const std::string& helpTarget);
  214. void WriteTargetDependRule(std::ostream& ruleFileStream,
  215. cmTarget& target);
  216. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  217. cmTarget& target,
  218. const std::vector<std::string>& files);
  219. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  220. cmTarget& target,
  221. const std::vector<std::string>& objects);
  222. void AppendRuleDepend(std::vector<std::string>& depends,
  223. const char* ruleFileName);
  224. void AppendRuleDepends(std::vector<std::string>& depends,
  225. std::vector<std::string> const& ruleFiles);
  226. void AppendCustomDepends(std::vector<std::string>& depends,
  227. const std::vector<cmCustomCommand>& ccs);
  228. void AppendCustomDepend(std::vector<std::string>& depends,
  229. cmCustomCommandGenerator const& cc);
  230. void AppendCustomCommands(std::vector<std::string>& commands,
  231. const std::vector<cmCustomCommand>& ccs,
  232. cmTarget* target,
  233. cmLocalGenerator::RelativeRoot relative =
  234. cmLocalGenerator::HOME_OUTPUT);
  235. void AppendCustomCommand(std::vector<std::string>& commands,
  236. cmCustomCommandGenerator const& ccg,
  237. cmTarget* target,
  238. bool echo_comment=false,
  239. cmLocalGenerator::RelativeRoot relative =
  240. cmLocalGenerator::HOME_OUTPUT,
  241. std::ostream* content = 0);
  242. void AppendCleanCommand(std::vector<std::string>& commands,
  243. const std::vector<std::string>& files,
  244. cmTarget& target, const char* filename =0);
  245. // Helper methods for dependeny updates.
  246. bool ScanDependencies(const char* targetDir,
  247. std::map<std::string, cmDepends::DependencyVector>& validDeps);
  248. void CheckMultipleOutputs(bool verbose);
  249. private:
  250. std::string ConvertShellCommand(std::string const& cmd, RelativeRoot root);
  251. std::string MakeLauncher(cmCustomCommandGenerator const& ccg,
  252. cmTarget* target, RelativeRoot relative);
  253. virtual void ComputeObjectFilenames(
  254. std::map<cmSourceFile const*, std::string>& mapping,
  255. cmGeneratorTarget const* gt = 0);
  256. friend class cmMakefileTargetGenerator;
  257. friend class cmMakefileExecutableTargetGenerator;
  258. friend class cmMakefileLibraryTargetGenerator;
  259. friend class cmMakefileUtilityTargetGenerator;
  260. friend class cmGlobalUnixMakefileGenerator3;
  261. ImplicitDependTargetMap ImplicitDepends;
  262. //==========================================================================
  263. // Configuration settings.
  264. int MakefileVariableSize;
  265. std::string IncludeDirective;
  266. std::string MakeSilentFlag;
  267. std::string ConfigurationName;
  268. bool DefineWindowsNULL;
  269. bool UnixCD;
  270. bool PassMakeflags;
  271. bool MakeCommandEscapeTargetTwice;
  272. bool BorlandMakeCurlyHack;
  273. //==========================================================================
  274. std::string HomeRelativeOutputPath;
  275. /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
  276. beginning of generation to avoid many duplicate lookups. */
  277. bool ColorMakefile;
  278. /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
  279. CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
  280. avoid many duplicate lookups. */
  281. bool SkipPreprocessedSourceRules;
  282. bool SkipAssemblySourceRules;
  283. struct LocalObjectEntry
  284. {
  285. cmTarget* Target;
  286. std::string Language;
  287. LocalObjectEntry(): Target(0), Language() {}
  288. LocalObjectEntry(cmTarget* t, const std::string& lang):
  289. Target(t), Language(lang) {}
  290. };
  291. struct LocalObjectInfo: public std::vector<LocalObjectEntry>
  292. {
  293. bool HasSourceExtension;
  294. bool HasPreprocessRule;
  295. bool HasAssembleRule;
  296. LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
  297. HasAssembleRule(false) {}
  298. };
  299. void GetLocalObjectFiles(
  300. std::map<std::string, LocalObjectInfo> &localObjectFiles);
  301. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  302. const char* comment, const char* output,
  303. LocalObjectInfo const& info);
  304. std::vector<std::string> LocalHelp;
  305. /* does the work for each target */
  306. std::map<std::string, std::string> MakeVariableMap;
  307. std::map<std::string, std::string> ShortMakeVariableMap;
  308. };
  309. #endif