# 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.

import("//build/buildflag_header.gni")
import("//build/config/nacl/config.gni")
import("//tools/ipc_fuzzer/ipc_fuzzer.gni")

declare_args() {
  enable_mojo_tracing = false
}

buildflag_header("mojo_buildflags") {
  header = "mojo_buildflags.h"

  flags = [ "MOJO_TRACE_ENABLED=$enable_mojo_tracing" ]
}

# Headers and sources which generated bindings can depend upon. No need for
# other targets to depend on this directly: just use the "bindings" target.
component("bindings_base") {
  sources = [
    "array_data_view.h",
    "array_traits.h",
    "array_traits_span.h",
    "array_traits_stl.h",
    "associated_group.h",
    "associated_group_controller.h",
    "clone_traits.h",
    "disconnect_reason.h",
    "enum_traits.h",
    "equals_traits.h",
    "interface_data_view.h",
    "interface_id.h",
    "lib/array_internal.cc",
    "lib/array_internal.h",
    "lib/array_serialization.h",
    "lib/associated_group.cc",
    "lib/associated_group_controller.cc",
    "lib/bindings_internal.h",
    "lib/buffer.cc",
    "lib/buffer.h",
    "lib/fixed_buffer.cc",
    "lib/fixed_buffer.h",
    "lib/handle_serialization.h",
    "lib/hash_util.h",
    "lib/map_data_internal.h",
    "lib/map_serialization.h",
    "lib/may_auto_lock.h",
    "lib/message.cc",
    "lib/message_header_validator.cc",
    "lib/message_internal.cc",
    "lib/message_internal.h",
    "lib/scoped_interface_endpoint_handle.cc",
    "lib/serialization.h",
    "lib/serialization.h",
    "lib/serialization_context.cc",
    "lib/serialization_context.h",
    "lib/serialization_forward.h",
    "lib/serialization_util.h",
    "lib/string_serialization.h",
    "lib/template_util.h",
    "lib/unserialized_message_context.cc",
    "lib/unserialized_message_context.h",
    "lib/validate_params.h",
    "lib/validation_context.cc",
    "lib/validation_context.h",
    "lib/validation_errors.cc",
    "lib/validation_errors.h",
    "lib/validation_util.cc",
    "lib/validation_util.h",
    "map.h",
    "map_data_view.h",
    "map_traits.h",
    "map_traits_flat_map.h",
    "map_traits_stl.h",
    "message.h",
    "message_header_validator.h",
    "scoped_interface_endpoint_handle.h",
    "string_data_view.h",
    "string_traits.h",
    "string_traits_stl.h",
    "string_traits_string_piece.h",
    "struct_ptr.h",
    "struct_traits.h",
    "type_converter.h",
    "union_traits.h",
  ]

  defines = [ "IS_MOJO_CPP_BINDINGS_BASE_IMPL" ]

  public_deps = [
    ":mojo_buildflags",
    "//base",
    "//mojo/public/cpp/system",
  ]

  if (enable_ipc_fuzzer) {
    all_dependent_configs = [ "//tools/ipc_fuzzer:ipc_fuzzer_config" ]
  }
}

component("bindings") {
  sources = [
    "associated_binding.h",
    "associated_binding_set.h",
    "associated_interface_ptr.h",
    "associated_interface_ptr_info.h",
    "associated_interface_request.h",
    "binding.h",
    "binding_set.h",
    "bindings_export.h",
    "callback_helpers.h",
    "connection_error_callback.h",
    "connector.h",
    "filter_chain.h",
    "interface_endpoint_client.h",
    "interface_endpoint_controller.h",
    "interface_ptr.h",
    "interface_ptr_info.h",
    "interface_ptr_set.h",
    "interface_request.h",
    "lib/associated_binding.cc",
    "lib/associated_interface_ptr.cc",
    "lib/associated_interface_ptr_state.cc",
    "lib/associated_interface_ptr_state.h",
    "lib/binding_state.cc",
    "lib/binding_state.h",
    "lib/connector.cc",
    "lib/control_message_handler.cc",
    "lib/control_message_handler.h",
    "lib/control_message_proxy.cc",
    "lib/control_message_proxy.h",
    "lib/filter_chain.cc",
    "lib/interface_endpoint_client.cc",
    "lib/interface_ptr_state.cc",
    "lib/interface_ptr_state.h",
    "lib/interface_serialization.h",
    "lib/multiplex_router.cc",
    "lib/multiplex_router.h",
    "lib/native_enum_data.h",
    "lib/native_enum_serialization.h",
    "lib/native_struct_serialization.cc",
    "lib/native_struct_serialization.h",
    "lib/pipe_control_message_handler.cc",
    "lib/pipe_control_message_proxy.cc",
    "lib/sequence_local_sync_event_watcher.cc",
    "lib/sync_call_restrictions.cc",
    "lib/sync_event_watcher.cc",
    "lib/sync_handle_registry.cc",
    "lib/sync_handle_watcher.cc",
    "lib/task_runner_helper.cc",
    "lib/task_runner_helper.h",
    "native_enum.h",
    "pipe_control_message_handler.h",
    "pipe_control_message_handler_delegate.h",
    "pipe_control_message_proxy.h",
    "raw_ptr_impl_ref_traits.h",
    "sequence_local_sync_event_watcher.h",
    "strong_associated_binding.h",
    "strong_binding.h",
    "strong_binding_set.h",
    "sync_call_restrictions.h",
    "sync_event_watcher.h",
    "sync_handle_registry.h",
    "sync_handle_watcher.h",
    "thread_safe_interface_ptr.h",
    "unique_ptr_impl_ref_traits.h",
  ]

  if (enable_ipc_fuzzer && !is_nacl_nonsfi) {
    sources += [
      "lib/message_dumper.cc",
      "message_dumper.h",
    ]
  }

  public_deps = [
    ":bindings_base",
    ":struct_traits",
    "//base",
    "//ipc:message_support",
    "//ipc:param_traits",
    "//mojo/public/cpp/system",
    "//mojo/public/interfaces/bindings",
  ]

  deps = [
    "//ipc:native_handle_type_converters",
  ]

  defines = [ "MOJO_CPP_BINDINGS_IMPLEMENTATION" ]
}

source_set("struct_traits") {
  sources = [
    "array_traits.h",
    "enum_traits.h",
    "lib/template_util.h",
    "map_traits.h",
    "string_traits.h",
    "struct_traits.h",
    "union_traits.h",
  ]
}

if (!is_ios) {
  # TODO(yzshen): crbug.com/617718 Consider moving this into blink.
  source_set("wtf_support") {
    sources = [
      "array_traits_wtf_vector.h",
      "lib/string_traits_wtf.cc",
      "lib/wtf_clone_equals_util.h",
      "lib/wtf_hash_util.h",
      "lib/wtf_serialization.h",
      "map_traits_wtf_hash_map.h",
      "string_traits_wtf.h",
    ]

    public_deps = [
      ":bindings",
      "//third_party/blink/renderer/platform:platform_export",
      "//third_party/blink/renderer/platform/wtf",
    ]

    public_configs = [ "//third_party/blink/renderer:config" ]
  }
}