protoc.gypi 4.0 KB

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