You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
5.9 KiB

  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 the rules for an object
  67. void WriteObjectRuleFiles(cmSourceFile& source);
  68. // write the build rule for an object
  69. void WriteObjectBuildFile(std::string &obj,
  70. const char *lang,
  71. cmSourceFile& source,
  72. std::vector<std::string>& depends);
  73. // write the depend.make file for an object
  74. void WriteObjectDependRules(cmSourceFile& source,
  75. std::vector<std::string>& depends);
  76. // write the build rule for a custom command
  77. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  78. // write a rule to drive building of more than one output from
  79. // another rule
  80. void GenerateExtraOutput(const char* out, const char* in,
  81. bool symbolic = false);
  82. // write out the variable that lists the objects for this target
  83. void WriteObjectsVariable(std::string& variableName,
  84. std::string& variableNameExternal);
  85. void WriteObjectsString(std::string& buildObjs);
  86. // write the driver rule to build target outputs
  87. void WriteTargetDriverRule(const char* main_output, bool relink);
  88. void DriveCustomCommands(std::vector<std::string>& depends);
  89. // Return the a string with -F flags on apple
  90. std::string GetFrameworkFlags();
  91. // append intertarget dependencies
  92. void AppendTargetDepends(std::vector<std::string>& depends);
  93. virtual void CloseFileStreams();
  94. void RemoveForbiddenFlags(const char* flagVar, const char* linkLang,
  95. std::string& linkFlags);
  96. cmStdString TargetName;
  97. cmTarget *Target;
  98. cmLocalUnixMakefileGenerator3 *LocalGenerator;
  99. cmGlobalUnixMakefileGenerator3 *GlobalGenerator;
  100. cmMakefile *Makefile;
  101. enum CustomCommandDriveType { OnBuild, OnDepends, OnUtility };
  102. CustomCommandDriveType CustomCommandDriver;
  103. // the full path to the build file
  104. std::string BuildFileName;
  105. std::string BuildFileNameFull;
  106. // the full path to the progress file
  107. std::string ProgressFileName;
  108. std::string ProgressFileNameFull;
  109. unsigned long NumberOfProgressActions;
  110. // the path to the directory the build file is in
  111. std::string TargetBuildDirectory;
  112. std::string TargetBuildDirectoryFull;
  113. // the stream for the build file
  114. cmGeneratedFileStream *BuildFileStream;
  115. // the stream for the flag file
  116. std::string FlagFileNameFull;
  117. cmGeneratedFileStream *FlagFileStream;
  118. // the stream for the info file
  119. std::string InfoFileNameFull;
  120. cmGeneratedFileStream *InfoFileStream;
  121. // files to clean
  122. std::vector<std::string> CleanFiles;
  123. // objects used by this target
  124. std::vector<std::string> Objects;
  125. std::vector<std::string> ExternalObjects;
  126. std::set<std::string> ExtraContent;
  127. // Set of object file names that will be built in this directory.
  128. std::set<cmStdString> ObjectFiles;
  129. //==================================================================
  130. // Convenience routines that do nothing more than forward to
  131. // implementaitons
  132. std::string Convert(const char* source,
  133. cmLocalGenerator::RelativeRoot relative,
  134. cmLocalGenerator::OutputFormat output =
  135. cmLocalGenerator::UNCHANGED,
  136. bool optional = false)
  137. {
  138. return this->LocalGenerator->Convert(source, relative, output, optional);
  139. }
  140. };
  141. #endif