# Copyright (c) 2021-2026 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/clang/clang.gni")
import("//build/ohos.gni")
import("//build/test.gni")
import("./idlize_config.gni")

# Config args
declare_args() {
  # ace debug flag, enable debug features: like dcheck, thread-checker, mem-monitor...
  enable_ace_debug = false

  # show the instance id in logs.
  enable_ace_instance_log = true

  # Disable glfw window to build for PC preview scenario.
  enable_glfw_window = false

  # Enable metal in iOS or MacOS
  shell_enable_metal = false

  # Enable pgo for building.
  ace_engine_feature_enable_pgo = false

  # Enable pgo for building.
  ace_engine_feature_enable_codemerge = false

  # Enable AArch64 instruction prefetch for building.
  ace_engine_feature_enable_inst_prefetch = false

  # Set pgo profdata path
  ace_engine_feature_pgo_path = ""

  # Enable atomic for building.
  ace_engine_feature_enable_atomic = false

  # Set Instruction Sched Model
  ace_engine_feature_sched_model = ""

  # Enable test coverage
  ace_engine_feature_enable_coverage = false

  # Enalbe point light
  ace_engine_feature_enable_point_light = true

  # Set atomicservice basic engine so path
  ace_engine_feature_asbng_path = ""

  # Sanitize debug
  ace_sanitize_debug = false

  # Enable when build for text engine adapter
  enable_graphic_text_gine = true

  # Enable split_mode support
  ace_engine_feature_enable_split_mode = false

  # Enable navigation split mode support
  ace_engine_feature_enable_nav_split_mode = false

  # Enable aps framework support
  ace_engine_feature_enable_aps = false

  # Enable wearable product support
  ace_engine_feature_wearable = false

  # Enable form size change animation
  ace_engine_feature_enable_form_size_change_animation = true

  # Enalbe form menu default, wearable product is not supported
  ace_engine_feature_form_menu_enable = true

  # Enable ace_engine circular screen
  ace_engine_feature_enable_digital_crown = false

  # Enable event extra handling
  ace_engine_feature_enable_event_extra_handling = false

  # Enable ace_engine circle feature
  ace_engine_enable_circle_feature = true

  # Enable long press gesture extra handling
  ace_engine_feature_enable_long_press_gesture_extra_handling = false

  # Enable skia upgrade
  ace_engine_feature_enable_upgrade_skia = true

  #Enable default click sound
  ace_engine_feature_enable_default_click_sound = false

  #Enable container_scope tracking
  ace_engine_feature_enable_container_scope_tracking = false
}

enable_dump_drawcmd = false
is_ohos_standard_system = is_standard_system && !is_arkui_x
use_mingw_win = "${current_os}_${current_cpu}" == "mingw_x86_64"
use_mac = "${current_os}_${current_cpu}" == "mac_x64" ||
          "${current_os}_${current_cpu}" == "mac_arm64"
use_ios = "${current_os}_${current_cpu}" == "ios_x64" ||
          "${current_os}_${current_cpu}" == "ios_arm64"
use_linux = "${current_os}_${current_cpu}" == "linux_x64" ||
            "${current_os}_${current_cpu}" == "linux_arm64"

use_hilog = is_mingw || is_mac || is_linux || is_ohos || is_ohos_standard_system

# Config path
ace_root = "//foundation/arkui/ace_engine"
hilog_root = "//base/hiviewdfx/hilog"
ace_napi_frameworks = "//foundation/arkui/ace_engine/frameworks"
ace_napi = "//foundation/arkui/napi"
arkui_root = "//foundation/arkui"
ace_graphic = "//foundation/graphic/graphic_2d"
vpe_enabled = false
if (defined(global_parts_info.multimedia_video_processing_engine)) {
  vpe_enabled = true
}

if (!defined(aosp_libs_dir)) {
  aosp_libs_dir = "//prebuilts/aosp_prebuilt_libs/asdk_libs"
}
libs_root = "${aosp_libs_dir}/sdk"

ability_runtime_path = "//foundation/ability/ability_runtime"
graphic_2d_path = "//foundation/graphic/graphic_2d"
ark_ets_path = "//arkcompiler/ets_runtime"
crossplatform_plugin_root = "//plugins"
crossplatform_multimedia_root = "//foundation/multimedia"
if (ace_engine_feature_enable_upgrade_skia) {
  skia_root_new = "//third_party/skia/m133"
} else {
  skia_root_new = "//third_party/skia"
}
c_utils_header_path = "//commonlibrary/c_utils/base/include"
ace_graphic_surface = "//foundation/graphic/graphic_surface"

# arkui-x
ark_toolchain_path = "//arkcompiler/toolchain"
ace_drag = "//base/msdp/device_status"
acd_input = "//foundation/multimodalinput/input"
arkuix_graphic_surface = "//foundation/appframework/graphic_surface"

# Config toolchain
windows_buildtool = "//build/toolchain/mingw:mingw_x86_64"
if (!defined(default_aosp_source_dir)) {
  default_aosp_source_dir = "/"
}
objcopy_default = "${default_aosp_source_dir}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin/objcopy"
objcopy_mingw = "${default_aosp_source_dir}/prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/bin/objcopy"
objcopy_x86_64 = "${default_clang_base_path}/bin/llvm-objcopy"
if ("${current_os}_${current_cpu}" == "mac_arm64") {
  mac_buildtool = "//build/toolchain/mac:clang_arm64"
} else if ("${current_os}_${current_cpu}" == "mac_x64") {
  mac_buildtool = "//build/toolchain/mac:clang_x64"
}

objcopy_clang = "$clang_base_path/bin/llvm-objcopy"

if (is_ohos_standard_system) {
  if (host_cpu == "arm64") {
    objcopy_default =
        "//prebuilts/clang/ohos/linux-aarch64/llvm/bin/llvm-objcopy"
  } else {
    objcopy_default =
        "//prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objcopy"
  }
} else if (is_arkui_x) {
  if (host_os == "mac") {
    objcopy_default = objcopy_clang
  } else if (defined(aosp_objcopy)) {
    objcopy_default = aosp_objcopy
  }
}

# Config subsystem name
ace_engine_subsystem = "arkui"

# Config part name
if (is_ohos_standard_system) {
  ace_engine_part = "ace_engine"
  hilog_deps = [ "hilog:libhilog" ]
  ark_runtime_path = "//arkcompiler/runtime_core"
} else {
  if (is_arkui_x) {
    ace_engine_part = "ace_engine_cross"
  } else {
    ace_engine_part = "ace_engine_full"
  }
  hilog_deps = [ "hilog:libhilog" ]
  ark_runtime_path = "//arkcompiler/runtime_core"
}

# Config defines
ace_wearable_defines = [ "WEARABLE_PRODUCT" ]
ace_ivi_defines = [ "IVI_PRODUCT" ]

ace_common_defines = [ "ACE_LOG_TAG=\"Ace\"" ]

if (use_hilog) {
  ace_common_defines += [ "USE_HILOG" ]
}

if (enable_glfw_window) {
  ace_common_defines += [ "USE_GLFW_WINDOW" ]
}

if (use_clang_coverage) {
  ace_common_defines += [ "USE_CLANG_COVERAGE" ]
  ace_engine_feature_enable_codemerge = false
}

if (enable_ace_debug) {
  ace_common_defines += [ "ACE_DEBUG" ]
}

if (enable_ace_instance_log) {
  ace_common_defines += [ "ACE_INSTANCE_LOG" ]
}

if (enable_dump_drawcmd) {
  ace_common_defines += [ "DUMP_DRAW_CMD" ]
}

if (build_variant == "user") {
  ace_common_defines += [ "IS_RELEASE_VERSION" ]
}

if (vpe_enabled) {
  ace_common_defines += [ "VPE_ENABLED" ]
}

ace_use_new_skia = true

ace_use_rosen_drawing = false
if (defined(use_rosen_drawing) && use_rosen_drawing) {
  ace_use_rosen_drawing = true
  ace_common_defines += [ "USE_ROSEN_DRAWING" ]
}

if (!defined(global_parts_info) ||
    defined(global_parts_info.account_os_account)) {
  os_account_exists = true
  ace_common_defines += [ "OS_ACCOUNT_EXISTS" ]
} else {
  os_account_exists = false
}

if (is_emulator) {
  ace_common_defines += [ "IS_EMULATOR" ]
}

if (defined(global_parts_info)) {
  if (defined(global_parts_info.resourceschedule_frame_aware_sched) ||
      defined(
          global_parts_info.hmosresourceschedule_frame_aware_sched_override)) {
    frame_trace_support = true
  } else {
    frame_trace_support = false
  }
}

if (defined(global_parts_info) &&
    defined(global_parts_info.resourceschedule_ffrt) && current_os == "ohos") {
  ffrt_support = true
} else {
  ffrt_support = false
}

if (defined(global_parts_info.multimedia_player_framework) || is_arkui_x) {
  enable_player_framework = true
  ace_common_defines += [ "PLAYER_FRAMEWORK_EXISTS" ]
} else {
  enable_player_framework = false
}

if (defined(global_parts_info.multimedia_audio_framework)) {
  enable_audio_framework = true
  ace_common_defines += [ "AUDIO_FRAMEWORK_EXISTS" ]
} else {
  enable_audio_framework = false
}

if (defined(global_parts_info.thirdparty_qrcodegen) || is_arkui_x) {
  qrcodegen_support = true
  ace_common_defines += [ "QRCODEGEN_SUPPORT" ]
} else {
  qrcodegen_support = false
}

if (!defined(global_parts_info) ||
    defined(global_parts_info.security_security_component_manager)) {
  security_component_enable = true
  ace_common_defines += [ "SECURITY_COMPONENT_ENABLE" ]
} else {
  security_component_enable = false
}

if (!defined(global_parts_info) ||
    defined(global_parts_info.ability_form_fwk)) {
  form_fwk_enable = true
} else {
  form_fwk_enable = false
}

if (defined(global_parts_info) &&
    defined(global_parts_info.hiviewdfx_hicollie)) {
  uiservice_xcollie_enable = true
} else {
  uiservice_xcollie_enable = false
}

if (!defined(global_parts_info) ||
    defined(global_parts_info.graphic_graphic_2d_ext)) {
  if (ace_engine_feature_enable_aps) {
    ace_common_defines += [ "APS_ENABLE" ]
  }
}

if (ace_engine_feature_asbng_path == "") {
  ace_engine_feature_asbng_path_enable = false
} else {
  ace_engine_feature_asbng_path_enable = true
}

ace_platforms = []

_ace_adapter_dir = rebase_path("$ace_root/adapter", root_build_dir)
_adapters = exec_script("build/search.py", [ _ace_adapter_dir ], "list lines")
foreach(item, _adapters) {
  import_var = {
  }
  import_var = {
    import("$ace_root/adapter/$item/build/platform.gni")
  }

  if (defined(import_var.platforms)) {
    foreach(platform, import_var.platforms) {
      if (!is_arkui_x ||
          (is_arkui_x && defined(platform.cross_platform_support) &&
           platform.cross_platform_support)) {
        if (defined(platform.name)) {
          ace_platforms += [ platform ]
        }
      }
    }
  }
}

current_platform = {
}
foreach(item, ace_platforms) {
  if ((use_mingw_win && item.name == "windows") ||
      (use_mac && item.name == "mac") || (use_linux && item.name == "linux")) {
    current_platform = item
  }
}

if (ace_engine_feature_enable_split_mode) {
  ace_common_defines += [ "ENABLE_SPLIT_MODE" ]
}

if (ace_engine_feature_enable_nav_split_mode) {
  ace_common_defines += [ "ENABLE_NAV_SPLIT_MODE" ]
}

if (ace_engine_feature_wearable) {
  ace_common_defines += [ "ARKUI_WEARABLE" ]
}

if (ohos_indep_compiler_enable) {
  indep_compile_includes =
      [ "//binarys/third_party/icu/innerapis/shared_icuuc/includes" ]
}

if (ace_engine_feature_enable_form_size_change_animation) {
  ace_common_defines += [ "FORM_SIZE_CHANGE_ANIMATION" ]
}

# Enable full test suite compilation for TDD
ace_enable_full_test_suite = true

# Enable ArkUI static instructive code
ace_engine_feature_enable_static_instructive_code = false

if (ace_engine_feature_enable_static_instructive_code) {
  ace_common_defines += [ "ACE_STATIC" ]
}

if (ace_engine_feature_enable_default_click_sound) {
    ace_common_defines += [ "ENABLE_DEFAULT_CLICK_SOUND" ]
}

if (defined(global_parts_info) && defined(global_parts_info.hiviewdfx_api_metrics)) {
  ace_common_defines += [ "ACE_ENGINE_API_METRICS_EXT_ENABLE" ]
}

if (ace_engine_feature_enable_container_scope_tracking) {
    ace_common_defines += [ "ENABLE_CONTAINER_SCOPE_TRACKING" ]
}