cmMakefileTargetGenerator.h 7.4 KB

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