blob: df209d47de8da910fdf70dab12fa5dce7d508558 [file] [log] [blame]
andrew@webrtc.org225f2b82013-05-20 21:12:58 +00001# Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
2#
3# Use of this source code is governed by a BSD-style license
4# that can be found in the LICENSE file in the root of the source
5# tree. An additional intellectual property rights grant can be found
6# in the file PATENTS. All contributing project authors may
7# be found in the AUTHORS file in the root of the source tree.
andrew@webrtc.orgcb181212011-10-26 00:27:17 +00008
andrew@webrtc.org225f2b82013-05-20 21:12:58 +00009# Copied from Chromium's src/build/protoc.gypi
10#
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000011# It was necessary to copy this file to WebRTC, because the path to
12# build/common.gypi is different for the standalone and Chromium builds. Gyp
13# doesn't permit conditional inclusion or variable expansion in include paths.
14# http://code.google.com/p/gyp/wiki/InputFormatReference#Including_Other_Files
kjellander40bebd32016-04-20 06:22:20 -070015#
16# Local changes:
17# * Removed <(DEPTH) from include_dir due to difficulties with generated
18# downstream code.
19
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000020
21# This file is meant to be included into a target to provide a rule
andrew@webrtc.org225f2b82013-05-20 21:12:58 +000022# to invoke protoc in a consistent manner. For Java-targets, see
23# protoc_java.gypi.
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000024#
25# To use this, create a gyp target with the following form:
26# {
27# 'target_name': 'my_proto_lib',
28# 'type': 'static_library',
29# 'sources': [
30# 'foo.proto',
31# 'bar.proto',
32# ],
33# 'variables': {
34# # Optional, see below: 'proto_in_dir': '.'
35# 'proto_out_dir': 'dir/for/my_proto_lib'
36# },
37# 'includes': ['path/to/this/gypi/file'],
38# }
39# If necessary, you may add normal .cc files to the sources list or other gyp
40# dependencies. The proto headers are guaranteed to be generated before any
41# source files, even within this target, are compiled.
42#
43# The 'proto_in_dir' variable must be the relative path to the
44# directory containing the .proto files. If left out, it defaults to '.'.
45#
46# The 'proto_out_dir' variable specifies the path suffix that output
47# files are generated under. Targets that gyp-depend on my_proto_lib
48# will be able to include the resulting proto headers with an include
49# like:
50# #include "dir/for/my_proto_lib/foo.pb.h"
51#
andrew@webrtc.org225f2b82013-05-20 21:12:58 +000052# If you need to add an EXPORT macro to a protobuf's c++ header, set the
53# 'cc_generator_options' variable with the value: 'dllexport_decl=FOO_EXPORT:'
54# e.g. 'dllexport_decl=BASE_EXPORT:'
55#
56# It is likely you also need to #include a file for the above EXPORT macro to
57# work. You can do so with the 'cc_include' variable.
58# e.g. 'base/base_export.h'
59#
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000060# Implementation notes:
61# A proto_out_dir of foo/bar produces
62# <(SHARED_INTERMEDIATE_DIR)/protoc_out/foo/bar/{file1,file2}.pb.{cc,h}
63# <(SHARED_INTERMEDIATE_DIR)/pyproto/foo/bar/{file1,file2}_pb2.py
64
65{
66 'variables': {
andrew@webrtc.org225f2b82013-05-20 21:12:58 +000067 'protoc_wrapper': '<(DEPTH)/tools/protoc_wrapper/protoc_wrapper.py',
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000068 'cc_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out/<(proto_out_dir)',
69 'py_dir': '<(PRODUCT_DIR)/pyproto/<(proto_out_dir)',
andrew@webrtc.org225f2b82013-05-20 21:12:58 +000070 'cc_generator_options%': '',
71 'cc_include%': '',
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000072 'proto_in_dir%': '.',
andrew@webrtc.org225f2b82013-05-20 21:12:58 +000073 'conditions': [
74 ['use_system_protobuf==0', {
75 'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
76 }, { # use_system_protobuf==1
77 'protoc': '<!(which protoc)',
78 }],
79 ],
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000080 },
81 'rules': [
82 {
83 'rule_name': 'genproto',
84 'extension': 'proto',
85 'inputs': [
andrew@webrtc.org225f2b82013-05-20 21:12:58 +000086 '<(protoc_wrapper)',
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000087 '<(protoc)',
88 ],
89 'outputs': [
90 '<(py_dir)/<(RULE_INPUT_ROOT)_pb2.py',
91 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.cc',
92 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h',
93 ],
94 'action': [
andrew@webrtc.org225f2b82013-05-20 21:12:58 +000095 'python',
96 '<(protoc_wrapper)',
ehmaldonadob0b0edb2016-08-24 08:16:21 -070097 '--protoc',
98 '<(protoc)',
andrew@webrtc.org225f2b82013-05-20 21:12:58 +000099 # Using the --arg val form (instead of --arg=val) allows gyp's msvs rule
100 # generation to correct 'val' which is a path.
101 '--proto-in-dir','<(proto_in_dir)',
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000102 # Naively you'd use <(RULE_INPUT_PATH) here, but protoc requires
103 # --proto_path is a strict prefix of the path given as an argument.
ehmaldonadob0b0edb2016-08-24 08:16:21 -0700104 '--cc-out-dir', '<(cc_generator_options)<(cc_dir)',
105 '--py-out-dir', '<(py_dir)',
106 '<(RULE_INPUT_ROOT)<(RULE_INPUT_EXT)',
andrew@webrtc.org225f2b82013-05-20 21:12:58 +0000107 ],
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000108 'message': 'Generating C++ and Python code from <(RULE_INPUT_PATH)',
109 'process_outputs_as_sources': 1,
110 },
111 ],
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000112 'include_dirs': [
113 '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
114 ],
115 'direct_dependent_settings': {
116 'include_dirs': [
117 '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000118 ]
119 },
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000120 # This target exports a hard dependency because it generates header
121 # files.
122 'hard_dependency': 1,
kjellander292e1922016-01-13 05:46:58 -0800123 'conditions': [
124 ['build_protobuf==1', {
125 'dependencies': [
126 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protoc#host',
127 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
128 ],
129 'export_dependent_settings': [
130 # The generated headers reference headers within protobuf_lite,
131 # so dependencies must be able to find those headers too.
132 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
133 ],
134 }],
135 ],
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000136}