michael@0: # Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: # This file is meant to be included into a target to provide a rule michael@0: # to invoke protoc in a consistent manner. michael@0: # michael@0: # To use this, create a gyp target with the following form: michael@0: # { michael@0: # 'target_name': 'my_proto_lib', michael@0: # 'type': 'static_library', michael@0: # 'sources': [ michael@0: # 'foo.proto', michael@0: # 'bar.proto', michael@0: # ], michael@0: # 'variables': { michael@0: # # Optional, see below: 'proto_in_dir': '.' michael@0: # 'proto_out_dir': 'dir/for/my_proto_lib' michael@0: # }, michael@0: # 'includes': ['path/to/this/gypi/file'], michael@0: # } michael@0: # If necessary, you may add normal .cc files to the sources list or other gyp michael@0: # dependencies. The proto headers are guaranteed to be generated before any michael@0: # source files, even within this target, are compiled. michael@0: # michael@0: # The 'proto_in_dir' variable must be the relative path to the michael@0: # directory containing the .proto files. If left out, it defaults to '.'. michael@0: # michael@0: # The 'proto_out_dir' variable specifies the path suffix that output michael@0: # files are generated under. Targets that gyp-depend on my_proto_lib michael@0: # will be able to include the resulting proto headers with an include michael@0: # like: michael@0: # #include "dir/for/my_proto_lib/foo.pb.h" michael@0: # michael@0: # If you need to add an EXPORT macro to a protobuf's c++ header, set the michael@0: # 'cc_generator_options' variable with the value: 'dllexport_decl=FOO_EXPORT:' michael@0: # e.g. 'dllexport_decl=BASE_EXPORT:' michael@0: # michael@0: # It is likely you also need to #include a file for the above EXPORT macro to michael@0: # work. You can do so with the 'cc_include' variable. michael@0: # e.g. 'base/base_export.h' michael@0: # michael@0: # Implementation notes: michael@0: # A proto_out_dir of foo/bar produces michael@0: # <(SHARED_INTERMEDIATE_DIR)/protoc_out/foo/bar/{file1,file2}.pb.{cc,h} michael@0: # <(SHARED_INTERMEDIATE_DIR)/pyproto/foo/bar/{file1,file2}_pb2.py michael@0: michael@0: { michael@0: 'variables': { michael@0: 'protoc_wrapper': '<(DEPTH)/tools/protoc_wrapper/protoc_wrapper.py', michael@0: 'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)', michael@0: 'cc_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out/<(proto_out_dir)', michael@0: 'py_dir': '<(PRODUCT_DIR)/pyproto/<(proto_out_dir)', michael@0: 'cc_generator_options%': '', michael@0: 'cc_include%': '', michael@0: 'proto_in_dir%': '.', michael@0: }, michael@0: 'rules': [ michael@0: { michael@0: 'rule_name': 'genproto', michael@0: 'extension': 'proto', michael@0: 'inputs': [ michael@0: '<(protoc_wrapper)', michael@0: '<(protoc)', michael@0: ], michael@0: 'outputs': [ michael@0: '<(py_dir)/<(RULE_INPUT_ROOT)_pb2.py', michael@0: '<(cc_dir)/<(RULE_INPUT_ROOT).pb.cc', michael@0: '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h', michael@0: ], michael@0: 'action': [ michael@0: 'python', michael@0: '<(protoc_wrapper)', michael@0: '--include', michael@0: '<(cc_include)', michael@0: '--protobuf', michael@0: '<(cc_dir)/<(RULE_INPUT_ROOT).pb.h', michael@0: '--', michael@0: '<(protoc)', michael@0: # Using the --arg val form (instead of --arg=val) allows gyp's msvs rule michael@0: # generation to correct 'val' which is a path. michael@0: '--proto_path','<(proto_in_dir)', michael@0: # Naively you'd use <(RULE_INPUT_PATH) here, but protoc requires michael@0: # --proto_path is a strict prefix of the path given as an argument. michael@0: '<(proto_in_dir)/<(RULE_INPUT_ROOT)<(RULE_INPUT_EXT)', michael@0: '--cpp_out', '<(cc_generator_options)<(cc_dir)', michael@0: '--python_out', '<(py_dir)', michael@0: ], michael@0: 'msvs_cygwin_shell': 0, michael@0: 'message': 'Generating C++ and Python code from <(RULE_INPUT_PATH)', michael@0: 'process_outputs_as_sources': 1, michael@0: }, michael@0: ], michael@0: 'dependencies': [ michael@0: '<(DEPTH)/third_party/protobuf/protobuf.gyp:protoc#host', michael@0: '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite', michael@0: ], michael@0: 'include_dirs': [ michael@0: '<(SHARED_INTERMEDIATE_DIR)/protoc_out', michael@0: '<(DEPTH)', michael@0: ], michael@0: 'direct_dependent_settings': { michael@0: 'include_dirs': [ michael@0: '<(SHARED_INTERMEDIATE_DIR)/protoc_out', michael@0: '<(DEPTH)', michael@0: ] michael@0: }, michael@0: 'export_dependent_settings': [ michael@0: # The generated headers reference headers within protobuf_lite, michael@0: # so dependencies must be able to find those headers too. michael@0: '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite', michael@0: ], michael@0: # This target exports a hard dependency because it generates header michael@0: # files. michael@0: 'hard_dependency': 1, michael@0: }