blob: 70bf71e1c4cc9847f52e482b769c2a28b41c6e63 [file] [log] [blame]
andrew@webrtc.orgcb181212011-10-26 00:27:17 +00001# Copyright (c) 2011 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# It was necessary to copy this file to WebRTC, because the path to
6# build/common.gypi is different for the standalone and Chromium builds. Gyp
7# doesn't permit conditional inclusion or variable expansion in include paths.
8# http://code.google.com/p/gyp/wiki/InputFormatReference#Including_Other_Files
9
10# This file is meant to be included into a target to provide a rule
11# to invoke protoc in a consistent manner.
12#
13# To use this, create a gyp target with the following form:
14# {
15# 'target_name': 'my_proto_lib',
16# 'type': 'static_library',
17# 'sources': [
18# 'foo.proto',
19# 'bar.proto',
20# ],
21# 'variables': {
22# # Optional, see below: 'proto_in_dir': '.'
23# 'proto_out_dir': 'dir/for/my_proto_lib'
24# },
25# 'includes': ['path/to/this/gypi/file'],
26# }
27# If necessary, you may add normal .cc files to the sources list or other gyp
28# dependencies. The proto headers are guaranteed to be generated before any
29# source files, even within this target, are compiled.
30#
31# The 'proto_in_dir' variable must be the relative path to the
32# directory containing the .proto files. If left out, it defaults to '.'.
33#
34# The 'proto_out_dir' variable specifies the path suffix that output
35# files are generated under. Targets that gyp-depend on my_proto_lib
36# will be able to include the resulting proto headers with an include
37# like:
38# #include "dir/for/my_proto_lib/foo.pb.h"
39#
40# Implementation notes:
41# A proto_out_dir of foo/bar produces
42# <(SHARED_INTERMEDIATE_DIR)/protoc_out/foo/bar/{file1,file2}.pb.{cc,h}
43# <(SHARED_INTERMEDIATE_DIR)/pyproto/foo/bar/{file1,file2}_pb2.py
44
45{
46 'variables': {
47 'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
48 'cc_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out/<(proto_out_dir)',
49 'py_dir': '<(PRODUCT_DIR)/pyproto/<(proto_out_dir)',
50 'proto_in_dir%': '.',
51 },
52 'rules': [
53 {
54 'rule_name': 'genproto',
55 'extension': 'proto',
56 'inputs': [
57 '<(protoc)',
58 ],
59 'outputs': [
60 '<(py_dir)/<(RULE_INPUT_ROOT)_pb2.py',
61 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.cc',
62 '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h',
63 ],
64 'action': [
65 '<(protoc)',
66 '--proto_path=<(proto_in_dir)',
67 # Naively you'd use <(RULE_INPUT_PATH) here, but protoc requires
68 # --proto_path is a strict prefix of the path given as an argument.
69 '<(proto_in_dir)/<(RULE_INPUT_ROOT)<(RULE_INPUT_EXT)',
70 '--cpp_out=<(cc_dir)',
71 '--python_out=<(py_dir)',
72 ],
73 'message': 'Generating C++ and Python code from <(RULE_INPUT_PATH)',
74 'process_outputs_as_sources': 1,
75 },
76 ],
77 'dependencies': [
78 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protoc#host',
79 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
80 ],
81 'include_dirs': [
82 '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
83 ],
84 'direct_dependent_settings': {
85 'include_dirs': [
86 '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
87 ]
88 },
89 'export_dependent_settings': [
90 # The generated headers reference headers within protobuf_lite,
91 # so dependencies must be able to find those headers too.
92 '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
93 ],
94 # This target exports a hard dependency because it generates header
95 # files.
96 'hard_dependency': 1,
97}