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

import("//build/config/cast.gni")
import("//build/config/locales.gni")
import("//components/cast_streaming/features.gni")
import("//media/media_options.gni")

# These args blocks should contain arguments used within the //chromecast
# directory. Arguments which are used in other Chrome components should
# be instead declared in //build/config/cast.gni.
declare_args() {
  # True if Chromecast build is targeted for linux desktop. This type of build
  # is useful for testing and development, but currently supports only a subset
  # of Cast functionality. Though this defaults to true for x86 Linux devices,
  # this should be overridden manually for an embedded x86 build.
  is_cast_desktop_build =
      target_os == "linux" && (target_cpu == "x86" || target_cpu == "x64") &&
      enable_cast_receiver
}

declare_args() {
  # If true, IS_CAST_DEBUG_BUILD() will evaluate to 1 in version.h. Otherwise,
  # it will evaluate to 0. Overriding this when is_debug=false is useful for
  # doing engineering builds.
  cast_is_debug = is_debug

  # The incremental build number. The Cast automated builders will set this
  # value to indicate the buildset. Note: The default value should be greater
  # than any value the builder may assign to prevent attempted automatic updates
  # when the default value is used.
  cast_build_incremental = "999999"

  # If true, the mixer will be instantiated inside cast_shell. When false, the
  # mixer is expected to be running in another process.
  mixer_in_cast_shell = true

  # unified flag to pick monotonic_clock OR monotonic_clock_raw
  media_clock_monotonic_raw = !is_android && !is_cast_desktop_build

  # Include 'Android' in user agent string to avoid being served desktop
  # versions of websites.
  # TODO(halliwell): consider making this default for all Cast hardware.
  use_android_user_agent = false

  # Contain default command line switches we want to set.
  # This will get joined into a comma-separated list that looks like:
  #   "test-flag-one=public,test-flag-two=true,test-flag-three=1,"
  # TODO(ziyangch): make the parsing logic have ability to quote/escape characters.
  default_command_line_flags = []

  # Set to true to enable external Mojo services to communicate with services
  # within cast_shell.
  enable_external_mojo_services = is_linux || is_chromeos || is_android

  # Recording happens at this sample rate. Must be 16000, 48000 or 96000 Hz.
  audio_input_sample_rate = 16000

  # Whether use unix sockets in Cast input/output stream.
  use_unix_sockets = is_linux || is_chromeos || is_android

  # Extra rpath to use for standalone services.
  iot_service_rpath = ""

  # True to use the Chromium runtime for cast rendering.
  enable_chromium_runtime_cast_renderer = false

  # device specific string to append to User string.
  device_user_agent_suffix = ""

  # link vendor-supplied functionality as shared libraries. When true,
  # cast_shared_library targets are normal shared libraries. When false,
  # they become source_sets.
  use_vendor_shlibs = !is_android

  # build APKs/bundles for the listed device types. Each APK has different
  # features enabled in its manifest to ensure it is only distributed to select
  # devices.
  android_device_types = [
    "generic",
    "atv",
    "tablet",
    "automotive",
  ]

  # Use Starboard graphics backend. Compile it in statically.
  enable_starboard_graphics = false

  # Build Starboard graphics backend as shared library.
  starboard_graphics_is_shared = false

  # Use Starboard media backend.
  enable_starboard_media = false

  # This is the Cast release version. It should have form that identify a
  #  release version in a unique way, separately from the incremental build
  #  number. In example can have a form of <major>.<minor>.
  # This values is a part if product version used by the crash reporting client,
  #  and expected to be set by the external build system.
  # For local user build we set it to "local.${USER}" value.
  cast_build_release = "local." + getenv("USER")
}

# All locales supported by Cast builds. This provides a single point of
# reference for all GN files referencing a locales list.
# |locales_without_pseudolocales| is declared in //build/config/locales.gni.
# See https://chromium-review.googlesource.com/488166/ for why we can't use
# pseudolocales in chromecast.
cast_locales = locales_without_pseudolocales

# Android currently supports more locales than Desktop and ChromeOS.
# If Cast will also the android files update this and the Cast grd files.
if (is_android) {
  # Subtract out additional Android locales
  cast_locales -= extended_locales
}
if (!(is_ios || is_chromeos)) {
  # Subtract out the additional desktop locales
  cast_locales -= [
    "af",
    "ur",
  ]
}

# Use Chromecast CDMs for protected content. Some Android platforms use
# MediaDrm for CDM support.
declare_args() {
  use_chromecast_cdms = true
}

foreach(target_type,
        [
          "executable",
          "loadable_module",
          "source_set",
        ]) {
  template("cast_${target_type}") {
    target(target_type, target_name) {
      forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
      forward_variables_from(invoker, [ "testonly" ])

      configs += [ "//chromecast:cast_config" ]
    }
  }
}

template("cast_shared_library") {
  if (use_vendor_shlibs) {
    target_type = "shared_library"
  } else {
    target_type = "source_set"
  }
  target(target_type, target_name) {
    forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
    forward_variables_from(invoker, [ "testonly" ])

    configs += [ "//chromecast:cast_config" ]
  }
}

# Set the defaults for each target. The defaults for these target wrappers
# should match their unwrapped counterparts in BUILDCONFIG.gn. The variables
# referenced below are declared in BUILDCONFIG.gn.
set_defaults("cast_executable") {
  configs = default_executable_configs
}

set_defaults("cast_shared_library") {
  configs = default_shared_library_configs
  if (is_android) {
    configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
  }
}

set_defaults("cast_loadable_module") {
  configs = default_shared_library_configs
  if (is_android) {
    configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
  }
}

set_defaults("cast_source_set") {
  configs = default_compiler_configs
}
