cmLocalUnixMakefileGenerator3.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 WriteSpecialTargetsBottom(std::ostream& makefileStream);
  96. std::string GetRelativeTargetDirectory(const cmTarget& target);
  97. // List the files for which to check dependency integrity. Each
  98. // language has its own list because integrity may be checked
  99. // differently.
  100. struct IntegrityCheckSet: public std::set<cmStdString> {};
  101. std::map<cmStdString, IntegrityCheckSet> &GetIntegrityCheckSet()
  102. { return m_CheckDependFiles;}
  103. void AppendTargetDepends(std::vector<std::string>& depends,
  104. const cmTarget& target);
  105. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  106. const cmTarget& target);
  107. void AppendEcho(std::vector<std::string>& commands,
  108. const char* text);
  109. protected:
  110. // write the target rules for the local Makefile into the stream
  111. void WriteLocalMakefileTargets(std::ostream& ruleFileStream);
  112. // create the cd to home commands
  113. void CreateJumpCommand(std::vector<std::string>& commands, std::string & localName);
  114. // these two methods just compute reasonable values for m_LibraryOutputPath and
  115. // m_ExecutableOutputPath
  116. void ConfigureOutputPaths();
  117. void FormatOutputPath(std::string& path, const char* name);
  118. // this converts a file name that is relative to the StartOuputDirectory
  119. // into a full path
  120. std::string ConvertToFullPath(const std::string& localPath);
  121. // this is responsible for writing all of the rules for all this
  122. // directories custom commands (but not utility targets)
  123. void WriteCustomCommands(const cmTarget &target,std::ostream& os,
  124. std::vector<std::string>& cleanFiles);
  125. // this method Writes the Directory informaiton files
  126. void WriteDirectoryInformationFile();
  127. // cleanup the name of a potential target
  128. std::string ConvertToMakeTarget(const char* tgt);
  129. // used in writing out Cmake files such as WriteDirectoryInformation
  130. void WriteCMakeArgument(std::ostream& os, const char* s);
  131. // write out all the rules for this target
  132. void WriteTargetRuleFiles(const cmTarget& target);
  133. void WriteUtilityRuleFiles(const cmTarget& target);
  134. // create the rule files for an object
  135. void WriteObjectRuleFiles(const cmTarget& target,
  136. const cmSourceFile& source,
  137. std::vector<std::string>& objects);
  138. // write the build rule for an object
  139. void WriteObjectBuildFile(std::string &obj,
  140. const char *lang,
  141. const cmTarget& target,
  142. const cmSourceFile& source,
  143. std::vector<std::string>& depends,
  144. std::string &depMakeFile);
  145. // write the depend.make file for an object
  146. void WriteObjectDependRules(std::ostream& ruleFileStream,
  147. std::string& obj,
  148. const char *lang,
  149. const cmSourceFile& source,
  150. std::vector<std::string>& depends,
  151. std::string& depMarkFile);
  152. // this is used only by WriteObjectDependFile
  153. bool GenerateDependsMakeFile(const std::string& lang,
  154. const char* objFile,
  155. std::string& depMakeFile,
  156. std::string& depMarkFile);
  157. // return the appropriate depends checker
  158. cmDepends* GetDependsChecker(const std::string& lang,
  159. const char* dir,
  160. const char* objFile,
  161. bool verbose);
  162. std::string GenerateCustomRuleFile(const cmCustomCommand& cc,
  163. const char *dir);
  164. // these three make some simple changes and then call WriteLibraryRule
  165. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  166. const char* ruleFileName,
  167. const cmTarget& target,
  168. const std::vector<std::string>& objects,
  169. const std::vector<std::string>& external_objects,
  170. std::vector<std::string>& cleanFiles);
  171. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  172. const char* ruleFileName,
  173. const cmTarget& target,
  174. const std::vector<std::string>& objects,
  175. const std::vector<std::string>& external_objects,
  176. std::vector<std::string>& cleanFiles);
  177. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  178. const char* ruleFileName,
  179. const cmTarget& target,
  180. const std::vector<std::string>& objects,
  181. const std::vector<std::string>& external_objects,
  182. std::vector<std::string>& cleanFiles);
  183. // the main code for writing the Executable target rules
  184. void WriteExecutableRule(std::ostream& ruleFileStream,
  185. const char* ruleFileName,
  186. const cmTarget& target,
  187. const std::vector<std::string>& objects,
  188. const std::vector<std::string>& external_objects,
  189. std::vector<std::string>& cleanFiles);
  190. // the main method for writing library rules
  191. void WriteLibraryRule(std::ostream& ruleFileStream,
  192. const char* ruleFileName,
  193. const cmTarget& target,
  194. const std::vector<std::string>& objects,
  195. const std::vector<std::string>& external_objects,
  196. const char* linkRuleVar,
  197. const char* extraLinkFlags,
  198. std::vector<std::string>& cleanFiles);
  199. void WriteLocalMakefile();
  200. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  201. const char* dependency);
  202. void WriteConvenienceRule(std::ostream& ruleFileStream,
  203. const char* realTarget,
  204. const char* helpTarget);
  205. void WriteObjectsVariable(std::ostream& ruleFileStream,
  206. const cmTarget& target,
  207. const std::vector<std::string>& objects,
  208. const std::vector<std::string>& external_objects,
  209. std::string& variableName,
  210. std::string& variableNameExternal);
  211. void WriteTargetDependRule(std::ostream& ruleFileStream,
  212. const cmTarget& target,
  213. const std::vector<std::string>& objects);
  214. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  215. const cmTarget& target,
  216. const std::vector<std::string>& files);
  217. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  218. const cmTarget& target,
  219. const std::vector<std::string>& objects);
  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 AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  227. bool assume_unknown_is_file=false);
  228. void AppendRuleDepend(std::vector<std::string>& depends,
  229. const char* ruleFileName);
  230. void AppendCustomDepends(std::vector<std::string>& depends,
  231. const std::vector<cmCustomCommand>& ccs);
  232. void AppendCustomDepend(std::vector<std::string>& depends,
  233. const cmCustomCommand& cc);
  234. void AppendCustomCommands(std::vector<std::string>& commands,
  235. const std::vector<cmCustomCommand>& ccs);
  236. void AppendCustomCommand(std::vector<std::string>& commands,
  237. const cmCustomCommand& cc);
  238. void AppendCleanCommand(std::vector<std::string>& commands,
  239. const std::vector<std::string>& files);
  240. //==========================================================================
  241. bool SamePath(const char* path1, const char* path2);
  242. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  243. std::string CreateMakeVariable(const char* sin, const char* s2in);
  244. //==========================================================================
  245. private:
  246. std::map<cmStdString, IntegrityCheckSet> m_CheckDependFiles;
  247. //==========================================================================
  248. // Configuration settings.
  249. int m_MakefileVariableSize;
  250. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  251. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  252. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  253. std::string m_IncludeDirective;
  254. std::string m_MakeSilentFlag;
  255. std::string m_ExecutableOutputPath;
  256. std::string m_LibraryOutputPath;
  257. bool m_PassMakeflags;
  258. //==========================================================================
  259. // Flag for whether echo command needs quotes.
  260. bool m_EchoNeedsQuote;
  261. // Set of object file names that will be built in this directory.
  262. std::set<cmStdString> m_ObjectFiles;
  263. };
  264. #endif