cmLocalUnixMakefileGenerator3.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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 char* 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 char* 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 Support Verbose Variable. If true, then .SILENT will
  103. * be not end with : i.e. .SILENT: or .SILENT
  104. */
  105. void SetSilentNoColon(bool v) {this->SilentNoColon = v;}
  106. /**
  107. * Set the command to use for native make shell echo. The value
  108. * should include all parts of the command up to the beginning of
  109. * the message (including a whitespace separator).
  110. */
  111. void SetNativeEchoCommand(const char* cmd, bool isWindows)
  112. { this->NativeEchoCommand = cmd; this->NativeEchoWindows = isWindows; }
  113. /**
  114. * Set the string used to include one makefile into another default
  115. * is include.
  116. */
  117. void SetIncludeDirective(const char* s) { this->IncludeDirective = s; }
  118. const char *GetIncludeDirective() { return this->IncludeDirective.c_str(); }
  119. /**
  120. * Set max makefile variable size, default is 0 which means unlimited.
  121. */
  122. void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
  123. /**
  124. * If ignore lib prefix is true, then do not strip lib from the name
  125. * of a library.
  126. */
  127. void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
  128. /**
  129. * Set whether passing a make target on a command line requires an
  130. * extra level of escapes.
  131. */
  132. void SetMakeCommandEscapeTargetTwice(bool b)
  133. { this->MakeCommandEscapeTargetTwice = b; }
  134. /**
  135. * Set whether the Borland curly brace command line hack should be
  136. * applied.
  137. */
  138. void SetBorlandMakeCurlyHack(bool b)
  139. { this->BorlandMakeCurlyHack = b; }
  140. // used in writing out Cmake files such as WriteDirectoryInformation
  141. static void WriteCMakeArgument(std::ostream& os, const char* s);
  142. /** creates the common disclainer text at the top of each makefile */
  143. void WriteDisclaimer(std::ostream& os);
  144. // write a comment line #====... in the stream
  145. void WriteDivider(std::ostream& os);
  146. /** used to create a recursive make call */
  147. std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
  148. // append flags to a string
  149. virtual void AppendFlags(std::string& flags, const char* newFlags);
  150. // append an echo command
  151. enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
  152. EchoGenerate, EchoGlobal };
  153. void AppendEcho(std::vector<std::string>& commands, const char* text,
  154. EchoColor color = EchoNormal);
  155. /** Get whether the makefile is to have color. */
  156. bool GetColorMakefile() const { return this->ColorMakefile; }
  157. virtual std::string GetTargetDirectory(cmTarget const& target) const;
  158. // create a command that cds to the start dir then runs the commands
  159. void CreateCDCommand(std::vector<std::string>& commands,
  160. const char *targetDir,
  161. cmLocalGenerator::RelativeRoot returnDir);
  162. static std::string ConvertToQuotedOutputPath(const char* p);
  163. std::string CreateMakeVariable(const char* sin, const char* s2in);
  164. /** Called from command-line hook to bring dependencies up to date
  165. for a target. */
  166. virtual bool UpdateDependencies(const char* tgtInfo,
  167. bool verbose, bool color);
  168. /** Called from command-line hook to clear dependencies. */
  169. virtual void ClearDependencies(cmMakefile* mf, bool verbose);
  170. /** write some extra rules such as make test etc */
  171. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  172. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  173. std::string GetRelativeTargetDirectory(cmTarget const& target);
  174. // File pairs for implicit dependency scanning. The key of the map
  175. // is the depender and the value is the explicit dependee.
  176. struct ImplicitDependFileMap: public std::map<cmStdString, cmStdString> {};
  177. struct ImplicitDependLanguageMap:
  178. public std::map<cmStdString, ImplicitDependFileMap> {};
  179. struct ImplicitDependTargetMap:
  180. public std::map<cmStdString, ImplicitDependLanguageMap> {};
  181. ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
  182. void AddImplicitDepends(cmTarget const& tgt, const char* lang,
  183. const char* obj, const char* src);
  184. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  185. cmTarget& target);
  186. // write the target rules for the local Makefile into the stream
  187. void WriteLocalAllRules(std::ostream& ruleFileStream);
  188. struct LocalObjectEntry
  189. {
  190. cmTarget* Target;
  191. std::string Language;
  192. LocalObjectEntry(): Target(0), Language() {}
  193. LocalObjectEntry(cmTarget* t, const char* lang):
  194. Target(t), Language(lang) {}
  195. };
  196. struct LocalObjectInfo: public std::vector<LocalObjectEntry>
  197. {
  198. bool HasSourceExtension;
  199. bool HasPreprocessRule;
  200. bool HasAssembleRule;
  201. LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
  202. HasAssembleRule(false) {}
  203. };
  204. std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
  205. { return this->LocalObjectFiles;}
  206. std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
  207. /** Get whether to create rules to generate preprocessed and
  208. assembly sources. This could be converted to a variable lookup
  209. later. */
  210. bool GetCreatePreprocessedSourceRules()
  211. {
  212. return !this->SkipPreprocessedSourceRules;
  213. }
  214. bool GetCreateAssemblySourceRules()
  215. {
  216. return !this->SkipAssemblySourceRules;
  217. }
  218. // Get the directories into which the .o files will go for this target
  219. void GetTargetObjectFileDirectories(cmTarget* target,
  220. std::vector<std::string>& dirs);
  221. // Fill the vector with the target names for the object files,
  222. // preprocessed files and assembly files. Currently only used by the
  223. // Eclipse generator.
  224. void GetIndividualFileTargets(std::vector<std::string>& targets);
  225. protected:
  226. void WriteLocalMakefile();
  227. // write the target rules for the local Makefile into the stream
  228. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  229. std::set<cmStdString> &emitted);
  230. // this method Writes the Directory information files
  231. void WriteDirectoryInformationFile();
  232. // write the depend info
  233. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  234. // write the local help rule
  235. void WriteHelpRule(std::ostream& ruleFileStream);
  236. // this converts a file name that is relative to the StartOuputDirectory
  237. // into a full path
  238. std::string ConvertToFullPath(const std::string& localPath);
  239. void WriteConvenienceRule(std::ostream& ruleFileStream,
  240. const char* realTarget,
  241. const char* helpTarget);
  242. void WriteTargetDependRule(std::ostream& ruleFileStream,
  243. cmTarget& target);
  244. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  245. cmTarget& target,
  246. const std::vector<std::string>& files);
  247. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  248. cmTarget& target,
  249. const std::vector<std::string>& objects);
  250. void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
  251. const char* comment, const char* output,
  252. LocalObjectInfo const& info);
  253. std::string GetObjectFileName(cmTarget& target,
  254. const cmSourceFile& source,
  255. std::string* nameWithoutTargetDir = 0,
  256. bool* hasSourceExtension = 0);
  257. void AppendRuleDepend(std::vector<std::string>& depends,
  258. const char* ruleFileName);
  259. void AppendRuleDepends(std::vector<std::string>& depends,
  260. std::vector<std::string> const& ruleFiles);
  261. void AppendCustomDepends(std::vector<std::string>& depends,
  262. const std::vector<cmCustomCommand>& ccs);
  263. void AppendCustomDepend(std::vector<std::string>& depends,
  264. const cmCustomCommand& cc);
  265. void AppendCustomCommands(std::vector<std::string>& commands,
  266. const std::vector<cmCustomCommand>& ccs,
  267. cmTarget* target,
  268. cmLocalGenerator::RelativeRoot relative =
  269. cmLocalGenerator::HOME_OUTPUT);
  270. void AppendCustomCommand(std::vector<std::string>& commands,
  271. const cmCustomCommand& cc,
  272. cmTarget* target,
  273. bool echo_comment=false,
  274. cmLocalGenerator::RelativeRoot relative =
  275. cmLocalGenerator::HOME_OUTPUT,
  276. std::ostream* content = 0);
  277. void AppendCleanCommand(std::vector<std::string>& commands,
  278. const std::vector<std::string>& files,
  279. cmTarget& target, const char* filename =0);
  280. // Helper methods for dependeny updates.
  281. bool ScanDependencies(const char* targetDir,
  282. std::map<std::string, cmDepends::DependencyVector>& validDeps);
  283. void CheckMultipleOutputs(bool verbose);
  284. private:
  285. std::string MakeLauncher(const cmCustomCommand& cc, cmTarget* target,
  286. RelativeRoot relative);
  287. friend class cmMakefileTargetGenerator;
  288. friend class cmMakefileExecutableTargetGenerator;
  289. friend class cmMakefileLibraryTargetGenerator;
  290. friend class cmMakefileUtilityTargetGenerator;
  291. friend class cmGlobalUnixMakefileGenerator3;
  292. ImplicitDependTargetMap ImplicitDepends;
  293. //==========================================================================
  294. // Configuration settings.
  295. int MakefileVariableSize;
  296. std::string IncludeDirective;
  297. std::string MakeSilentFlag;
  298. std::string ConfigurationName;
  299. std::string NativeEchoCommand;
  300. bool NativeEchoWindows;
  301. bool DefineWindowsNULL;
  302. bool UnixCD;
  303. bool PassMakeflags;
  304. bool SilentNoColon;
  305. bool MakeCommandEscapeTargetTwice;
  306. bool BorlandMakeCurlyHack;
  307. //==========================================================================
  308. std::string HomeRelativeOutputPath;
  309. /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
  310. beginning of generation to avoid many duplicate lookups. */
  311. bool ColorMakefile;
  312. /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
  313. CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
  314. avoid many duplicate lookups. */
  315. bool SkipPreprocessedSourceRules;
  316. bool SkipAssemblySourceRules;
  317. std::map<cmStdString, LocalObjectInfo> LocalObjectFiles;
  318. std::vector<cmStdString> LocalHelp;
  319. /* does the work for each target */
  320. std::map<cmStdString, cmStdString> MakeVariableMap;
  321. std::map<cmStdString, cmStdString> ShortMakeVariableMap;
  322. };
  323. #endif