• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
13import("//build/ohos.gni")
14
15###############################################################################
16declare_args() {
17  c_utils_feature_coverage = false
18  c_utils_debug_refbase = false
19  c_utils_track_all = false
20  c_utils_print_track_at_once = false
21  c_utils_debug_log_enabled = false
22  c_utils_feature_intsan = true
23  c_utils_parcel_object_check = true
24}
25
26config("utils_config") {
27  include_dirs = [ "include" ]
28}
29
30config("utils_coverage_config") {
31  visibility = [ ":*" ]
32  if (c_utils_feature_coverage) {
33    cflags = [ "--coverage" ]
34    ldflags = [ "--coverage" ]
35  }
36}
37
38config("debug_log_enabled") {
39  visibility = [ ":*" ]
40  defines = [ "DEBUG_UTILS" ]
41}
42
43config("debug_refbase") {
44  visibility = [ ":*" ]
45  defines = [ "DEBUG_REFBASE" ]
46}
47
48config("print_track_at_once") {
49  visibility = [ ":*" ]
50  defines = [ "PRINT_TRACK_AT_ONCE" ]
51}
52
53config("track_all") {
54  visibility = [ ":*" ]
55  defines = [ "TRACK_ALL" ]
56}
57
58config("parcel_object_check") {
59  visibility = [ ":*" ]
60  defines = [ "PARCEL_OBJECT_CHECK" ]
61}
62
63sources_utils = [
64  "src/string_ex.cpp",
65  "src/unicode_ex.cpp",
66  "src/directory_ex.cpp",
67  "src/datetime_ex.cpp",
68  "src/refbase.cpp",
69  "src/parcel.cpp",
70  "src/semaphore_ex.cpp",
71  "src/thread_pool.cpp",
72  "src/file_ex.cpp",
73  "src/mapped_file.cpp",
74  "src/observer.cpp",
75  "src/thread_ex.cpp",
76  "src/io_event_handler.cpp",
77  "src/io_event_reactor.cpp",
78  "src/io_event_epoll.cpp",
79  "src/event_handler.cpp",
80  "src/event_reactor.cpp",
81  "src/event_demultiplexer.cpp",
82  "src/timer.cpp",
83  "src/timer_event_handler.cpp",
84  "src/ashmem.cpp",
85  "src/rwlock.cpp",
86]
87
88if (current_os == "ios") {
89  sources_utils_ios = [
90    "src/directory_ex.cpp",
91    "src/parcel.cpp",
92    "src/refbase.cpp",
93    "src/rwlock.cpp",
94    "src/string_ex.cpp",
95  ]
96}
97
98ohos_static_library("utilsbase") {
99  if (current_os == "ios") {
100    sources = sources_utils_ios
101    configs = [ ":utils_coverage_config" ]
102    all_dependent_configs = [ ":utils_config" ]
103    public_deps = [ "//third_party/bounds_checking_function:libsec_static" ]
104    defines = [ "IOS_PLATFORM" ]
105
106    subsystem_name = "commonlibrary"
107    part_name = "c_utils"
108  } else {
109    sources = sources_utils
110    configs = [ ":utils_coverage_config" ]
111    all_dependent_configs = [ ":utils_config" ]
112    if (current_os != "android" && current_os != "ios") {
113      defines = [ "CONFIG_HILOG" ]
114    }
115    if (c_utils_debug_log_enabled) {
116      configs += [ ":debug_log_enabled" ]
117    }
118    external_deps = [ "hilog:libhilog_base" ]
119    public_deps = [ "//third_party/bounds_checking_function:libsec_static" ]
120
121    subsystem_name = "commonlibrary"
122    part_name = "c_utils"
123  }
124}
125
126ohos_static_library("utilsbase_rtti") {
127  visibility = [ "//foundation/multimedia/media_foundation/engine/plugin/plugins/source/video_capture:std_video_capture" ]
128  sources = sources_utils
129  all_dependent_configs = [ ":utils_config" ]
130  if (current_os != "android" && current_os != "ios") {
131    defines = [ "CONFIG_HILOG" ]
132  }
133  external_deps = [ "hilog:libhilog_base" ]
134  public_deps = [ "//third_party/bounds_checking_function:libsec_static" ]
135  remove_configs = [ "//build/config/compiler:no_rtti" ]
136  cflags = [ "-frtti" ]
137  subsystem_name = "commonlibrary"
138  part_name = "c_utils"
139}
140
141ohos_shared_library("utils") {
142  innerapi_tags = [
143    "chipsetsdk",
144    "platformsdk",
145    "sasdk",
146  ]
147  if (current_os == "ios") {
148    sources = sources_utils_ios
149    configs = [ ":utils_coverage_config" ]
150    all_dependent_configs = [ ":utils_config" ]
151    public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
152    defines = [ "IOS_PLATFORM" ]
153
154    subsystem_name = "commonlibrary"
155    part_name = "c_utils"
156  } else {
157    sources = sources_utils
158    configs = [ ":utils_coverage_config" ]
159
160    if (!is_arkui_x) {
161      if (c_utils_feature_intsan) {
162        sanitize = {
163          integer_overflow = true
164        }
165      }
166    }
167
168    if (c_utils_debug_refbase) {
169      configs += [ ":debug_refbase" ]
170      if (c_utils_track_all) {
171        configs += [ ":track_all" ]
172      }
173      if (c_utils_print_track_at_once) {
174        configs += [ ":print_track_at_once" ]
175      }
176    }
177    if (c_utils_parcel_object_check) {
178      configs += [ ":parcel_object_check" ]
179    }
180    all_dependent_configs = [ ":utils_config" ]
181    if (current_os != "android" && current_os != "ios") {
182      defines = [ "CONFIG_HILOG" ]
183    }
184    if (c_utils_debug_log_enabled) {
185      configs += [ ":debug_log_enabled" ]
186    }
187    external_deps = [ "hilog:libhilog_base" ]
188    public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
189
190    subsystem_name = "commonlibrary"
191    part_name = "c_utils"
192    install_images = [
193      "system",
194      "updater",
195    ]
196  }
197}
198
199########## modules for `c_utils` in rust ##########
200# rust compiler is not supportted on mac
201if (host_os == "linux" && !is_arkui_x) {
202  import("//build/templates/rust/rust_cxx.gni")  # used for templates rust_cxx()
203  rust_cxx("cxx_rust_gen") {
204    sources = [
205      "src/rust/ashmem.rs",
206      "src/rust/directory_ex.rs",
207      "src/rust/file_ex.rs",
208    ]
209  }
210
211  ohos_static_library("utils_static_cxx_rust") {
212    sources = [
213      "src/ashmem.cpp",
214      "src/directory_ex.cpp",
215      "src/file_ex.cpp",
216      "src/refbase.cpp",
217    ]
218    sources += get_target_outputs(":cxx_rust_gen")
219    defines = [ "UTILS_CXX_RUST" ]
220    include_dirs = [
221      "include",
222      "${target_gen_dir}",
223      "//third_party/rust/crates/cxx/include",
224    ]
225    deps = [
226      ":cxx_rust_gen",
227      "//third_party/rust/crates/cxx:cxx_cppdeps",
228    ]
229    public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
230
231    subsystem_name = "commonlibrary"
232    part_name = "c_utils"
233  }
234
235  ohos_rust_shared_library("utils_rs") {
236    sources = [
237      "src/rust/ashmem.rs",
238      "src/rust/directory_ex.rs",
239      "src/rust/file_ex.rs",
240      "src/rust/lib.rs",
241    ]
242    deps = [
243      ":utils_static_cxx_rust",
244      "//third_party/rust/crates/cxx:lib",
245    ]
246
247    crate_root = "src/rust/lib.rs"
248    crate_name = "utils_rust"
249    crate_type = "dylib"
250    output_extension = "dylib.so"
251    subsystem_name = "commonlibrary"
252    part_name = "c_utils"
253    install_images = [
254      "system",
255      "updater",
256    ]
257  }
258}
259
260group("utils_rust") {
261  public_deps = []
262  if (host_os == "linux" && !is_arkui_x) {
263    public_deps += [ ":utils_rs" ]
264  }
265}
266###############################################################################
267