1# Copyright (c) 2021-2022 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")
16import("//foundation/arkui/ace_engine/build/ace_controller.gni")
17import("//foundation/arkui/ace_engine/build/ace_lib.gni")
18
19# generate libace_engine and libace_debug targets
20foreach(item, ace_platforms) {
21  platform = item.name
22  engine_config = {
23  }
24  engine_config = item.config
25  support_engines = []
26  support_engines = engine_config.js_engines
27
28  # generate libace_static lib
29  libace_static("libace_static_" + item.name) {
30    platform = item.name
31    config = {
32    }
33
34    if (defined(item.config)) {
35      config = item.config
36    }
37  }
38
39  # generate separated libace_engine lib
40  if (current_os == "ohos") {
41    build_in_engine = defined(engine_config.use_build_in_js_engine) &&
42                      engine_config.use_build_in_js_engine
43    foreach(engine, support_engines) {
44      if (!build_in_engine) {
45        # generate libace_engine
46        ace_bridge_engine("libace_engine_${engine.engine_name}_${platform}") {
47          platform = item.name
48          engine_name = engine.engine_name
49          build_type = "engine"
50          use_js_debug = false
51        }
52
53        # generate libace_engine_debug
54        if (defined(engine.have_debug) && engine.have_debug) {
55          ace_bridge_engine(
56              "libace_engine_${engine.engine_name}_debug_${platform}") {
57            platform = item.name
58            engine_name = engine.engine_name
59            build_type = "engine"
60            use_js_debug = true
61          }
62        }
63
64        # generate libace_engine_declarative
65        ace_bridge_engine(
66            "libace_engine_declarative_${engine.engine_name}_${platform}") {
67          platform = item.name
68          engine_name = engine.engine_name
69          build_type = "engine_declarative"
70        }
71      }
72
73      # generate libace_engine_pa
74      if (defined(engine_config.js_pa_support) && engine_config.js_pa_support &&
75          platform != "ohos_ng") {
76        ace_bridge_engine("libace_engine_pa_${engine.engine_name}") {
77          platform = item.name
78          engine_name = engine.engine_name
79          build_type = "engine_pa"
80          pa_engine_path = engine_config.pa_engine_path
81        }
82      }
83    }
84  }
85}
86
87# Config for reduceing eh_frame section on aosp platform to save rom size.
88config("reduce_eh_frame_config") {
89  if (!use_mingw_win && !use_mac && !use_linux) {
90    cflags = [
91      "-fno-unwind-tables",
92      "-fomit-frame-pointer",
93    ]
94    cflags_cc = cflags
95  }
96}
97
98config("ace_engine_public_config") {
99  if (use_hilog) {
100    defines = [ "USE_HILOG" ]
101  }
102}
103
104config("lto_link_config") {
105  ldflags = [ "-Wl,--lto-O2" ]
106  if (ace_engine_feature_enable_pgo && enable_enhanced_opt) {
107    ldflags +=
108        [ "-Wl,-mllvm,-force-sched-model=${ace_engine_feature_sched_model}" ]
109  }
110}
111
112ohos_shared_library("libace_compatible") {
113  public_configs = [ ":ace_engine_public_config" ]
114  external_deps = []
115  if (use_hilog) {
116    external_deps += [ "hilog:libhilog" ]
117  }
118  if (is_ohos) {
119    sanitize = {
120      integer_overflow = true
121      boundary_sanitize = true
122      debug = ace_sanitize_debug
123    }
124    deps = [ "$ace_root/build:libace_static_ohos" ]
125    version_script = "libace.map"
126    innerapi_tags = [ "platformsdk" ]
127    configs = [ "$ace_root:ace_coverage_config" ]
128    if (is_clang && (target_cpu == "arm" || target_cpu == "arm64") &&
129        enhanced_opt) {
130      configs += [ ":lto_link_config" ]
131    }
132  } else if (use_mingw_win) {
133    deps = [ "$ace_root/build:libace_static_windows" ]
134  } else if (use_mac) {
135    deps = [ "$ace_root/build:libace_static_mac" ]
136  } else if (use_linux) {
137    deps = [ "$ace_root/build:libace_static_linux" ]
138  }
139  public_external_deps = external_deps
140  part_name = ace_engine_part
141  subsystem_name = ace_engine_subsystem
142}
143
144if (!is_asan && ace_engine_feature_enable_libace) {
145  ohos_shared_library("libace") {
146    external_deps = []
147    if (use_hilog) {
148      external_deps += [ "hilog:libhilog" ]
149    }
150    if (is_ohos) {
151      sanitize = {
152        integer_overflow = true
153        boundary_sanitize = true
154        debug = ace_sanitize_debug
155      }
156      deps = [ "$ace_root/build:libace_static_ohos_ng" ]
157      version_script = "libace.map"
158      innerapi_tags = [ "platformsdk" ]
159      configs = [ "$ace_root:ace_coverage_config" ]
160    } else if (use_mingw_win) {
161      deps = [ "$ace_root/build:libace_static_windows" ]
162    } else if (use_mac) {
163      deps = [ "$ace_root/build:libace_static_mac" ]
164    } else if (use_linux) {
165      deps = [ "$ace_root/build:libace_static_linux" ]
166    }
167    public_external_deps = external_deps
168    part_name = ace_engine_part
169    subsystem_name = ace_engine_subsystem
170  }
171} else {
172  group("libace") {
173    # fake target for asan
174  }
175}
176