cmLocalNinjaGenerator.h 4.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*============================================================================
  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

#  include "cmLocalGenerator.h"
#  include "cmNinjaTypes.h"

19
class cmCustomCommandGenerator;
20 21 22 23 24 25 26 27 28 29 30 31 32 33
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.
 */
class cmLocalNinjaGenerator : public cmLocalGenerator
{
public:
34 35
  cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent,
                        cmState::Snapshot snapshot);
36 37 38 39 40 41 42 43 44 45 46 47 48

  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();

49 50
  std::string const& GetConfigName() const
  { return this->ConfigName; }
51 52 53 54 55 56

  /// @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
57
  std::string ConvertToNinjaPath(const std::string& path);
58 59 60

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

68 69 70 71
  map_to_ninja_path MapToNinjaPath() {
    return map_to_ninja_path(this);
  }

72 73
  void ExpandRuleVariables(std::string& string,
                           const RuleVariables& replaceValues) {
74 75
    cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
  }
76 77 78

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

79 80 81
  void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
  void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);

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

88 89
  virtual std::string ConvertToLinkReference(std::string const& lib,
                                             OutputFormat format = SHELL);
90

91 92 93 94
  virtual void ComputeObjectFilenames(
                        std::map<cmSourceFile const*, std::string>& mapping,
                        cmGeneratorTarget const* gt = 0);

95 96

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


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

  void WriteBuildFileTop();
  void WriteProjectHeader(std::ostream& os);
108
  void WriteNinjaRequiredVersion(std::ostream& os);
109 110
  void WriteNinjaFilesInclusion(std::ostream& os);
  void WriteProcessedMakefile(std::ostream& os);
111
  void WritePools(std::ostream& os);
112 113 114

  void SetConfigName();

115
  void WriteCustomCommandRule();
116
  void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
117 118 119 120
                                        const cmNinjaDeps& orderOnlyDeps);

  void WriteCustomCommandBuildStatements();

121
  std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
122

123 124 125
  std::string ConfigName;
  std::string HomeRelativeOutputPath;

126
  typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
127 128 129 130 131
    CustomCommandTargetMap;
  CustomCommandTargetMap CustomCommandTargets;
};

#endif // ! cmLocalNinjaGenerator_h