cmLocalUnixMakefileGenerator3.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmLocalUnixMakefileGenerator3_h
  14. #define cmLocalUnixMakefileGenerator3_h
  15. #include "cmLocalGenerator.h"
  16. class cmCustomCommand;
  17. class cmDependInformation;
  18. class cmDepends;
  19. class cmMakeDepend;
  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 m_Makefile.
  27. */
  28. class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator
  29. {
  30. public:
  31. cmLocalUnixMakefileGenerator3();
  32. virtual ~cmLocalUnixMakefileGenerator3();
  33. /**
  34. * Generate the makefile for this directory.
  35. */
  36. virtual void Generate();
  37. /** creates the common disclainer text at the top of each makefile */
  38. void WriteDisclaimer(std::ostream& os);
  39. // this returns the relative path between the HomeOutputDirectory and this
  40. // local generators StartOutputDirectory
  41. std::string GetHomeRelativeOutputPath();
  42. // Write out a make rule
  43. void WriteMakeRule(std::ostream& os,
  44. const char* comment,
  45. const char* target,
  46. const std::vector<std::string>& depends,
  47. const std::vector<std::string>& commands);
  48. // write the main variables used by the makefiles
  49. void WriteMakeVariables(std::ostream& makefileStream);
  50. // write a comment line #====... in the stream
  51. void WriteDivider(std::ostream& os);
  52. /**
  53. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  54. * that do not use environment variables.
  55. *
  56. */
  57. void SetPassMakeflags(bool s){m_PassMakeflags = s;}
  58. bool GetPassMakeflags() { return m_PassMakeflags; }
  59. /**
  60. * Set the flag used to keep the make program silent.
  61. */
  62. void SetMakeSilentFlag(const char* s) { m_MakeSilentFlag = s; }
  63. std::string &GetMakeSilentFlag() { return m_MakeSilentFlag; }
  64. /** used to create a recursive make call */
  65. std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
  66. /** Set whether the echo command needs its argument quoted. */
  67. void SetEchoNeedsQuote(bool b) { m_EchoNeedsQuote = b; }
  68. /**
  69. * Set to true if the shell being used is the windows shell.
  70. * This controls if statements in the makefile and the SHELL variable.
  71. * The default is false.
  72. */
  73. void SetWindowsShell(bool v) {m_WindowsShell = v;}
  74. /**
  75. * Set the string used to include one makefile into another default
  76. * is include.
  77. */
  78. void SetIncludeDirective(const char* s) { m_IncludeDirective = s; }
  79. const char *GetIncludeDirective() { return m_IncludeDirective.c_str(); }
  80. /**
  81. * Set max makefile variable size, default is 0 which means unlimited.
  82. */
  83. void SetMakefileVariableSize(int s) { m_MakefileVariableSize = s; }
  84. /**
  85. * If ignore lib prefix is true, then do not strip lib from the name
  86. * of a library.
  87. */
  88. void SetIgnoreLibPrefix(bool s) { m_IgnoreLibPrefix = s; }
  89. /** Called from command-line hook to scan dependencies. */
  90. virtual bool ScanDependencies(std::vector<std::string> const& args);
  91. /** Called from command-line hook to check dependencies. */
  92. virtual void CheckDependencies(cmMakefile* mf, bool verbose);
  93. /** write some extra rules suahc as make test etc */
  94. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  95. void WriteMainTargetIncludes(std::ostream& makefileStream,const char *file,
  96. const char *rule);
  97. void WriteMainTargetRules(std::ostream& makefileStream,const char *file,
  98. const char *rule, bool inAll);
  99. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  100. std::string GetRelativeTargetDirectory(const cmTarget& target);
  101. void WriteLocalCleanRule(std::ostream& makefileStream);
  102. // List the files for which to check dependency integrity. Each
  103. // language has its own list because integrity may be checked
  104. // differently.
  105. struct IntegrityCheckSet: public std::set<cmStdString> {};
  106. std::map<cmStdString, IntegrityCheckSet> &GetIntegrityCheckSet()
  107. { return m_CheckDependFiles;}
  108. protected:
  109. // write the target rules for the local Makefile into the stream
  110. void WriteLocalMakefileTargets(std::ostream& ruleFileStream);
  111. // create the cd to home commands
  112. void CreateJumpCommand(std::vector<std::string>& commands, std::string & localName);
  113. // these two methods just compute reasonable values for m_LibraryOutputPath and
  114. // m_ExecutableOutputPath
  115. void ConfigureOutputPaths();
  116. void FormatOutputPath(std::string& path, const char* name);
  117. // this converts a file name that is relative to the StartOuputDirectory
  118. // into a full path
  119. std::string ConvertToFullPath(const std::string& localPath);
  120. // this is responsible for writing all of the rules for all this
  121. // directories custom commands (but not utility targets)
  122. void WriteCustomCommands();
  123. // this method Writes the Directory informaiton files
  124. void WriteDirectoryInformationFile();
  125. // cleanup the name of a potential target
  126. std::string ConvertToMakeTarget(const char* tgt);
  127. // used in writing out Cmake files such as WriteDirectoryInformation
  128. void WriteCMakeArgument(std::ostream& os, const char* s);
  129. // write out all the rules for this target
  130. void WriteTargetRuleFiles(const cmTarget& target);
  131. void WriteUtilityRuleFiles(const cmTarget& target);
  132. // create the rule files for an object
  133. void WriteObjectRuleFiles(const cmTarget& target,
  134. const cmSourceFile& source,
  135. std::vector<std::string>& objects,
  136. std::vector<std::string>& provides_requires);
  137. // write the build rule for an object
  138. void WriteObjectBuildFile(std::string &obj,
  139. const char *lang,
  140. const cmTarget& target,
  141. const cmSourceFile& source,
  142. std::vector<std::string>& depends,
  143. std::string &depMakeFile,
  144. std::vector<std::string>& provides_requires);
  145. // write the depend.make file for an object
  146. void WriteObjectDependFile(std::string& obj,
  147. const char *lang,
  148. const cmSourceFile& source,
  149. std::vector<std::string>& depends,
  150. std::string& depMarkFile);
  151. // this is used only by WriteObjectDependFile
  152. bool GenerateDependsMakeFile(const std::string& lang,
  153. const char* objFile,
  154. std::string& depMakeFile,
  155. std::string& depMarkFile);
  156. // return the appropriate depends checker
  157. static cmDepends* GetDependsChecker(const std::string& lang,
  158. const char* dir,
  159. const char* objFile,
  160. bool verbose);
  161. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  162. // these three make some simple changes and then call WriteLibraryRule
  163. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  164. const char* ruleFileName,
  165. const cmTarget& target,
  166. const std::vector<std::string>& objects,
  167. const std::vector<std::string>& external_objects,
  168. const std::vector<std::string>& provides_requires);
  169. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  170. const char* ruleFileName,
  171. const cmTarget& target,
  172. const std::vector<std::string>& objects,
  173. const std::vector<std::string>& external_objects,
  174. const std::vector<std::string>& provides_requires);
  175. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  176. const char* ruleFileName,
  177. const cmTarget& target,
  178. const std::vector<std::string>& objects,
  179. const std::vector<std::string>& external_objects,
  180. const std::vector<std::string>& provides_requires);
  181. // the main code for writing the Executable target rules
  182. void WriteExecutableRule(std::ostream& ruleFileStream,
  183. const char* ruleFileName,
  184. const cmTarget& target,
  185. const std::vector<std::string>& objects,
  186. const std::vector<std::string>& external_objects,
  187. const std::vector<std::string>& provides_requires);
  188. // the main method for writing library rules
  189. void WriteLibraryRule(std::ostream& ruleFileStream,
  190. const char* ruleFileName,
  191. const cmTarget& target,
  192. const std::vector<std::string>& objects,
  193. const std::vector<std::string>& external_objects,
  194. const char* linkRuleVar,
  195. const char* extraLinkFlags,
  196. const std::vector<std::string>& provides_requires);
  197. void WriteLocalMakefile();
  198. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  199. const char* dependency);
  200. void WriteConvenienceRule(std::ostream& ruleFileStream,
  201. const char* realTarget,
  202. const char* helpTarget);
  203. void WriteObjectsVariable(std::ostream& ruleFileStream,
  204. const cmTarget& target,
  205. const std::vector<std::string>& objects,
  206. const std::vector<std::string>& external_objects,
  207. std::string& variableName,
  208. std::string& variableNameExternal);
  209. void WriteTargetDependRule(const char* ruleFileName,
  210. const cmTarget& target,
  211. const std::vector<std::string>& objects);
  212. void WriteTargetCleanRule(const char *ruleFileName,
  213. const cmTarget& target,
  214. const std::vector<std::string>& files,
  215. const std::vector<std::string>& objects,
  216. const std::vector<std::string>& external_objects);
  217. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  218. const cmTarget& target,
  219. const std::vector<std::string>& provides_requires);
  220. std::string GetTargetDirectory(const cmTarget& target);
  221. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  222. std::string GetObjectFileName(const cmTarget& target,
  223. const cmSourceFile& source);
  224. const char* GetSourceFileLanguage(const cmSourceFile& source);
  225. std::string ConvertToQuotedOutputPath(const char* p);
  226. void AppendTargetDepends(std::vector<std::string>& depends,
  227. const cmTarget& target);
  228. void AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  229. bool assume_unknown_is_file=false);
  230. void AppendRuleDepend(std::vector<std::string>& depends,
  231. const char* ruleFileName);
  232. void AppendCustomDepends(std::vector<std::string>& depends,
  233. const std::vector<cmCustomCommand>& ccs);
  234. void AppendCustomDepend(std::vector<std::string>& depends,
  235. const cmCustomCommand& cc);
  236. void AppendCustomCommands(std::vector<std::string>& commands,
  237. const std::vector<cmCustomCommand>& ccs);
  238. void AppendCustomCommand(std::vector<std::string>& commands,
  239. const cmCustomCommand& cc);
  240. void AppendCleanCommand(std::vector<std::string>& commands,
  241. const std::vector<std::string>& files);
  242. void AppendEcho(std::vector<std::string>& commands,
  243. const char* text);
  244. //==========================================================================
  245. bool SamePath(const char* path1, const char* path2);
  246. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  247. std::string CreateMakeVariable(const char* sin, const char* s2in);
  248. //==========================================================================
  249. private:
  250. std::map<cmStdString, IntegrityCheckSet> m_CheckDependFiles;
  251. //==========================================================================
  252. // Configuration settings.
  253. int m_MakefileVariableSize;
  254. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  255. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  256. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  257. std::string m_IncludeDirective;
  258. std::string m_MakeSilentFlag;
  259. std::string m_ExecutableOutputPath;
  260. std::string m_LibraryOutputPath;
  261. bool m_PassMakeflags;
  262. //==========================================================================
  263. // Flag for whether echo command needs quotes.
  264. bool m_EchoNeedsQuote;
  265. // Set of custom rule files that have been generated.
  266. std::set<cmStdString> m_CustomRuleFiles;
  267. // Set of object file names that will be built in this directory.
  268. std::set<cmStdString> m_ObjectFiles;
  269. };
  270. #endif