cmMakefileTargetGenerator.h 7.9 KB

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