1# Copyright (c) 2021 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/ohos.gni")
15import("//foundation/arkui/ace_engine/ace_config.gni")
16
17# build javascript engine library
18template("js_engine") {
19  forward_variables_from(invoker, "*")
20
21  ohos_source_set(target_name) {
22    subsystem_name = ace_engine_subsystem
23    part_name = ace_engine_part
24    defines += invoker.defines
25    if (target_cpu == "arm64") {
26      if (!is_mingw) {
27        defines += [ "_ARM64_" ]
28      }
29    }
30    if (current_os == "ohos" && current_cpu == "x86_64") {
31      defines += [ "SIMULATOR_64" ]
32    }
33    deps = []
34    external_deps = []
35    if (use_hilog) {
36      external_deps += [ "hilog:libhilog" ]
37    }
38    configs = [ "$ace_root:ace_config" ]
39
40    if (use_js_debug) {
41      deps +=
42          [ "${engine_path}:js_engine_bridge_${engine_name}_debug_$platform" ]
43    } else {
44      deps += [ "${engine_path}:js_engine_bridge_${engine_name}_$platform" ]
45    }
46
47    # if support napi
48    sources = [ "common/js_engine.cpp" ]
49
50    external_deps += [ "napi:ace_napi" ]
51
52    if (defined(config.use_build_in_js_engine) &&
53        config.use_build_in_js_engine) {
54      deps += [ "$ace_root/frameworks/bridge:framework_bridge_$platform" ]
55    } else {
56      deps += [ "$ace_root/build:libace_compatible" ]
57      if (defined(config.build_container_scope_lib) &&
58          config.build_container_scope_lib) {
59        if (is_arkui_x) {
60          deps += [ "$ace_napi:ace_container_scope_static" ]
61        } else {
62          external_deps += [ "napi:ace_container_scope" ]
63        }
64      }
65    }
66  }
67}
68
69# dynamic generate js_engine targets
70foreach(item, ace_platforms) {
71  platform = item.name
72  engine_config = {
73  }
74  engine_config = item.config
75  support_engines = []
76  support_engines = engine_config.js_engines
77  foreach(engine, support_engines) {
78    js_engine("js_engine_${engine.engine_name}_$platform") {
79      platform = item.name
80      engine_name = engine.engine_name
81      engine_path = engine.engine_path
82      defines = engine.engine_defines
83      use_js_debug = false
84      config = {
85      }
86      if (defined(item.config)) {
87        config = item.config
88      }
89      if (defined(config.defines)) {
90        defines += config.defines
91      }
92    }
93    if (defined(engine.have_debug) && engine.have_debug) {
94      js_engine("js_engine_${engine.engine_name}_debug_$platform") {
95        platform = item.name
96        engine_name = engine.engine_name
97        engine_path = engine.engine_path
98        defines = engine.engine_defines
99        use_js_debug = true
100        config = {
101        }
102        if (defined(item.config)) {
103          config = item.config
104        }
105        if (defined(config.defines)) {
106          defines += config.defines
107        }
108      }
109    }
110  }
111}
112