# Copyright (c) 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This file contains configs that need to be added or removed to all
# SwiftShader libraries

configs_to_add = []
configs_to_delete = []

if (is_win) {
  configs_to_delete += [ "//build/config/win:unicode" ]
}

if (is_debug) {
  # always build optimized version of SwiftShader for performance reasons
  configs_to_delete += [ "//build/config/compiler:default_optimization" ]
  configs_to_add += [ "//build/config/compiler:optimize" ]
}

configs_to_delete += [ "//build/config/compiler:chromium_code" ]
configs_to_add += [
  "//build/config/compiler:no_chromium_code",
  "//third_party/swiftshader:swiftshader_config",
]

template("swiftshader_source_set") {
  source_set(target_name) {
    configs -= configs_to_delete
    configs += configs_to_add
    forward_variables_from(invoker, "*", [ "configs" ])
    if (defined(invoker.configs)) {
      configs += invoker.configs
    }
  }
}

template("swiftshader_shared_library") {
  shared_library(target_name) {
    configs -= configs_to_delete
    configs += configs_to_add
    forward_variables_from(invoker, "*", [ "configs" ])
    if (defined(invoker.configs)) {
      configs += invoker.configs
    }
  }
}

template("swiftshader_static_library") {
  static_library(target_name) {
    configs -= configs_to_delete
    configs += configs_to_add
    forward_variables_from(invoker, "*", [ "configs" ])
    if (defined(invoker.configs)) {
      configs += invoker.configs
    }
  }
}