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 branch_protector_ret = "pac_ret" 74 sanitize = { 75 boundary_sanitize = true 76 ubsan = true 77 cfi = true 78 cfi_cross_dso = true 79 debug = false 80 } 81 cflags_cc = [ 82 "-std=c++17", 83 "-stdlib=libc++", 84 "-fvisibility=hidden", 85 ] 86 all_dependent_configs = [ ":native_preferences_public_config" ] 87 sources = base_sources 88 sources += [ 89 "${preferences_native_path}/platform/src/preferences_db_adapter.cpp", 90 "${preferences_native_path}/src/preferences_enhance_impl.cpp", 91 "${preferences_native_path}/src/preferences_value_parcel.cpp", 92 ] 93 94 innerapi_tags = [ 95 "platformsdk", 96 "sasdk", 97 ] 98 99 configs = [ ":native_preferences_config" ] 100 101 external_deps = [ 102 "ability_base:zuri", 103 "ability_runtime:dataobs_manager", 104 "access_token:libaccesstoken_sdk", 105 "bounds_checking_function:libsec_shared", 106 "c_utils:utils", 107 "hilog:libhilog", 108 "hisysevent:libhisysevent", 109 "hitrace:hitrace_meter", 110 "ipc:ipc_core", 111 "libxml2:libxml2", 112 ] 113 public_configs = [ ":native_preferences_public_config" ] 114 subsystem_name = "distributeddatamgr" 115 part_name = "preferences" 116 } 117} else if (is_mingw || is_mac) { 118 ohos_shared_library("native_preferences") { 119 all_dependent_configs = [ ":native_preferences_public_config" ] 120 sources = base_sources 121 sources += mock_sources 122 innerapi_tags = [ "platformsdk" ] 123 124 configs = [ ":native_preferences_config" ] 125 126 configs += [ ":mock_config" ] 127 configs += [ ":adaptor_config" ] 128 129 cflags_cc = [ 130 "-std=c++17", 131 "-stdlib=libc++", 132 ] 133 if (is_mac) { 134 buildos = "mac" 135 defines = [ "MAC_PLATFORM" ] 136 } else { 137 buildos = "windows" 138 defines = [ "WINDOWS_PLATFORM" ] 139 ldflags = [ "-lws2_32" ] 140 } 141 deps = [ 142 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${buildos}", 143 ] 144 external_deps = [ 145 "bounds_checking_function:libsec_shared", 146 "libxml2:static_libxml2", 147 ] 148 public_configs = [ ":native_preferences_public_config" ] 149 150 subsystem_name = "distributeddatamgr" 151 part_name = "preferences" 152 } 153} else if (is_android) { 154 ohos_source_set("native_preferences") { 155 all_dependent_configs = [ ":native_preferences_public_config" ] 156 sources = base_sources 157 sources += mock_sources 158 159 defines = [ "ANDROID_PLATFORM" ] 160 161 configs = [ ":native_preferences_config" ] 162 configs += [ ":mock_config" ] 163 cflags_cc = [ "-fvisibility=hidden" ] 164 deps = [ 165 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_android", 166 "//commonlibrary/c_utils/base:utilsbase", 167 "//third_party/bounds_checking_function:libsec_static", 168 "//third_party/libxml2:libxml2", 169 ] 170 public_configs = [ ":native_preferences_public_config" ] 171 subsystem_name = "distributeddatamgr" 172 part_name = "preferences" 173 } 174} else if (is_ios) { 175 ohos_source_set("native_preferences") { 176 all_dependent_configs = [ ":native_preferences_public_config" ] 177 sources = base_sources 178 sources += mock_sources 179 defines = [ "IOS_PLATFORM" ] 180 181 configs = [ ":native_preferences_config" ] 182 configs += [ ":mock_config" ] 183 cflags_cc = [ "-fvisibility=hidden" ] 184 deps = [ 185 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${target_os}", 186 "//commonlibrary/c_utils/base:utilsbase", 187 "//third_party/bounds_checking_function:libsec_static", 188 "//third_party/libxml2:libxml2", 189 ] 190 public_configs = [ ":native_preferences_public_config" ] 191 subsystem_name = "distributeddatamgr" 192 part_name = "preferences" 193 } 194} 195 196ohos_static_library("native_preferences_static") { 197 sources = base_sources 198 configs = [ ":native_preferences_config" ] 199 200 if (is_mingw || is_mac) { 201 configs += [ ":mock_config" ] 202 configs += [ ":adaptor_config" ] 203 204 sources += mock_sources 205 cflags_cc = [ 206 "-std=c++17", 207 "-stdlib=libc++", 208 ] 209 if (is_mac) { 210 buildos = "mac" 211 defines = [ "MAC_PLATFORM" ] 212 } else { 213 buildos = "windows" 214 defines = [ "WINDOWS_PLATFORM" ] 215 ldflags = [ "-lws2_32" ] 216 } 217 deps = [ 218 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${buildos}", 219 ] 220 external_deps = [ 221 "bounds_checking_function:libsec_shared", 222 "libxml2:static_libxml2", 223 ] 224 } else { 225 if (is_ohos) { 226 branch_protector_ret = "pac_ret" 227 sanitize = { 228 boundary_sanitize = true 229 ubsan = true 230 cfi = true 231 cfi_cross_dso = true 232 debug = false 233 } 234 sources += [ 235 "${preferences_native_path}/platform/src/preferences_db_adapter.cpp", 236 "${preferences_native_path}/src/preferences_enhance_impl.cpp", 237 "${preferences_native_path}/src/preferences_value_parcel.cpp", 238 ] 239 } 240 external_deps = [ 241 "ability_base:zuri", 242 "ability_runtime:dataobs_manager", 243 "access_token:libaccesstoken_sdk", 244 "bounds_checking_function:libsec_shared", 245 "c_utils:utils", 246 "hilog:libhilog", 247 "hisysevent:libhisysevent", 248 "hitrace:hitrace_meter", 249 "ipc:ipc_core", 250 "libxml2:libxml2", 251 ] 252 } 253 254 public_configs = [ ":native_preferences_public_config" ] 255 256 subsystem_name = "distributeddatamgr" 257 part_name = "preferences" 258} 259