# Copyright (c) 2023 Huawei Technologies Co., Ltd. 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.

# wrapper of target `shared_library()`
#
# parameters:
# - subsystem_name: subsystem name, default is "common"
# - part_name: part name, default is subsystem_name
# - configs: configs to add
# - remove_configs: configs to remove
# - use_exceptions: use exceptions, default is false
# - use_rtti: use rtti, default is false
template("ft_shared_library") {
  # Change output dir
  output_dir = "${root_out_dir}/lib"

  # Call `shared_library()`
  shared_library("${target_name}") {
    forward_variables_from(invoker,
                           "*",
                           [
                             # variable_to_not_forward_list
                             "configs",
                             "remove_configs",
                             #"no_default_deps",
                             #"external_deps",
                             #"install_images",
                             #"module_install_dir",
                             #"relative_install_dir",
                             #"symlink_target_name",
                             "output_dir",
                             #"install_enable",
                             #"version_script",
                             #"license_file",
                             #"license_as_sources",
                             "use_exceptions",
                             "use_rtti",
                             #"stl",
                           ])
    if (defined(invoker.configs)) {
      configs += invoker.configs
    }
    if (defined(invoker.remove_configs)) {
      configs -= invoker.remove_configs
    }

    if (defined(invoker.use_exceptions) && invoker.use_exceptions) {
      configs += [ "//project_build/gn/configs/compiler:exceptions" ]
      configs -= [ "//project_build/gn/configs/compiler:no_exceptions" ]
    }

    if (defined(invoker.use_rtti) && invoker.use_rtti) {
      configs += [ "//project_build/gn/configs/compiler:rtti" ]
      configs -= [ "//project_build/gn/configs/compiler:no_rtti" ]
    }
  }
}