cmLocalNinjaGenerator.h 3.9 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

  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
53 54 55
  {
    return this->HomeRelativeOutputPath;
  }
56

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

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

65 66
  void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
  void AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs);
67

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

75 76
  virtual std::string ConvertToLinkReference(std::string const& lib,
                                             OutputFormat format = SHELL);
77

78
  virtual void ComputeObjectFilenames(
79 80
    std::map<cmSourceFile const*, std::string>& mapping,
    cmGeneratorTarget const* gt = 0);
81 82

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

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

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

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

  void WriteCustomCommandBuildStatements();

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

106 107
  std::string HomeRelativeOutputPath;

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

#endif // ! cmLocalNinjaGenerator_h