# 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/graphic/graphic_2d/graphic_config.gni")

## Build uieffect_napi.so
rosen_is_ohos = current_os == "ohos"
config("graphic_napi_uieffect_config") {
  visibility = [ ":*" ]

  cflags = [
    "-g3",
    "-Wno-pointer-arith",
    "-Wno-non-virtual-dtor",
    "-Wno-missing-field-initializers",
    "-Wno-c++11-narrowing",
    "-Wno-unused-but-set-variable",
  ]
}

ohos_shared_library("uieffect_napi") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }
  include_dirs = [
    "include",
    "$graphic_2d_root/rosen/modules/2d_graphics/include",
    "$graphic_2d_root/rosen/modules/render_service_client/core/ui_effect",
    "$graphic_2d_root/utils/log",
  ]

  configs = [ ":graphic_napi_uieffect_config" ]

  sources = [
    "src/effect_napi.cpp",
    "src/filter_napi.cpp",
    "src/mask_napi.cpp",
    "src/native_module_ohos_ui_effect.cpp",
    "src/ui_effect_napi_utils.cpp",
  ]

  deps = [
    "$graphic_2d_root/rosen/modules/2d_graphics:2d_graphics",
    "$graphic_2d_root/rosen/modules/render_service_client:librender_service_client",
  ]

  external_deps = [
    "hilog:libhilog",
    "napi:ace_napi",
  ]

  if (rosen_is_ohos) {
    defines = [
      "ENABLE_IPC_SECURITY",
      "IMAGE_NAPI_ENABLE"
    ]
    external_deps += [
      "access_token:libaccesstoken_sdk",
      "bundle_framework:appexecfwk_base",
      "bundle_framework:appexecfwk_core",
      "image_framework:image",
      "image_framework:image_native",
      "ipc:ipc_core",
      "samgr:samgr_proxy",
    ]
  }

  if (defined(arkgraphic2d_api_metrics) && arkgraphic2d_api_metrics) {
    external_deps += [ "api_metrics:histogrammanager" ]
    defines += [ "HISTOGRAM_MANAGEMENT_ENABLE=1" ]
  }
  cflags_cc = [ "-std=c++17" ]

  relative_install_dir = "module/graphics"
  part_name = "graphic_2d"
  subsystem_name = "graphic"
}
## Build uieffect_napi.so