cmLocalNinjaGenerator.h 3.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*============================================================================
  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
Brad King's avatar
Brad King committed
14
#define cmLocalNinjaGenerator_h
15

Brad King's avatar
Brad King committed
16 17 18
#include "cmLocalCommonGenerator.h"

#include "cmNinjaTypes.h"
19

20
class cmCustomCommandGenerator;
21 22 23 24 25 26 27 28 29 30 31
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.
 */
32
class cmLocalNinjaGenerator : public cmLocalCommonGenerator
33 34
{
public:
35
  cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
36 37 38 39 40

  virtual ~cmLocalNinjaGenerator();

  virtual void Generate();

41 42
  virtual
  std::string GetTargetDirectory(cmGeneratorTarget const* target) const;
43 44 45 46 47 48 49 50 51 52 53 54

  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; }

55 56
  void ExpandRuleVariables(std::string& string,
                           const RuleVariables& replaceValues) {
57 58
    cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
  }
59 60 61

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

62 63
  void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
  void AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs);
64

65 66
  void AddCustomCommandTarget(cmCustomCommand const* cc,
                              cmGeneratorTarget* target);
67
  void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
68
                                std::vector<std::string> &cmdLines);
69
  void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
70 71
                               cmNinjaDeps &ninjaDeps);

72 73
  virtual std::string ConvertToLinkReference(std::string const& lib,
                                             OutputFormat format = SHELL);
74

75 76 77 78
  virtual void ComputeObjectFilenames(
                        std::map<cmSourceFile const*, std::string>& mapping,
                        cmGeneratorTarget const* gt = 0);

79 80

protected:
81
  virtual std::string ConvertToIncludeReference(std::string const& path,
82 83
                                                OutputFormat format = SHELL,
                                                bool forceFullPaths = false);
84 85 86 87 88 89 90 91


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

  void WriteBuildFileTop();
  void WriteProjectHeader(std::ostream& os);
92
  void WriteNinjaRequiredVersion(std::ostream& os);
93 94
  void WriteNinjaFilesInclusion(std::ostream& os);
  void WriteProcessedMakefile(std::ostream& os);
95
  void WritePools(std::ostream& os);
96

97
  void WriteCustomCommandRule();
98
  void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
99 100 101 102
                                        const cmNinjaDeps& orderOnlyDeps);

  void WriteCustomCommandBuildStatements();

103
  std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
104

105 106
  std::string HomeRelativeOutputPath;

107
  typedef std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*> >
108 109
    CustomCommandTargetMap;
  CustomCommandTargetMap CustomCommandTargets;
110
  std::vector<cmCustomCommand const*> CustomCommands;
111 112 113
};

#endif // ! cmLocalNinjaGenerator_h