# Copyright (c) 2021-2022 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/aafwk/standard/aafwk.gni")
import("//foundation/aafwk/standard/form_runtime/form_runtime.gni")

################################### libfms ########################################
config("formmgr_config") {
  include_dirs = [
    "services/include",
    "//third_party/json/include",
  ]
}

ohos_shared_library("libfms") {
  cflags_cc = []
  include_dirs = [
    "${ability_runtime_path}/services/common/include",
    "${ability_runtime_kits_path}/appkit/native/ability_runtime",
  ]
  sources = [
    "services/src/form_ability_connection.cpp",
    "services/src/form_acquire_connection.cpp",
    "services/src/form_acquire_state_connection.cpp",
    "services/src/form_ams_helper.cpp",
    "services/src/form_batch_delete_connection.cpp",
    "services/src/form_bms_helper.cpp",
    "services/src/form_cache_mgr.cpp",
    "services/src/form_cast_temp_connection.cpp",
    "services/src/form_data_mgr.cpp",
    "services/src/form_db_cache.cpp",
    "services/src/form_db_info.cpp",
    "services/src/form_delete_connection.cpp",
    "services/src/form_dump_mgr.cpp",
    "services/src/form_event_notify_connection.cpp",
    "services/src/form_host_callback.cpp",
    "services/src/form_host_record.cpp",
    "services/src/form_info_mgr.cpp",
    "services/src/form_info_storage.cpp",
    "services/src/form_info_storage_mgr.cpp",
    "services/src/form_item_info.cpp",
    "services/src/form_mgr_adapter.cpp",
    "services/src/form_mgr_service.cpp",
    "services/src/form_msg_event_connection.cpp",
    "services/src/form_provider_mgr.cpp",
    "services/src/form_refresh_connection.cpp",
    "services/src/form_refresh_limiter.cpp",
    "services/src/form_storage_mgr.cpp",
    "services/src/form_supply_callback.cpp",
    "services/src/form_sys_event_receiver.cpp",
    "services/src/form_task_mgr.cpp",
    "services/src/form_timer_mgr.cpp",
    "services/src/form_util.cpp",
    "services/src/kvstore_death_recipient_callback.cpp",
  ]

  defines = [
    "AMS_LOG_TAG = \"FormMgrService\"",
    "AMS_LOG_DOMAIN = 0xD001120",
  ]

  configs = [
    ":formmgr_config",
    ":formmgr_sdk_config",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  deps = [
    "${ability_runtime_kits_path}/appkit:app_context",
    "${ability_runtime_services_path}/common:perm_verification",
  ]

  external_deps = [
    "ability_base:base",
    "ability_base:want",
    "ability_base:zuri",
    "ability_runtime:ability_manager",
    "ability_runtime:app_manager",
    "ability_runtime:wantagent_innerkits",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "common_event_service:cesfwk_core",
    "common_event_service:cesfwk_innerkits",
    "device_usage_statistics:usagestatsinner",
    "distributeddatamgr:distributeddata_inner",
    "eventhandler:libeventhandler",
    "form_runtime:form_manager",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
    "power_manager_native:powermgr_client",
    "safwk:system_ability_fwk",
    "samgr_standard:samgr_proxy",
    "time_native:time_service",
    "utils_base:utils",
  ]

  if (os_account_part_enabled) {
    cflags_cc += [ "-DOS_ACCOUNT_PART_ENABLED" ]
    external_deps += [
      "os_account:libaccountkits",
      "os_account:os_account_innerkits",
    ]
  }

  subsystem_name = "aafwk"
  part_name = "form_runtime"
}

################################### fmskit_native ########################################
config("fmskit_config") {
  defines = [
    "AMS_LOG_TAG = \"FmskitNative\"",
    "AMS_LOG_DOMAIN = 0xD001151",
  ]
}

config("fmskit_public_config") {
  include_dirs = [
    "interfaces/kits/native/include",
    "${ability_runtime_path}/services/common/include",
    "${form_runtime_path}/interfaces/inner_api/include",
    "${bundlefwk_inner_api_path}/appexecfwk_base/include",
    "${ability_base_innerapi_path}/want/include",
  ]
}

ohos_shared_library("fmskit_native") {
  configs = [ ":fmskit_config" ]
  public_configs = [ ":fmskit_public_config" ]
  sources = [
    "interfaces/kits/native/src/form_errors.cpp",
    "interfaces/kits/native/src/form_host_client.cpp",
    "interfaces/kits/native/src/form_mgr.cpp",
  ]

  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }

  deps = []

  external_deps = [
    "ability_base:want",
    "ability_runtime:app_manager",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "form_runtime:form_manager",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
    "samgr_standard:samgr_proxy",
    "utils_base:utils",
  ]

  subsystem_name = "aafwk"
  part_name = "form_runtime"
}

################################### form_manager ########################################
config("formmgr_sdk_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "interfaces/inner_api/include/",
    "//third_party/json/include",
    "${ability_runtime_kits_path}/ability/native/include",
    "${ability_runtime_innerapi_path}/ability_manager/include",
    "${ability_runtime_innerapi_path}/app_manager/include/appmgr",
    "${ability_runtime_path}/services/common/include",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
}

ohos_shared_library("form_manager") {
  sources = [
    "interfaces/inner_api/src/form_host_proxy.cpp",
    "interfaces/inner_api/src/form_host_stub.cpp",
    "interfaces/inner_api/src/form_js_info.cpp",
    "interfaces/inner_api/src/form_mgr_proxy.cpp",
    "interfaces/inner_api/src/form_mgr_stub.cpp",
    "interfaces/inner_api/src/form_provider_data.cpp",
    "interfaces/inner_api/src/form_provider_info.cpp",
    "interfaces/inner_api/src/form_provider_proxy.cpp",
    "interfaces/inner_api/src/form_provider_stub.cpp",
    "interfaces/inner_api/src/form_supply_proxy.cpp",
    "interfaces/inner_api/src/form_supply_stub.cpp",
    "interfaces/inner_api/src/provider_connect_proxy.cpp",
    "interfaces/inner_api/src/provider_connect_stub.cpp",
  ]

  defines = [
    "AMS_LOG_TAG = \"FormMgrService\"",
    "AMS_LOG_DOMAIN = 0xD001120",
  ]

  public_configs = [
    ":formmgr_sdk_config",
    "${form_runtime_path}:formmgr_config",
  ]

  deps = [ "//third_party/jsoncpp:jsoncpp" ]

  external_deps = [
    "ability_base:configuration",
    "ability_base:want",
    "ability_runtime:app_manager",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "dataability:native_dataability",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
    "relational_store:native_appdatafwk",
    "relational_store:native_rdb",
    "utils_base:utils",
  ]

  subsystem_name = "aafwk"
  part_name = "form_runtime"
}

group("form_napi_packages") {
  if (ability_runtime_graphics) {
    deps = [
      "${form_runtime_napi_path}:formbindingdata_napi",
      "${form_runtime_napi_path}:formerror_napi",
      "${form_runtime_napi_path}:formextension_napi",
      "${form_runtime_napi_path}:formextensioncontext_napi",
      "${form_runtime_napi_path}:formhost_napi",
      "${form_runtime_napi_path}:forminfo_napi",
      "${form_runtime_napi_path}:formmanager",
      "${form_runtime_napi_path}:formprovider_napi",
      "${form_runtime_napi_path}:formutil_napi",
    ]
  }
}

group("fms_innerkits_target") {
  if (ability_runtime_graphics) {
    deps = [ ":form_manager" ]
  }
}

group("fms_target") {
  deps = [ ":libfms" ]
}

group("fms_services_target") {
  if (ability_runtime_graphics) {
    deps = [ ":fms_target" ]
  }
}
