# Copyright (c) 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")
import("../../dbms.gni")

group("dbms_target") {
  if (distributed_bundle_framework_graphics) {
    deps = [ ":libdbms" ]
  }
}

config("distributed_bms_config") {
  include_dirs = [ "include" ]
}

ohos_shared_library("libdbms") {
  branch_protector_ret = "pac_ret"

  sanitize = {
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
    integer_overflow = true
    ubsan = true
  }

  cflags = [ "-fstack-protector-strong" ]
  cflags_cc = [
    "-Os",
    "-fno-unwind-tables",
    "-fstack-protector-strong",
  ]

  sources = [
    "src/account_manager_helper.cpp",
    "src/dbms_device_manager.cpp",
    "src/distributed_bms.cpp",
    "src/distributed_bms_host.cpp",
    "src/distributed_data_storage.cpp",
  ]

  defines = [
    "APP_LOG_TAG = \"DistributedBundleMgrService\"",
    "LOG_DOMAIN = 0xD0011E0",
  ]

  configs = [ ":distributed_bms_config" ]

  deps = [ "${dbms_inner_api_path}:dbms_fwk" ]

  external_deps = [
    "ability_base:want",
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "bundle_framework:libappexecfwk_common",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "device_manager:devicemanagersdk",
    "hicollie:libhicollie",
    "hilog:libhilog",
    "i18n:intl_util",
    "init:libbegetutil",
    "ipc:ipc_core",
    "kv_store:distributeddata_inner",
    "resource_management:global_resmgr",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  if (hisysevent_enable_dbms) {
    sources += [ "src/event_report.cpp" ]
    external_deps += [ "hisysevent:libhisysevent" ]
    defines += [ "HISYSEVENT_ENABLE" ]
  }

  if (account_enable_dbms) {
    external_deps += [ "os_account:libaccountkits" ]
    external_deps += [ "os_account:os_account_innerkits" ]
    defines += [ "ACCOUNT_ENABLE" ]
  }

  if (distributed_bundle_image_framework_enable) {
    sources += [ "src/image_compress.cpp" ]
    external_deps += [ "image_framework:image_native" ]
    defines += [ "DISTRIBUTED_BUNDLE_IMAGE_ENABLE" ]
  }

  shlib_type = "sa"
  part_name = "distributed_bundle_framework"
  subsystem_name = "bundlemanager"
}