# Copyright (C) 2024 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")

BT_PART_DIR = "../../.."
BT_CJ_DIR = "$BT_PART_DIR/frameworks/cj/ble"
BT_NAPI_DIR = "$BT_PART_DIR/frameworks/js/napi"

ohos_shared_library("cj_bluetooth_ble_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",
  ]
  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
  }

  include_dirs = [
    "$BT_CJ_DIR/include",
    "$BT_CJ_DIR/src",
    "$BT_NAPI_DIR/include",
    "$BT_PART_DIR/frameworks/inner/include",
    "$BT_PART_DIR/frameworks/inner/ipc/parcel",
  ]

  sources = [
    "src/bluetooth_ble_clientDevice.cpp",
    "src/bluetooth_ble_common.cpp",
    "src/bluetooth_ble_ffi.cpp",
    "src/bluetooth_ble_ffiAdvertiseCallback.cpp",
    "src/bluetooth_ble_ffiCentralManagerCallback.cpp",
    "src/bluetooth_ble_ffiGattClientCallback.cpp",
    "src/bluetooth_ble_ffiGattServerCallback.cpp",
    "src/bluetooth_ble_gattServer.cpp",
    "src/bluetooth_ble_impl.cpp",
  ]

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

  external_deps = [
    "c_utils:utils",
    "hicollie:libhicollie",
    "hilog:libhilog",
    "napi:ace_napi",
    "napi:cj_bind_ffi",
    "napi:cj_bind_native",
  ]

  innerapi_tags = [ "platformsdk" ]
  subsystem_name = "communication"
  part_name = "bluetooth"
}