cmNinjaTargetGenerator.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 cmNinjaTargetGenerator_h
  12. #define cmNinjaTargetGenerator_h
  13. #include "cmStandardIncludes.h"
  14. #include "cmNinjaTypes.h"
  15. #include "cmLocalNinjaGenerator.h"
  16. class cmTarget;
  17. class cmGlobalNinjaGenerator;
  18. class cmGeneratedFileStream;
  19. class cmMakefile;
  20. class cmSourceFile;
  21. class cmCustomCommand;
  22. class cmNinjaTargetGenerator
  23. {
  24. public:
  25. /// Create a cmNinjaTargetGenerator according to the @a target's type.
  26. static cmNinjaTargetGenerator* New(cmTarget* target);
  27. /// Build a NinjaTargetGenerator.
  28. cmNinjaTargetGenerator(cmTarget* target);
  29. /// Destructor.
  30. virtual ~cmNinjaTargetGenerator();
  31. virtual void Generate() = 0;
  32. std::string GetTargetPDB() const;
  33. std::string GetTargetName() const;
  34. protected:
  35. cmGeneratedFileStream& GetBuildFileStream() const;
  36. cmGeneratedFileStream& GetRulesFileStream() const;
  37. cmTarget* GetTarget() const
  38. { return this->Target; }
  39. cmLocalNinjaGenerator* GetLocalGenerator() const
  40. { return this->LocalGenerator; }
  41. cmGlobalNinjaGenerator* GetGlobalGenerator() const;
  42. cmMakefile* GetMakefile() const
  43. { return this->Makefile; }
  44. const char* GetConfigName() const;
  45. std::string LanguageCompilerRule(const std::string& lang) const
  46. { return lang + "_COMPILER"; }
  47. const char* GetFeature(const char* feature);
  48. bool GetFeatureAsBool(const char* feature);
  49. void AddFeatureFlags(std::string& flags, const char* lang);
  50. /**
  51. * Compute the flags for compilation of object files for a given @a language.
  52. * @note Generally it is the value of the variable whose name is computed
  53. * by LanguageFlagsVarName().
  54. */
  55. std::string ComputeFlagsForObject(cmSourceFile *source,
  56. const std::string& language);
  57. std::string ComputeDefines(cmSourceFile *source,
  58. const std::string& language);
  59. std::string ConvertToNinjaPath(const char *path) const {
  60. return this->GetLocalGenerator()->ConvertToNinjaPath(path);
  61. }
  62. cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
  63. return this->GetLocalGenerator()->MapToNinjaPath();
  64. }
  65. /// @return the list of link dependency for the given target @a target.
  66. cmNinjaDeps ComputeLinkDeps() const;
  67. /// @return the source file path for the given @a source.
  68. std::string GetSourceFilePath(cmSourceFile* source) const;
  69. /// @return the object file path for the given @a source.
  70. std::string GetObjectFilePath(cmSourceFile* source) const;
  71. /// @return the file path where the target named @a name is generated.
  72. std::string GetTargetFilePath(const std::string& name) const;
  73. /// @return the output path for the target.
  74. virtual std::string GetTargetOutputDir() const;
  75. void WriteLanguageRules(const std::string& language);
  76. void WriteCompileRule(const std::string& language);
  77. void WriteObjectBuildStatements();
  78. void WriteObjectBuildStatement(cmSourceFile* source);
  79. void WriteCustomCommandBuildStatement(cmCustomCommand *cc);
  80. cmNinjaDeps GetObjects() const
  81. { return this->Objects; }
  82. // Helper to add flag for windows .def file.
  83. void AddModuleDefinitionFlag(std::string& flags);
  84. private:
  85. cmTarget* Target;
  86. cmMakefile* Makefile;
  87. cmLocalNinjaGenerator* LocalGenerator;
  88. /// List of object files for this target.
  89. cmNinjaDeps Objects;
  90. // The windows module definition source file (.def), if any.
  91. std::string ModuleDefinitionFile;
  92. };
  93. #endif // ! cmNinjaTargetGenerator_h