blob: 52fb8a2b6098d7f6b41a69c105b23363952511ab [file] [log] [blame]
[email protected]69e1c462012-07-31 01:07:321# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6fa9e6f2011-08-18 21:52:152# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
[email protected]69e1c462012-07-31 01:07:325# This file is meant to be included into a target to provide a rule
[email protected]d339e3c2012-11-14 21:20:476# to invoke protoc in a consistent manner. For Java-targets, see
7# protoc_java.gypi.
[email protected]6fa9e6f2011-08-18 21:52:158#
9# To use this, create a gyp target with the following form:
10# {
11# 'target_name': 'my_proto_lib',
12# 'type': 'static_library',
13# 'sources': [
14# 'foo.proto',
15# 'bar.proto',
16# ],
17# 'variables': {
18# # Optional, see below: 'proto_in_dir': '.'
19# 'proto_out_dir': 'dir/for/my_proto_lib'
20# },
21# 'includes': ['path/to/this/gypi/file'],
22# }
23# If necessary, you may add normal .cc files to the sources list or other gyp
24# dependencies. The proto headers are guaranteed to be generated before any
25# source files, even within this target, are compiled.
26#
27# The 'proto_in_dir' variable must be the relative path to the
28# directory containing the .proto files. If left out, it defaults to '.'.
29#
30# The 'proto_out_dir' variable specifies the path suffix that output
31# files are generated under. Targets that gyp-depend on my_proto_lib
32# will be able to include the resulting proto headers with an include
33# like:
34# #include "dir/for/my_proto_lib/foo.pb.h"
35#
[email protected]c6ccf422012-09-13 02:27:5236# If you need to add an EXPORT macro to a protobuf's c++ header, set the
37# 'cc_generator_options' variable with the value: 'dllexport_decl=FOO_EXPORT:'
38# e.g. 'dllexport_decl=BASE_EXPORT:'
39#
40# It is likely you also need to #include a file for the above EXPORT macro to
41# work. You can do so with the 'cc_include' variable.
42# e.g. 'base/base_export.h'
43#
[email protected]6fa9e6f2011-08-18 21:52:1544# Implementation notes:
[email protected]3354c312012-02-28 05:25:0645# A proto_out_dir of foo/bar produces
[email protected]6fa9e6f2011-08-18 21:52:1546# <(SHARED_INTERMEDIATE_DIR)/protoc_out/foo/bar/{file1,file2}.pb.{cc,h}
47# <(SHARED_INTERMEDIATE_DIR)/pyproto/foo/bar/{file1,file2}_pb2.py
48
49{
50 'variables': {
[email protected]c6ccf422012-09-13 02:27:5251 'protoc_wrapper': '<(DEPTH)/tools/protoc_wrapper/protoc_wrapper.py',
[email protected]6fa9e6f2011-08-18 21:52:1552 'cc_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out/<(proto_out_dir)',
53 'py_dir': '<(PRODUCT_DIR)/pyproto/<(proto_out_dir)',
[email protected]c6ccf422012-09-13 02:27:5254 'cc_generator_options%': '',
55 'cc_include%': '',
[email protected]6fa9e6f2011-08-18 21:52:1556 'proto_in_dir%': '.',
[email protected]2f325672012-10-31 23:29:3757 'conditions': [
58 ['use_system_protobuf==0', {
59 'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
60 }, { # use_system_protobuf==1
61 'protoc': '<!(which protoc)',
62 }],
63 ],
[email protected]6fa9e6f2011-08-18 21:52:1564 },
65 'rules': [
66 {
67 'rule_name': 'genproto',
68 'extension': 'proto',
69 'inputs': [
[email protected]c6ccf422012-09-13 02:27:5270 '<(protoc_wrapper)',
[email protected]6fa9e6f2011-08-18 21:52:1571 '<(protoc)',
72 ],
73 'outputs': [
[email protected]3354c312012-02-28 05:25:0674 '<(py_dir)/<(RULE_INPUT_ROOT)_pb2.py',
75 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.cc',
76 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h',
[email protected]6fa9e6f2011-08-18 21:52:1577 ],
78 'action': [
[email protected]c6ccf422012-09-13 02:27:5279 'python',
80 '<(protoc_wrapper)',
81 '--include',
82 '<(cc_include)',
83 '--protobuf',
84 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h',
[email protected]69e1c462012-07-31 01:07:3285 # Using the --arg val form (instead of --arg=val) allows gyp's msvs rule
86 # generation to correct 'val' which is a path.
[email protected]0837d0c2012-12-04 19:08:1787 '--proto-in-dir','<(proto_in_dir)',
[email protected]6fa9e6f2011-08-18 21:52:1588 # Naively you'd use <(RULE_INPUT_PATH) here, but protoc requires
89 # --proto_path is a strict prefix of the path given as an argument.
[email protected]0837d0c2012-12-04 19:08:1790 '--proto-in-file','<(RULE_INPUT_ROOT)<(RULE_INPUT_EXT)',
91 '--use-system-protobuf=<(use_system_protobuf)',
92 '--',
93 '<(protoc)',
[email protected]c6ccf422012-09-13 02:27:5294 '--cpp_out', '<(cc_generator_options)<(cc_dir)',
95 '--python_out', '<(py_dir)',
96 ],
[email protected]69e1c462012-07-31 01:07:3297 'msvs_cygwin_shell': 0,
[email protected]6fa9e6f2011-08-18 21:52:1598 'message': 'Generating C++ and Python code from <(RULE_INPUT_PATH)',
99 'process_outputs_as_sources': 1,
100 },
101 ],
102 'dependencies': [
103 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protoc#host',
104 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
105 ],
106 'include_dirs': [
107 '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
[email protected]c6ccf422012-09-13 02:27:52108 '<(DEPTH)',
[email protected]6fa9e6f2011-08-18 21:52:15109 ],
110 'direct_dependent_settings': {
111 'include_dirs': [
112 '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
[email protected]c6ccf422012-09-13 02:27:52113 '<(DEPTH)',
[email protected]6fa9e6f2011-08-18 21:52:15114 ]
115 },
[email protected]f30e11dc2011-08-19 18:19:52116 'export_dependent_settings': [
117 # The generated headers reference headers within protobuf_lite,
118 # so dependencies must be able to find those headers too.
119 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
120 ],
[email protected]6fa9e6f2011-08-18 21:52:15121 # This target exports a hard dependency because it generates header
122 # files.
123 'hard_dependency': 1,
124}