# 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("//base/hiviewdfx/faultloggerd/faultloggerd.gni")

dfx_local_handler_sources = [
  "dfx_crash_local_handler.cpp",
  "dfx_signal_local_handler.cpp",
]

if (!defined(ohos_lite)) {
  config("dfx_local_handler_config") {
    visibility = [ "*:*" ]
    include_dirs = [
      "include",
      "$faultloggerd_interfaces_path/common",
      "$faultloggerd_path/common/cutil",
      "$faultloggerd_path/common/dfxlog",
      "$faultloggerd_path/common/dfx_util",
      "$faultloggerd_interfaces_path/innerkits/unwinder",
      "$faultloggerd_interfaces_path/innerkits/signal_handler/include",
    ]
  }
  ohos_source_set("dfx_local_handler_src") {
    branch_protector_ret = "pac_ret"
    public_configs = [
      ":dfx_local_handler_config",
      "$faultloggerd_frameworks_path/allocator:dfx_allocator_config",
    ]
    include_dirs = [ "$faultloggerd_common_path/dfxlog" ]
    sources = dfx_local_handler_sources
    sources += [ "$faultloggerd_interfaces_path/innerkits/signal_handler/dfx_signalhandler_exception.c" ]
    defines = [ "DFX_LOG_HILOG_BASE" ]
    deps = [
      "$faultloggerd_common_path/cutil:dfx_cutil",
      "$faultloggerd_common_path/cppcrash_formatter:cppcrash_formatter_src",
      "$faultloggerd_common_path/dfxutil:dfx_util",
      "$faultloggerd_frameworks_path/allocator:dfx_allocator_src",
      "$faultloggerd_interfaces_path/innerkits/faultloggerd_client:libfaultloggerd",
      "$faultloggerd_interfaces_path/innerkits/unwinder:libunwinder",
    ]

    external_deps = [
      "bounds_checking_function:libsec_shared",
      "c_utils:utils",
      "hisysevent:libhisysevent",
      "cJSON:cjson",
    ]
    part_name = "faultloggerd"
    subsystem_name = "hiviewdfx"
  }

  ohos_source_set("dfx_local_handler_src_cfi") {
    branch_protector_ret = "pac_ret"
    sanitize = {
        cfi = true
        cfi_cross_dso = true
        cfi_vcall_icall_only = true
        debug = false
    }
    public_configs = [
      ":dfx_local_handler_config",
      "$faultloggerd_frameworks_path/allocator:dfx_allocator_config",
    ]
    include_dirs = [ "$faultloggerd_common_path/dfxlog" ]
    sources = dfx_local_handler_sources
    sources += [ "$faultloggerd_interfaces_path/innerkits/signal_handler/dfx_signalhandler_exception.c" ]
    defines = [ "DFX_LOG_HILOG_BASE" ]
    deps = [
      "$faultloggerd_common_path/cutil:dfx_cutil_cfi",
      "$faultloggerd_common_path/cppcrash_formatter:cppcrash_formatter_src_cfi",
      "$faultloggerd_common_path/dfxutil:libdfx_util",
      "$faultloggerd_frameworks_path/allocator:dfx_allocator_src_cfi",
      "$faultloggerd_interfaces_path/innerkits/faultloggerd_client:libfaultloggerd",
      "$faultloggerd_interfaces_path/innerkits/unwinder:libunwinder",
    ]

    external_deps = [
      "bounds_checking_function:libsec_shared",
      "c_utils:utils",
      "hisysevent:libhisysevent",
      "cJSON:cjson",
    ]
    part_name = "faultloggerd"
    subsystem_name = "hiviewdfx"
  }
}