cmLocalNinjaGenerator.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2011 Peter Collingbourne <[email protected]>
  4. Copyright 2011 Nicolas Despres <[email protected]>
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. #ifndef cmLocalNinjaGenerator_h
  12. # define cmLocalNinjaGenerator_h
  13. # include "cmLocalCommonGenerator.h"
  14. # include "cmNinjaTypes.h"
  15. class cmCustomCommandGenerator;
  16. class cmGlobalNinjaGenerator;
  17. class cmGeneratedFileStream;
  18. class cmake;
  19. /**
  20. * \class cmLocalNinjaGenerator
  21. * \brief Write a local build.ninja file.
  22. *
  23. * cmLocalNinjaGenerator produces a local build.ninja file from its
  24. * member Makefile.
  25. */
  26. class cmLocalNinjaGenerator : public cmLocalCommonGenerator
  27. {
  28. public:
  29. cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
  30. virtual ~cmLocalNinjaGenerator();
  31. virtual void Generate();
  32. virtual
  33. std::string GetTargetDirectory(cmGeneratorTarget const* target) const;
  34. const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
  35. cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
  36. const cmake* GetCMakeInstance() const;
  37. cmake* GetCMakeInstance();
  38. /// @returns the relative path between the HomeOutputDirectory and this
  39. /// local generators StartOutputDirectory.
  40. std::string GetHomeRelativeOutputPath() const
  41. { return this->HomeRelativeOutputPath; }
  42. void ExpandRuleVariables(std::string& string,
  43. const RuleVariables& replaceValues) {
  44. cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
  45. }
  46. std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
  47. void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
  48. void AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs);
  49. void AddCustomCommandTarget(cmCustomCommand const* cc,
  50. cmGeneratorTarget* target);
  51. void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
  52. std::vector<std::string> &cmdLines);
  53. void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
  54. cmNinjaDeps &ninjaDeps);
  55. virtual std::string ConvertToLinkReference(std::string const& lib,
  56. OutputFormat format = SHELL);
  57. virtual void ComputeObjectFilenames(
  58. std::map<cmSourceFile const*, std::string>& mapping,
  59. cmGeneratorTarget const* gt = 0);
  60. protected:
  61. virtual std::string ConvertToIncludeReference(std::string const& path,
  62. OutputFormat format = SHELL,
  63. bool forceFullPaths = false);
  64. private:
  65. cmGeneratedFileStream& GetBuildFileStream() const;
  66. cmGeneratedFileStream& GetRulesFileStream() const;
  67. void WriteBuildFileTop();
  68. void WriteProjectHeader(std::ostream& os);
  69. void WriteNinjaRequiredVersion(std::ostream& os);
  70. void WriteNinjaFilesInclusion(std::ostream& os);
  71. void WriteProcessedMakefile(std::ostream& os);
  72. void WritePools(std::ostream& os);
  73. void WriteCustomCommandRule();
  74. void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
  75. const cmNinjaDeps& orderOnlyDeps);
  76. void WriteCustomCommandBuildStatements();
  77. std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
  78. std::string HomeRelativeOutputPath;
  79. typedef std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*> >
  80. CustomCommandTargetMap;
  81. CustomCommandTargetMap CustomCommandTargets;
  82. std::vector<cmCustomCommand const*> CustomCommands;
  83. };
  84. #endif // ! cmLocalNinjaGenerator_h