cmLocalNinjaGenerator.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2011 Peter Collingbourne <[email protected]>
  4. Copyright 2011 Nicolas Despres <[email protected]>
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. #ifndef cmLocalNinjaGenerator_h
  12. # define cmLocalNinjaGenerator_h
  13. # include "cmLocalGenerator.h"
  14. # include "cmNinjaTypes.h"
  15. class cmGlobalNinjaGenerator;
  16. class cmGeneratedFileStream;
  17. class cmake;
  18. /**
  19. * \class cmLocalNinjaGenerator
  20. * \brief Write a local build.ninja file.
  21. *
  22. * cmLocalNinjaGenerator produces a local build.ninja file from its
  23. * member Makefile.
  24. */
  25. class cmLocalNinjaGenerator : public cmLocalGenerator
  26. {
  27. public:
  28. /// Default constructor.
  29. cmLocalNinjaGenerator();
  30. /// Destructor.
  31. virtual ~cmLocalNinjaGenerator();
  32. /// Overloaded methods. @see cmLocalGenerator::Generate()
  33. virtual void Generate();
  34. /// Overloaded methods. @see cmLocalGenerator::Configure()
  35. virtual void Configure();
  36. /// Overloaded methods. @see cmLocalGenerator::GetTargetDirectory()
  37. virtual std::string GetTargetDirectory(cmTarget const& target) const;
  38. const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
  39. cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
  40. /**
  41. * Shortcut to get the cmake instance throw the global generator.
  42. * @return an instance of the cmake object.
  43. */
  44. const cmake* GetCMakeInstance() const;
  45. cmake* GetCMakeInstance();
  46. const char* GetConfigName() const
  47. { return this->ConfigName.c_str(); }
  48. /// @return whether we are processing the top CMakeLists.txt file.
  49. bool isRootMakefile() const;
  50. /// @returns the relative path between the HomeOutputDirectory and this
  51. /// local generators StartOutputDirectory.
  52. std::string GetHomeRelativeOutputPath() const
  53. { return this->HomeRelativeOutputPath; }
  54. std::string ConvertToNinjaPath(const char *path);
  55. struct map_to_ninja_path {
  56. cmLocalNinjaGenerator *LocalGenerator;
  57. map_to_ninja_path(cmLocalNinjaGenerator *LocalGen)
  58. : LocalGenerator(LocalGen) {}
  59. std::string operator()(const std::string &path) {
  60. return LocalGenerator->ConvertToNinjaPath(path.c_str());
  61. }
  62. };
  63. map_to_ninja_path MapToNinjaPath() {
  64. return map_to_ninja_path(this);
  65. }
  66. void ExpandRuleVariables(std::string& string,
  67. const RuleVariables& replaceValues) {
  68. cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
  69. }
  70. std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
  71. void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
  72. void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
  73. void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target);
  74. void AppendCustomCommandLines(const cmCustomCommand *cc,
  75. std::vector<std::string> &cmdLines);
  76. void AppendCustomCommandDeps(const cmCustomCommand *cc,
  77. cmNinjaDeps &ninjaDeps);
  78. virtual std::string ConvertToLinkReference(std::string const& lib);
  79. protected:
  80. virtual std::string ConvertToIncludeReference(std::string const& path);
  81. private:
  82. cmGeneratedFileStream& GetBuildFileStream() const;
  83. cmGeneratedFileStream& GetRulesFileStream() const;
  84. void WriteBuildFileTop();
  85. void WriteProjectHeader(std::ostream& os);
  86. void WriteNinjaFilesInclusion(std::ostream& os);
  87. void WriteProcessedMakefile(std::ostream& os);
  88. void WritePools(std::ostream& os);
  89. void SetConfigName();
  90. void WriteCustomCommandRule();
  91. void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
  92. const cmNinjaDeps& orderOnlyDeps);
  93. void WriteCustomCommandBuildStatements();
  94. std::string MakeCustomLauncher(const cmCustomCommand& cc);
  95. std::string ConfigName;
  96. std::string HomeRelativeOutputPath;
  97. typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
  98. CustomCommandTargetMap;
  99. CustomCommandTargetMap CustomCommandTargets;
  100. };
  101. #endif // ! cmLocalNinjaGenerator_h