cmLocalNinjaGenerator.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 cmSourceFile;
  23. class cmake;
  24. /**
  25. * \class cmLocalNinjaGenerator
  26. * \brief Write a local build.ninja file.
  27. *
  28. * cmLocalNinjaGenerator produces a local build.ninja file from its
  29. * member Makefile.
  30. */
  31. class cmLocalNinjaGenerator : public cmLocalCommonGenerator
  32. {
  33. public:
  34. cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
  35. ~cmLocalNinjaGenerator() CM_OVERRIDE;
  36. void Generate() CM_OVERRIDE;
  37. cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const CM_OVERRIDE;
  38. std::string GetTargetDirectory(cmGeneratorTarget const* target) const
  39. CM_OVERRIDE;
  40. const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
  41. cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
  42. const cmake* GetCMakeInstance() const;
  43. cmake* GetCMakeInstance();
  44. /// @returns the relative path between the HomeOutputDirectory and this
  45. /// local generators StartOutputDirectory.
  46. std::string GetHomeRelativeOutputPath() const
  47. {
  48. return this->HomeRelativeOutputPath;
  49. }
  50. std::string BuildCommandLine(const std::vector<std::string>& cmdLines);
  51. void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
  52. void AppendTargetDepends(
  53. cmGeneratorTarget* target, cmNinjaDeps& outputs,
  54. cmNinjaTargetDepends depends = DependOnTargetArtifact);
  55. void AddCustomCommandTarget(cmCustomCommand const* cc,
  56. cmGeneratorTarget* target);
  57. void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
  58. std::vector<std::string>& cmdLines);
  59. void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
  60. cmNinjaDeps& ninjaDeps);
  61. void ComputeObjectFilenames(
  62. std::map<cmSourceFile const*, std::string>& mapping,
  63. cmGeneratorTarget const* gt = nullptr) CM_OVERRIDE;
  64. protected:
  65. std::string ConvertToIncludeReference(
  66. std::string const& path,
  67. cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
  68. bool forceFullPaths = false) CM_OVERRIDE;
  69. private:
  70. cmGeneratedFileStream& GetBuildFileStream() const;
  71. cmGeneratedFileStream& GetRulesFileStream() const;
  72. void WriteBuildFileTop();
  73. void WriteProjectHeader(std::ostream& os);
  74. void WriteNinjaRequiredVersion(std::ostream& os);
  75. void WriteNinjaFilesInclusion(std::ostream& os);
  76. void WriteProcessedMakefile(std::ostream& os);
  77. void WritePools(std::ostream& os);
  78. void WriteCustomCommandRule();
  79. void WriteCustomCommandBuildStatement(cmCustomCommand const* cc,
  80. const cmNinjaDeps& orderOnlyDeps);
  81. void WriteCustomCommandBuildStatements();
  82. std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
  83. std::string HomeRelativeOutputPath;
  84. typedef std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*>>
  85. CustomCommandTargetMap;
  86. CustomCommandTargetMap CustomCommandTargets;
  87. std::vector<cmCustomCommand const*> CustomCommands;
  88. };
  89. #endif // ! cmLocalNinjaGenerator_h