# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if (is_win) {
  config_h_dir = "vsprojects"
} else {
  config_h_dir = "."
}

config("protobuf_config") {
  include_dirs = [
    "src",
    config_h_dir,
  ]
  defines = [
    "PROTOBUF_USE_DLLS",
    "GOOGLE_PROTOBUF_NO_RTTI",
    "GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
  ]

  if (is_win) {
    # TODO(jschuh): http://crbug.com/167187 size_t -> int.
    cflags = [ "/wd4267" ]
  }
}

# This condif should be applied to targets using generated code from the proto
# compiler. It sets up the include directories properly.
config("using_proto") {
  include_dirs = [
    "$root_gen_dir/protoc_out",
  ]
}

protobuf_lite_sources = [
  "src/google/protobuf/extension_set.cc",
  "src/google/protobuf/extension_set.h",
  "src/google/protobuf/generated_message_util.cc",
  "src/google/protobuf/generated_message_util.h",
  "src/google/protobuf/io/coded_stream.cc",
  "src/google/protobuf/io/coded_stream.h",
  "src/google/protobuf/io/coded_stream_inl.h",
  "src/google/protobuf/io/zero_copy_stream.cc",
  "src/google/protobuf/io/zero_copy_stream.h",
  "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
  "src/google/protobuf/io/zero_copy_stream_impl_lite.h",
  "src/google/protobuf/message_lite.cc",
  "src/google/protobuf/message_lite.h",
  "src/google/protobuf/repeated_field.cc",
  "src/google/protobuf/repeated_field.h",
  "src/google/protobuf/stubs/atomicops.h",
  "src/google/protobuf/stubs/atomicops_internals_arm_gcc.h",
  "src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h",
  "src/google/protobuf/stubs/atomicops_internals_macosx.h",
  "src/google/protobuf/stubs/atomicops_internals_mips_gcc.h",
  "src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc",
  "src/google/protobuf/stubs/atomicops_internals_x86_gcc.h",
  "src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc",
  "src/google/protobuf/stubs/atomicops_internals_x86_msvc.h",
  "src/google/protobuf/stubs/common.cc",
  "src/google/protobuf/stubs/common.h",
  "src/google/protobuf/stubs/hash.h",
  "src/google/protobuf/stubs/map-util.h",
  "src/google/protobuf/stubs/once.cc",
  "src/google/protobuf/stubs/once.h",
  "src/google/protobuf/stubs/platform_macros.h",
  "src/google/protobuf/unknown_field_set.cc",
  "src/google/protobuf/unknown_field_set.h",
  "src/google/protobuf/wire_format_lite.cc",
  "src/google/protobuf/wire_format_lite.h",
  "src/google/protobuf/wire_format_lite_inl.h",
  "$config_h_dir/config.h",
]

protobuf_lite_cflags = []
if (is_win) {
  protobuf_lite_cflags = [
    "/wd4018",  # signed/unsigned mismatch in comparison
    "/wd4244",  # implicit conversion, possible loss of data
    "/wd4355",  # 'this' used in base member initializer list
    "/wd4267",  # size_t to int truncation
    "/wd4291",  # no matching operator delete for a placement new
  ]
}

source_set("protobuf_lite") {
  sources = protobuf_lite_sources

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
  direct_dependent_configs = [ ":protobuf_config" ]

  cflags = protobuf_lite_cflags

  # Required for component builds. See http://crbug.com/172800.
  defines = [ "LIBPROTOBUF_EXPORTS" ]
}

# This is the full, heavy protobuf lib that's needed for c++ .protos that don't
# specify the LITE_RUNTIME option. The protocol compiler itself (protoc) falls
# into that category. Do not use in Chrome code.

source_set("protobuf_full") {
  visibility = ":*"  # Prevent people from depending on this outside our file.

  sources = protobuf_lite_sources
  sources += [
    "src/google/protobuf/descriptor.h",
    "src/google/protobuf/descriptor.pb.h",
    "src/google/protobuf/descriptor_database.h",
    "src/google/protobuf/dynamic_message.h",
    "src/google/protobuf/generated_enum_reflection.h",
    "src/google/protobuf/generated_message_reflection.h",
    "src/google/protobuf/message.h",
    "src/google/protobuf/reflection_ops.h",
    "src/google/protobuf/service.h",
    "src/google/protobuf/text_format.h",
    "src/google/protobuf/wire_format.h",
    "src/google/protobuf/io/gzip_stream.h",
    "src/google/protobuf/io/printer.h",
    "src/google/protobuf/io/tokenizer.h",
    "src/google/protobuf/io/zero_copy_stream_impl.h",
    "src/google/protobuf/compiler/code_generator.h",
    "src/google/protobuf/compiler/command_line_interface.h",
    "src/google/protobuf/compiler/importer.h",
    "src/google/protobuf/compiler/java/java_doc_comment.cc",
    "src/google/protobuf/compiler/java/java_doc_comment.h",
    "src/google/protobuf/compiler/parser.h",

    "src/google/protobuf/stubs/strutil.cc",
    "src/google/protobuf/stubs/strutil.h",
    "src/google/protobuf/stubs/substitute.cc",
    "src/google/protobuf/stubs/substitute.h",
    "src/google/protobuf/stubs/stl_util.h",
    "src/google/protobuf/stubs/stringprintf.cc",
    "src/google/protobuf/stubs/stringprintf.h",
    "src/google/protobuf/stubs/structurally_valid.cc",
    "src/google/protobuf/stubs/template_util.h",
    "src/google/protobuf/stubs/type_traits.h",

    "src/google/protobuf/descriptor.cc",
    "src/google/protobuf/descriptor.pb.cc",
    "src/google/protobuf/descriptor_database.cc",
    "src/google/protobuf/dynamic_message.cc",
    "src/google/protobuf/extension_set_heavy.cc",
    "src/google/protobuf/generated_message_reflection.cc",
    "src/google/protobuf/message.cc",
    "src/google/protobuf/reflection_ops.cc",
    "src/google/protobuf/service.cc",
    "src/google/protobuf/text_format.cc",
    "src/google/protobuf/wire_format.cc",
    # This file pulls in zlib, but it's not actually used by protoc, so
    # instead of compiling zlib for the host, let's just exclude this.
    # "src/src/google/protobuf/io/gzip_stream.cc",
    "src/google/protobuf/io/printer.cc",
    "src/google/protobuf/io/tokenizer.cc",
    "src/google/protobuf/io/zero_copy_stream_impl.cc",
    "src/google/protobuf/compiler/importer.cc",
    "src/google/protobuf/compiler/parser.cc",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
  direct_dependent_configs = [ ":protobuf_config" ]

  cflags = protobuf_lite_cflags
}

# Only compile the compiler for the host architecture.
if (current_toolchain == host_toolchain) {
  executable("protoc") {
    sources = [
      "src/google/protobuf/compiler/code_generator.cc",
      "src/google/protobuf/compiler/command_line_interface.cc",
      "src/google/protobuf/compiler/plugin.cc",
      "src/google/protobuf/compiler/plugin.pb.cc",
      "src/google/protobuf/compiler/subprocess.cc",
      "src/google/protobuf/compiler/subprocess.h",
      "src/google/protobuf/compiler/zip_writer.cc",
      "src/google/protobuf/compiler/zip_writer.h",
      "src/google/protobuf/compiler/cpp/cpp_enum.cc",
      "src/google/protobuf/compiler/cpp/cpp_enum.h",
      "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
      "src/google/protobuf/compiler/cpp/cpp_enum_field.h",
      "src/google/protobuf/compiler/cpp/cpp_extension.cc",
      "src/google/protobuf/compiler/cpp/cpp_extension.h",
      "src/google/protobuf/compiler/cpp/cpp_field.cc",
      "src/google/protobuf/compiler/cpp/cpp_field.h",
      "src/google/protobuf/compiler/cpp/cpp_file.cc",
      "src/google/protobuf/compiler/cpp/cpp_file.h",
      "src/google/protobuf/compiler/cpp/cpp_generator.cc",
      "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
      "src/google/protobuf/compiler/cpp/cpp_helpers.h",
      "src/google/protobuf/compiler/cpp/cpp_message.cc",
      "src/google/protobuf/compiler/cpp/cpp_message.h",
      "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
      "src/google/protobuf/compiler/cpp/cpp_message_field.h",
      "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
      "src/google/protobuf/compiler/cpp/cpp_primitive_field.h",
      "src/google/protobuf/compiler/cpp/cpp_service.cc",
      "src/google/protobuf/compiler/cpp/cpp_service.h",
      "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
      "src/google/protobuf/compiler/cpp/cpp_string_field.h",
      "src/google/protobuf/compiler/java/java_enum.cc",
      "src/google/protobuf/compiler/java/java_enum.h",
      "src/google/protobuf/compiler/java/java_enum_field.cc",
      "src/google/protobuf/compiler/java/java_enum_field.h",
      "src/google/protobuf/compiler/java/java_extension.cc",
      "src/google/protobuf/compiler/java/java_extension.h",
      "src/google/protobuf/compiler/java/java_field.cc",
      "src/google/protobuf/compiler/java/java_field.h",
      "src/google/protobuf/compiler/java/java_file.cc",
      "src/google/protobuf/compiler/java/java_file.h",
      "src/google/protobuf/compiler/java/java_generator.cc",
      "src/google/protobuf/compiler/java/java_helpers.cc",
      "src/google/protobuf/compiler/java/java_helpers.h",
      "src/google/protobuf/compiler/java/java_message.cc",
      "src/google/protobuf/compiler/java/java_message.h",
      "src/google/protobuf/compiler/java/java_message_field.cc",
      "src/google/protobuf/compiler/java/java_message_field.h",
      "src/google/protobuf/compiler/java/java_primitive_field.cc",
      "src/google/protobuf/compiler/java/java_primitive_field.h",
      "src/google/protobuf/compiler/java/java_service.cc",
      "src/google/protobuf/compiler/java/java_service.h",
      "src/google/protobuf/compiler/java/java_string_field.cc",
      "src/google/protobuf/compiler/java/java_string_field.h",
      "src/google/protobuf/compiler/python/python_generator.cc",
      "src/google/protobuf/compiler/main.cc",
    ]

    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [ "//build/config/compiler:no_chromium_code" ]
    if (is_win) {
      # This is defined internally, don't warn on duplicate.
      configs -= [ "//build/config/win:lean_and_mean" ]
    }

    cflags = protobuf_lite_cflags

    deps = [
      ":protobuf_full",
    ]
  }
}