# Copyright 2024 The ANGLE Project 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("//gni/angle.gni")

template("ocl_cts_source_set") {
  angle_source_set(target_name) {
    cflags = [
      "-Wno-deprecated-declarations",
      "-Wno-#warnings",
      "-Wno-format",
      "-Wno-vla-cxx-extension",
      "-Wno-deprecated-volatile",
      "-Wno-c++11-narrowing",
    ]
    defines = [ "CL_TARGET_OPENCL_VERSION=300" ]
    defines += [ "CL_USE_DEPRECATED_OPENCL_2_2_APIS=1" ]
    defines += [ "CL_USE_DEPRECATED_OPENCL_2_1_APIS=1" ]
    defines += [ "CL_USE_DEPRECATED_OPENCL_2_0_APIS=1" ]
    defines += [ "CL_USE_DEPRECATED_OPENCL_1_2_APIS=1" ]
    defines += [ "CL_USE_DEPRECATED_OPENCL_1_1_APIS=1" ]
    defines += [ "CL_USE_DEPRECATED_OPENCL_1_0_APIS=1" ]
    defines += [ "CL_NO_EXTENSION_PROTOTYPES" ]
    defines += [ "CL_ENABLE_BETA_EXTENSIONS" ]

    # Rename main() to avoid conflict with the gtest-based main()
    defines += [ "main=ANGLE_oclcts_main" ]
    deps = [
      "$angle_root:cl_includes",
      "$angle_root/third_party/OpenCL-CTS/gn:test_common",
      "$angle_root/third_party/OpenCL-ICD-Loader:opencl_icd_loader",
    ]
    suppressed_configs += [
      "//build/config/compiler:chromium_code",
      "//build/config/compiler:no_exceptions",
      "//build/config/compiler:no_rtti",
      "$angle_root:extra_warnings",
      "$angle_root:constructor_and_destructor_warnings",
    ]
    include_dirs = [
      "$angle_root/third_party/OpenCL-CTS/src/test_common",
      "$angle_root/third_party/OpenCL-CTS/src/test_common/autotest",
      "$angle_root/third_party/OpenCL-CTS/src/test_common/harness",
      "$angle_root/third_party/OpenCL-CTS/src/test_common/miniz",
      "$angle_root/third_party/OpenCL-ICD-Loader/src/loader",
    ]

    forward_variables_from(invoker,
                           "*",
                           [
                             "configs",
                             "deps",
                             "include_dirs",
                             "cflags",
                           ])
    if (defined(invoker.configs)) {
      configs += invoker.configs
    }
    if (defined(invoker.deps)) {
      deps += invoker.deps
    }
    if (defined(invoker.include_dirs)) {
      include_dirs += invoker.include_dirs
    }
    if (defined(invoker.cflags)) {
      cflags += invoker.cflags
    }
  }
}
