1# Copyright (c) 2023 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") 14import("//foundation/distributeddatamgr/preferences/preferences.gni") 15config("native_preferences_config") { 16 visibility = [ ":*" ] 17 include_dirs = [ 18 "include", 19 "${preferences_base_path}/frameworks/common/include", 20 "${preferences_native_path}/include", 21 "${preferences_native_path}/platform/include/", 22 ] 23} 24 25config("mock_config") { 26 include_dirs = [ 27 "${preferences_native_path}/mock/ability_runtime/dataobs_manager/include", 28 "${preferences_native_path}/mock/ability_base/zuri/include", 29 ] 30 if (!is_android) { 31 include_dirs += 32 [ "${preferences_native_path}/mock/c_utils/utils/base/include" ] 33 } 34} 35 36config("native_preferences_public_config") { 37 visibility = [ ":*" ] 38 include_dirs = [ "include" ] 39} 40 41config("adaptor_config") { 42 include_dirs = [ "//commonlibrary/c_utils/base/include" ] 43} 44 45base_sources = [ 46 "${preferences_native_path}/platform/src/preferences_dfx_adapter.cpp", 47 "${preferences_native_path}/platform/src/preferences_file_lock.cpp", 48 "${preferences_native_path}/platform/src/preferences_thread.cpp", 49 "${preferences_native_path}/src/base64_helper.cpp", 50 "${preferences_native_path}/src/preferences_base.cpp", 51 "${preferences_native_path}/src/preferences_helper.cpp", 52 "${preferences_native_path}/src/preferences_impl.cpp", 53 "${preferences_native_path}/src/preferences_observer.cpp", 54 "${preferences_native_path}/src/preferences_utils.cpp", 55 "${preferences_native_path}/src/preferences_value.cpp", 56 "${preferences_native_path}/src/preferences_xml_utils.cpp", 57] 58 59if (!is_ohos) { 60 mock_sources = [ 61 "${preferences_native_path}/mock/ability_base/zuri/src/uri.cpp", 62 "${preferences_native_path}/mock/ability_runtime/dataobs_manager/src/data_ability_observer_stub.cpp", 63 "${preferences_native_path}/mock/ability_runtime/dataobs_manager/src/dataobs_mgr_client.cpp", 64 ] 65 if (!is_android) { 66 mock_sources += 67 [ "${preferences_native_path}/mock/c_utils/utils/base/src/refbase.cpp" ] 68 } 69} 70 71if (is_ohos) { 72 ohos_shared_library("native_preferences") { 73 defines = [] 74 if (!defined(global_parts_info) || 75 defined(global_parts_info.distributeddatamgr_arkdata_database_core)) { 76 defines += [ "ARKDATA_DATABASE_CORE_ENABLE" ] 77 } 78 branch_protector_ret = "pac_ret" 79 sanitize = { 80 boundary_sanitize = true 81 ubsan = true 82 cfi = true 83 cfi_cross_dso = true 84 debug = false 85 } 86 cflags_cc = [ 87 "-std=c++17", 88 "-stdlib=libc++", 89 "-fvisibility=hidden", 90 ] 91 sources = base_sources 92 sources += [ 93 "${preferences_native_path}/platform/src/preferences_db_adapter.cpp", 94 "${preferences_native_path}/src/preferences_enhance_impl.cpp", 95 "${preferences_native_path}/src/preferences_value_parcel.cpp", 96 ] 97 98 innerapi_tags = [ 99 "platformsdk", 100 "sasdk", 101 ] 102 103 configs = [ ":native_preferences_config" ] 104 105 external_deps = [ 106 "ability_base:zuri", 107 "ability_runtime:dataobs_manager", 108 "access_token:libaccesstoken_sdk", 109 "bounds_checking_function:libsec_shared", 110 "c_utils:utils", 111 "hilog:libhilog", 112 "hisysevent:libhisysevent", 113 "hitrace:hitrace_meter", 114 "ipc:ipc_single", 115 "libxml2:libxml2", 116 ] 117 public_configs = [ ":native_preferences_public_config" ] 118 subsystem_name = "distributeddatamgr" 119 part_name = "preferences" 120 } 121} else if (is_mingw || is_mac) { 122 ohos_shared_library("native_preferences") { 123 sources = base_sources 124 sources += mock_sources 125 innerapi_tags = [ "platformsdk" ] 126 127 configs = [ ":native_preferences_config" ] 128 129 configs += [ ":mock_config" ] 130 configs += [ ":adaptor_config" ] 131 132 cflags_cc = [ 133 "-std=c++17", 134 "-stdlib=libc++", 135 ] 136 if (is_mac) { 137 buildos = "mac" 138 defines = [ 139 "MAC_PLATFORM", 140 "CROSS_PLATFORM", 141 ] 142 } else { 143 buildos = "windows" 144 defines = [ 145 "WINDOWS_PLATFORM", 146 "CROSS_PLATFORM", 147 ] 148 ldflags = [ "-lws2_32" ] 149 } 150 deps = [ 151 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${buildos}", 152 ] 153 external_deps = [ 154 "bounds_checking_function:libsec_shared", 155 "libxml2:static_libxml2", 156 ] 157 public_configs = [ ":native_preferences_public_config" ] 158 159 subsystem_name = "distributeddatamgr" 160 part_name = "preferences" 161 } 162} else if (is_android) { 163 ohos_source_set("native_preferences") { 164 sources = base_sources 165 sources += mock_sources 166 167 defines = [ 168 "ANDROID_PLATFORM", 169 "CROSS_PLATFORM", 170 ] 171 172 configs = [ ":native_preferences_config" ] 173 configs += [ ":mock_config" ] 174 cflags_cc = [ "-fvisibility=hidden" ] 175 deps = [ 176 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_android", 177 "//commonlibrary/c_utils/base:utilsbase", 178 "//third_party/bounds_checking_function:libsec_static", 179 "//third_party/libxml2:libxml2", 180 ] 181 public_configs = [ ":native_preferences_public_config" ] 182 subsystem_name = "distributeddatamgr" 183 part_name = "preferences" 184 } 185} else if (is_ios) { 186 ohos_source_set("native_preferences") { 187 sources = base_sources 188 sources += mock_sources 189 defines = [ 190 "IOS_PLATFORM", 191 "CROSS_PLATFORM", 192 ] 193 194 configs = [ ":native_preferences_config" ] 195 configs += [ ":mock_config" ] 196 cflags_cc = [ "-fvisibility=hidden" ] 197 deps = [ 198 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${target_os}", 199 "//commonlibrary/c_utils/base:utilsbase", 200 "//third_party/bounds_checking_function:libsec_static", 201 "//third_party/libxml2:libxml2", 202 ] 203 public_configs = [ ":native_preferences_public_config" ] 204 subsystem_name = "distributeddatamgr" 205 part_name = "preferences" 206 } 207} 208 209ohos_static_library("native_preferences_static") { 210 sources = base_sources 211 configs = [ ":native_preferences_config" ] 212 213 if (is_mingw || is_mac) { 214 configs += [ ":mock_config" ] 215 configs += [ ":adaptor_config" ] 216 217 sources += mock_sources 218 cflags_cc = [ 219 "-std=c++17", 220 "-stdlib=libc++", 221 ] 222 if (is_mac) { 223 buildos = "mac" 224 defines = [ 225 "MAC_PLATFORM", 226 "CROSS_PLATFORM", 227 ] 228 } else { 229 buildos = "windows" 230 defines = [ 231 "WINDOWS_PLATFORM", 232 "CROSS_PLATFORM", 233 ] 234 ldflags = [ "-lws2_32" ] 235 } 236 deps = [ 237 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${buildos}", 238 ] 239 external_deps = [ 240 "bounds_checking_function:libsec_shared", 241 "libxml2:static_libxml2", 242 ] 243 } else { 244 if (is_ohos) { 245 defines = [] 246 if (!defined(global_parts_info) || 247 defined(global_parts_info.distributeddatamgr_arkdata_database_core)) { 248 defines += [ "ARKDATA_DATABASE_CORE_ENABLE" ] 249 } 250 branch_protector_ret = "pac_ret" 251 sanitize = { 252 boundary_sanitize = true 253 ubsan = true 254 cfi = true 255 cfi_cross_dso = true 256 debug = false 257 } 258 sources += [ 259 "${preferences_native_path}/platform/src/preferences_db_adapter.cpp", 260 "${preferences_native_path}/src/preferences_enhance_impl.cpp", 261 "${preferences_native_path}/src/preferences_value_parcel.cpp", 262 ] 263 } 264 external_deps = [ 265 "ability_base:zuri", 266 "ability_runtime:dataobs_manager", 267 "access_token:libaccesstoken_sdk", 268 "bounds_checking_function:libsec_shared", 269 "c_utils:utils", 270 "hilog:libhilog", 271 "hisysevent:libhisysevent", 272 "hitrace:hitrace_meter", 273 "ipc:ipc_single", 274 "libxml2:libxml2", 275 ] 276 } 277 278 public_configs = [ ":native_preferences_public_config" ] 279 280 subsystem_name = "distributeddatamgr" 281 part_name = "preferences" 282} 283