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