1
0

cmLocalUnixMakefileGenerator2.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 "cmLocalUnixMakefileGenerator.h"
  16. class cmCustomCommand;
  17. class cmDependInformation;
  18. class cmMakeDepend;
  19. class cmTarget;
  20. class cmSourceFile;
  21. /** \class cmLocalUnixMakefileGenerator2
  22. * \brief Write a LocalUnix makefiles.
  23. *
  24. * cmLocalUnixMakefileGenerator2 produces a LocalUnix makefile from its
  25. * member m_Makefile.
  26. */
  27. class cmLocalUnixMakefileGenerator2 : public cmLocalUnixMakefileGenerator
  28. {
  29. public:
  30. ///! Set cache only and recurse to false by default.
  31. cmLocalUnixMakefileGenerator2();
  32. virtual ~cmLocalUnixMakefileGenerator2();
  33. /** Set the command used when there are no dependencies or rules for
  34. a target. This is used to avoid errors on some make
  35. implementations. */
  36. void SetEmptyCommand(const char* cmd);
  37. /**
  38. * Generate the makefile for this directory. fromTheTop indicates if this
  39. * is being invoked as part of a global Generate or specific to this
  40. * directory. The difference is that when done from the Top we might skip
  41. * some steps to save time, such as dependency generation for the
  42. * makefiles. This is done by a direct invocation from make.
  43. */
  44. virtual void Generate(bool fromTheTop);
  45. /** Called from command-line hook to scan dependencies. */
  46. static bool ScanDependencies(std::vector<std::string> const& args);
  47. /** Called from command-line hook to check dependencies. */
  48. static void CheckDependencies(const char* depCheck);
  49. protected:
  50. void GenerateMakefile();
  51. void GenerateCMakefile();
  52. void GenerateTargetRuleFile(const cmTarget& target);
  53. void GenerateObjectRuleFile(const cmTarget& target,
  54. const cmSourceFile& source);
  55. void GenerateCustomRuleFile(const cmSourceFile& source);
  56. std::string GenerateDependsMakeFile(const char* file);
  57. void WriteMakeRule(std::ostream& os,
  58. const char* comment,
  59. const char* preEcho,
  60. const char* target,
  61. const std::vector<std::string>& depends,
  62. const std::vector<std::string>& commands,
  63. const char* postEcho=0);
  64. void WriteDivider(std::ostream& os);
  65. void WriteDisclaimer(std::ostream& os);
  66. void WriteMakeVariables(std::ostream& makefileStream);
  67. void WriteSpecialTargetsTop(std::ostream& makefileStream);
  68. void WriteSpecialTargetsBottom(std::ostream& makefileStream);
  69. void WriteRuleFileIncludes(std::ostream& makefileStream);
  70. void WriteAllRules(std::ostream& makefileStream);
  71. void WritePassRules(std::ostream& makefileStream,
  72. const char* pass, const char* comment,
  73. const std::vector<std::string>& depends);
  74. void WriteDriverRules(std::ostream& makefileStream, const char* pass,
  75. const char* local1, const char* local2=0);
  76. void WriteSubdirRules(std::ostream& makefileStream, const char* pass);
  77. void WriteSubdirRule(std::ostream& makefileStream, const char* pass,
  78. const char* subdir, std::string& last);
  79. void WriteSubdirDriverRule(std::ostream& makefileStream, const char* pass,
  80. const char* order, const std::string& last);
  81. void WriteConvenienceRules(std::ostream& ruleFileStream,
  82. const cmTarget& target,
  83. const char* targetFullPath);
  84. void WriteConvenienceRule(std::ostream& ruleFileStream,
  85. const char* realTarget,
  86. const char* helpTarget);
  87. void WriteExecutableRule(std::ostream& ruleFileStream,
  88. const char* ruleFileName,
  89. const cmTarget& target,
  90. std::vector<std::string>& objects);
  91. void WriteStaticLibraryRule(std::ostream& ruleFileStream,
  92. const char* ruleFileName,
  93. const cmTarget& target,
  94. std::vector<std::string>& objects);
  95. void WriteSharedLibraryRule(std::ostream& ruleFileStream,
  96. const char* ruleFileName,
  97. const cmTarget& target,
  98. std::vector<std::string>& objects);
  99. void WriteModuleLibraryRule(std::ostream& ruleFileStream,
  100. const char* ruleFileName,
  101. const cmTarget& target,
  102. std::vector<std::string>& objects);
  103. void WriteLibraryRule(std::ostream& ruleFileStream,
  104. const char* ruleFileName,
  105. const cmTarget& target,
  106. std::vector<std::string>& objects,
  107. const char* linkRuleVar,
  108. const char* extraLinkFlags);
  109. void WriteObjectsVariable(std::ostream& ruleFileStream,
  110. const cmTarget& target,
  111. std::vector<std::string>& objects);
  112. void WriteTargetDependsRule(std::ostream& ruleFileStream,
  113. const char* ruleFileName,
  114. const cmTarget& target,
  115. const std::vector<std::string>& objects);
  116. void WriteTargetCleanRule(std::ostream& ruleFileStream,
  117. const cmTarget& target,
  118. const std::vector<std::string>& files);
  119. std::string GetTargetDirectory(const cmTarget& target);
  120. std::string GetSubdirTargetName(const char* pass, const char* subdir);
  121. std::string GetObjectFileName(const cmTarget& target,
  122. const cmSourceFile& source);
  123. std::string GetCustomBaseName(const cmCustomCommand& cc);
  124. const char* GetSourceFileLanguage(const cmSourceFile& source);
  125. std::string ConvertToFullPath(const std::string& localPath);
  126. void AddLanguageFlags(std::string& flags, const char* lang);
  127. void AddSharedFlags(std::string& flags, const char* lang, bool shared);
  128. void AddConfigVariableFlags(std::string& flags, const char* var);
  129. void AppendFlags(std::string& flags, const char* newFlags);
  130. void AppendLibDepends(const cmTarget& target,
  131. std::vector<std::string>& depends);
  132. void AppendLibDepend(std::vector<std::string>& depends, const char* name);
  133. std::string GetRecursiveMakeCall(const char* tgt);
  134. void WriteJumpAndBuildRules(std::ostream& makefileStream);
  135. static bool ScanDependenciesC(const char* objFile, const char* srcFile,
  136. std::vector<std::string> const& includes);
  137. static void CheckDependencies(const char* dir, const char* file);
  138. static void WriteEmptyDependMakeFile(const char* file,
  139. const char* depMarkFileFull,
  140. const char* depMakeFileFull);
  141. private:
  142. // Map from target name to build directory containing it for
  143. // jump-and-build targets.
  144. struct RemoteTarget
  145. {
  146. std::string m_BuildDirectory;
  147. std::string m_FilePath;
  148. };
  149. std::map<cmStdString, RemoteTarget> m_JumpAndBuild;
  150. // List the files for which to check dependency integrity.
  151. std::set<cmStdString> m_CheckDependFiles;
  152. // Command used when a rule has no dependencies or commands.
  153. std::vector<std::string> m_EmptyCommands;
  154. // List of make rule files that need to be included by the makefile.
  155. std::vector<std::string> m_IncludeRuleFiles;
  156. // Set of custom rule files that have been generated.
  157. std::set<cmStdString> m_CustomRuleFiles;
  158. // List of target-level rules for each pass. These are populated by
  159. // target rule file writing methods.
  160. std::vector<std::string> m_DependTargets;
  161. std::vector<std::string> m_BuildTargets;
  162. std::vector<std::string> m_InstallTargets;
  163. std::vector<std::string> m_CleanTargets;
  164. };
  165. #endif