Upstream version 5.34.104.0
[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,
21                         const Toolchain* debug_toolchain,
22                         const SourceDir& gyp_dir,
23                         std::ostream& out);
24   virtual ~GypBinaryTargetWriter();
25
26   virtual void Run() OVERRIDE;
27
28  private:
29   struct Flags {
30     Flags();
31     ~Flags();
32
33     std::vector<std::string> defines;
34     std::vector<SourceDir> include_dirs;
35
36     std::vector<std::string> cflags;
37     std::vector<std::string> cflags_c;
38     std::vector<std::string> cflags_cc;
39     std::vector<std::string> cflags_objc;
40     std::vector<std::string> cflags_objcc;
41     std::vector<std::string> ldflags;
42     std::vector<SourceDir> lib_dirs;
43     std::vector<std::string> libs;
44   };
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(const Target* target, 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   // Writes out the given target and optional host flags. This will insert a
67   // target conditionn if there is a host build.
68   void WriteMacTargetAndHostFlags(const BuilderRecord* target,
69                                   const BuilderRecord* host,
70                                   int indent);
71
72   // Shared helpers for writing specific parts of GYP files.
73   void WriteSources(const Target* target, int indent);
74   void WriteDeps(const Target* target, int indent);
75   void WriteIncludeDirs(const Flags& flags, int indent);
76   void WriteDirectDependentSettings(int indent);
77   void WriteAllDependentSettings(int indent);
78
79   // Writes out the given flags and such from all configs in the given list.
80   void WriteSettingsFromConfigList(const std::vector<const Config*>& configs,
81                                    int indent);
82
83   // Fills the given flags structure.
84   Flags FlagsFromTarget(const Target* target) const;
85   Flags FlagsFromConfigList(const LabelConfigVector& configs) const;
86
87   // Writes the given array with the given name. The indent should be the
88   // indenting for the name, the values will be indented 2 spaces from there.
89   // Writes nothing if there is nothing in the array.
90   void WriteNamedArray(const char* name,
91                        const std::vector<std::string>& values,
92                        int indent);
93
94   // All associated targets.
95   TargetGroup group_;
96
97   DISALLOW_COPY_AND_ASSIGN(GypBinaryTargetWriter);
98 };
99
100 #endif  // TOOLS_GN_GYP_BINARY_TARGET_WRITER_H_
101