blob: 897e446e8e86266844183a00ba625733378f8df7 [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]6fa9e6f2011-08-18 21:52:156# to invoke protoc in a consistent manner.
7#
8# To use this, create a gyp target with the following form:
9# {
10# 'target_name': 'my_proto_lib',
11# 'type': 'static_library',
12# 'sources': [
13# 'foo.proto',
14# 'bar.proto',
15# ],
16# 'variables': {
17# # Optional, see below: 'proto_in_dir': '.'
18# 'proto_out_dir': 'dir/for/my_proto_lib'
19# },
20# 'includes': ['path/to/this/gypi/file'],
21# }
22# If necessary, you may add normal .cc files to the sources list or other gyp
23# dependencies. The proto headers are guaranteed to be generated before any
24# source files, even within this target, are compiled.
25#
26# The 'proto_in_dir' variable must be the relative path to the
27# directory containing the .proto files. If left out, it defaults to '.'.
28#
29# The 'proto_out_dir' variable specifies the path suffix that output
30# files are generated under. Targets that gyp-depend on my_proto_lib
31# will be able to include the resulting proto headers with an include
32# like:
33# #include "dir/for/my_proto_lib/foo.pb.h"
34#
[email protected]c6ccf422012-09-13 02:27:5235# If you need to add an EXPORT macro to a protobuf's c++ header, set the
36# 'cc_generator_options' variable with the value: 'dllexport_decl=FOO_EXPORT:'
37# e.g. 'dllexport_decl=BASE_EXPORT:'
38#
39# It is likely you also need to #include a file for the above EXPORT macro to
40# work. You can do so with the 'cc_include' variable.
41# e.g. 'base/base_export.h'
42#
[email protected]6fa9e6f2011-08-18 21:52:1543# Implementation notes:
[email protected]3354c312012-02-28 05:25:0644# A proto_out_dir of foo/bar produces
[email protected]6fa9e6f2011-08-18 21:52:1545# <(SHARED_INTERMEDIATE_DIR)/protoc_out/foo/bar/{file1,file2}.pb.{cc,h}
46# <(SHARED_INTERMEDIATE_DIR)/pyproto/foo/bar/{file1,file2}_pb2.py
47
48{
49 'variables': {
[email protected]c6ccf422012-09-13 02:27:5250 'protoc_wrapper': '<(DEPTH)/tools/protoc_wrapper/protoc_wrapper.py',
[email protected]6fa9e6f2011-08-18 21:52:1551 'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
52 '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%': '.',
57 },
58 'rules': [
59 {
60 'rule_name': 'genproto',
61 'extension': 'proto',
62 'inputs': [
[email protected]c6ccf422012-09-13 02:27:5263 '<(protoc_wrapper)',
[email protected]6fa9e6f2011-08-18 21:52:1564 '<(protoc)',
65 ],
66 'outputs': [
[email protected]3354c312012-02-28 05:25:0667 '<(py_dir)/<(RULE_INPUT_ROOT)_pb2.py',
68 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.cc',
69 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h',
[email protected]6fa9e6f2011-08-18 21:52:1570 ],
71 'action': [
[email protected]c6ccf422012-09-13 02:27:5272 'python',
73 '<(protoc_wrapper)',
74 '--include',
75 '<(cc_include)',
76 '--protobuf',
77 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h',
78 '--',
[email protected]6fa9e6f2011-08-18 21:52:1579 '<(protoc)',
[email protected]69e1c462012-07-31 01:07:3280 # Using the --arg val form (instead of --arg=val) allows gyp's msvs rule
81 # generation to correct 'val' which is a path.
82 '--proto_path','<(proto_in_dir)',
[email protected]6fa9e6f2011-08-18 21:52:1583 # Naively you'd use <(RULE_INPUT_PATH) here, but protoc requires
84 # --proto_path is a strict prefix of the path given as an argument.
[email protected]3354c312012-02-28 05:25:0685 '<(proto_in_dir)/<(RULE_INPUT_ROOT)<(RULE_INPUT_EXT)',
[email protected]c6ccf422012-09-13 02:27:5286 '--cpp_out', '<(cc_generator_options)<(cc_dir)',
87 '--python_out', '<(py_dir)',
88 ],
[email protected]69e1c462012-07-31 01:07:3289 'msvs_cygwin_shell': 0,
[email protected]6fa9e6f2011-08-18 21:52:1590 'message': 'Generating C++ and Python code from <(RULE_INPUT_PATH)',
91 'process_outputs_as_sources': 1,
92 },
93 ],
94 'dependencies': [
95 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protoc#host',
96 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
97 ],
98 'include_dirs': [
99 '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
[email protected]c6ccf422012-09-13 02:27:52100 '<(DEPTH)',
[email protected]6fa9e6f2011-08-18 21:52:15101 ],
102 'direct_dependent_settings': {
103 'include_dirs': [
104 '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
[email protected]c6ccf422012-09-13 02:27:52105 '<(DEPTH)',
[email protected]6fa9e6f2011-08-18 21:52:15106 ]
107 },
[email protected]f30e11dc2011-08-19 18:19:52108 'export_dependent_settings': [
109 # The generated headers reference headers within protobuf_lite,
110 # so dependencies must be able to find those headers too.
111 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
112 ],
[email protected]6fa9e6f2011-08-18 21:52:15113 # This target exports a hard dependency because it generates header
114 # files.
115 'hard_dependency': 1,
116}