- add sources.
[platform/framework/web/crosswalk.git] / src / tools / gn / gyp_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_GYP_BINARY_TARGET_WRITER_H_
6 #define TOOLS_GN_GYP_BINARY_TARGET_WRITER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "tools/gn/gyp_target_writer.h"
13 #include "tools/gn/target.h"
14 #include "tools/gn/toolchain.h"
15
16 // Writes a portion of a .gyp file for a binary target type (an executable, a
17 // shared library, or a static library).
18 class GypBinaryTargetWriter : public GypTargetWriter {
19  public:
20   GypBinaryTargetWriter(const TargetGroup& group, std::ostream& out);
21   virtual ~GypBinaryTargetWriter();
22
23   virtual void Run() OVERRIDE;
24
25  private:
26   struct Flags {
27     Flags();
28     ~Flags();
29
30     std::vector<std::string> defines;
31     std::vector<SourceDir> include_dirs;
32
33     std::vector<std::string> cflags;
34     std::vector<std::string> cflags_c;
35     std::vector<std::string> cflags_cc;
36     std::vector<std::string> cflags_objc;
37     std::vector<std::string> cflags_objcc;
38     std::vector<std::string> ldflags;
39     std::vector<SourceDir> lib_dirs;
40     std::vector<std::string> libs;
41   };
42
43   // Writes the given number of spaces to the output stream and returns it.
44   std::ostream& Indent(int spaces);
45
46   void WriteName(int indent);
47   void WriteType(int indent);
48
49   // Writes the flags, sources, and deps.
50   void WriteVCConfiguration(int indent);
51   void WriteLinuxConfiguration(int indent);
52   void WriteMacConfiguration(int indent);
53
54   // Writes the flags, defines, etc. The flags input is non-const because the
55   // cflags will be fixed up to account for things converted to VC settings
56   // (rather than compiler flags).
57   void WriteVCFlags(Flags& flags, int indent);
58   void WriteMacFlags(Flags& flags, int indent);
59
60   // Writes the Linux compiler and linker flags. The first version does the
61   // flags for the given target, the second version takes a pregenerted list of
62   // flags.
63   void WriteLinuxFlagsForTarget(const Target* target, int indent);
64   void WriteLinuxFlags(const Flags& flags, int indent);
65
66   // Shared helpers for writing specific parts of GYP files.
67   void WriteSources(const Target* target, int indent);
68   void WriteDeps(const Target* target, int indent);
69   void WriteIncludeDirs(const Flags& flags, int indent);
70   void WriteDirectDependentSettings(int indent);
71   void WriteAllDependentSettings(int indent);
72
73   // Writes out the given flags and such from all configs in the given list.
74   void WriteSettingsFromConfigList(const std::vector<const Config*>& configs,
75                                    int indent);
76
77   // Fills the given flags structure.
78   Flags FlagsFromTarget(const Target* target) const;
79   Flags FlagsFromConfigList(const LabelConfigVector& configs) const;
80
81   // All associated targets.
82   TargetGroup group_;
83
84   DISALLOW_COPY_AND_ASSIGN(GypBinaryTargetWriter);
85 };
86
87 #endif  // TOOLS_GN_GYP_BINARY_TARGET_WRITER_H_
88