andrew@webrtc.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 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. |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 8 | |
andrew@webrtc.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 9 | # Copied from Chromium's src/build/protoc.gypi |
| 10 | # |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 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 |
kjellander | 40bebd3 | 2016-04-20 06:22:20 -0700 | [diff] [blame] | 15 | # |
| 16 | # Local changes: |
| 17 | # * Removed <(DEPTH) from include_dir due to difficulties with generated |
| 18 | # downstream code. |
| 19 | |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 20 | |
| 21 | # This file is meant to be included into a target to provide a rule |
andrew@webrtc.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 22 | # to invoke protoc in a consistent manner. For Java-targets, see |
| 23 | # protoc_java.gypi. |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 24 | # |
| 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.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 52 | # 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.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 60 | # 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.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 67 | 'protoc_wrapper': '<(DEPTH)/tools/protoc_wrapper/protoc_wrapper.py', |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 68 | 'cc_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out/<(proto_out_dir)', |
| 69 | 'py_dir': '<(PRODUCT_DIR)/pyproto/<(proto_out_dir)', |
andrew@webrtc.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 70 | 'cc_generator_options%': '', |
| 71 | 'cc_include%': '', |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 72 | 'proto_in_dir%': '.', |
andrew@webrtc.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 73 | '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.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 80 | }, |
| 81 | 'rules': [ |
| 82 | { |
| 83 | 'rule_name': 'genproto', |
| 84 | 'extension': 'proto', |
| 85 | 'inputs': [ |
andrew@webrtc.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 86 | '<(protoc_wrapper)', |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 87 | '<(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.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 95 | 'python', |
| 96 | '<(protoc_wrapper)', |
ehmaldonado | b0b0edb | 2016-08-24 08:16:21 -0700 | [diff] [blame] | 97 | '--protoc', |
| 98 | '<(protoc)', |
andrew@webrtc.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 99 | # 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.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 102 | # 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. |
ehmaldonado | b0b0edb | 2016-08-24 08:16:21 -0700 | [diff] [blame] | 104 | '--cc-out-dir', '<(cc_generator_options)<(cc_dir)', |
| 105 | '--py-out-dir', '<(py_dir)', |
| 106 | '<(RULE_INPUT_ROOT)<(RULE_INPUT_EXT)', |
andrew@webrtc.org | 225f2b8 | 2013-05-20 21:12:58 +0000 | [diff] [blame] | 107 | ], |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 108 | 'message': 'Generating C++ and Python code from <(RULE_INPUT_PATH)', |
| 109 | 'process_outputs_as_sources': 1, |
| 110 | }, |
| 111 | ], |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 112 | 'include_dirs': [ |
| 113 | '<(SHARED_INTERMEDIATE_DIR)/protoc_out', |
| 114 | ], |
| 115 | 'direct_dependent_settings': { |
| 116 | 'include_dirs': [ |
| 117 | '<(SHARED_INTERMEDIATE_DIR)/protoc_out', |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 118 | ] |
| 119 | }, |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 120 | # This target exports a hard dependency because it generates header |
| 121 | # files. |
| 122 | 'hard_dependency': 1, |
kjellander | 292e192 | 2016-01-13 05:46:58 -0800 | [diff] [blame] | 123 | '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.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 136 | } |