# Copyright (c) 2022-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("../windowmanager_aafwk.gni")

ispreview = false
if (is_mingw || is_mac || is_linux) {
  ispreview = true
}
if (!ispreview) {
  group("previewer_window") {
  }

  group("previewer_window_napi") {
  }
} else {
  if (current_os == "mac") {
    suffix = ".dylib"
  } else if (current_os == "linux") {
    suffix = ".so"
  } else if (current_os == "mingw") {
    suffix = ".dll"
  }

  config("previewer_window_config") {
    visibility = [ "*:*" ]
    visibility += [
      "${graphic_base_path}/graphic_2d/rosen/modules/platform/image_native",
      "${graphic_base_path}/graphic_2d/rosen/modules/platform/ipc_core",
      "${graphic_base_path}/graphic_2d/rosen/modules/platform/utils",
    ]

    include_dirs = [
      "include",
      "../utils/include",
      "${graphic_base_path}/graphic_2d/rosen/modules/platform/utils",
      "${graphic_base_path}/graphic_2d/rosen/modules/platform/ipc_core",
      "${graphic_base_path}/graphic_2d/rosen/modules/platform/image_native",
      "${window_base_path}/interfaces/innerkits/wm",
    ]
  }

  ohos_shared_library("previewer_window") {
    libs = []

    public_configs = [
      ":previewer_window_config",
      "${ability_runtime_path}/frameworks/simulator/common:ability_simulator_common_config",
    ]
    sources = [
      "../utils/src/window_manager_hilog.cpp",
      "../utils/src/window_transition_info.cpp",
      "../utils/src/wm_math.cpp",
      "src/vsync_station.cpp",
      "src/window.cpp",
      "src/window_display.cpp",
      "src/window_impl.cpp",
      "src/window_model.cpp",
      "src/window_option.cpp",
      "src/window_scene.cpp",
    ]

    include_dirs = [
      "include",
      "${arkui_path}/ace_engine/adapter/preview/external/multimodalinput",
      "${arkui_path}/ace_engine/",
      "mock",
      "../utils/include",
      "${ide_previewer_external_path}",
      "${window_base_path}/interfaces/kits/napi/window_animation",
    ]
    public_deps = [
      "${graphic_base_path}/graphic_2d/rosen/modules/platform:ipc_core",
      "${graphic_base_path}/graphic_2d/rosen/modules/platform:utils",
    ]

    external_deps = [
      "ace_engine:ace_uicontent",
      "graphic_2d:librender_service_base",
      "graphic_2d:librender_service_client",
      "hilog:libhilog",
    ]

    cflags = [ "-std=c++11" ]
    cflags_cc = [ "-std=c++17" ]
    part_name = "window_manager"
    subsystem_name = "window"
  }

  config("previewer_window_napi_config") {
    visibility = [ ":*" ]

    include_dirs = [
      "../interfaces/kits/napi/window_runtime/window_napi",
      "../interfaces/kits/napi/window_runtime/window_stage_napi",
    ]
  }

  ohos_shared_library("previewer_window_napi") {
    public_configs = [ ":previewer_window_napi_config" ]

    libs = []

    sources = [
      "${ability_runtime_path}/frameworks/simulator/ability_simulator/src/js_runtime_utils.cpp",
      "../interfaces/kits/napi/window_animation/js_window_animation_utils.cpp",
      "../interfaces/kits/napi/window_runtime/window_napi/js_window.cpp",
      "../interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp",
      "../interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp",
      "../utils/src/window_manager_hilog.cpp",

      # mock
      "mock/js_transition_controller.cpp",
      "mock/js_window_listener.cpp",
      "mock/js_window_register_manager.cpp",
      "mock/permission.cpp",
      "mock/pixel_map_napi.cpp",
      "mock/window_manager_napi/js_window_manager.cpp",
      "mock/window_manager_napi/window_manager_module.cpp",
    ]

    include_dirs = [
      ".",
      "include",
      "../utils/include",
      "mock",
      "${ability_runtime_path}/interfaces/inner_api/runtime/include",
      "${window_base_path}/interfaces/kits/napi/window_animation",
    ]

    deps = [
      ":previewer_window",
      "${graphic_base_path}/graphic_2d/rosen/modules/platform:eventhandler",
      "${graphic_base_path}/graphic_2d/rosen/modules/platform:utils",
    ]

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

    if (!build_ohos_sdk && !is_mingw) {
      external_deps += [ "ability_runtime:ability_manager" ]
    }

    cflags_cc = [ "-DWINDOW_PREVIEW" ]
    cflags = [ "-std=c++11" ]

    part_name = "window_manager"
    subsystem_name = "window"
  }

  ohos_copy("window_stage_copy_modules") {
    deps = []
    sources = []
    napi_modules = [ "window_stage_modules:windowstage" ]

    foreach(module, napi_modules) {
      deps += [ module ]
      out_path = get_label_info(module, "root_out_dir")
      out_name = get_label_info(module, "name")
      sources += [ out_path + "/window/window_manager/lib" + out_name + suffix ]
    }

    target_path = get_label_info(":copy_previewer_library", "target_out_dir")

    outputs =
        [ target_path +
          "/previewer/common/bin/module/application/{{source_file_part}}" ]
    part_name = "window_manager"
    subsystem_name = "window"
  }
  ohos_copy("copy_previewer_library") {
    shared_library_path = get_label_info(":previewer_window", "root_out_dir")
    sources = [ shared_library_path +
                "/window/window_manager/libpreviewer_window" + suffix ]
    deps = [ ":previewer_window" ]

    if (current_os == "mingw" || current_os == "mac") {
      deps += [ ":window_stage_copy_modules" ]
      shared_library_path =
          get_label_info(":previewer_window_napi", "root_out_dir")
      sources += [ shared_library_path +
                   "/window/window_manager/libpreviewer_window_napi" + suffix ]
      deps += [ ":previewer_window_napi" ]
    }

    outputs = [ target_out_dir + "/previewer/common/bin/{{source_file_part}}" ]
    module_source_dir = target_out_dir + "/previewer/common/bin/"
    module_install_name = ""

    part_name = "window_manager"
    subsystem_name = "window"
  }
}