cmMakefileTargetGenerator.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. class cmCustomCommand;
  14. class cmDependInformation;
  15. class cmDepends;
  16. class cmGeneratedFileStream;
  17. class cmGlobalUnixMakefileGenerator3;
  18. class cmLocalUnixMakefileGenerator3;
  19. class cmMakefile;
  20. class cmTarget;
  21. class cmSourceFile;
  22. /** \class cmMakefileTargetGenerator
  23. * \brief Support Routines for writing makefiles
  24. *
  25. */
  26. class cmMakefileTargetGenerator
  27. {
  28. public:
  29. // constructor to set the ivars
  30. cmMakefileTargetGenerator(cmTarget* target);
  31. virtual ~cmMakefileTargetGenerator() {};
  32. // construct using this factory call
  33. static cmMakefileTargetGenerator *New(cmTarget *tgt);
  34. /* the main entry point for this class. Writes the Makefiles associated
  35. with this target */
  36. virtual void WriteRuleFiles() = 0;
  37. /* return the number of actions that have progress reporting on them */
  38. virtual unsigned long GetNumberOfProgressActions() {
  39. return this->NumberOfProgressActions;}
  40. std::string GetProgressFileNameFull()
  41. { return this->ProgressFileNameFull; }
  42. cmTarget* GetTarget() { return this->Target;}
  43. protected:
  44. // create the file and directory etc
  45. void CreateRuleFile();
  46. // outputs the rules for object files and custom commands used by
  47. // this target
  48. void WriteTargetBuildRules();
  49. // write some common code at the top of build.make
  50. void WriteCommonCodeRules();
  51. void WriteTargetLanguageFlags();
  52. // write the provide require rules for this target
  53. void WriteTargetRequiresRules();
  54. // write the clean rules for this target
  55. void WriteTargetCleanRules();
  56. // write the depend rules for this target
  57. void WriteTargetDependRules();
  58. // write rules for Mac OS X Application Bundle content.
  59. void WriteMacOSXContentRules(cmSourceFile& source, const char* pkgloc);
  60. // write the rules for an object
  61. void WriteObjectRuleFiles(cmSourceFile& source);
  62. // write the build rule for an object
  63. void WriteObjectBuildFile(std::string &obj,
  64. const char *lang,
  65. cmSourceFile& source,
  66. std::vector<std::string>& depends);
  67. // write the depend.make file for an object
  68. void WriteObjectDependRules(cmSourceFile& source,
  69. std::vector<std::string>& depends);
  70. // write the build rule for a custom command
  71. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  72. // write a rule to drive building of more than one output from
  73. // another rule
  74. void GenerateExtraOutput(const char* out, const char* in,
  75. bool symbolic = false);
  76. void AppendProgress(std::vector<std::string>& commands);
  77. // write out the variable that lists the objects for this target
  78. void WriteObjectsVariable(std::string& variableName,
  79. std::string& variableNameExternal);
  80. void WriteObjectsString(std::string& buildObjs);
  81. void WriteObjectsStrings(std::vector<std::string>& objStrings,
  82. std::string::size_type limit = std::string::npos);
  83. // write the driver rule to build target outputs
  84. void WriteTargetDriverRule(const char* main_output, bool relink);
  85. void DriveCustomCommands(std::vector<std::string>& depends);
  86. // Return the a string with -F flags on apple
  87. std::string GetFrameworkFlags();
  88. // append intertarget dependencies
  89. void AppendTargetDepends(std::vector<std::string>& depends);
  90. /** In order to support parallel builds for custom commands with
  91. multiple outputs the outputs are given a serial order, and only
  92. the first output actually has the build rule. Other outputs
  93. just depend on the first one. The check-build-system step must
  94. remove a dependee if the depender is missing to make sure both
  95. are regenerated properly. This method is used by the local
  96. makefile generators to register such pairs. */
  97. void AddMultipleOutputPair(const char* depender, const char* dependee);
  98. /** Create a script to hold link rules and a command to invoke the
  99. script at build time. */
  100. void CreateLinkScript(const char* name,
  101. std::vector<std::string> const& link_commands,
  102. std::vector<std::string>& makefile_commands,
  103. std::vector<std::string>& makefile_depends);
  104. /** Create a response file with the given set of options. Returns
  105. the relative path from the target build working directory to the
  106. response file name. */
  107. std::string CreateResponseFile(const char* name,
  108. std::string const& options,
  109. std::vector<std::string>& makefile_depends);
  110. /** Create lists of object files for linking and cleaning. */
  111. void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
  112. bool useResponseFile, std::string& buildObjs,
  113. std::vector<std::string>& makefile_depends);
  114. virtual void CloseFileStreams();
  115. void RemoveForbiddenFlags(const char* flagVar, const char* linkLang,
  116. std::string& linkFlags);
  117. cmTarget *Target;
  118. cmLocalUnixMakefileGenerator3 *LocalGenerator;
  119. cmGlobalUnixMakefileGenerator3 *GlobalGenerator;
  120. cmMakefile *Makefile;
  121. const char *ConfigName;
  122. enum CustomCommandDriveType { OnBuild, OnDepends, OnUtility };
  123. CustomCommandDriveType CustomCommandDriver;
  124. // the full path to the build file
  125. std::string BuildFileName;
  126. std::string BuildFileNameFull;
  127. // the full path to the progress file
  128. std::string ProgressFileNameFull;
  129. unsigned long NumberOfProgressActions;
  130. bool NoRuleMessages;
  131. // the path to the directory the build file is in
  132. std::string TargetBuildDirectory;
  133. std::string TargetBuildDirectoryFull;
  134. // the stream for the build file
  135. cmGeneratedFileStream *BuildFileStream;
  136. // the stream for the flag file
  137. std::string FlagFileNameFull;
  138. cmGeneratedFileStream *FlagFileStream;
  139. // the stream for the info file
  140. std::string InfoFileNameFull;
  141. cmGeneratedFileStream *InfoFileStream;
  142. // files to clean
  143. std::vector<std::string> CleanFiles;
  144. // objects used by this target
  145. std::vector<std::string> Objects;
  146. std::vector<std::string> ExternalObjects;
  147. // Set of object file names that will be built in this directory.
  148. std::set<cmStdString> ObjectFiles;
  149. // Set of extra output files to be driven by the build.
  150. std::set<cmStdString> ExtraFiles;
  151. typedef std::map<cmStdString, cmStdString> MultipleOutputPairsType;
  152. MultipleOutputPairsType MultipleOutputPairs;
  153. // Target name info.
  154. std::string TargetNameOut;
  155. std::string TargetNameSO;
  156. std::string TargetNameReal;
  157. std::string TargetNameImport;
  158. std::string TargetNamePDB;
  159. // Mac OS X content info.
  160. std::string MacContentDirectory;
  161. std::set<cmStdString> MacContentFolders;
  162. // Target-wide Fortran module output directory.
  163. bool FortranModuleDirectoryComputed;
  164. std::string FortranModuleDirectory;
  165. const char* GetFortranModuleDirectory();
  166. // Compute target-specific Fortran language flags.
  167. void AddFortranFlags(std::string& flags);
  168. //==================================================================
  169. // Convenience routines that do nothing more than forward to
  170. // implementaitons
  171. std::string Convert(const char* source,
  172. cmLocalGenerator::RelativeRoot relative,
  173. cmLocalGenerator::OutputFormat output =
  174. cmLocalGenerator::UNCHANGED,
  175. bool optional = false)
  176. {
  177. return this->LocalGenerator->Convert(source, relative, output, optional);
  178. }
  179. };
  180. #endif