# Copyright (c) 2021-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/communication/netstack/netstack_config.gni")

group("common_utils") {
  deps = [
    ":stack_utils_common",
    "napi_utils:napi_utils",
  ]
}

config("stack_utils_common_public_config") {
  include_dirs = [
    "common_utils/include",
    "log/include",
  ]
  if (product_name == "ohcore") {
    defines = [ "OH_CORE_NETSTACK_PERMISSION_CHECK" ]
  }
  if (is_mingw) {
    defines = [ "WINDOWS_PLATFORM" ]
  }
}

ohos_shared_library("stack_utils_common") {
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }

  branch_protector_ret = "pac_ret"

  cflags = [
    "-D_FORTIFY_SOURCE=2",
    "-O2",
  ]
  cflags_cc = [
    "-D_FORTIFY_SOURCE=2",
    "-O2",
  ]

  sources = [
    "common_utils/src/netstack_apipolicy_utils.cpp",
    "common_utils/src/netstack_bundle_utils.cpp",
    "common_utils/src/netstack_common_utils.cpp",
    "common_utils/src/netstack_hisysevent.cpp",
    "common_utils/src/request_tracer.cpp",
  ]

  public_configs = [ ":stack_utils_common_public_config" ]

  external_deps = [
    "bounds_checking_function:libsec_shared",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "samgr:samgr_proxy",
  ]

  if (defined(global_parts_info) &&
      defined(global_parts_info.communication_netmanager_base) &&
      global_parts_info.communication_netmanager_base) {
    external_deps += [
      "hitrace:hitrace_meter",
      "netmanager_base:net_conn_manager_if",
      "netmanager_base:net_security_config_if",
    ]
    defines = [ "HAS_NETMANAGER_BASE=1" ]
    external_deps += [ "openssl:libcrypto_shared" ]
  } else {
    defines = [ "HAS_NETMANAGER_BASE=0" ]
  }

  innerapi_tags = [ "platformsdk" ]
  part_name = "netstack"
  subsystem_name = "communication"
}