# Copyright 2020 The Tint Authors.
#
# 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("//build_overrides/tint.gni")

# This file contains Tint-related build flags.

if (!defined(tint_standalone)) {
  if (defined(dawn_standalone)) {
    tint_standalone = dawn_standalone
  } else {
    tint_standalone = false
  }
}

if (!defined(tint_has_build)) {
  tint_has_build = true
}

tint_has_fuzzers = tint_has_build

declare_args() {
  # Path to tint checkout
  if (!defined(tint_root_dir)) {
    tint_root_dir = "//"
  }

  # Path to spirv-tools checkout
  if (!defined(tint_spirv_tools_dir)) {
    tint_spirv_tools_dir = "//third_party/vulkan-deps/spirv-tools/src"
  }

  # Path to glslang checkout
  if (!defined(tint_glslang_dir)) {
    tint_glslang_dir = "//third_party/vulkan-deps/glslang/src"
  }

  # Path to googletest checkout
  if (!defined(tint_googletest_dir)) {
    tint_googletest_dir = "//third_party/googletest"
  }

  # Path to spirv-headers checkout
  if (!defined(tint_spirv_headers_dir)) {
    tint_spirv_headers_dir = "//third_party/vulkan-deps/spirv-headers/src"
  }

  if (!defined(tint_build_cmds)) {
    tint_build_cmds = tint_standalone
  }

  # Build the SPIR-V input reader
  if (!defined(tint_build_spv_reader)) {
    tint_build_spv_reader = true
  }

  # Build the SPIR-V output writer
  if (!defined(tint_build_spv_writer)) {
    tint_build_spv_writer = true
  }

  # Build the WGSL input reader
  if (!defined(tint_build_wgsl_reader)) {
    tint_build_wgsl_reader = true
  }

  # Build the WGSL output writer
  if (!defined(tint_build_wgsl_writer)) {
    tint_build_wgsl_writer = true
  }

  # Build the MSL output writer
  if (!defined(tint_build_msl_writer)) {
    tint_build_msl_writer = true
  }

  # Build the HLSL output writer
  if (!defined(tint_build_hlsl_writer)) {
    tint_build_hlsl_writer = true
  }

  # Build the GLSL output writer
  if (!defined(tint_build_glsl_writer)) {
    tint_build_glsl_writer = true
  }

  # Build the GLSL output validator
  if (!defined(tint_build_glsl_validator)) {
    tint_build_glsl_validator = true
  }

  # Build the Syntax Tree writer
  if (!defined(tint_build_syntax_tree_writer)) {
    tint_build_syntax_tree_writer = false
  }

  # Build unittests
  if (!defined(tint_build_unittests)) {
    tint_build_unittests = true
  }

  # Build benchmarks
  if (!defined(tint_build_benchmarks)) {
    tint_build_benchmarks = true
  }
}

declare_args() {
  # Directory holding tint source
  if (!defined(tint_src_dir)) {
    tint_src_dir = "${tint_root_dir}/src/tint"
  }
}
