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

config("location_common_config") {
  visibility = [ ":*" ]
  include_dirs = [ "$LOCATION_ROOT_DIR/interfaces/inner_api/include" ]
}

local_base_sources = [
  "$LOCATION_COMMON_DIR/source/app_identity.cpp",
  "$LOCATION_COMMON_DIR/source/beacon_fence.cpp",
  "$LOCATION_COMMON_DIR/source/beacon_fence_request.cpp",
  "$LOCATION_COMMON_DIR/source/bluetooth_scan_result.cpp",
  "$LOCATION_COMMON_DIR/source/common_hisysevent.cpp",
  "$LOCATION_COMMON_DIR/source/common_utils.cpp",
  "$LOCATION_COMMON_DIR/source/geo_address.cpp",
  "$LOCATION_COMMON_DIR/source/geocode_convert_address_request.cpp",
  "$LOCATION_COMMON_DIR/source/geocode_convert_location_request.cpp",
  "$LOCATION_COMMON_DIR/source/geocoding_mock_info.cpp",
  "$LOCATION_COMMON_DIR/source/hook_utils.cpp",
  "$LOCATION_COMMON_DIR/source/location_data_rdb_helper.cpp",
  "$LOCATION_COMMON_DIR/source/location_data_rdb_manager.cpp",
  "$LOCATION_COMMON_DIR/source/location_dumper.cpp",
  "$LOCATION_COMMON_DIR/source/permission_manager.cpp",
  "$LOCATION_COMMON_DIR/source/proxy_freeze_manager.cpp",
  "$LOCATION_COMMON_DIR/source/request.cpp",
  "$LOCATION_COMMON_DIR/source/sa_load_with_statistic.cpp",
  "$LOCATION_COMMON_DIR/source/ui_extension_ability_connection.cpp",
  "$LOCATION_ROOT_DIR/frameworks/base_module/source/location.cpp",
  "$LOCATION_ROOT_DIR/frameworks/base_module/source/request_config.cpp",
  "$LOCATION_ROOT_DIR/frameworks/base_module/source/satellite_status.cpp",
]

ohos_shared_library("lbsservice_common") {
  public_configs = [
    ":location_common_config",
    "$LOCATION_NATIVE_DIR/locator_sdk:locator_interface_config",
  ]

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

  sources = local_base_sources

  deps = [ "$LOCATION_ROOT_DIR/frameworks/base_module:lbsbase_module" ]

  external_deps = [
    "ability_runtime:ability_connect_callback_stub",
    "cJSON:cjson",
    "ability_runtime:app_manager",
  ]

  public_external_deps = [
    "ability_base:zuri",
    "ability_runtime:extension_manager",
    "ability_runtime:wantagent_innerkits",
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "c_utils:utils",
    "data_share:datashare_consumer",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "init:libbegetutil",
    "ipc:ipc_single",
    "os_account:os_account_innerkits",
    "samgr:samgr_proxy",
  ]

  defines = []

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

  if (resourceschedule_background_task_mgr_enable) {
    external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
    defines += [ "BGTASKMGR_SUPPORT" ]
  }

  if (ability_form_fwk_enable) {
    external_deps += [ "form_fwk:fmskit_native" ]
    defines += [ "FMSKIT_NATIVE_SUPPORT" ]
  }

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

  cflags_cc = [
    "-ffunction-sections",
    "-fdata-sections",
    "-flto=thin",
    "-Os",
  ]

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

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

ohos_static_library("lbsservice_common_static") {
  public_configs = [
    ":location_common_config",
  ]

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

  sources = local_base_sources

  deps = [ "$LOCATION_ROOT_DIR/frameworks/base_module:lbsbase_module" ]

  public_external_deps = [
    "ability_base:zuri",
    "ability_runtime:extension_manager",
    "ability_runtime:wantagent_innerkits",
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "c_utils:utils",
    "data_share:datashare_consumer",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "init:libbegetutil",
    "ipc:ipc_single",
    "os_account:os_account_innerkits",
    "samgr:samgr_proxy",
  ]

  external_deps = [
    "cJSON:cjson"
    ]

  defines = []

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

  part_name = "location"
  subsystem_name = "location"
}