# Copyright (C) 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/config/components/ets_frontend/ets2abc_config.gni")
import("//build/ohos.gni")
import("//build/ohos/taihe_idl/taihe.gni")
import("./../../multimedia_camera_framework.gni")

subsystem_name = "multimedia"
part_name = "camera_framework"
taihe_generated_file_path_camera =
    "$taihe_file_path/out/$subsystem_name/$part_name/camera"
taihe_generated_file_path_cameraPicker =
    "$taihe_file_path/out/$subsystem_name/$part_name/cameraPicker"

copy_taihe_idl("copy_camera_taihe") {
  sources = [
    "${multimedia_camera_framework_path}/frameworks/taihe/idl/ohos.multimedia.camera.context.taihe",
    "${multimedia_camera_framework_path}/frameworks/taihe/idl/ohos.multimedia.camera.taihe",
    "${multimedia_camera_framework_path}/frameworks/taihe/idl/ohos.multimedia.cameraPicker.context.taihe",
    "${multimedia_camera_framework_path}/frameworks/taihe/idl/ohos.multimedia.cameraPicker.taihe",
  ]
  external_deps = [ "image_framework:copy_image_taihe" ]
}

ohos_taihe("camera_run_taihe") {
  taihe_generated_file_path = "${taihe_generated_file_path_camera}"
  deps = [ ":copy_camera_taihe" ]
  outputs = [
    "$taihe_generated_file_path/src/ohos.multimedia.camera.ani.cpp",
    "$taihe_generated_file_path/src/ohos.multimedia.camera.abi.c",
  ]
}

taihe_shared_library("camera_taihe") {
  taihe_generated_file_path = "${taihe_generated_file_path_camera}"
  subsystem_name = "$subsystem_name"
  part_name = "$part_name"
  shlib_type = "ani"
  version_script = "camera_framework.versionscript"

  include_dirs = [
    "include",
    "include/ability",
    "include/input",
    "include/output",
    "include/query",
    "include/session",
    "include/mode",
    "include/picker",
    "include/transfer",
  ]

  sources = get_target_outputs(":camera_run_taihe")
  sources += [
    "src/camera_constructor_taihe.cpp",
    "src/camera_security_utils_taihe.cpp",
    "src/camera_utils_taihe.cpp",
    "src/camera_worker_queue_keeper_taihe.cpp",
    "src/capture_photo_taihe.cpp",
    "src/deferred_photo_proxy_taihe.cpp",
    "src/input/camera_input_taihe.cpp",
    "src/input/camera_manager_taihe.cpp",
    "src/listener_base_taihe.cpp",
    "src/mode/light_painting_photo_session_taihe.cpp",
    "src/mode/night_photo_session_taihe.cpp",
    "src/mode/photo_session_taihe.cpp",
    "src/mode/portrait_photo_session_taihe.cpp",
    "src/mode/professional_session_taihe.cpp",
    "src/mode/secure_session_taihe.cpp",
    "src/mode/secure_session_taihe_for_sys.cpp",
    "src/mode/slow_motion_video_session_taihe.cpp",
    "src/mode/time_lapse_photo_session_taihe.cpp",
    "src/mode/video_session_for_sys_taihe.cpp",
    "src/mode/video_session_taihe.cpp",
    "src/output/camera_output_taihe.cpp",
    "src/output/depth_data_output_taihe.cpp",
    "src/output/depth_data_taihe.cpp",
    "src/output/metadata_output_taihe.cpp",
    "src/output/movie_file_output_taihe.cpp",
    "src/output/photo_output_taihe.cpp",
    "src/output/preview_output_taihe.cpp",
    "src/output/unify_movie_file_output_taihe.cpp",
    "src/output/video_capability_taihe.cpp",
    "src/output/video_output_taihe.cpp",
    "src/photo_taihe.cpp",
    "src/query/camera_query_taihe.cpp",
    "src/quickthumbnail_taihe.cpp",
    "src/session/camera_session_taihe.cpp",
    "src/transfer/camera_transfer_taihe.cpp",
    "src/session/control_center_session_taihe.cpp",
  ]

  deps = [
    ":camera_run_taihe",
    "${multimedia_camera_framework_path}/common:camera_utils",
    "${multimedia_camera_framework_path}/frameworks/native/camera/base:camera_framework",
    "${multimedia_camera_framework_path}/frameworks/native/camera/extension:camera_framework_ex",
  ]

  external_deps = [
    "ability_runtime:abilitykit_native",
    "c_utils:utils",
    "drivers_interface_camera:libcamera_proxy_1.0",
    "drivers_interface_camera:libcamera_proxy_1.1",
    "drivers_interface_display:display_commontype_idl_headers",
    "eventhandler:libeventhandler",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "hitrace:hitrace_meter",
    "image_framework:image_native",
    "image_framework:image_taihe",
    "ipc:ipc_core",
    "media_library:media_library_camera_helper",
    "media_library:medialibrary_ani_utils",
    "napi:ace_napi",
    "runtime_core:ani_helpers",
  ]

  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  cflags = [
    "-fPIC",
    "-fdata-sections",
    "-ffunction-sections",
    "-fno-asynchronous-unwind-tables",
    "-fno-unwind-tables",
    "-fvisibility=hidden",
    "-DIMAGE_COLORSPACE_FLAG",
    "-Os",
  ]
  cflags_cc = cflags

  ldflags = [
    "-Wl,--exclude-libs=ALL",
    "-Wl,--gc-sections",
  ]
}

generate_static_abc("camera_framework_taihe_abc") {
  base_url = "${taihe_generated_file_path_camera}"
  files = [ "${taihe_generated_file_path_camera}/@ohos.multimedia.camera.ets" ]
  is_boot_abc = "True"
  device_dst_file = "/system/framework/camera_framework_taihe_abc.abc"
  dependencies = [ ":camera_run_taihe" ]
}

ohos_taihe("camera_picker_run_taihe") {
  taihe_generated_file_path = "${taihe_generated_file_path_cameraPicker}"
  deps = [ ":copy_camera_taihe" ]
  outputs = [
    "$taihe_generated_file_path/src/ohos.multimedia.cameraPicker.ani.cpp",
    "$taihe_generated_file_path/src/ohos.multimedia.cameraPicker.abi.c",
  ]
}

taihe_shared_library("camera_picker_taihe") {
  taihe_generated_file_path = "${taihe_generated_file_path_cameraPicker}"
  subsystem_name = "$subsystem_name"
  part_name = "$part_name"
  shlib_type = "ani"
  version_script = "camera_framework.versionscript"

  include_dirs = [
    "include",
    "include/picker",
  ]

  sources = get_target_outputs(":camera_picker_run_taihe")
  sources += [
    "src/camera_picker_constructor_taihe.cpp",
    "src/camera_security_utils_taihe.cpp",
    "src/camera_utils_taihe.cpp",
    "src/camera_worker_queue_keeper_taihe.cpp",
    "src/picker/camera_picker_taihe.cpp",
  ]

  deps = [
    ":camera_picker_run_taihe",
    ":camera_taihe",
    "${multimedia_camera_framework_path}/common:camera_utils",
    "${multimedia_camera_framework_path}/frameworks/native/camera/base:camera_framework",
    "${multimedia_camera_framework_path}/frameworks/native/camera/extension:camera_framework_ex",
  ]

  external_deps = [
    "ability_base:configuration",
    "ability_base:want",
    "ability_runtime:ability_context_native",
    "ability_runtime:abilitykit_native",
    "ability_runtime:ani_base_context",
    "ability_runtime:ui_extension",
    "ace_engine:ace_uicontent",
    "c_utils:utils",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_core",
  ]

  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  cflags = [
    "-fPIC",
    "-fdata-sections",
    "-ffunction-sections",
    "-fno-asynchronous-unwind-tables",
    "-fno-unwind-tables",
    "-fvisibility=hidden",
    "-DIMAGE_COLORSPACE_FLAG",
    "-Os",
  ]
  cflags_cc = cflags

  ldflags = [
    "-Wl,--exclude-libs=ALL",
    "-Wl,--gc-sections",
  ]
}

generate_static_abc("camera_picker_taihe_abc") {
  base_url = "${taihe_generated_file_path_cameraPicker}"
  files = [ "${taihe_generated_file_path_cameraPicker}/@ohos.multimedia.cameraPicker.ets" ]
  is_boot_abc = "True"
  device_dst_file = "/system/framework/camera_picker_taihe_abc.abc"
  dependencies = [ ":camera_picker_run_taihe" ]
}

ohos_prebuilt_etc("camera_framework_etc") {
  source = "$target_out_dir/camera_framework_taihe_abc.abc"
  module_install_dir = "framework"
  part_name = "$part_name"
  subsystem_name = "$subsystem_name"
  deps = [ ":camera_framework_taihe_abc" ]
}

ohos_prebuilt_etc("camera_picker_etc") {
  source = "$target_out_dir/camera_picker_taihe_abc.abc"

  module_install_dir = "framework"
  part_name = "$part_name"
  subsystem_name = "$subsystem_name"
  deps = [ ":camera_picker_taihe_abc" ]
}

group("camera_framework_taihe") {
  deps = [
    ":camera_framework_etc",
    ":camera_picker_etc",
    ":camera_picker_taihe",
    ":camera_taihe",
  ]
}