cmLocalNinjaGenerator.h 3.82 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, cmMakefile* mf);
35 36 37 38 39

  virtual ~cmLocalNinjaGenerator();

  virtual void Generate();

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

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

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

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

61 62 63
  void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
  void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);

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

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

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

77 78

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


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

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

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

  void WriteCustomCommandBuildStatements();

101
  std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
102

103 104
  std::string HomeRelativeOutputPath;

105
  typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
106 107 108 109 110
    CustomCommandTargetMap;
  CustomCommandTargetMap CustomCommandTargets;
};

#endif // ! cmLocalNinjaGenerator_h