- add sources.
[platform/framework/web/crosswalk.git] / src / tools / gn / ninja_binary_target_writer.h
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_
6 #define TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_
7
8 #include "base/compiler_specific.h"
9 #include "tools/gn/ninja_target_writer.h"
10 #include "tools/gn/toolchain.h"
11
12 // Writes a .ninja file for a binary target type (an executable, a shared
13 // library, or a static library).
14 class NinjaBinaryTargetWriter : public NinjaTargetWriter {
15  public:
16   NinjaBinaryTargetWriter(const Target* target,
17                           const Toolchain* toolchain,
18                           std::ostream& out);
19   virtual ~NinjaBinaryTargetWriter();
20
21   virtual void Run() OVERRIDE;
22
23  private:
24   typedef std::set<OutputFile> OutputFileSet;
25
26   void WriteCompilerVars();
27   void WriteSources(std::vector<OutputFile>* object_files);
28   void WriteLinkerStuff(const std::vector<OutputFile>& object_files);
29   void WriteLinkerFlags();
30
31   // Writes the build line for linking the target. Includes newline.
32   void WriteLinkCommand(const OutputFile& external_output_file,
33                         const OutputFile& internal_output_file,
34                         const std::vector<OutputFile>& object_files);
35
36   // Writes the stamp line for a source set. These are not linked.
37   void WriteSourceSetStamp(const std::vector<OutputFile>& object_files);
38
39   // Gets all target dependencies and classifies them, as well as accumulates
40   // object files from source sets we need to link.
41   void GetDeps(std::set<OutputFile>* extra_object_files,
42                std::vector<const Target*>* linkable_deps,
43                std::vector<const Target*>* non_linkable_deps) const;
44
45   // Classifies the dependency as linkable or nonlinkable with the current
46   // target, adding it to the appropriate vector. If the dependency is a source
47   // set we should link in, the source set's object files will be appended to
48   // |extra_object_files|.
49   void ClassifyDependency(const Target* dep,
50                           std::set<OutputFile>* extra_object_files,
51                           std::vector<const Target*>* linkable_deps,
52                           std::vector<const Target*>* non_linkable_deps) const;
53
54   // Writes the implicit dependencies for the link or stamp line. This is
55   // the "||" and everything following it on the ninja line.
56   //
57   // The implicit dependencies are the non-linkable deps passed in as an
58   // argument, plus the data file depdencies in the target.
59   void WriteImplicitDependencies(
60       const std::vector<const Target*>& non_linkable_deps);
61
62   Toolchain::ToolType tool_type_;
63
64   DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter);
65 };
66
67 #endif  // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_
68