# Copyright 2020 The Dawn & Tint Authors
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
#    list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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"
  }
}
