cmLocalNinjaGenerator.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 "cmLocalGenerator.h"
  14. # include "cmNinjaTypes.h"
  15. class cmGlobalNinjaGenerator;
  16. class cmGeneratedFileStream;
  17. class cmake;
  18. /**
  19. * \class cmLocalNinjaGenerator
  20. * \brief Write a local build.ninja file.
  21. *
  22. * cmLocalNinjaGenerator produces a local build.ninja file from its
  23. * member Makefile.
  24. */
  25. class cmLocalNinjaGenerator : public cmLocalGenerator
  26. {
  27. public:
  28. /// Default constructor.
  29. cmLocalNinjaGenerator();
  30. /// Destructor.
  31. virtual ~cmLocalNinjaGenerator();
  32. /// Overloaded methods. @see cmLocalGenerator::Generate()
  33. virtual void Generate();
  34. /// Overloaded methods. @see cmLocalGenerator::Configure()
  35. virtual void Configure();
  36. /// Overloaded methods. @see cmLocalGenerator::GetTargetDirectory()
  37. virtual std::string GetTargetDirectory(cmTarget const& target) const;
  38. public:
  39. const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
  40. cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
  41. /**
  42. * Shortcut to get the cmake instance throw the global generator.
  43. * @return an instance of the cmake object.
  44. */
  45. const cmake* GetCMakeInstance() const;
  46. cmake* GetCMakeInstance();
  47. const char* GetConfigName() const
  48. { return this->ConfigName.c_str(); }
  49. /// @return whether we are processing the top CMakeLists.txt file.
  50. bool isRootMakefile() const;
  51. /// @returns the relative path between the HomeOutputDirectory and this
  52. /// local generators StartOutputDirectory.
  53. std::string GetHomeRelativeOutputPath() const
  54. { return this->HomeRelativeOutputPath; }
  55. protected:
  56. virtual std::string ConvertToLinkReference(std::string const& lib);
  57. virtual std::string ConvertToIncludeReference(std::string const& path);
  58. private:
  59. friend class cmGlobalNinjaGenerator;
  60. // In order to access to protected member of the local generator.
  61. friend class cmNinjaTargetGenerator;
  62. friend class cmNinjaNormalTargetGenerator;
  63. friend class cmNinjaUtilityTargetGenerator;
  64. private:
  65. cmGeneratedFileStream& GetBuildFileStream() const;
  66. cmGeneratedFileStream& GetRulesFileStream() const;
  67. void WriteBuildFileTop();
  68. void WriteProjectHeader(std::ostream& os);
  69. void WriteNinjaFilesInclusion(std::ostream& os);
  70. void WriteProcessedMakefile(std::ostream& os);
  71. void SetConfigName();
  72. std::string ConvertToNinjaPath(const char *path);
  73. struct map_to_ninja_path;
  74. friend struct map_to_ninja_path;
  75. struct map_to_ninja_path {
  76. cmLocalNinjaGenerator *LocalGenerator;
  77. map_to_ninja_path(cmLocalNinjaGenerator *LocalGen)
  78. : LocalGenerator(LocalGen) {}
  79. std::string operator()(const std::string &path) {
  80. return LocalGenerator->ConvertToNinjaPath(path.c_str());
  81. }
  82. };
  83. map_to_ninja_path MapToNinjaPath() {
  84. return map_to_ninja_path(this);
  85. }
  86. void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
  87. void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
  88. void AppendCustomCommandDeps(const cmCustomCommand *cc,
  89. cmNinjaDeps &ninjaDeps);
  90. std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
  91. void AppendCustomCommandLines(const cmCustomCommand *cc,
  92. std::vector<std::string> &cmdLines);
  93. void WriteCustomCommandRule();
  94. void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
  95. const cmNinjaDeps& orderOnlyDeps);
  96. void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target);
  97. void WriteCustomCommandBuildStatements();
  98. private:
  99. std::string ConfigName;
  100. std::string HomeRelativeOutputPath;
  101. typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
  102. CustomCommandTargetMap;
  103. CustomCommandTargetMap CustomCommandTargets;
  104. };
  105. #endif // ! cmLocalNinjaGenerator_h