cmLocalNinjaGenerator.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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(
  50. std::vector<std::string> const& cmdLines,
  51. std::string const& customStep = std::string(),
  52. cmGeneratorTarget const* target = nullptr) const;
  53. void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
  54. void AppendTargetDepends(
  55. cmGeneratorTarget* target, cmNinjaDeps& outputs,
  56. cmNinjaTargetDepends depends = DependOnTargetArtifact);
  57. void AddCustomCommandTarget(cmCustomCommand const* cc,
  58. cmGeneratorTarget* target);
  59. void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
  60. std::vector<std::string>& cmdLines);
  61. void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
  62. cmNinjaDeps& ninjaDeps);
  63. protected:
  64. std::string ConvertToIncludeReference(
  65. std::string const& path,
  66. cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
  67. bool forceFullPaths = false) override;
  68. private:
  69. cmGeneratedFileStream& GetBuildFileStream() const;
  70. cmGeneratedFileStream& GetRulesFileStream() const;
  71. void WriteBuildFileTop();
  72. void WriteProjectHeader(std::ostream& os);
  73. void WriteNinjaRequiredVersion(std::ostream& os);
  74. void WriteNinjaFilesInclusion(std::ostream& os);
  75. void WriteProcessedMakefile(std::ostream& os);
  76. void WritePools(std::ostream& os);
  77. void WriteCustomCommandRule();
  78. void WriteCustomCommandBuildStatement(cmCustomCommand const* cc,
  79. const cmNinjaDeps& orderOnlyDeps);
  80. void WriteCustomCommandBuildStatements();
  81. std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
  82. std::string WriteCommandScript(std::vector<std::string> const& cmdLines,
  83. std::string const& customStep,
  84. cmGeneratorTarget const* target) const;
  85. void AdditionalCleanFiles();
  86. std::string HomeRelativeOutputPath;
  87. typedef std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*>>
  88. CustomCommandTargetMap;
  89. CustomCommandTargetMap CustomCommandTargets;
  90. std::vector<cmCustomCommand const*> CustomCommands;
  91. };
  92. #endif // ! cmLocalNinjaGenerator_h