cmLocalUnixMakefileGenerator3.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 Support Verbose Variable. If true, then .SILENT will
  92. * be not end with : i.e. .SILENT: or .SILENT
  93. */
  94. void SetSilentNoColon(bool v) {m_SilentNoColon = v;}
  95. /**
  96. * Set the string used to include one makefile into another default
  97. * is include.
  98. */
  99. void SetIncludeDirective(const char* s) { m_IncludeDirective = s; }
  100. const char *GetIncludeDirective() { return m_IncludeDirective.c_str(); }
  101. /**
  102. * Set max makefile variable size, default is 0 which means unlimited.
  103. */
  104. void SetMakefileVariableSize(int s) { m_MakefileVariableSize = s; }
  105. /**
  106. * If ignore lib prefix is true, then do not strip lib from the name
  107. * of a library.
  108. */
  109. void SetIgnoreLibPrefix(bool s) { m_IgnoreLibPrefix = s; }
  110. /** Called from command-line hook to scan dependencies. */
  111. virtual bool ScanDependencies(std::vector<std::string> const& args);
  112. /** Called from command-line hook to check dependencies. */
  113. virtual void CheckDependencies(cmMakefile* mf, bool verbose,
  114. bool clear);
  115. /** write some extra rules suahc as make test etc */
  116. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  117. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  118. std::string GetRelativeTargetDirectory(cmTarget& target);
  119. // List the files for which to check dependency integrity. Each
  120. // language has its own list because integrity may be checked
  121. // differently.
  122. struct IntegrityCheckSet: public std::set<cmSourceFile *> {};
  123. struct IntegrityCheckSetMap: public std::map<cmStdString, IntegrityCheckSet> {};
  124. std::map<cmStdString, IntegrityCheckSetMap> &GetIntegrityCheckSet()
  125. { return m_CheckDependFiles;}
  126. void AppendTargetDepends(std::vector<std::string>& depends,
  127. cmTarget& target);
  128. void AppendGlobalTargetDepends(std::vector<std::string>& depends,
  129. cmTarget& target);
  130. void AppendEcho(std::vector<std::string>& commands,
  131. const char* text);
  132. // write the target rules for the local Makefile into the stream
  133. void WriteLocalAllRules(std::ostream& ruleFileStream);
  134. std::map<cmStdString,std::vector<cmTarget *> > GetLocalObjectFiles()
  135. { return m_LocalObjectFiles;}
  136. protected:
  137. // Return the a string with -F flags on apple
  138. std::string GetFrameworkFlags(cmTarget&);
  139. // write the depend info
  140. void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
  141. // write the target rules for the local Makefile into the stream
  142. void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
  143. std::set<cmStdString> &emitted);
  144. // write the local help rule
  145. void WriteHelpRule(std::ostream& ruleFileStream);
  146. // create a command that cds to the start dir then runs the commands
  147. void CreateCDCommand(std::vector<std::string>& commands,
  148. const char *targetDir, const char *returnDir);
  149. // these two methods just compute reasonable values for m_LibraryOutputPath
  150. // and m_ExecutableOutputPath
  151. void ConfigureOutputPaths();
  152. void FormatOutputPath(std::string& path, const char* name);
  153. // this converts a file name that is relative to the StartOuputDirectory
  154. // into a full path
  155. std::string ConvertToFullPath(const std::string& localPath);
  156. // this is responsible for writing all of the rules for all this
  157. // directories custom commands (but not utility targets)
  158. void WriteCustomCommands(std::ostream& os,
  159. std::vector<std::string>& cleanFiles);
  160. // this method Writes the Directory informaiton files
  161. void WriteDirectoryInformationFile();
  162. // cleanup the name of a potential target
  163. std::string ConvertToMakeTarget(const char* tgt);
  164. // used in writing out Cmake files such as WriteDirectoryInformation
  165. void WriteCMakeArgument(std::ostream& os, const char* s);
  166. // write out all the rules for this target
  167. void WriteTargetRuleFiles(cmTarget& target);
  168. void WriteUtilityRuleFiles(cmTarget& target);
  169. // create the rule files for an object
  170. void WriteObjectRuleFiles(cmTarget& target,
  171. cmSourceFile& source,
  172. std::vector<std::string>& objects,
  173. std::ostream &filestr,
  174. std::ostream &flagstr);
  175. // write the build rule for an object
  176. void WriteObjectBuildFile(std::string &obj,
  177. const char *lang,
  178. cmTarget& target,
  179. cmSourceFile& source,
  180. std::vector<std::string>& depends,
  181. std::ostream &filestr,
  182. std::ostream &flagstr);
  183. // write the depend.make file for an object
  184. void WriteObjectDependRules(cmSourceFile& source,
  185. std::vector<std::string>& depends);
  186. // this is used only by WriteObjectDependFile
  187. bool GenerateDependsMakeFile(const std::string& lang,
  188. const char* objFile);
  189. // return the appropriate depends checker
  190. cmDepends* GetDependsChecker(const std::string& lang,
  191. bool verbose);
  192. void GenerateCustomRuleFile(const cmCustomCommand& cc,
  193. std::ostream &ruleStream);
  194. // these three make some simple changes and then call WriteLibraryRule
  195. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  196. const char* ruleFileName,
  197. cmTarget& target,
  198. const std::vector<std::string>& objects,
  199. const std::vector<std::string>& external_objects,
  200. std::vector<std::string>& cleanFiles);
  201. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  202. const char* ruleFileName,
  203. cmTarget& target,
  204. const std::vector<std::string>& objects,
  205. const std::vector<std::string>& external_objects,
  206. std::vector<std::string>& cleanFiles);
  207. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  208. const char* ruleFileName,
  209. cmTarget& target,
  210. const std::vector<std::string>& objects,
  211. const std::vector<std::string>& external_objects,
  212. std::vector<std::string>& cleanFiles);
  213. // the main code for writing the Executable target rules
  214. void WriteExecutableRule(std::ostream& ruleFileStream,
  215. const char* ruleFileName,
  216. cmTarget& target,
  217. const std::vector<std::string>& objects,
  218. const std::vector<std::string>& external_objects,
  219. std::vector<std::string>& cleanFiles);
  220. // the main method for writing library rules
  221. void WriteLibraryRule(std::ostream& ruleFileStream,
  222. const char* ruleFileName,
  223. cmTarget& target,
  224. const std::vector<std::string>& objects,
  225. const std::vector<std::string>& external_objects,
  226. const char* linkRuleVar,
  227. const char* extraLinkFlags,
  228. std::vector<std::string>& cleanFiles);
  229. void WriteLocalMakefile();
  230. void WriteConvenienceRule(std::ostream& ruleFileStream,
  231. const char* realTarget,
  232. const char* helpTarget);
  233. void WriteObjectsVariable(std::ostream& ruleFileStream,
  234. cmTarget& target,
  235. const std::vector<std::string>& objects,
  236. const std::vector<std::string>& external_objects,
  237. std::string& variableName,
  238. std::string& variableNameExternal);
  239. void WriteTargetDependRule(std::ostream& ruleFileStream,
  240. cmTarget& target);
  241. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  242. cmTarget& target,
  243. const std::vector<std::string>& files);
  244. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  245. cmTarget& target,
  246. const std::vector<std::string>& objects);
  247. std::string GetTargetDirectory(cmTarget& target);
  248. std::string GetObjectFileName(cmTarget& target,
  249. const cmSourceFile& source,
  250. std::string* nameWithoutTargetDir = 0);
  251. const char* GetSourceFileLanguage(const cmSourceFile& source);
  252. std::string ConvertToQuotedOutputPath(const char* p);
  253. void AppendRuleDepend(std::vector<std::string>& depends,
  254. const char* ruleFileName);
  255. void AppendCustomDepends(std::vector<std::string>& depends,
  256. const std::vector<cmCustomCommand>& ccs);
  257. void AppendCustomDepend(std::vector<std::string>& depends,
  258. const cmCustomCommand& cc);
  259. void AppendCustomCommands(std::vector<std::string>& commands,
  260. const std::vector<cmCustomCommand>& ccs);
  261. void AppendCustomCommand(std::vector<std::string>& commands,
  262. const cmCustomCommand& cc);
  263. void AppendCleanCommand(std::vector<std::string>& commands,
  264. const std::vector<std::string>& files);
  265. //==========================================================================
  266. bool SamePath(const char* path1, const char* path2);
  267. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  268. std::string CreateMakeVariable(const char* sin, const char* s2in);
  269. //==========================================================================
  270. void ComputeHomeRelativeOutputPath();
  271. private:
  272. std::map<cmStdString, IntegrityCheckSetMap> m_CheckDependFiles;
  273. //==========================================================================
  274. // Configuration settings.
  275. int m_MakefileVariableSize;
  276. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  277. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  278. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  279. std::string m_IncludeDirective;
  280. std::string m_MakeSilentFlag;
  281. std::string m_ExecutableOutputPath;
  282. std::string m_LibraryOutputPath;
  283. std::string m_ConfigurationName;
  284. bool m_DefineWindowsNULL;
  285. bool m_UnixCD;
  286. bool m_PassMakeflags;
  287. bool m_SilentNoColon;
  288. //==========================================================================
  289. // Flag for whether echo command needs quotes.
  290. bool m_EchoNeedsQuote;
  291. std::string m_HomeRelativeOutputPath;
  292. // Set of object file names that will be built in this directory.
  293. std::set<cmStdString> m_ObjectFiles;
  294. std::map<cmStdString,std::vector<cmTarget *> > m_LocalObjectFiles;
  295. };
  296. #endif