# 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/netmanager_ext/netmanager_ext_config.gni")

group("common_target") {
  deps = [
    ":net_event_report",
    ":net_manager_ext_common",
  ]
}

config("netmgr_ext_common_config") {
  include_dirs = [
    "log/include",
    "event_report/include",
  ]
}

ohos_shared_library("net_manager_ext_common") {
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    blocklist = "./cfi_blocklist.txt"
    debug = false
  }

  branch_protector_ret = "pac_ret"

  sources = [ "log/src/netmgr_ext_log_wrapper.cpp" ]

  defines = [
    "NETMGR_EXT_LOG_TAG = \"NetMgrExtCommon\"",
    "LOG_DOMAIN = 0xD0015B0",
  ]

  if (is_standard_system) {
    defines += [ "STANDARD_SYSTEM_ENABLE" ]
  }

  public_configs = [
    ":netmgr_ext_common_config",
    "$C_UTILS_ROOT/base:utils_config",
  ]

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

  if (is_double_framework) {
    cflags_cc = [ "-DCONFIG_DUAL_FRAMEWORK" ]
    cflags_cc += [ "-fstack-protector-strong" ]
  } else {
    cflags_cc = [ "-fstack-protector-strong" ]
  }

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

  if (is_standard_system) {
    external_deps = [
      "c_utils:utils",
      "hilog:libhilog",
    ]
  } else {
    external_deps = [
      "c_utils:utils",
      "hilog:libhilog",
    ]
  }

  part_name = "netmanager_ext"
  subsystem_name = "communication"
}

ohos_shared_library("net_event_report") {
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    blocklist = "./cfi_blocklist.txt"
    debug = false
  }

  branch_protector_ret = "pac_ret"

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

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

  sources = [ "event_report/src/net_event_report.cpp" ]

  public_configs = [ ":netmgr_ext_common_config" ]

  external_deps = [ "hisysevent:libhisysevent" ]

  part_name = "netmanager_ext"
  subsystem_name = "communication"
}