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

SUBSYSTEM_DIR = "//foundation/communication"

ohos_shared_library("bluetooth") {
  branch_protector_ret = "pac_ret"  # Enable PAC CFI

  #install_enable = true
  include_dirs = [
    "include",
    "src",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/inner/include",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/access",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/base_profile",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/constant",
  ]

  defines = [
    "BT_LOG_TAG = \"bluetooth_napi\"",
    "BT_LOG_DOMAIN = 0xD000100",
    "BT_MODULE_NAME = \"bluetooth\"",
  ]
  sanitize = {
    cfi = true  # Enable/disable control flow integrity detection
    boundary_sanitize = true  # Enable boundary san detection
    cfi_cross_dso = true  # Cross-SO CFI Checks
    integer_overflow = true  # Enable integer overflow detection
    ubsan = true  # Enable some Ubsan options
    debug = false
  }
  sources = [
    "src/a2dp/napi_bluetooth_a2dp_src.cpp",
    "src/a2dp/napi_bluetooth_a2dp_src_observer.cpp",
    "src/access/napi_bluetooth_access.cpp",
    "src/access/napi_bluetooth_access_observer.cpp",
    "src/audio_manager/napi_bluetooth_audio_manager.cpp",
    "src/base_profile/napi_bluetooth_base_profile.cpp",
    "src/ble/napi_bluetooth_ble.cpp",
    "src/ble/napi_bluetooth_ble_advertise_callback.cpp",
    "src/ble/napi_bluetooth_ble_central_manager_callback.cpp",
    "src/ble/napi_bluetooth_ble_utils.cpp",
    "src/ble/napi_bluetooth_gatt_client.cpp",
    "src/ble/napi_bluetooth_gatt_client_callback.cpp",
    "src/ble/napi_bluetooth_gatt_server.cpp",
    "src/ble/napi_bluetooth_gatt_server_callback.cpp",
    "src/common/napi_bluetooth_profile.cpp",
    "src/connection/napi_bluetooth_connection.cpp",
    "src/connection/napi_bluetooth_connection_observer.cpp",
    "src/connection/napi_bluetooth_remote_device_observer.cpp",
    "src/constant/napi_bluetooth_constant.cpp",
    "src/hfp/napi_bluetooth_hfp_ag.cpp",
    "src/hfp/napi_bluetooth_hfp_ag_observer.cpp",
    "src/hfp/napi_bluetooth_hfp_hf.cpp",
    "src/hfp/napi_bluetooth_hfp_hf_observer.cpp",
    "src/hid/napi_bluetooth_hid_host.cpp",
    "src/hid/napi_bluetooth_hid_host_observer.cpp",
    "src/napi_bluetooth_a2dp_snk.cpp",
    "src/napi_bluetooth_a2dp_snk_observer.cpp",
    "src/napi_bluetooth_avrcp_ct.cpp",
    "src/napi_bluetooth_avrcp_ct_observer.cpp",
    "src/napi_bluetooth_avrcp_tg.cpp",
    "src/napi_bluetooth_avrcp_tg_observer.cpp",
    "src/napi_bluetooth_host.cpp",
    "src/native_module.cpp",
    "src/pan/napi_bluetooth_pan.cpp",
    "src/pan/napi_bluetooth_pan_observer.cpp",
    "src/socket/napi_bluetooth_spp_client.cpp",
    "src/socket/napi_bluetooth_spp_server.cpp",
  ]

  deps = [ "$SUBSYSTEM_DIR/bluetooth/frameworks/inner:btframework" ]

  external_deps = [
    "ability_base:want",
    "ability_runtime:ability_manager",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "c_utils:utils",
    "hicollie:libhicollie",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "ipc:ipc_single",
    "libuv:uv",
    "napi:ace_napi",
  ]

  relative_install_dir = "module"
  part_name = "bluetooth"
  subsystem_name = "communication"
}

ohos_shared_library("bluetoothmanager") {
  branch_protector_ret = "pac_ret"  # Enable PAC CFI

  #install_enable = true
  include_dirs = [
    "include",
    "src",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/inner/include",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/access",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/base_profile",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/constant",
  ]

  defines = [
    "BT_LOG_TAG = \"bluetooth_napi\"",
    "BT_LOG_DOMAIN = 0xD000100",
    "ENABLE_NAPI_BLUETOOTH_MANAGER",
    "BT_MODULE_NAME = \"bluetoothmanager\"",
  ]

  sanitize = {
    cfi = true  # Enable/disable control flow integrity detection
    boundary_sanitize = true  # Enable boundary san detection
    cfi_cross_dso = true  # Cross-SO CFI Checks
    integer_overflow = true  # Enable integer overflow detection
    ubsan = true  # Enable some Ubsan options
    debug = false
  }
  sources = [
    "src/a2dp/napi_bluetooth_a2dp_src.cpp",
    "src/a2dp/napi_bluetooth_a2dp_src_observer.cpp",
    "src/access/napi_bluetooth_access.cpp",
    "src/access/napi_bluetooth_access_observer.cpp",
    "src/audio_manager/napi_bluetooth_audio_manager.cpp",
    "src/base_profile/napi_bluetooth_base_profile.cpp",
    "src/ble/napi_bluetooth_ble.cpp",
    "src/ble/napi_bluetooth_ble_advertise_callback.cpp",
    "src/ble/napi_bluetooth_ble_central_manager_callback.cpp",
    "src/ble/napi_bluetooth_ble_utils.cpp",
    "src/ble/napi_bluetooth_gatt_client.cpp",
    "src/ble/napi_bluetooth_gatt_client_callback.cpp",
    "src/ble/napi_bluetooth_gatt_server.cpp",
    "src/ble/napi_bluetooth_gatt_server_callback.cpp",
    "src/common/napi_bluetooth_profile.cpp",
    "src/connection/napi_bluetooth_connection.cpp",
    "src/connection/napi_bluetooth_connection_observer.cpp",
    "src/connection/napi_bluetooth_remote_device_observer.cpp",
    "src/constant/napi_bluetooth_constant.cpp",
    "src/hfp/napi_bluetooth_hfp_ag.cpp",
    "src/hfp/napi_bluetooth_hfp_ag_observer.cpp",
    "src/hfp/napi_bluetooth_hfp_hf.cpp",
    "src/hfp/napi_bluetooth_hfp_hf_observer.cpp",
    "src/hid/napi_bluetooth_hid_host.cpp",
    "src/hid/napi_bluetooth_hid_host_observer.cpp",
    "src/napi_bluetooth_a2dp_snk.cpp",
    "src/napi_bluetooth_a2dp_snk_observer.cpp",
    "src/napi_bluetooth_avrcp_ct.cpp",
    "src/napi_bluetooth_avrcp_ct_observer.cpp",
    "src/napi_bluetooth_avrcp_tg.cpp",
    "src/napi_bluetooth_avrcp_tg_observer.cpp",
    "src/napi_bluetooth_host.cpp",
    "src/native_module.cpp",
    "src/pan/napi_bluetooth_pan.cpp",
    "src/pan/napi_bluetooth_pan_observer.cpp",
    "src/socket/napi_bluetooth_spp_client.cpp",
    "src/socket/napi_bluetooth_spp_server.cpp",
  ]

  deps = [ "$SUBSYSTEM_DIR/bluetooth/frameworks/inner:btframework" ]

  external_deps = [
    "ability_base:want",
    "ability_runtime:ability_manager",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "c_utils:utils",
    "hicollie:libhicollie",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "ipc:ipc_core",
    "ipc:ipc_single",
    "libuv:uv",
    "napi:ace_napi",
  ]

  relative_install_dir = "module"
  part_name = "bluetooth"
  subsystem_name = "communication"
}

group("bluetooth_napi") {
  deps = [
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi:bluetooth",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi:bluetoothmanager",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/a2dp:a2dp",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/access:access",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/audio_manager:weardetection",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/base_profile:baseprofile",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/ble:ble",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/connection:connection",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/constant:constant",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/hfp:hfp",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/hid:hid",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/map:map",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/opp:opp",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/pan:pan",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/pbap:pbap",
    "$SUBSYSTEM_DIR/bluetooth/frameworks/js/napi/src/socket:socket",
  ]
}