• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(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   // Writes the given array with the given name. The indent should be the
82   // indenting for the name, the values will be indented 2 spaces from there.
83   // Writes nothing if there is nothing in the array.
84   void WriteNamedArray(const char* name,
85                        const std::vector<std::string>& values,
86                        int indent);
87 
88   // All associated targets.
89   TargetGroup group_;
90 
91   DISALLOW_COPY_AND_ASSIGN(GypBinaryTargetWriter);
92 };
93 
94 #endif  // TOOLS_GN_GYP_BINARY_TARGET_WRITER_H_
95 
96