cmLocalUnixMakefileGenerator3.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. /**
  38. * Process the CMakeLists files for this directory to fill in the
  39. * m_Makefile ivar
  40. */
  41. virtual void Configure();
  42. /** creates the common disclainer text at the top of each makefile */
  43. void WriteDisclaimer(std::ostream& os);
  44. // this returns the relative path between the HomeOutputDirectory and this
  45. // local generators StartOutputDirectory
  46. const std::string &GetHomeRelativeOutputPath();
  47. // Write out a make rule
  48. void WriteMakeRule(std::ostream& os,
  49. const char* comment,
  50. const char* target,
  51. const std::vector<std::string>& depends,
  52. const std::vector<std::string>& commands);
  53. // write the main variables used by the makefiles
  54. void WriteMakeVariables(std::ostream& makefileStream);
  55. // write a comment line #====... in the stream
  56. void WriteDivider(std::ostream& os);
  57. /**
  58. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  59. * that do not use environment variables.
  60. *
  61. */
  62. void SetPassMakeflags(bool s){m_PassMakeflags = s;}
  63. bool GetPassMakeflags() { return m_PassMakeflags; }
  64. /**
  65. * Set the flag used to keep the make program silent.
  66. */
  67. void SetMakeSilentFlag(const char* s) { m_MakeSilentFlag = s; }
  68. std::string &GetMakeSilentFlag() { return m_MakeSilentFlag; }
  69. /** used to create a recursive make call */
  70. std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
  71. /** Set whether the echo command needs its argument quoted. */
  72. void SetEchoNeedsQuote(bool b) { m_EchoNeedsQuote = b; }
  73. /**
  74. * Set to true if the shell being used is the windows shell.
  75. * This controls if statements in the makefile and the SHELL variable.
  76. * The default is false.
  77. */
  78. void SetWindowsShell(bool v) {m_WindowsShell = v;}
  79. /**
  80. * If set to true, then NULL is set to nil for non Windows_NT.
  81. * This uses make syntax used by nmake and borland.
  82. * The default is false.
  83. */
  84. void SetDefineWindowsNULL(bool v) {m_DefineWindowsNULL = v;}
  85. /**
  86. * If set to true, cd dir && command is used to
  87. * run commands in a different directory.
  88. */
  89. void SetUnixCD(bool v) {m_UnixCD = v;}
  90. /**
  91. * Set the string used to include one makefile into another default
  92. * is include.
  93. */
  94. void SetIncludeDirective(const char* s) { m_IncludeDirective = s; }
  95. const char *GetIncludeDirective() { return m_IncludeDirective.c_str(); }
  96. /**
  97. * Set max makefile variable size, default is 0 which means unlimited.
  98. */
  99. void SetMakefileVariableSize(int s) { m_MakefileVariableSize = s; }
  100. /**
  101. * If ignore lib prefix is true, then do not strip lib from the name
  102. * of a library.
  103. */
  104. void SetIgnoreLibPrefix(bool s) { m_IgnoreLibPrefix = s; }
  105. /** Called from command-line hook to scan dependencies. */
  106. virtual bool ScanDependencies(std::vector<std::string> const& args);
  107. /** Called from command-line hook to check dependencies. */
  108. virtual void CheckDependencies(cmMakefile* mf, bool verbose,
  109. bool clear);
  110. /** write some extra rules suahc as make test etc */
  111. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  112. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  113. std::string GetRelativeTargetDirectory(cmTarget& target);
  114. // List the files for which to check dependency integrity. Each
  115. // language has its own list because integrity may be checked
  116. // differently.
  117. struct IntegrityCheckSet: public std::set<cmSourceFile *> {};
  118. struct IntegrityCheckSetMap: public std::map<cmStdString, IntegrityCheckSet> {};
  119. std::map<cmStdString, IntegrityCheckSetMap> &GetIntegrityCheckSet()
  120. { return m_CheckDependFiles;}
  121. void AppendTargetDepends(std::vector<std::string>& depends,
  122. cmTarget& target);
  123. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  124. cmTarget& target);
  125. void AppendEcho(std::vector<std::string>& commands,
  126. const char* text);
  127. // write the target rules for the local Makefile into the stream
  128. void WriteLocalAllRules(std::ostream& ruleFileStream);
  129. protected:
  130. // write the depend info
  131. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  132. // write the target rules for the local Makefile into the stream
  133. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  134. std::set<cmStdString> &emitted);
  135. // write the local help rule
  136. void WriteHelpRule(std::ostream& ruleFileStream);
  137. // create the cd to home commands
  138. void CreateJumpCommand(std::vector<std::string>& commands,
  139. const char *MakefileName,
  140. std::string & localName);
  141. // create a command that cds to the start dir then runs the commands
  142. void CreateCDCommand(std::vector<std::string>& commands,
  143. const char *targetDir, const char *returnDir);
  144. // these two methods just compute reasonable values for m_LibraryOutputPath
  145. // and m_ExecutableOutputPath
  146. void ConfigureOutputPaths();
  147. void FormatOutputPath(std::string& path, const char* name);
  148. // this converts a file name that is relative to the StartOuputDirectory
  149. // into a full path
  150. std::string ConvertToFullPath(const std::string& localPath);
  151. // this is responsible for writing all of the rules for all this
  152. // directories custom commands (but not utility targets)
  153. void WriteCustomCommands(std::ostream& os,
  154. std::vector<std::string>& cleanFiles);
  155. // this method Writes the Directory informaiton files
  156. void WriteDirectoryInformationFile();
  157. // cleanup the name of a potential target
  158. std::string ConvertToMakeTarget(const char* tgt);
  159. // used in writing out Cmake files such as WriteDirectoryInformation
  160. void WriteCMakeArgument(std::ostream& os, const char* s);
  161. // write out all the rules for this target
  162. void WriteTargetRuleFiles(cmTarget& target);
  163. void WriteUtilityRuleFiles(cmTarget& target);
  164. // create the rule files for an object
  165. void WriteObjectRuleFiles(cmTarget& target,
  166. cmSourceFile& source,
  167. std::vector<std::string>& objects,
  168. std::ostream &filestr,
  169. std::ostream &flagstr);
  170. // write the build rule for an object
  171. void WriteObjectBuildFile(std::string &obj,
  172. const char *lang,
  173. cmTarget& target,
  174. cmSourceFile& source,
  175. std::vector<std::string>& depends,
  176. std::ostream &filestr,
  177. std::ostream &flagstr);
  178. // write the depend.make file for an object
  179. void WriteObjectDependRules(cmSourceFile& source,
  180. std::vector<std::string>& depends);
  181. // this is used only by WriteObjectDependFile
  182. bool GenerateDependsMakeFile(const std::string& lang,
  183. const char* objFile);
  184. // return the appropriate depends checker
  185. cmDepends* GetDependsChecker(const std::string& lang,
  186. bool verbose);
  187. void GenerateCustomRuleFile(const cmCustomCommand& cc,
  188. std::ostream &ruleStream);
  189. // these three make some simple changes and then call WriteLibraryRule
  190. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  191. const char* ruleFileName,
  192. cmTarget& target,
  193. const std::vector<std::string>& objects,
  194. const std::vector<std::string>& external_objects,
  195. std::vector<std::string>& cleanFiles);
  196. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  197. const char* ruleFileName,
  198. cmTarget& target,
  199. const std::vector<std::string>& objects,
  200. const std::vector<std::string>& external_objects,
  201. std::vector<std::string>& cleanFiles);
  202. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  203. const char* ruleFileName,
  204. cmTarget& target,
  205. const std::vector<std::string>& objects,
  206. const std::vector<std::string>& external_objects,
  207. std::vector<std::string>& cleanFiles);
  208. // the main code for writing the Executable target rules
  209. void WriteExecutableRule(std::ostream& ruleFileStream,
  210. const char* ruleFileName,
  211. cmTarget& target,
  212. const std::vector<std::string>& objects,
  213. const std::vector<std::string>& external_objects,
  214. std::vector<std::string>& cleanFiles);
  215. // the main method for writing library rules
  216. void WriteLibraryRule(std::ostream& ruleFileStream,
  217. const char* ruleFileName,
  218. cmTarget& target,
  219. const std::vector<std::string>& objects,
  220. const std::vector<std::string>& external_objects,
  221. const char* linkRuleVar,
  222. const char* extraLinkFlags,
  223. std::vector<std::string>& cleanFiles);
  224. void WriteLocalMakefile();
  225. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  226. const char* dependency);
  227. void WriteConvenienceRule(std::ostream& ruleFileStream,
  228. const char* realTarget,
  229. const char* helpTarget);
  230. void WriteObjectsVariable(std::ostream& ruleFileStream,
  231. cmTarget& target,
  232. const std::vector<std::string>& objects,
  233. const std::vector<std::string>& external_objects,
  234. std::string& variableName,
  235. std::string& variableNameExternal);
  236. void WriteTargetDependRule(std::ostream& ruleFileStream,
  237. cmTarget& target);
  238. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  239. cmTarget& target,
  240. const std::vector<std::string>& files);
  241. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  242. cmTarget& target,
  243. const std::vector<std::string>& objects);
  244. std::string GetTargetDirectory(cmTarget& target);
  245. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  246. std::string GetObjectFileName(cmTarget& target,
  247. const cmSourceFile& source);
  248. const char* GetSourceFileLanguage(const cmSourceFile& source);
  249. std::string ConvertToQuotedOutputPath(const char* p);
  250. void AppendAnyDepend(std::vector<std::string>& depends, const char* name,
  251. bool assume_unknown_is_file=false);
  252. void AppendRuleDepend(std::vector<std::string>& depends,
  253. const char* ruleFileName);
  254. void AppendCustomDepends(std::vector<std::string>& depends,
  255. const std::vector<cmCustomCommand>& ccs);
  256. void AppendCustomDepend(std::vector<std::string>& depends,
  257. const cmCustomCommand& cc);
  258. void AppendCustomCommands(std::vector<std::string>& commands,
  259. const std::vector<cmCustomCommand>& ccs);
  260. void AppendCustomCommand(std::vector<std::string>& commands,
  261. const cmCustomCommand& cc);
  262. void AppendCleanCommand(std::vector<std::string>& commands,
  263. const std::vector<std::string>& files);
  264. //==========================================================================
  265. bool SamePath(const char* path1, const char* path2);
  266. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  267. std::string CreateMakeVariable(const char* sin, const char* s2in);
  268. //==========================================================================
  269. void ComputeHomeRelativeOutputPath();
  270. private:
  271. std::map<cmStdString, IntegrityCheckSetMap> m_CheckDependFiles;
  272. //==========================================================================
  273. // Configuration settings.
  274. int m_MakefileVariableSize;
  275. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  276. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  277. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  278. std::string m_IncludeDirective;
  279. std::string m_MakeSilentFlag;
  280. std::string m_ExecutableOutputPath;
  281. std::string m_LibraryOutputPath;
  282. bool m_DefineWindowsNULL;
  283. bool m_UnixCD;
  284. bool m_PassMakeflags;
  285. //==========================================================================
  286. // Flag for whether echo command needs quotes.
  287. bool m_EchoNeedsQuote;
  288. std::string m_HomeRelativeOutputPath;
  289. // Set of object file names that will be built in this directory.
  290. std::set<cmStdString> m_ObjectFiles;
  291. std::map<cmStdString,std::vector<cmTarget *> > m_LocalObjectFiles;
  292. };
  293. #endif