# Copyright 2021 The Cobalt Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//starboard/build/config/starboard_target_type.gni")

group("gn_all") {
  testonly = true

  deps = [
    ":default",
    "//starboard/client_porting/cwrappers:cwrappers_test",
    "//starboard/client_porting/eztime",
    "//starboard/client_porting/eztime:eztime_test",
    "//starboard/client_porting/icu_init",
    "//starboard/client_porting/poem:poem_unittests",
    "//starboard/examples/hello_world:starboard_hello_world_example",
    "//starboard/examples/window:starboard_window_example",
    "//starboard/extension:extension_test",
    "//starboard/loader_app:app_key_files_test",
    "//starboard/nplb",
    "//starboard/nplb/nplb_evergreen_compat_tests",
  ]

  if (gl_type != "none") {
    deps += [ "//starboard/examples/glclear:starboard_glclear_example" ]
  }

  if (has_platform_targets) {
    deps += [ "//$starboard_path/platform_targets" ]
  }

  if (platform_tests_path == "") {
    deps += [ ":starboard_platform_tests($starboard_toolchain)" ]
  } else {
    deps += [ platform_tests_path ]
  }

  if (sb_filter_based_player) {
    deps += [
      "//starboard/shared/starboard/player/filter/testing:player_filter_tests($starboard_toolchain)",
      "//starboard/shared/starboard/player/filter/tools:audio_dmp_player($starboard_toolchain)",
    ]
  }

  if (sb_enable_benchmark) {
    deps += [ "//starboard/benchmark" ]
  }

  if (build_with_separate_cobalt_toolchain && is_cobalt_toolchain) {
    assert(sb_is_modular,
           "sb_is_modular should be set when building with cobalt_toolchain")
  }

  if (!sb_is_evergreen) {
    deps += [ "//third_party/lz4_lib:lz4" ]

    if (sb_is_evergreen_compatible) {
      deps += [ "//third_party/crashpad/client" ]
      data_deps = [
        "//starboard/loader_app",
        "//third_party/crashpad/handler:crashpad_handler(//$starboard_path/toolchain:native_target)",
      ]
    }
  }
}

group("default") {
  deps = [
    ":starboard",
    "//starboard/tools:build_app_launcher_zip",
  ]
}

group("starboard") {
  public_deps = [
    ":starboard_headers_only",
    "//starboard/client_porting/cwrappers",
    "//starboard/client_porting/eztime",
  ]

  if (sb_is_modular) {
    public_deps += [
      "//third_party/llvm-project/compiler-rt:compiler_rt",
      "//third_party/llvm-project/libcxx:cxx",
      "//third_party/llvm-project/libcxxabi:cxxabi",
      "//third_party/musl:c",
    ]
    if (sb_is_evergreen) {
      public_deps += [ "//starboard/elf_loader:sabi_string" ]
    }
    if (build_with_separate_cobalt_toolchain) {
      data_deps = [ ":starboard_platform_group($starboard_toolchain)" ]
    } else {
      public_deps += [ "//third_party/llvm-project/libunwind:unwind_evergreen" ]
    }
  } else {
    public_deps += [
      ":starboard_platform_group($starboard_toolchain)",
      "//starboard/common",
    ]

    if (!build_with_separate_cobalt_toolchain) {
      if (sb_is_evergreen_compatible) {
        public_deps += [ "//third_party/crashpad/wrapper" ]
      } else {
        public_deps += [ "//third_party/crashpad/wrapper:wrapper_stub" ]
      }
    }

    if (final_executable_type == "shared_library" &&
        current_toolchain != default_toolchain) {
      set_defaults("executable") {
        sources = [ "//starboard/shared/starboard/shared_main_adapter.cc" ]
      }
    }
  }
}

source_set("starboard_headers_only") {
  # We include starboard/common/log.h in starboard_headers, but some common
  # files include starboard headers.
  check_includes = false

  sources = [
    "atomic.h",
    "audio_sink.h",
    "byte_swap.h",
    "condition_variable.h",
    "configuration.h",
    "configuration_constants.h",
    "cpu_features.h",
    "decode_target.h",
    "directory.h",
    "drm.h",
    "egl.h",
    "event.h",
    "export.h",
    "file.h",
    "gles.h",
    "input.h",
    "key.h",
    "log.h",
    "media.h",
    "memory.h",
    "microphone.h",
    "mutex.h",
    "once.h",
    "player.h",
    "queue.h",
    "socket.h",
    "socket_waiter.h",
    "storage.h",
    "string.h",
    "system.h",
    "thread.h",
    "time.h",
    "time_zone.h",
    "types.h",
    "user.h",
    "window.h",
  ]

  if (is_internal_build) {
    public_deps = [ "//internal/starboard/private:private_starboard_headers" ]
  }
}

if (current_toolchain == starboard_toolchain) {
  target(starboard_target_type, "starboard_platform_group") {
    if (starboard_target_type == "shared_library") {
      build_loader = false
    }
    public_deps = [
      "//starboard/client_porting/cwrappers",
      "//starboard/client_porting/eztime",
      "//starboard/common",
      "//starboard/egl_and_gles",
    ]
    if (sb_is_evergreen_compatible) {
      public_deps += [ "//third_party/crashpad/wrapper" ]
    } else {
      public_deps += [ "//third_party/crashpad/wrapper:wrapper_stub" ]
    }
    if (!sb_is_modular) {
      public_deps += [ "//$starboard_path:starboard_platform" ]
    }
  }

  if (platform_tests_path == "") {
    # If 'starboard_platform_tests' is not defined by the platform, then an
    # empty 'starboard_platform_tests' target is defined.
    target(starboard_level_gtest_target_type, "starboard_platform_tests") {
      testonly = true

      sources = [ "//starboard/common/test_main.cc" ]

      public_deps = [
        ":starboard",
        "//testing/gmock",
        "//testing/gtest",
      ]
    }
  }
}
