# Copyright (c) 2021-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("//build/ohos.gni")
import(
    "//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni")

config("utils_external_config") {
  include_dirs = [
    "${common_path}/utils/include",
    "${utils_path}/include",
  ]
}

ohos_shared_library("distributedhardwareutils") {
  sanitize = {
    boundary_sanitize = true
    integer_overflow = true
    ubsan = true
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  branch_protector_ret = "pac_ret"
  public_configs = [
    ":utils_external_config",
    "${innerkits_path}:dhfwk_idl_hardware_config"
  ]

  include_dirs = [
    "${common_path}/log/include",
    "${common_path}/utils/include",
    "include",
  ]

  sources = [
    "src/anonymous_string.cpp",
    "src/device_param_mgr.cpp",
    "src/dh_utils_hisysevent.cpp",
    "src/dh_utils_hitrace.cpp",
    "src/dh_utils_tool.cpp",
    "src/histreamer_ability_parser.cpp",
    "src/histreamer_query_tool.cpp",
  ]

  defines = [
    "HI_LOG_ENABLE",
    "DH_LOG_TAG=\"distributedhardwareutils\"",
    "LOG_DOMAIN=0xD004100",
    "OPENSSL_SUPPRESS_DEPRECATED",
  ]

  cflags = [
    "-fstack-protector-strong",
    "-D_FORTIFY_SOURCE=2",
    "-O2",
  ]

  cflags_cc = cflags

  ldflags = [
    "-fpie",
    "-Wl,-z,relro",
    "-Wl,-z,now",
  ]

  external_deps = [
    "cJSON:cjson",
    "c_utils:utils",
    "device_manager:devicemanagersdk",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "openssl:libcrypto_shared",
    "zlib:shared_libz",
  ]

  if (dhfwk_os_account) {
    external_deps += [
      "os_account:libaccountkits",
      "os_account:os_account_innerkits",
    ]
  }

  if (dhfwk_os_account) {
    defines += [ "OS_ACCOUNT_PART" ]
  }

  subsystem_name = "distributedhardware"

  part_name = "distributed_hardware_fwk"
}