cmLocalNinjaGenerator.h 3.5 KB

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