# 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("//foundation/filemanagement/dfs_service/distributedfile.gni")

config("public_config") {
  include_dirs = [ "." ]
}

config("private_config") {
  include_dirs = [
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner_lite/include",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/include",
    "${distributedfile_path}/interfaces/inner_api/native/cloudsync_kit_inner",
    "${distributedfile_path}/utils/log/include",
  ]
}

config("optimize-size") {
  cflags = [
    "-fdata-sections",
    "-ffunction-sections",
    "-Oz",
  ]
  cflags_cc = [
    "-fvisibility-inlines-hidden",
    "-Oz",
  ]
}

ohos_shared_library("cloudsync_kit_inner") {
  branch_protector_ret = "pac_ret"
  configs = [ ":optimize-size" ]
  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  sources = [
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_callback_client.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_callback_stub.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_uri_manager.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_callback_client.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_callback_stub.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_common.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_service_proxy.cpp",
    "${distributedfile_path}/utils/log/src/utils_log.cpp",
  ]

  defines = [
    "LOG_DOMAIN=0xD004308",
    "LOG_TAG=\"CLOUDSYNC_API\"",
  ]

  configs += [ ":private_config" ]
  public_configs = [ ":public_config" ]

  external_deps = [
    "ability_base:zuri",
    "ability_runtime:ability_manager",
    "ability_runtime:dataobs_manager",
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_single",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  if (cloudsync_service_media_library) {
    external_deps += [ "media_library:media_library" ]
    defines += [ "SUPPORT_MEDIA_LIBRARY" ]
  }

  use_exceptions = true
  part_name = "dfs_service"
  subsystem_name = "filemanagement"
}

ohos_shared_library("cloudsync_asset_kit_inner") {
  branch_protector_ret = "pac_ret"
  configs = [ ":optimize-size" ]
  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  sources = [
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_uri_manager.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_asset_manager.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_asset_manager_impl.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_common.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_service_proxy.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/download_asset_callback_client.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/download_asset_callback_stub.cpp",
  ]

  defines = [
    "LOG_DOMAIN=0xD004309",
    "LOG_TAG=\"CLOUD_ASSET_API\"",
  ]

  configs += [ ":private_config" ]
  public_configs = [ ":public_config" ]

  external_deps = [
    "ability_base:zuri",
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_single",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  deps = [ "${utils_path}:libdistributedfileutils_lite" ]

  use_exceptions = true
  innerapi_tags = [ "platformsdk" ]
  part_name = "dfs_service"
  subsystem_name = "filemanagement"
}

ohos_shared_library("cloudsync_kit_inner_lite") {
  branch_protector_ret = "pac_ret"
  configs = [ ":optimize-size" ]
  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
    cfi_vcall_icall_only = true
  }
  sources = [
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner_lite/src/cloud_sync_manager_impl_lite.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner_lite/src/cloud_sync_manager_lite.cpp",
    "${distributedfile_path}/frameworks/native/cloudsync_kit_inner_lite/src/cloud_sync_service_proxy_lite.cpp",
  ]

  defines = [
    "LOG_DOMAIN=0xD004308",
    "LOG_TAG=\"CloudFileDaemon\"",
  ]

  configs += [ ":private_config" ]
  public_configs = [ ":public_config" ]

  external_deps = [
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_single",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  deps = [ "${utils_path}:libdistributedfileutils_lite" ]

  use_exceptions = true
  innerapi_tags = [ "platformsdk" ]
  part_name = "dfs_service"
  subsystem_name = "filemanagement"
}