# Copyright (C) 2025 Huawei Device Co., Ltd.
# 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/ohos.gni")

ohos_shared_library("cj_bluetooth_hfp_ffi") {
  cflags_cc = [
    "-Os",
    "-fno-rtti",
    "-fno-exceptions",
    "-fdata-sections",
    "-ffunction-sections",
    "-fno-unwind-tables",
    "-fno-asynchronous-unwind-tables",
    "-fno-merge-all-constants",
    "-flto",
  ]
  ldflags = [
    "-Wl,--as-needed",
    "-Wl,--gc-sections",
  ]
  branch_protector_ret = "pac_ret"  # Enable PAC CFI
  sanitize = {
    cfi = true  # Enable/disable control flow integrity detection
    boundary_sanitize = true  # Enable boundary san detection
    cfi_cross_dso = true  # Cross-SO CFI Checks
    cfi_vcall_icall_only = true  # CFI optimization, restrict CFI detection scope
    integer_overflow = true  # Enable integer overflow detection
    ubsan = true  # Enable some Ubsan options
    debug = false
  }

  if (!defined(defines)) {
    defines = []
  }
  include_dirs = [
    "include",
    "../../js/napi/include",
    "../../../frameworks/inner/include",
    "../../../frameworks/inner/ipc/parcel",
  ]

  deps = [
    "../../../frameworks/inner:btframework",
    "../../../frameworks/js/napi/src/common:bt_napi_common",
  ]

  external_deps = [
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_single",
    "libuv:uv",
    "napi:ace_napi",
    "napi:cj_bind_ffi",
    "napi:cj_bind_native",
    "node:node_header_notice",
  ]

  sources = [
    "src/bluetooth_hfp_ag_impl.cpp",
    "src/bluetooth_hfp_ffi.cpp",
    "src/bluetooth_hfp_hf_observer_impl.cpp",
    "src/bluetooth_hfp_utils.cpp",
  ]

  if (is_ohos) {
    defines += [ "OHOS_PLATFORM" ]
  }

  if (is_mingw) {
    defines += [ "WINDOWS_PLATFORM" ]
  }

  innerapi_tags = [ "platformsdk" ]

  part_name = "bluetooth"
  subsystem_name = "communication"
}