cmLocalNinjaGenerator.h 4.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
  Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
#ifndef cmLocalNinjaGenerator_h
#  define cmLocalNinjaGenerator_h

16
#  include "cmLocalCommonGenerator.h"
17 18
#  include "cmNinjaTypes.h"

19
class cmCustomCommandGenerator;
20 21 22 23 24 25 26 27 28 29 30
class cmGlobalNinjaGenerator;
class cmGeneratedFileStream;
class cmake;

/**
 * \class cmLocalNinjaGenerator
 * \brief Write a local build.ninja file.
 *
 * cmLocalNinjaGenerator produces a local build.ninja file from its
 * member Makefile.
 */
31
class cmLocalNinjaGenerator : public cmLocalCommonGenerator
32 33
{
public:
34
  cmLocalNinjaGenerator(cmGlobalGenerator* gg,
35
                        cmState::Snapshot snapshot);
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

  virtual ~cmLocalNinjaGenerator();

  virtual void Generate();

  virtual std::string GetTargetDirectory(cmTarget const& target) const;

  const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
  cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();

  const cmake* GetCMakeInstance() const;
  cmake* GetCMakeInstance();

  /// @returns the relative path between the HomeOutputDirectory and this
  /// local generators StartOutputDirectory.
  std::string GetHomeRelativeOutputPath() const
  { return this->HomeRelativeOutputPath; }

Ben Boeckel's avatar
Ben Boeckel committed
54
  std::string ConvertToNinjaPath(const std::string& path);
55 56 57

  struct map_to_ninja_path {
    cmLocalNinjaGenerator *LocalGenerator;
58 59
    map_to_ninja_path(cmLocalNinjaGenerator *LocalGen)
      : LocalGenerator(LocalGen) {}
60
    std::string operator()(const std::string &path) {
61
      return LocalGenerator->ConvertToNinjaPath(path);
62 63
    }
  };
64

65 66 67 68
  map_to_ninja_path MapToNinjaPath() {
    return map_to_ninja_path(this);
  }

69 70
  void ExpandRuleVariables(std::string& string,
                           const RuleVariables& replaceValues) {
71 72
    cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
  }
73 74 75

  std::string BuildCommandLine(const std::vector<std::string> &cmdLines);

76 77 78
  void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
  void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);

79
  void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target);
80
  void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
81
                                std::vector<std::string> &cmdLines);
82
  void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
83 84
                               cmNinjaDeps &ninjaDeps);

85 86
  virtual std::string ConvertToLinkReference(std::string const& lib,
                                             OutputFormat format = SHELL);
87

88 89 90 91
  virtual void ComputeObjectFilenames(
                        std::map<cmSourceFile const*, std::string>& mapping,
                        cmGeneratorTarget const* gt = 0);

92 93

protected:
94
  virtual std::string ConvertToIncludeReference(std::string const& path,
95 96
                                                OutputFormat format = SHELL,
                                                bool forceFullPaths = false);
97 98 99 100 101 102 103 104


private:
  cmGeneratedFileStream& GetBuildFileStream() const;
  cmGeneratedFileStream& GetRulesFileStream() const;

  void WriteBuildFileTop();
  void WriteProjectHeader(std::ostream& os);
105
  void WriteNinjaRequiredVersion(std::ostream& os);
106 107
  void WriteNinjaFilesInclusion(std::ostream& os);
  void WriteProcessedMakefile(std::ostream& os);
108
  void WritePools(std::ostream& os);
109

110
  void WriteCustomCommandRule();
111
  void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
112 113 114 115
                                        const cmNinjaDeps& orderOnlyDeps);

  void WriteCustomCommandBuildStatements();

116
  std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
117

118 119
  std::string HomeRelativeOutputPath;

120
  typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
121 122 123 124 125
    CustomCommandTargetMap;
  CustomCommandTargetMap CustomCommandTargets;
};

#endif // ! cmLocalNinjaGenerator_h