# 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("//base/location/location/config.gni")
import("//build/ohos.gni")

config("geofence_sdk_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "$LOCATION_ROOT_DIR/interfaces/inner_api/include",
    "$LOCATION_ROOT_DIR/frameworks/js/napi/include",
    "$LOCATION_ROOT_DIR/frameworks/native/notification/include",
  ]
}

local_base_sources = [
  "$LOCATION_NATIVE_DIR/geofence_sdk/source/geofence.cpp",
  "$LOCATION_NATIVE_DIR/geofence_sdk/source/geofence_request.cpp",
  "$LOCATION_NATIVE_DIR/geofence_sdk/source/geofence_sdk.cpp",
  "$LOCATION_NATIVE_DIR/geofence_sdk/source/fusion_fence_request.cpp",
]

ohos_shared_library("geofence_sdk") {
  install_enable = true

  public_configs = [ ":geofence_sdk_config" ]

  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  branch_protector_ret = "pac_ret"

  sources = local_base_sources

  deps = [
    "$LOCATION_COMMON_DIR:lbsservice_common",
    "$LOCATION_NATIVE_DIR/locator_sdk:liblocator_interface_proxy",
    "$LOCATION_ROOT_DIR/frameworks/base_module:lbsbase_module",
  ]

  public_external_deps = [
    "hilog:libhilog",
    "init:libbegetutil",
    "ipc:ipc_single",
    "samgr:samgr_proxy",
  ]

  external_deps = [
    "ability_base:configuration",
    "bundle_framework:appexecfwk_core",
  ]

  defines = []

  if (notification_distributed_notification_service_enable) {
    public_external_deps += [ "distributed_notification_service:ans_innerkits" ]
    defines += [ "NOTIFICATION_ENABLE" ]
  }

  if (is_emulator) {
    defines += [ "EMULATOR_ENABLED" ]
  }

  cflags_cc = [
    "-std=c++17",
    "-fno-rtti",
    "-ffunction-sections",
    "-fdata-sections",
    "-Os",
  ]

  ldflags = [
    "-fPIC",
    "-Wl,-E",
    "-Wl,--as-needed",
    "-Wl,--gc-sections",
  ]

  # Used to control the export of dynamic library symbols.
  version_script = "libgeofence_sdk_version_script.txt"

  innerapi_tags = [ "platformsdk" ]
  part_name = "location"
  subsystem_name = "location"
}

ohos_static_library("geofence_sdk_static") {
  public_configs = [ ":geofence_sdk_config" ]

  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  branch_protector_ret = "pac_ret"

  sources = local_base_sources

  deps = [
    "$LOCATION_COMMON_DIR:lbsservice_common",
    "$LOCATION_NATIVE_DIR/locator_sdk:liblocator_interface_proxy",
    "$LOCATION_ROOT_DIR/frameworks/base_module:lbsbase_module",
  ]

  external_deps = [
    "ability_base:configuration",
    "bundle_framework:appexecfwk_core",
  ]

  public_external_deps = [
    "hilog:libhilog",
    "init:libbegetutil",
    "ipc:ipc_single",
    "samgr:samgr_proxy",
  ]

  defines = []

  if (notification_distributed_notification_service_enable) {
    public_external_deps += [ "distributed_notification_service:ans_innerkits" ]
    defines += [ "NOTIFICATION_ENABLE" ]
  }

  if (is_emulator) {
    defines += [ "EMULATOR_ENABLED" ]
  }

  cflags_cc = [
    "-std=c++17",
    "-fno-rtti",
  ]

  ldflags = [
    "-fPIC",
    "-Wl,-E",
  ]

  part_name = "location"
  subsystem_name = "location"
}