1# 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.
8
9# Copied from Chromium's src/build/protoc.gypi
10#
11# 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
15
16# This file is meant to be included into a target to provide a rule
17# to invoke protoc in a consistent manner. For Java-targets, see
18# protoc_java.gypi.
19#
20# To use this, create a gyp target with the following form:
21# {
22#   'target_name': 'my_proto_lib',
23#   'type': 'static_library',
24#   'sources': [
25#     'foo.proto',
26#     'bar.proto',
27#   ],
28#   'variables': {
29#     # Optional, see below: 'proto_in_dir': '.'
30#     'proto_out_dir': 'dir/for/my_proto_lib'
31#   },
32#   'includes': ['path/to/this/gypi/file'],
33# }
34# If necessary, you may add normal .cc files to the sources list or other gyp
35# dependencies.  The proto headers are guaranteed to be generated before any
36# source files, even within this target, are compiled.
37#
38# The 'proto_in_dir' variable must be the relative path to the
39# directory containing the .proto files.  If left out, it defaults to '.'.
40#
41# The 'proto_out_dir' variable specifies the path suffix that output
42# files are generated under.  Targets that gyp-depend on my_proto_lib
43# will be able to include the resulting proto headers with an include
44# like:
45#   #include "dir/for/my_proto_lib/foo.pb.h"
46#
47# If you need to add an EXPORT macro to a protobuf's c++ header, set the
48# 'cc_generator_options' variable with the value: 'dllexport_decl=FOO_EXPORT:'
49# e.g. 'dllexport_decl=BASE_EXPORT:'
50#
51# It is likely you also need to #include a file for the above EXPORT macro to
52# work. You can do so with the 'cc_include' variable.
53# e.g. 'base/base_export.h'
54#
55# Implementation notes:
56# A proto_out_dir of foo/bar produces
57#   <(SHARED_INTERMEDIATE_DIR)/protoc_out/foo/bar/{file1,file2}.pb.{cc,h}
58#   <(SHARED_INTERMEDIATE_DIR)/pyproto/foo/bar/{file1,file2}_pb2.py
59
60{
61  'variables': {
62    'protoc_wrapper': '<(DEPTH)/tools/protoc_wrapper/protoc_wrapper.py',
63    'cc_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out/<(proto_out_dir)',
64    'py_dir': '<(PRODUCT_DIR)/pyproto/<(proto_out_dir)',
65    'cc_generator_options%': '',
66    'cc_include%': '',
67    'proto_in_dir%': '.',
68    'conditions': [
69      ['use_system_protobuf==0', {
70        'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
71      }, { # use_system_protobuf==1
72        'protoc': '<!(which protoc)',
73      }],
74    ],
75  },
76  'rules': [
77    {
78      'rule_name': 'genproto',
79      'extension': 'proto',
80      'inputs': [
81        '<(protoc_wrapper)',
82        '<(protoc)',
83      ],
84      'outputs': [
85        '<(py_dir)/<(RULE_INPUT_ROOT)_pb2.py',
86        '<(cc_dir)/<(RULE_INPUT_ROOT).pb.cc',
87        '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h',
88      ],
89      'action': [
90        'python',
91        '<(protoc_wrapper)',
92        '--include',
93        '<(cc_include)',
94        '--protobuf',
95        '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h',
96        # Using the --arg val form (instead of --arg=val) allows gyp's msvs rule
97        # generation to correct 'val' which is a path.
98        '--proto-in-dir','<(proto_in_dir)',
99        # Naively you'd use <(RULE_INPUT_PATH) here, but protoc requires
100        # --proto_path is a strict prefix of the path given as an argument.
101        '--proto-in-file','<(RULE_INPUT_ROOT)<(RULE_INPUT_EXT)',
102        '--use-system-protobuf=<(use_system_protobuf)',
103        '--',
104        '<(protoc)',
105        '--cpp_out', '<(cc_generator_options)<(cc_dir)',
106        '--python_out', '<(py_dir)',
107      ],
108      'message': 'Generating C++ and Python code from <(RULE_INPUT_PATH)',
109      'process_outputs_as_sources': 1,
110    },
111  ],
112  'dependencies': [
113    '<(DEPTH)/third_party/protobuf/protobuf.gyp:protoc#host',
114    '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
115  ],
116  'include_dirs': [
117    '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
118    '<(DEPTH)',
119  ],
120  'direct_dependent_settings': {
121    'include_dirs': [
122      '<(SHARED_INTERMEDIATE_DIR)/protoc_out',
123      '<(DEPTH)',
124    ]
125  },
126  'export_dependent_settings': [
127    # The generated headers reference headers within protobuf_lite,
128    # so dependencies must be able to find those headers too.
129    '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite',
130  ],
131  # This target exports a hard dependency because it generates header
132  # files.
133  'hard_dependency': 1,
134}
135