cmMakefileTargetGenerator.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 cmGlobalGenerator;
  21. class cmLocalUnixMakefileGenerator3;
  22. class cmMakeDepend;
  23. class cmMakefile;
  24. class cmTarget;
  25. class cmSourceFile;
  26. /** \class cmMakefileTargetGenerator
  27. * \brief Support Routines for writing makefiles
  28. *
  29. */
  30. class cmMakefileTargetGenerator
  31. {
  32. public:
  33. // constructor to set the ivars
  34. cmMakefileTargetGenerator();
  35. virtual ~cmMakefileTargetGenerator() {};
  36. // construct using this factory call
  37. static cmMakefileTargetGenerator *New(cmLocalUnixMakefileGenerator3 *lg,
  38. cmStdString tgtName,
  39. cmTarget *tgt);
  40. /* the main entry point for this class. Writes the Makefiles associated
  41. with this target */
  42. virtual void WriteRuleFiles() = 0;
  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 the rules for an object
  59. void WriteObjectRuleFiles(cmSourceFile& source);
  60. // write the build rule for an object
  61. void WriteObjectBuildFile(std::string &obj,
  62. const char *lang,
  63. cmSourceFile& source,
  64. std::vector<std::string>& depends);
  65. // write the depend.make file for an object
  66. void WriteObjectDependRules(cmSourceFile& source,
  67. std::vector<std::string>& depends);
  68. // write the build rule for a custom command
  69. void GenerateCustomRuleFile(const cmCustomCommand& cc);
  70. // write out the variable that lists the objects for this target
  71. void WriteObjectsVariable(std::string& variableName,
  72. std::string& variableNameExternal);
  73. void WriteObjectsString(std::string& buildObjs);
  74. // write the driver rule to build target outputs
  75. void WriteTargetDriverRule(const char* main_output, bool relink);
  76. // Return the a string with -F flags on apple
  77. std::string GetFrameworkFlags();
  78. // append intertarget dependencies
  79. void AppendTargetDepends(std::vector<std::string>& depends);
  80. virtual void CloseFileStreams();
  81. void RemoveForbiddenFlags(const char* flagVar, const char* linkLang,
  82. std::string& linkFlags);
  83. cmStdString TargetName;
  84. cmTarget *Target;
  85. cmLocalUnixMakefileGenerator3 *LocalGenerator;
  86. cmGlobalGenerator *GlobalGenerator;
  87. cmMakefile *Makefile;
  88. // the full path to the build file
  89. std::string BuildFileName;
  90. std::string BuildFileNameFull;
  91. // the path to the directory the build file is in
  92. std::string TargetBuildDirectory;
  93. std::string TargetBuildDirectoryFull;
  94. // the stream for the build file
  95. cmGeneratedFileStream *BuildFileStream;
  96. // the stream for the flag file
  97. std::string FlagFileNameFull;
  98. cmGeneratedFileStream *FlagFileStream;
  99. // the stream for the info file
  100. std::string InfoFileNameFull;
  101. cmGeneratedFileStream *InfoFileStream;
  102. // files to clean
  103. std::vector<std::string> CleanFiles;
  104. // objects used by this target
  105. std::vector<std::string> Objects;
  106. std::vector<std::string> ExternalObjects;
  107. std::set<std::string> ExtraContent;
  108. // Set of object file names that will be built in this directory.
  109. std::set<cmStdString> ObjectFiles;
  110. //==================================================================
  111. // Convenience routines that do nothing more than forward to
  112. // implementaitons
  113. std::string Convert(const char* source,
  114. cmLocalGenerator::RelativeRoot relative,
  115. cmLocalGenerator::OutputFormat output =
  116. cmLocalGenerator::UNCHANGED,
  117. bool optional = false)
  118. {
  119. return this->LocalGenerator->Convert(source, relative, output, optional);
  120. }
  121. };
  122. #endif