cmLocalNinjaGenerator.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmLocalNinjaGenerator_h
  4. #define cmLocalNinjaGenerator_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <iosfwd>
  7. #include <map>
  8. #include <set>
  9. #include <string>
  10. #include <vector>
  11. #include "cmLocalCommonGenerator.h"
  12. #include "cmNinjaTypes.h"
  13. #include "cmOutputConverter.h"
  14. class cmCustomCommand;
  15. class cmCustomCommandGenerator;
  16. class cmGeneratedFileStream;
  17. class cmGeneratorTarget;
  18. class cmGlobalGenerator;
  19. class cmGlobalNinjaGenerator;
  20. class cmMakefile;
  21. class cmRulePlaceholderExpander;
  22. class cmake;
  23. /**
  24. * \class cmLocalNinjaGenerator
  25. * \brief Write a local build.ninja file.
  26. *
  27. * cmLocalNinjaGenerator produces a local build.ninja file from its
  28. * member Makefile.
  29. */
  30. class cmLocalNinjaGenerator : public cmLocalCommonGenerator
  31. {
  32. public:
  33. cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
  34. ~cmLocalNinjaGenerator() override;
  35. void Generate() override;
  36. cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const override;
  37. std::string GetTargetDirectory(
  38. cmGeneratorTarget const* target) const override;
  39. const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
  40. cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
  41. const cmake* GetCMakeInstance() const;
  42. cmake* GetCMakeInstance();
  43. /// @returns the relative path between the HomeOutputDirectory and this
  44. /// local generators StartOutputDirectory.
  45. std::string GetHomeRelativeOutputPath() const
  46. {
  47. return this->HomeRelativeOutputPath;
  48. }
  49. std::string BuildCommandLine(const std::vector<std::string>& cmdLines);
  50. void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
  51. void AppendTargetDepends(
  52. cmGeneratorTarget* target, cmNinjaDeps& outputs,
  53. cmNinjaTargetDepends depends = DependOnTargetArtifact);
  54. void AddCustomCommandTarget(cmCustomCommand const* cc,
  55. cmGeneratorTarget* target);
  56. void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
  57. std::vector<std::string>& cmdLines);
  58. void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
  59. cmNinjaDeps& ninjaDeps);
  60. protected:
  61. std::string ConvertToIncludeReference(
  62. std::string const& path,
  63. cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
  64. bool forceFullPaths = false) override;
  65. private:
  66. cmGeneratedFileStream& GetBuildFileStream() const;
  67. cmGeneratedFileStream& GetRulesFileStream() const;
  68. void WriteBuildFileTop();
  69. void WriteProjectHeader(std::ostream& os);
  70. void WriteNinjaRequiredVersion(std::ostream& os);
  71. void WriteNinjaFilesInclusion(std::ostream& os);
  72. void WriteProcessedMakefile(std::ostream& os);
  73. void WritePools(std::ostream& os);
  74. void WriteCustomCommandRule();
  75. void WriteCustomCommandBuildStatement(cmCustomCommand const* cc,
  76. const cmNinjaDeps& orderOnlyDeps);
  77. void WriteCustomCommandBuildStatements();
  78. std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
  79. std::string HomeRelativeOutputPath;
  80. typedef std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*>>
  81. CustomCommandTargetMap;
  82. CustomCommandTargetMap CustomCommandTargets;
  83. std::vector<cmCustomCommand const*> CustomCommands;
  84. };
  85. #endif // ! cmLocalNinjaGenerator_h