cmMakefileTargetGenerator.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmMakefileTargetGenerator_h
  11. #define cmMakefileTargetGenerator_h
  12. #include "cmLocalUnixMakefileGenerator3.h"
  13. #include "cmOSXBundleGenerator.h"
  14. class cmCustomCommandGenerator;
  15. class cmDependInformation;
  16. class cmDepends;
  17. class cmGeneratorTarget;
  18. class cmGeneratedFileStream;
  19. class cmGlobalUnixMakefileGenerator3;
  20. class cmLocalUnixMakefileGenerator3;
  21. class cmMakefile;
  22. class cmTarget;
  23. class cmSourceFile;
  24. /** \class cmMakefileTargetGenerator
  25. * \brief Support Routines for writing makefiles
  26. *
  27. */
  28. class cmMakefileTargetGenerator
  29. {
  30. public:
  31. // constructor to set the ivars
  32. cmMakefileTargetGenerator(cmTarget* target);
  33. virtual ~cmMakefileTargetGenerator();
  34. // construct using this factory call
  35. static cmMakefileTargetGenerator *New(cmGeneratorTarget *tgt);
  36. /* the main entry point for this class. Writes the Makefiles associated
  37. with this target */
  38. virtual void WriteRuleFiles() = 0;
  39. /* return the number of actions that have progress reporting on them */
  40. virtual unsigned long GetNumberOfProgressActions() {
  41. return this->NumberOfProgressActions;}
  42. std::string GetProgressFileNameFull()
  43. { return this->ProgressFileNameFull; }
  44. cmTarget* GetTarget() { return this->Target;}
  45. protected:
  46. // create the file and directory etc
  47. void CreateRuleFile();
  48. // outputs the rules for object files and custom commands used by
  49. // this target
  50. void WriteTargetBuildRules();
  51. // write some common code at the top of build.make
  52. void WriteCommonCodeRules();
  53. void WriteTargetLanguageFlags();
  54. // write the provide require rules for this target
  55. void WriteTargetRequiresRules();
  56. // write the clean rules for this target
  57. void WriteTargetCleanRules();
  58. // write the depend rules for this target
  59. void WriteTargetDependRules();
  60. // write rules for Mac OS X Application Bundle content.
  61. struct MacOSXContentGeneratorType :
  62. cmOSXBundleGenerator::MacOSXContentGeneratorType
  63. {
  64. MacOSXContentGeneratorType(cmMakefileTargetGenerator* gen) :
  65. Generator(gen) {}
  66. void operator()(cmSourceFile const& source, const char* pkgloc);
  67. private:
  68. cmMakefileTargetGenerator* Generator;
  69. };
  70. friend struct MacOSXContentGeneratorType;
  71. // write the rules for an object
  72. void WriteObjectRuleFiles(cmSourceFile const& source);
  73. // write the build rule for an object
  74. void WriteObjectBuildFile(std::string &obj,
  75. const std::string& lang,
  76. cmSourceFile const& source,
  77. std::vector<std::string>& depends);
  78. // write the depend.make file for an object
  79. void WriteObjectDependRules(cmSourceFile const& source,
  80. std::vector<std::string>& depends);
  81. // write the build rule for a custom command
  82. void GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg);
  83. // write a rule to drive building of more than one output from
  84. // another rule
  85. void GenerateExtraOutput(const char* out, const char* in,
  86. bool symbolic = false);
  87. void AppendProgress(std::vector<std::string>& commands);
  88. // write out the variable that lists the objects for this target
  89. void WriteObjectsVariable(std::string& variableName,
  90. std::string& variableNameExternal,
  91. bool useWatcomQuote);
  92. void WriteObjectsString(std::string& buildObjs);
  93. void WriteObjectsStrings(std::vector<std::string>& objStrings,
  94. std::string::size_type limit = std::string::npos);
  95. // write the driver rule to build target outputs
  96. void WriteTargetDriverRule(const std::string& main_output, bool relink);
  97. void DriveCustomCommands(std::vector<std::string>& depends);
  98. // Return the a string with -F flags on apple
  99. std::string GetFrameworkFlags(std::string const& l);
  100. void AppendFortranFormatFlags(std::string& flags,
  101. cmSourceFile const& source);
  102. // append intertarget dependencies
  103. void AppendTargetDepends(std::vector<std::string>& depends);
  104. // Append object file dependencies.
  105. void AppendObjectDepends(std::vector<std::string>& depends);
  106. // Append link rule dependencies (objects, etc.).
  107. void AppendLinkDepends(std::vector<std::string>& depends);
  108. // Lookup the link rule for this target.
  109. std::string GetLinkRule(const std::string& linkRuleVar);
  110. /** In order to support parallel builds for custom commands with
  111. multiple outputs the outputs are given a serial order, and only
  112. the first output actually has the build rule. Other outputs
  113. just depend on the first one. The check-build-system step must
  114. remove a dependee if the depender is missing to make sure both
  115. are regenerated properly. This method is used by the local
  116. makefile generators to register such pairs. */
  117. void AddMultipleOutputPair(const char* depender, const char* dependee);
  118. /** Create a script to hold link rules and a command to invoke the
  119. script at build time. */
  120. void CreateLinkScript(const char* name,
  121. std::vector<std::string> const& link_commands,
  122. std::vector<std::string>& makefile_commands,
  123. std::vector<std::string>& makefile_depends);
  124. /** Create a response file with the given set of options. Returns
  125. the relative path from the target build working directory to the
  126. response file name. */
  127. std::string CreateResponseFile(const char* name,
  128. std::string const& options,
  129. std::vector<std::string>& makefile_depends);
  130. /** Create list of flags for link libraries. */
  131. void CreateLinkLibs(std::string& linkLibs, bool relink,
  132. bool useResponseFile,
  133. std::vector<std::string>& makefile_depends,
  134. bool useWatcomQuote);
  135. /** Create lists of object files for linking and cleaning. */
  136. void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
  137. bool useResponseFile, std::string& buildObjs,
  138. std::vector<std::string>& makefile_depends,
  139. bool useWatcomQuote);
  140. void AddIncludeFlags(std::string& flags, const std::string& lang);
  141. virtual void CloseFileStreams();
  142. void RemoveForbiddenFlags(const char* flagVar, const std::string& linkLang,
  143. std::string& linkFlags);
  144. cmTarget *Target;
  145. cmGeneratorTarget* GeneratorTarget;
  146. cmLocalUnixMakefileGenerator3 *LocalGenerator;
  147. cmGlobalUnixMakefileGenerator3 *GlobalGenerator;
  148. cmMakefile *Makefile;
  149. std::string ConfigName;
  150. enum CustomCommandDriveType { OnBuild, OnDepends, OnUtility };
  151. CustomCommandDriveType CustomCommandDriver;
  152. // the full path to the build file
  153. std::string BuildFileName;
  154. std::string BuildFileNameFull;
  155. // the full path to the progress file
  156. std::string ProgressFileNameFull;
  157. unsigned long NumberOfProgressActions;
  158. bool NoRuleMessages;
  159. // the path to the directory the build file is in
  160. std::string TargetBuildDirectory;
  161. std::string TargetBuildDirectoryFull;
  162. // the stream for the build file
  163. cmGeneratedFileStream *BuildFileStream;
  164. // the stream for the flag file
  165. std::string FlagFileNameFull;
  166. cmGeneratedFileStream *FlagFileStream;
  167. class StringList: public std::vector<std::string> {};
  168. std::map<std::string, StringList> FlagFileDepends;
  169. // the stream for the info file
  170. std::string InfoFileNameFull;
  171. cmGeneratedFileStream *InfoFileStream;
  172. // files to clean
  173. std::vector<std::string> CleanFiles;
  174. // objects used by this target
  175. std::vector<std::string> Objects;
  176. std::vector<std::string> ExternalObjects;
  177. // Set of object file names that will be built in this directory.
  178. std::set<std::string> ObjectFiles;
  179. // Set of extra output files to be driven by the build.
  180. std::set<std::string> ExtraFiles;
  181. typedef std::map<std::string, std::string> MultipleOutputPairsType;
  182. MultipleOutputPairsType MultipleOutputPairs;
  183. // Target name info.
  184. std::string TargetNameOut;
  185. std::string TargetNameSO;
  186. std::string TargetNameReal;
  187. std::string TargetNameImport;
  188. std::string TargetNamePDB;
  189. // Mac OS X content info.
  190. std::set<std::string> MacContentFolders;
  191. cmOSXBundleGenerator* OSXBundleGenerator;
  192. MacOSXContentGeneratorType* MacOSXContentGenerator;
  193. typedef std::map<std::string, std::string> ByLanguageMap;
  194. std::string GetFlags(const std::string &l);
  195. ByLanguageMap FlagsByLanguage;
  196. std::string GetDefines(const std::string &l);
  197. ByLanguageMap DefinesByLanguage;
  198. // Target-wide Fortran module output directory.
  199. bool FortranModuleDirectoryComputed;
  200. std::string FortranModuleDirectory;
  201. const char* GetFortranModuleDirectory();
  202. // Compute target-specific Fortran language flags.
  203. void AddFortranFlags(std::string& flags);
  204. // Helper to add flag for windows .def file.
  205. void AddModuleDefinitionFlag(std::string& flags);
  206. // Add language feature flags.
  207. void AddFeatureFlags(std::string& flags, const std::string& lang);
  208. // Feature query methods.
  209. const char* GetFeature(const std::string& feature);
  210. bool GetFeatureAsBool(const std::string& feature);
  211. //==================================================================
  212. // Convenience routines that do nothing more than forward to
  213. // implementaitons
  214. std::string Convert(const std::string& source,
  215. cmLocalGenerator::RelativeRoot relative,
  216. cmLocalGenerator::OutputFormat output =
  217. cmLocalGenerator::UNCHANGED,
  218. bool optional = false)
  219. {
  220. return this->LocalGenerator->Convert(source, relative, output, optional);
  221. }
  222. };
  223. #endif