cmLocalUnixMakefileGenerator2.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 cmLocalUnixMakefileGenerator2_h
  14. #define cmLocalUnixMakefileGenerator2_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 cmLocalUnixMakefileGenerator2
  23. * \brief Write a LocalUnix makefiles.
  24. *
  25. * cmLocalUnixMakefileGenerator2 produces a LocalUnix makefile from its
  26. * member m_Makefile.
  27. */
  28. class cmLocalUnixMakefileGenerator2 : public cmLocalGenerator
  29. {
  30. public:
  31. ///! Set cache only and recurse to false by default.
  32. cmLocalUnixMakefileGenerator2();
  33. virtual ~cmLocalUnixMakefileGenerator2();
  34. /** Set the command used when there are no dependencies or rules for
  35. a target. This is used to avoid errors on some make
  36. implementations. */
  37. void SetEmptyCommand(const char* cmd);
  38. /**
  39. * Set to true if the shell being used is the windows shell.
  40. * This controls if statements in the makefile and the SHELL variable.
  41. * The default is false.
  42. */
  43. void SetWindowsShell(bool v) {m_WindowsShell = v;}
  44. /**
  45. * Set the string used to include one makefile into another default
  46. * is include.
  47. */
  48. void SetIncludeDirective(const char* s) { m_IncludeDirective = s; }
  49. /**
  50. * Set the flag used to keep the make program silent.
  51. */
  52. void SetMakeSilentFlag(const char* s) { m_MakeSilentFlag = s; }
  53. /**
  54. * Set max makefile variable size, default is 0 which means unlimited.
  55. */
  56. void SetMakefileVariableSize(int s) { m_MakefileVariableSize = s; }
  57. /**
  58. * If ignore lib prefix is true, then do not strip lib from the name
  59. * of a library.
  60. */
  61. void SetIgnoreLibPrefix(bool s) { m_IgnoreLibPrefix = s; }
  62. /**
  63. * If true, then explicitly pass MAKEFLAGS on the make all target for makes
  64. * that do not use environment variables.
  65. *
  66. */
  67. void SetPassMakeflags(bool s){m_PassMakeflags = s;}
  68. /**
  69. * Generate the makefile for this directory. fromTheTop indicates if this
  70. * is being invoked as part of a global Generate or specific to this
  71. * directory. The difference is that when done from the Top we might skip
  72. * some steps to save time, such as dependency generation for the
  73. * makefiles. This is done by a direct invocation from make.
  74. */
  75. virtual void Generate(bool fromTheTop);
  76. /** Called from command-line hook to scan dependencies. */
  77. static bool ScanDependencies(std::vector<std::string> const& args);
  78. /** Called from command-line hook to check dependencies. */
  79. static void CheckDependencies(cmMakefile* mf);
  80. protected:
  81. void GenerateMakefile();
  82. void GenerateCMakefile();
  83. void GenerateDirectoryInformationFile();
  84. void GenerateTargetRuleFile(const cmTarget& target);
  85. void GenerateObjectRuleFile(const cmTarget& target,
  86. const cmSourceFile& source,
  87. std::vector<std::string>& objects,
  88. std::vector<std::string>& provides_requires);
  89. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  90. void GenerateUtilityRuleFile(const cmTarget& target);
  91. bool GenerateDependsMakeFile(const std::string& lang,
  92. const char* objFile,
  93. std::string& depMakeFile,
  94. std::string& depMarkFile);
  95. void WriteMakeRule(std::ostream& os,
  96. const char* comment,
  97. const char* preEcho,
  98. const char* target,
  99. const std::vector<std::string>& depends,
  100. const std::vector<std::string>& commands,
  101. const char* postEcho=0);
  102. void WriteDivider(std::ostream& os);
  103. void WriteDisclaimer(std::ostream& os);
  104. void WriteMakeVariables(std::ostream& makefileStream);
  105. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  106. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  107. void WriteRuleFileIncludes(std::ostream& makefileStream);
  108. void WriteAllRules(std::ostream& makefileStream);
  109. void WritePassRules(std::ostream& makefileStream, const char* pass);
  110. void WriteDriverRules(std::ostream& makefileStream, const char* pass,
  111. const char* local1, const char* local2=0);
  112. void WriteSubdirRules(std::ostream& makefileStream, const char* pass);
  113. void WriteSubdirRule(std::ostream& makefileStream, const char* pass,
  114. const char* subdir, std::string& last);
  115. void WriteSubdirDriverRule(std::ostream& makefileStream, const char* pass,
  116. const char* order, const std::string& last);
  117. void WriteLocalRule(std::ostream& ruleFileStream, const char* pass,
  118. const char* dependency);
  119. void WriteConvenienceRules(std::ostream& ruleFileStream,
  120. const cmTarget& target,
  121. const char* targetOutPath);
  122. void WriteConvenienceRule(std::ostream& ruleFileStream,
  123. const char* realTarget,
  124. const char* helpTarget);
  125. void WriteExecutableRule(std::ostream& ruleFileStream,
  126. const char* ruleFileName,
  127. const cmTarget& target,
  128. const std::vector<std::string>& objects,
  129. const std::vector<std::string>& external_objects,
  130. const std::vector<std::string>& provides_requires);
  131. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  132. const char* ruleFileName,
  133. const cmTarget& target,
  134. const std::vector<std::string>& objects,
  135. const std::vector<std::string>& external_objects,
  136. const std::vector<std::string>& provides_requires);
  137. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  138. const char* ruleFileName,
  139. const cmTarget& target,
  140. const std::vector<std::string>& objects,
  141. const std::vector<std::string>& external_objects,
  142. const std::vector<std::string>& provides_requires);
  143. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  144. const char* ruleFileName,
  145. const cmTarget& target,
  146. const std::vector<std::string>& objects,
  147. const std::vector<std::string>& external_objects,
  148. const std::vector<std::string>& provides_requires);
  149. void WriteLibraryRule(std::ostream& ruleFileStream,
  150. const char* ruleFileName,
  151. const cmTarget& target,
  152. const std::vector<std::string>& objects,
  153. const std::vector<std::string>& external_objects,
  154. const char* linkRuleVar,
  155. const char* extraLinkFlags,
  156. const std::vector<std::string>& provides_requires);
  157. void WriteObjectsVariable(std::ostream& ruleFileStream,
  158. const cmTarget& target,
  159. const std::vector<std::string>& objects,
  160. const std::vector<std::string>& external_objects,
  161. std::string& variableName,
  162. std::string& variableNameExternal);
  163. void WriteTargetDependsRule(std::ostream& ruleFileStream,
  164. const char* ruleFileName,
  165. const cmTarget& target,
  166. const std::vector<std::string>& objects);
  167. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  168. const cmTarget& target,
  169. const std::vector<std::string>& files);
  170. void WriteTargetRequiresRule(std::ostream& ruleFileStream,
  171. const cmTarget& target,
  172. const std::vector<std::string>& provides_requires);
  173. void WriteLocalCleanRule(std::ostream& makefileStream);
  174. void WriteCMakeArgument(std::ostream& os, const char* s);
  175. std::string GetTargetDirectory(const cmTarget& target);
  176. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  177. std::string GetObjectFileName(const cmTarget& target,
  178. const cmSourceFile& source);
  179. const char* GetSourceFileLanguage(const cmSourceFile& source);
  180. std::string ConvertToFullPath(const std::string& localPath);
  181. std::string ConvertToRelativeOutputPath(const char* p);
  182. std::string ConvertToQuotedOutputPath(const char* p);
  183. void ConfigureOutputPaths();
  184. void FormatOutputPath(std::string& path, const char* name);
  185. void AppendTargetDepends(std::vector<std::string>& depends,
  186. const cmTarget& target);
  187. void AppendAnyDepend(std::vector<std::string>& depends, const char* name);
  188. void AppendCustomDepends(std::vector<std::string>& depends,
  189. const std::vector<cmCustomCommand>& ccs);
  190. void AppendCustomDepend(std::vector<std::string>& depends,
  191. const cmCustomCommand& cc);
  192. void AppendCustomCommands(std::vector<std::string>& commands,
  193. const std::vector<cmCustomCommand>& ccs);
  194. void AppendCustomCommand(std::vector<std::string>& commands,
  195. const cmCustomCommand& cc);
  196. void AppendCleanCommand(std::vector<std::string>& commands,
  197. const std::vector<std::string>& files);
  198. //==========================================================================
  199. void OutputEcho(std::ostream& fout, const char* msg);
  200. bool SamePath(const char* path1, const char* path2);
  201. std::string GetBaseTargetName(const cmTarget& t);
  202. void GetLibraryNames(const cmTarget& t,
  203. std::string& name, std::string& soName,
  204. std::string& realName, std::string& baseName);
  205. std::string ConvertToMakeTarget(const char* tgt);
  206. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  207. std::string CreateMakeVariable(const char* sin, const char* s2in);
  208. //==========================================================================
  209. std::string GetRecursiveMakeCall(const char* tgt);
  210. void WriteJumpAndBuildRules(std::ostream& makefileStream);
  211. static cmDepends* GetDependsChecker(const std::string& lang,
  212. const char* dir,
  213. const char* objFile);
  214. private:
  215. // Map from target name to build directory containing it for
  216. // jump-and-build targets.
  217. struct RemoteTarget
  218. {
  219. std::string m_BuildDirectory;
  220. std::string m_FilePath;
  221. };
  222. std::map<cmStdString, RemoteTarget> m_JumpAndBuild;
  223. // List the files for which to check dependency integrity. Each
  224. // language has its own list because integrity may be checked
  225. // differently.
  226. struct IntegrityCheckSet: public std::set<cmStdString> {};
  227. std::map<cmStdString, IntegrityCheckSet> m_CheckDependFiles;
  228. // Command used when a rule has no dependencies or commands.
  229. std::vector<std::string> m_EmptyCommands;
  230. //==========================================================================
  231. // Configuration settings.
  232. int m_MakefileVariableSize;
  233. std::map<cmStdString, cmStdString> m_MakeVariableMap;
  234. std::map<cmStdString, cmStdString> m_ShortMakeVariableMap;
  235. std::map<cmStdString, cmStdString> m_UniqueObjectNamesMap;
  236. std::string m_IncludeDirective;
  237. std::string m_MakeSilentFlag;
  238. std::string m_ExecutableOutputPath;
  239. std::string m_LibraryOutputPath;
  240. bool m_PassMakeflags;
  241. //==========================================================================
  242. // List of make rule files that need to be included by the makefile.
  243. std::vector<std::string> m_IncludeRuleFiles;
  244. // Set of custom rule files that have been generated.
  245. std::set<cmStdString> m_CustomRuleFiles;
  246. // Set of object file names that will be built in this directory.
  247. std::set<cmStdString> m_ObjectFiles;
  248. };
  249. #endif