cmLocalUnixMakefileGenerator3.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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 cmDependInformation;
  17. class cmDepends;
  18. class cmMakefileTargetGenerator;
  19. class cmTarget;
  20. class cmSourceFile;
  21. /** \class cmLocalUnixMakefileGenerator3
  22. * \brief Write a LocalUnix makefiles.
  23. *
  24. * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
  25. * member Makefile.
  26. */
  27. class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator
  28. {
  29. public:
  30. cmLocalUnixMakefileGenerator3();
  31. virtual ~cmLocalUnixMakefileGenerator3();
  32. /**
  33. * Process the CMakeLists files for this directory to fill in the
  34. * Makefile ivar
  35. */
  36. virtual void Configure();
  37. /**
  38. * Generate the makefile for this directory.
  39. */
  40. virtual void Generate();
  41. // this returns the relative path between the HomeOutputDirectory and this
  42. // local generators StartOutputDirectory
  43. const std::string &GetHomeRelativeOutputPath();
  44. // Write out a make rule
  45. void WriteMakeRule(std::ostream& os,
  46. const char* comment,
  47. const std::string& target,
  48. const std::vector<std::string>& depends,
  49. const std::vector<std::string>& commands,
  50. bool symbolic,
  51. bool in_help = false);
  52. // write the main variables used by the makefiles
  53. void WriteMakeVariables(std::ostream& makefileStream);
  54. /**
  55. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  56. * that do not use environment variables.
  57. *
  58. */
  59. void SetPassMakeflags(bool s){this->PassMakeflags = s;}
  60. bool GetPassMakeflags() { return this->PassMakeflags; }
  61. /**
  62. * Set the flag used to keep the make program silent.
  63. */
  64. void SetMakeSilentFlag(const std::string& s) { this->MakeSilentFlag = s; }
  65. std::string &GetMakeSilentFlag() { return this->MakeSilentFlag; }
  66. /**
  67. * Set to true if the shell being used is the windows shell.
  68. * This controls if statements in the makefile and the SHELL variable.
  69. * The default is false.
  70. */
  71. void SetWindowsShell(bool v) {this->WindowsShell = v;}
  72. /**
  73. * Set to true if the make tool being used is Watcom WMake.
  74. */
  75. void SetWatcomWMake(bool v) {this->WatcomWMake = v;}
  76. /**
  77. * Set to true if the make tool being used is MinGW Make.
  78. */
  79. void SetMinGWMake(bool v) {this->MinGWMake = v;}
  80. /**
  81. * Set to true if the make tool being used is NMake.
  82. */
  83. void SetNMake(bool v) {this->NMake = v;}
  84. /**
  85. * Set to true if the shell being used is the MSYS shell.
  86. * This controls if statements in the makefile and the SHELL variable.
  87. * The default is false.
  88. */
  89. void SetMSYSShell(bool v) {this->MSYSShell = v;}
  90. /**
  91. * If set to true, then NULL is set to nil for non Windows_NT.
  92. * This uses make syntax used by nmake and borland.
  93. * The default is false.
  94. */
  95. void SetDefineWindowsNULL(bool v) {this->DefineWindowsNULL = v;}
  96. /**
  97. * If set to true, cd dir && command is used to
  98. * run commands in a different directory.
  99. */
  100. void SetUnixCD(bool v) {this->UnixCD = v;}
  101. /**
  102. * Set the string used to include one makefile into another default
  103. * is include.
  104. */
  105. void SetIncludeDirective(const std::string& s)
  106. { this->IncludeDirective = s; }
  107. const std::string& GetIncludeDirective() { return this->IncludeDirective; }
  108. /**
  109. * Set max makefile variable size, default is 0 which means unlimited.
  110. */
  111. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  112. /**
  113. * If ignore lib prefix is true, then do not strip lib from the name
  114. * of a library.
  115. */
  116. void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
  117. /**
  118. * Set whether passing a make target on a command line requires an
  119. * extra level of escapes.
  120. */
  121. void SetMakeCommandEscapeTargetTwice(bool b)
  122. { this->MakeCommandEscapeTargetTwice = b; }
  123. /**
  124. * Set whether the Borland curly brace command line hack should be
  125. * applied.
  126. */
  127. void SetBorlandMakeCurlyHack(bool b)
  128. { this->BorlandMakeCurlyHack = b; }
  129. // used in writing out Cmake files such as WriteDirectoryInformation
  130. static void WriteCMakeArgument(std::ostream& os, const char* s);
  131. /** creates the common disclaimer text at the top of each makefile */
  132. void WriteDisclaimer(std::ostream& os);
  133. // write a comment line #====... in the stream
  134. void WriteDivider(std::ostream& os);
  135. /** used to create a recursive make call */
  136. std::string GetRecursiveMakeCall(const char *makefile,
  137. const std::string& tgt);
  138. // append flags to a string
  139. virtual void AppendFlags(std::string& flags, const char* newFlags);
  140. // append an echo command
  141. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  142. EchoGenerate, EchoGlobal };
  143. void AppendEcho(std::vector<std::string>& commands, const char* text,
  144. EchoColor color = EchoNormal);
  145. /** Get whether the makefile is to have color. */
  146. bool GetColorMakefile() const { return this->ColorMakefile; }
  147. virtual std::string GetTargetDirectory(cmTarget const& target) const;
  148. // create a command that cds to the start dir then runs the commands
  149. void CreateCDCommand(std::vector<std::string>& commands,
  150. const char *targetDir,
  151. cmLocalGenerator::RelativeRoot returnDir);
  152. static std::string ConvertToQuotedOutputPath(const char* p);
  153. std::string CreateMakeVariable(const std::string& sin,
  154. const std::string& s2in);
  155. /** Called from command-line hook to bring dependencies up to date
  156. for a target. */
  157. virtual bool UpdateDependencies(const char* tgtInfo,
  158. bool verbose, bool color);
  159. /** Called from command-line hook to clear dependencies. */
  160. virtual void ClearDependencies(cmMakefile* mf, bool verbose);
  161. /** write some extra rules such as make test etc */
  162. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  163. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  164. std::string GetRelativeTargetDirectory(cmTarget const& target);
  165. // File pairs for implicit dependency scanning. The key of the map
  166. // is the depender and the value is the explicit dependee.
  167. struct ImplicitDependFileMap:
  168. public std::map<std::string, cmDepends::DependencyVector> {};
  169. struct ImplicitDependLanguageMap:
  170. public std::map<std::string, ImplicitDependFileMap> {};
  171. struct ImplicitDependTargetMap:
  172. public std::map<std::string, ImplicitDependLanguageMap> {};
  173. ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
  174. void AddImplicitDepends(cmTarget const& tgt, const std::string& lang,
  175. const char* obj, const char* src);
  176. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  177. cmTarget& target);
  178. // write the target rules for the local Makefile into the stream
  179. void WriteLocalAllRules(std::ostream& ruleFileStream);
  180. void AddLocalObjectFile(cmTarget* target, cmSourceFile* sf,
  181. std::string objNoTargetDir,
  182. bool hasSourceExtension);
  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. const cmCustomCommand& 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. const cmCustomCommand& cc,
  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(const cmCustomCommand& cc, cmTarget* target,
  254. RelativeRoot relative);
  255. friend class cmMakefileTargetGenerator;
  256. friend class cmMakefileExecutableTargetGenerator;
  257. friend class cmMakefileLibraryTargetGenerator;
  258. friend class cmMakefileUtilityTargetGenerator;
  259. friend class cmGlobalUnixMakefileGenerator3;
  260. ImplicitDependTargetMap ImplicitDepends;
  261. //==========================================================================
  262. // Configuration settings.
  263. int MakefileVariableSize;
  264. std::string IncludeDirective;
  265. std::string MakeSilentFlag;
  266. std::string ConfigurationName;
  267. bool DefineWindowsNULL;
  268. bool UnixCD;
  269. bool PassMakeflags;
  270. bool MakeCommandEscapeTargetTwice;
  271. bool BorlandMakeCurlyHack;
  272. //==========================================================================
  273. std::string HomeRelativeOutputPath;
  274. /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
  275. beginning of generation to avoid many duplicate lookups. */
  276. bool ColorMakefile;
  277. /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
  278. CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
  279. avoid many duplicate lookups. */
  280. bool SkipPreprocessedSourceRules;
  281. bool SkipAssemblySourceRules;
  282. struct LocalObjectEntry
  283. {
  284. cmTarget* Target;
  285. std::string Language;
  286. LocalObjectEntry(): Target(0), Language() {}
  287. LocalObjectEntry(cmTarget* t, const std::string& lang):
  288. Target(t), Language(lang) {}
  289. };
  290. struct LocalObjectInfo: public std::vector<LocalObjectEntry>
  291. {
  292. bool HasSourceExtension;
  293. bool HasPreprocessRule;
  294. bool HasAssembleRule;
  295. LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
  296. HasAssembleRule(false) {}
  297. };
  298. std::map<std::string, LocalObjectInfo> LocalObjectFiles;
  299. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  300. const char* comment, const char* output,
  301. LocalObjectInfo const& info);
  302. std::vector<std::string> LocalHelp;
  303. /* does the work for each target */
  304. std::map<std::string, std::string> MakeVariableMap;
  305. std::map<std::string, std::string> ShortMakeVariableMap;
  306. };
  307. #endif