cmLocalNinjaGenerator.h 3.6 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>
  6. #include "cmLocalCommonGenerator.h"
  7. #include "cmLocalGenerator.h"
  8. #include "cmNinjaTypes.h"
  9. #include "cmOutputConverter.h"
  10. #include <iosfwd>
  11. #include <map>
  12. #include <set>
  13. #include <string>
  14. #include <vector>
  15. class cmCustomCommand;
  16. class cmCustomCommandGenerator;
  17. class cmGeneratedFileStream;
  18. class cmGeneratorTarget;
  19. class cmGlobalGenerator;
  20. class cmGlobalNinjaGenerator;
  21. class cmMakefile;
  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. std::string GetTargetDirectory(cmGeneratorTarget const* target) const
  38. CM_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. void ExpandRuleVariables(std::string& string,
  50. const RuleVariables& replaceValues)
  51. {
  52. cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
  53. }
  54. std::string BuildCommandLine(const std::vector<std::string>& cmdLines);
  55. void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
  56. void AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs);
  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. std::string ConvertToLinkReference(std::string const& lib) CM_OVERRIDE;
  64. void ComputeObjectFilenames(
  65. std::map<cmSourceFile const*, std::string>& mapping,
  66. cmGeneratorTarget const* gt = CM_NULLPTR) CM_OVERRIDE;
  67. protected:
  68. std::string ConvertToIncludeReference(
  69. std::string const& path,
  70. cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
  71. bool forceFullPaths = false) CM_OVERRIDE;
  72. private:
  73. cmGeneratedFileStream& GetBuildFileStream() const;
  74. cmGeneratedFileStream& GetRulesFileStream() const;
  75. void WriteBuildFileTop();
  76. void WriteProjectHeader(std::ostream& os);
  77. void WriteNinjaRequiredVersion(std::ostream& os);
  78. void WriteNinjaFilesInclusion(std::ostream& os);
  79. void WriteProcessedMakefile(std::ostream& os);
  80. void WritePools(std::ostream& os);
  81. void WriteCustomCommandRule();
  82. void WriteCustomCommandBuildStatement(cmCustomCommand const* cc,
  83. const cmNinjaDeps& orderOnlyDeps);
  84. void WriteCustomCommandBuildStatements();
  85. std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
  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