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.
5 #ifndef TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_
6 #define TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_
8 #include "base/macros.h"
9 #include "tools/gn/config_values.h"
10 #include "tools/gn/ninja_target_writer.h"
11 #include "tools/gn/toolchain.h"
12 #include "tools/gn/unique_vector.h"
16 // Writes a .ninja file for a binary target type (an executable, a shared
17 // library, or a static library).
18 class NinjaBinaryTargetWriter
: public NinjaTargetWriter
{
20 NinjaBinaryTargetWriter(const Target
* target
, std::ostream
& out
);
21 ~NinjaBinaryTargetWriter() override
;
26 typedef std::set
<OutputFile
> OutputFileSet
;
28 void WriteCompilerVars();
29 void WriteSources(std::vector
<OutputFile
>* object_files
);
30 void WriteLinkerStuff(const std::vector
<OutputFile
>& object_files
);
31 void WriteLinkerFlags();
33 void WriteOutputExtension();
34 void WriteSolibs(const std::vector
<OutputFile
>& solibs
);
36 // Writes the stamp line for a source set. These are not linked.
37 void WriteSourceSetStamp(const std::vector
<OutputFile
>& object_files
);
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(UniqueVector
<OutputFile
>* extra_object_files
,
42 UniqueVector
<const Target
*>* linkable_deps
,
43 UniqueVector
<const Target
*>* non_linkable_deps
) const;
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 UniqueVector
<OutputFile
>* extra_object_files
,
51 UniqueVector
<const Target
*>* linkable_deps
,
52 UniqueVector
<const Target
*>* non_linkable_deps
) const;
54 // Writes the implicit dependencies for the link or stamp line. This is
55 // the "||" and everything following it on the ninja line.
57 // The order-only dependencies are the non-linkable deps passed in as an
58 // argument, plus the data file depdencies in the target.
59 void WriteOrderOnlyDependencies(
60 const UniqueVector
<const Target
*>& non_linkable_deps
);
62 // Computes the set of output files resulting from compiling the given source
63 // file. If the file can be compiled and the tool exists, fills the outputs in
64 // and writes the tool type to computed_tool_type. If the file is not
65 // compilable, returns false.
67 // The target that the source belongs to is passed as an argument. In the
68 // case of linking to source sets, this can be different than the target
69 // this class is currently writing.
71 // The function can succeed with a "NONE" tool type for object files which are
72 // just passed to the output. The output will always be overwritten, not
74 bool GetOutputFilesForSource(const Target
* target
,
75 const SourceFile
& source
,
76 Toolchain::ToolType
* computed_tool_type
,
77 std::vector
<OutputFile
>* outputs
) const;
81 DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter
);
84 #endif // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_