Home | History | Annotate | Download | only in protobuf
      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 
      5 {
      6   'conditions': [
      7     ['use_system_protobuf==0', {
      8       'conditions': [
      9         ['OS!="win"', {
     10           'variables': {
     11             'config_h_dir':
     12               '.',  # crafted for gcc/linux.
     13           },
     14         }, {  # else, OS=="win"
     15           'variables': {
     16             'config_h_dir':
     17               'vsprojects',  # crafted for msvc.
     18           },
     19           'target_defaults': {
     20             'msvs_disabled_warnings': [
     21               4018,  # signed/unsigned mismatch in comparison
     22               4244,  # implicit conversion, possible loss of data
     23               4355,  # 'this' used in base member initializer list
     24               4267,  # size_t to int truncation
     25               4291,  # no matching operator delete for a placement new
     26             ],
     27             'defines!': [
     28               'WIN32_LEAN_AND_MEAN',  # Protobuf defines this itself.
     29             ],
     30           },
     31         }],
     32         ['OS=="ios" and "<(GENERATOR)"!="ninja"', {
     33           'variables': {
     34             'ninja_output_dir': 'ninja-protoc',
     35             'ninja_product_dir':
     36               '<(DEPTH)/xcodebuild/<(ninja_output_dir)/<(CONFIGURATION_NAME)',
     37             # Gyp to rerun
     38             're_run_targets': [
     39               'third_party/protobuf/protobuf.gyp',
     40             ],
     41           },
     42           'targets': [
     43             {
     44               # On iOS, generating protoc is done via two actions: (1) compiling
     45               # the executable with ninja, and (2) copying the executable into a
     46               # location that is shared with other projects. These actions are
     47               # separated into two targets in order to be able to specify that the
     48               # second action should not run until the first action finishes (since
     49               # the ordering of multiple actions in one target is defined only by
     50               # inputs and outputs, and it's impossible to set correct inputs for
     51               # the ninja build, so setting all the inputs and outputs isn't an
     52               # option). The first target is given here; the second target is the
     53               # normal protoc target under the condition that "OS==iOS".
     54               'target_name': 'compile_protoc',
     55               'type': 'none',
     56               'includes': ['../../build/ios/mac_build.gypi'],
     57               'actions': [
     58                 {
     59                   'action_name': 'compile protoc',
     60                   'inputs': [],
     61                   'outputs': [],
     62                   'action': [
     63                     '<@(ninja_cmd)',
     64                     'protoc',
     65                   ],
     66                   'message': 'Generating the C++ protocol buffers compiler',
     67                 },
     68               ],
     69             },
     70           ],
     71         }],
     72       ],
     73       'targets': [
     74         # The "lite" lib is about 1/7th the size of the heavy lib,
     75         # but it doesn't support some of the more exotic features of
     76         # protobufs, like reflection.  To generate C++ code that can link
     77         # against the lite version of the library, add the option line:
     78         #
     79         #   option optimize_for = LITE_RUNTIME;
     80         #
     81         # to your .proto file.
     82         {
     83           'target_name': 'protobuf_lite',
     84           'type': '<(component)',
     85           'toolsets': ['host', 'target'],
     86           'includes': [
     87             'protobuf_lite.gypi',
     88           ],
     89           # Required for component builds. See http://crbug.com/172800.
     90           'defines': [
     91             'LIBPROTOBUF_EXPORTS',
     92             'PROTOBUF_USE_DLLS',
     93           ],
     94           'direct_dependent_settings': {
     95             'defines': [
     96               'PROTOBUF_USE_DLLS',
     97             ],
     98           },
     99         },
    100         # This is the full, heavy protobuf lib that's needed for c++ .protos
    101         # that don't specify the LITE_RUNTIME option.  The protocol
    102         # compiler itself (protoc) falls into that category.
    103         #
    104         # DO NOT LINK AGAINST THIS TARGET IN CHROME CODE  --agl
    105         {
    106           'target_name': 'protobuf_full_do_not_use',
    107           'type': 'static_library',
    108           'toolsets': ['host','target'],
    109           'includes': [
    110             'protobuf_lite.gypi',
    111           ],
    112           'sources': [
    113             'src/google/protobuf/descriptor.h',
    114             'src/google/protobuf/descriptor.pb.h',
    115             'src/google/protobuf/descriptor_database.h',
    116             'src/google/protobuf/dynamic_message.h',
    117             'src/google/protobuf/generated_enum_reflection.h',
    118             'src/google/protobuf/generated_message_reflection.h',
    119             'src/google/protobuf/message.h',
    120             'src/google/protobuf/reflection_ops.h',
    121             'src/google/protobuf/service.h',
    122             'src/google/protobuf/text_format.h',
    123             'src/google/protobuf/wire_format.h',
    124             'src/google/protobuf/io/gzip_stream.h',
    125             'src/google/protobuf/io/printer.h',
    126             'src/google/protobuf/io/tokenizer.h',
    127             'src/google/protobuf/io/zero_copy_stream_impl.h',
    128             'src/google/protobuf/compiler/code_generator.h',
    129             'src/google/protobuf/compiler/command_line_interface.h',
    130             'src/google/protobuf/compiler/importer.h',
    131             'src/google/protobuf/compiler/java/java_doc_comment.cc',
    132             'src/google/protobuf/compiler/java/java_doc_comment.h',
    133             'src/google/protobuf/compiler/parser.h',
    134 
    135             'src/google/protobuf/stubs/strutil.cc',
    136             'src/google/protobuf/stubs/strutil.h',
    137             'src/google/protobuf/stubs/substitute.cc',
    138             'src/google/protobuf/stubs/substitute.h',
    139             'src/google/protobuf/stubs/stl_util.h',
    140             'src/google/protobuf/stubs/stringprintf.cc',
    141             'src/google/protobuf/stubs/stringprintf.h',
    142             'src/google/protobuf/stubs/structurally_valid.cc',
    143             'src/google/protobuf/stubs/template_util.h',
    144             'src/google/protobuf/stubs/type_traits.h',
    145 
    146             'src/google/protobuf/descriptor.cc',
    147             'src/google/protobuf/descriptor.pb.cc',
    148             'src/google/protobuf/descriptor_database.cc',
    149             'src/google/protobuf/dynamic_message.cc',
    150             'src/google/protobuf/extension_set.cc',
    151             'src/google/protobuf/extension_set.h',
    152             'src/google/protobuf/extension_set_heavy.cc',
    153             'src/google/protobuf/generated_message_reflection.cc',
    154             'src/google/protobuf/message.cc',
    155             'src/google/protobuf/reflection_ops.cc',
    156             'src/google/protobuf/service.cc',
    157             'src/google/protobuf/text_format.cc',
    158             'src/google/protobuf/wire_format.cc',
    159             # This file pulls in zlib, but it's not actually used by protoc, so
    160             # instead of compiling zlib for the host, let's just exclude this.
    161             # 'src/src/google/protobuf/io/gzip_stream.cc',
    162             'src/google/protobuf/io/printer.cc',
    163             'src/google/protobuf/io/tokenizer.cc',
    164             'src/google/protobuf/io/zero_copy_stream_impl.cc',
    165             'src/google/protobuf/compiler/importer.cc',
    166             'src/google/protobuf/compiler/parser.cc',
    167           ],
    168         },
    169         {
    170           'target_name': 'protoc',
    171           'conditions': [
    172             ['OS!="ios" or "<(GENERATOR)"=="ninja"', {
    173               'type': 'executable',
    174               'toolsets': ['host'],
    175               'sources': [
    176                 'src/google/protobuf/compiler/code_generator.cc',
    177                 'src/google/protobuf/compiler/command_line_interface.cc',
    178                 'src/google/protobuf/compiler/plugin.cc',
    179                 'src/google/protobuf/compiler/plugin.pb.cc',
    180                 'src/google/protobuf/compiler/subprocess.cc',
    181                 'src/google/protobuf/compiler/subprocess.h',
    182                 'src/google/protobuf/compiler/zip_writer.cc',
    183                 'src/google/protobuf/compiler/zip_writer.h',
    184                 'src/google/protobuf/compiler/cpp/cpp_enum.cc',
    185                 'src/google/protobuf/compiler/cpp/cpp_enum.h',
    186                 'src/google/protobuf/compiler/cpp/cpp_enum_field.cc',
    187                 'src/google/protobuf/compiler/cpp/cpp_enum_field.h',
    188                 'src/google/protobuf/compiler/cpp/cpp_extension.cc',
    189                 'src/google/protobuf/compiler/cpp/cpp_extension.h',
    190                 'src/google/protobuf/compiler/cpp/cpp_field.cc',
    191                 'src/google/protobuf/compiler/cpp/cpp_field.h',
    192                 'src/google/protobuf/compiler/cpp/cpp_file.cc',
    193                 'src/google/protobuf/compiler/cpp/cpp_file.h',
    194                 'src/google/protobuf/compiler/cpp/cpp_generator.cc',
    195                 'src/google/protobuf/compiler/cpp/cpp_helpers.cc',
    196                 'src/google/protobuf/compiler/cpp/cpp_helpers.h',
    197                 'src/google/protobuf/compiler/cpp/cpp_message.cc',
    198                 'src/google/protobuf/compiler/cpp/cpp_message.h',
    199                 'src/google/protobuf/compiler/cpp/cpp_message_field.cc',
    200                 'src/google/protobuf/compiler/cpp/cpp_message_field.h',
    201                 'src/google/protobuf/compiler/cpp/cpp_primitive_field.cc',
    202                 'src/google/protobuf/compiler/cpp/cpp_primitive_field.h',
    203                 'src/google/protobuf/compiler/cpp/cpp_service.cc',
    204                 'src/google/protobuf/compiler/cpp/cpp_service.h',
    205                 'src/google/protobuf/compiler/cpp/cpp_string_field.cc',
    206                 'src/google/protobuf/compiler/cpp/cpp_string_field.h',
    207                 'src/google/protobuf/compiler/java/java_enum.cc',
    208                 'src/google/protobuf/compiler/java/java_enum.h',
    209                 'src/google/protobuf/compiler/java/java_enum_field.cc',
    210                 'src/google/protobuf/compiler/java/java_enum_field.h',
    211                 'src/google/protobuf/compiler/java/java_extension.cc',
    212                 'src/google/protobuf/compiler/java/java_extension.h',
    213                 'src/google/protobuf/compiler/java/java_field.cc',
    214                 'src/google/protobuf/compiler/java/java_field.h',
    215                 'src/google/protobuf/compiler/java/java_file.cc',
    216                 'src/google/protobuf/compiler/java/java_file.h',
    217                 'src/google/protobuf/compiler/java/java_generator.cc',
    218                 'src/google/protobuf/compiler/java/java_helpers.cc',
    219                 'src/google/protobuf/compiler/java/java_helpers.h',
    220                 'src/google/protobuf/compiler/java/java_message.cc',
    221                 'src/google/protobuf/compiler/java/java_message.h',
    222                 'src/google/protobuf/compiler/java/java_message_field.cc',
    223                 'src/google/protobuf/compiler/java/java_message_field.h',
    224                 'src/google/protobuf/compiler/java/java_primitive_field.cc',
    225                 'src/google/protobuf/compiler/java/java_primitive_field.h',
    226                 'src/google/protobuf/compiler/java/java_service.cc',
    227                 'src/google/protobuf/compiler/java/java_service.h',
    228                 'src/google/protobuf/compiler/java/java_string_field.cc',
    229                 'src/google/protobuf/compiler/java/java_string_field.h',
    230                 'src/google/protobuf/compiler/python/python_generator.cc',
    231                 'src/google/protobuf/compiler/main.cc',
    232               ],
    233               'dependencies': [
    234                 'protobuf_full_do_not_use',
    235               ],
    236               'include_dirs': [
    237                 '<(config_h_dir)',
    238                 'src/src',
    239               ],
    240             }, {  # else, OS=="ios" and "<(GENERATOR)"!="ninja"
    241               'type': 'none',
    242               'dependencies': [
    243                 'compile_protoc',
    244               ],
    245               'actions': [
    246                 {
    247                   'action_name': 'copy protoc',
    248                   'inputs': [
    249                     '<(ninja_product_dir)/protoc',
    250                   ],
    251                   'outputs': [
    252                     '<(PRODUCT_DIR)/protoc',
    253                   ],
    254                   'action': [
    255                     'cp',
    256                     '<(ninja_product_dir)/protoc',
    257                     '<(PRODUCT_DIR)/protoc',
    258                   ],
    259                 },
    260               ],
    261             }],
    262           ],
    263         },
    264         {
    265           # Generate the python module needed by all protoc-generated Python code.
    266           'target_name': 'py_proto',
    267           'type': 'none',
    268           'copies': [
    269             {
    270               'destination': '<(PRODUCT_DIR)/pyproto/google/',
    271               'files': [
    272                 # google/ module gets an empty __init__.py.
    273                 '__init__.py',
    274               ],
    275             },
    276             {
    277               'destination': '<(PRODUCT_DIR)/pyproto/google/protobuf',
    278               'files': [
    279                 'python/google/protobuf/__init__.py',
    280                 'python/google/protobuf/descriptor.py',
    281                 'python/google/protobuf/descriptor_database.py',
    282                 'python/google/protobuf/descriptor_pool.py',
    283                 'python/google/protobuf/message.py',
    284                 'python/google/protobuf/message_factory.py',
    285                 'python/google/protobuf/reflection.py',
    286                 'python/google/protobuf/service.py',
    287                 'python/google/protobuf/service_reflection.py',
    288                 'python/google/protobuf/text_format.py',
    289 
    290                 # TODO(ncarter): protoc's python generator treats
    291                 # descriptor.proto specially, but it's not possible to trigger
    292                 # the special treatment unless you run protoc from ./src/src
    293                 # (the treatment is based on the path to the .proto file
    294                 # matching a constant exactly). I'm not sure how to convince
    295                 # gyp to execute a rule from a different directory.  Until this
    296                 # is resolved, use a copy of descriptor_pb2.py that I manually
    297                 # generated.
    298                 'descriptor_pb2.py',
    299               ],
    300             },
    301             {
    302               'destination': '<(PRODUCT_DIR)/pyproto/google/protobuf/internal',
    303               'files': [
    304                 'python/google/protobuf/internal/__init__.py',
    305                 'python/google/protobuf/internal/api_implementation.py',
    306                 'python/google/protobuf/internal/containers.py',
    307                 'python/google/protobuf/internal/cpp_message.py',
    308                 'python/google/protobuf/internal/decoder.py',
    309                 'python/google/protobuf/internal/encoder.py',
    310                 'python/google/protobuf/internal/enum_type_wrapper.py',
    311                 'python/google/protobuf/internal/generator_test.py',
    312                 'python/google/protobuf/internal/message_listener.py',
    313                 'python/google/protobuf/internal/python_message.py',
    314                 'python/google/protobuf/internal/type_checkers.py',
    315                 'python/google/protobuf/internal/wire_format.py',
    316               ],
    317             },
    318           ],
    319       #   # We can't generate a proper descriptor_pb2.py -- see earlier comment.
    320       #   'rules': [
    321       #     {
    322       #       'rule_name': 'genproto',
    323       #       'extension': 'proto',
    324       #       'inputs': [
    325       #         '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
    326       #       ],
    327       #       'variables': {
    328       #         # The protoc compiler requires a proto_path argument with the
    329       #           # directory containing the .proto file.
    330       #           'rule_input_relpath': 'src/google/protobuf',
    331       #         },
    332       #         'outputs': [
    333       #           '<(PRODUCT_DIR)/pyproto/google/protobuf/<(RULE_INPUT_ROOT)_pb2.py',
    334       #         ],
    335       #         'action': [
    336       #           '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
    337       #           '-I./src',
    338       #           '-I.',
    339       #           '--python_out=<(PRODUCT_DIR)/pyproto/google/protobuf',
    340       #           'google/protobuf/descriptor.proto',
    341       #         ],
    342       #         'message': 'Generating Python code from <(RULE_INPUT_PATH)',
    343       #       },
    344       #     ],
    345       #     'dependencies': [
    346       #       'protoc#host',
    347       #     ],
    348       #     'sources': [
    349       #       'src/google/protobuf/descriptor.proto',
    350       #     ],
    351          },
    352       ],
    353     }, { # use_system_protobuf==1
    354       'targets': [
    355         {
    356           'target_name': 'protobuf_lite',
    357           'type': 'none',
    358           'direct_dependent_settings': {
    359             'cflags': [
    360               # Use full protobuf, because vanilla protobuf doesn't have
    361               # our custom patch to retain unknown fields in lite mode.
    362               '<!@(pkg-config --cflags protobuf)',
    363             ],
    364             'defines': [
    365               'USE_SYSTEM_PROTOBUF',
    366 
    367               # This macro must be defined to suppress the use
    368               # of dynamic_cast<>, which requires RTTI.
    369               'GOOGLE_PROTOBUF_NO_RTTI',
    370               'GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER',
    371             ],
    372           },
    373           'link_settings': {
    374             # Use full protobuf, because vanilla protobuf doesn't have
    375             # our custom patch to retain unknown fields in lite mode.
    376             'ldflags': [
    377               '<!@(pkg-config --libs-only-L --libs-only-other protobuf)',
    378             ],
    379             'libraries': [
    380               '<!@(pkg-config --libs-only-l protobuf)',
    381             ],
    382           },
    383         },
    384         {
    385           'target_name': 'protoc',
    386           'type': 'none',
    387           'toolsets': ['host', 'target'],
    388         },
    389         {
    390           'target_name': 'py_proto',
    391           'type': 'none',
    392         },
    393       ],
    394     }],
    395   ],
    396 }
    397