# 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("//build/ohos.gni")
import("//foundation/distributeddatamgr/preferences/preferences.gni")

config("common_public_config") {
  visibility = [ ":*" ]
  include_dirs = [ "include" ]
}

config("common_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "include",
    "${preferences_base_path}/frameworks/common/include",
  ]
}

if (is_ohos) {
  ohos_shared_library("preferences_jscommon") {
    branch_protector_ret = "pac_ret"
    sanitize = {
      boundary_sanitize = true
      ubsan = true
      cfi = true
      cfi_cross_dso = true
      debug = false
    }

    cflags_cc = [
      "-std=c++17",
      "-stdlib=libc++",
    ]

    sources = [
      "${preferences_napi_path}/common/src/js_ability.cpp",
      "${preferences_napi_path}/common/src/js_common_utils.cpp",
      "${preferences_napi_path}/common/src/js_observer.cpp",
      "${preferences_napi_path}/common/src/js_sendable_utils.cpp",
      "${preferences_napi_path}/common/src/napi_async_call.cpp",
      "${preferences_napi_path}/common/src/napi_preferences_error.cpp",
      "${preferences_napi_path}/common/src/napi_preferences_observer.cpp",
      "${preferences_napi_path}/common/src/uv_queue.cpp",
    ]
    configs = [ ":common_config" ]
    public_configs = [ ":common_public_config" ]
    deps =
        [ "${preferences_base_path}/interfaces/inner_api:native_preferences" ]
    version_script = "libcommon.map"
    external_deps = [
      "ability_runtime:abilitykit_native",
      "ability_runtime:napi_base_context",
      "bounds_checking_function:libsec_shared",
      "hilog:libhilog",
      "napi:ace_napi",
    ]

    subsystem_name = "distributeddatamgr"
    part_name = "preferences"
  }
}