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_file_lock.cpp", 47 "${preferences_native_path}/platform/src/preferences_thread.cpp", 48 "${preferences_native_path}/src/base64_helper.cpp", 49 "${preferences_native_path}/src/preferences_helper.cpp", 50 "${preferences_native_path}/src/preferences_impl.cpp", 51 "${preferences_native_path}/src/preferences_observer.cpp", 52 "${preferences_native_path}/src/preferences_value.cpp", 53 "${preferences_native_path}/src/preferences_xml_utils.cpp", 54] 55 56if (!is_ohos) { 57 mock_sources = [ 58 "${preferences_native_path}/mock/ability_base/zuri/src/uri.cpp", 59 "${preferences_native_path}/mock/ability_runtime/dataobs_manager/src/data_ability_observer_stub.cpp", 60 "${preferences_native_path}/mock/ability_runtime/dataobs_manager/src/dataobs_mgr_client.cpp", 61 ] 62 if (!is_android) { 63 mock_sources += 64 [ "${preferences_native_path}/mock/c_utils/utils/base/src/refbase.cpp" ] 65 } 66} 67 68if (is_ohos) { 69 ohos_shared_library("native_preferences") { 70 branch_protector_ret = "pac_ret" 71 sanitize = { 72 cfi = true 73 cfi_cross_dso = true 74 debug = false 75 } 76 all_dependent_configs = [ ":native_preferences_public_config" ] 77 sources = base_sources 78 79 innerapi_tags = [ 80 "platformsdk", 81 "sasdk", 82 ] 83 84 configs = [ ":native_preferences_config" ] 85 86 cflags_cc = [ "-fvisibility=hidden" ] 87 deps = [ "//third_party/libxml2:libxml2" ] 88 external_deps = [ 89 "ability_base:zuri", 90 "ability_runtime:dataobs_manager", 91 "c_utils:utils", 92 "hilog:libhilog", 93 "hitrace:hitrace_meter", 94 "ipc:ipc_core", 95 ] 96 public_configs = [ ":native_preferences_public_config" ] 97 subsystem_name = "distributeddatamgr" 98 part_name = "preferences" 99 } 100} else if (is_mingw || is_mac) { 101 ohos_shared_library("native_preferences") { 102 all_dependent_configs = [ ":native_preferences_public_config" ] 103 sources = base_sources 104 sources += mock_sources 105 innerapi_tags = [ "platformsdk" ] 106 107 configs = [ ":native_preferences_config" ] 108 109 configs += [ ":mock_config" ] 110 configs += [ ":adaptor_config" ] 111 112 cflags_cc = [ 113 "-std=c++17", 114 "-stdlib=libc++", 115 ] 116 if (is_mac) { 117 buildos = "mac" 118 defines = [ "MAC_PLATFORM" ] 119 } else { 120 buildos = "windows" 121 defines = [ "WINDOWS_PLATFORM" ] 122 ldflags = [ "-lws2_32" ] 123 } 124 deps = [ 125 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${buildos}", 126 "//third_party/libxml2:static_libxml2", 127 ] 128 public_configs = [ ":native_preferences_public_config" ] 129 130 subsystem_name = "distributeddatamgr" 131 part_name = "preferences" 132 } 133} else if (is_android) { 134 ohos_source_set("native_preferences") { 135 all_dependent_configs = [ ":native_preferences_public_config" ] 136 sources = base_sources 137 sources += mock_sources 138 139 defines = [ "ANDROID_PLATFORM" ] 140 141 configs = [ ":native_preferences_config" ] 142 configs += [ ":mock_config" ] 143 cflags_cc = [ "-fvisibility=hidden" ] 144 deps = [ 145 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_android", 146 "//commonlibrary/c_utils/base:utilsbase", 147 "//third_party/libxml2:libxml2", 148 ] 149 public_configs = [ ":native_preferences_public_config" ] 150 subsystem_name = "distributeddatamgr" 151 part_name = "preferences" 152 } 153} else if (is_ios) { 154 ohos_source_set("native_preferences") { 155 all_dependent_configs = [ ":native_preferences_public_config" ] 156 sources = base_sources 157 sources += mock_sources 158 defines = [ "IOS_PLATFORM" ] 159 160 configs = [ ":native_preferences_config" ] 161 configs += [ ":mock_config" ] 162 cflags_cc = [ "-fvisibility=hidden" ] 163 deps = [ 164 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${target_os}", 165 "//commonlibrary/c_utils/base:utilsbase", 166 "//third_party/libxml2:static_libxml2", 167 ] 168 public_configs = [ ":native_preferences_public_config" ] 169 subsystem_name = "distributeddatamgr" 170 part_name = "preferences" 171 } 172} 173 174ohos_static_library("native_preferences_static") { 175 all_dependent_configs = [ ":native_preferences_public_config" ] 176 sources = base_sources 177 configs = [ ":native_preferences_config" ] 178 179 if (is_mingw || is_mac) { 180 configs += [ ":mock_config" ] 181 configs += [ ":adaptor_config" ] 182 183 sources += mock_sources 184 cflags_cc = [ 185 "-std=c++17", 186 "-stdlib=libc++", 187 ] 188 if (is_mac) { 189 buildos = "mac" 190 defines = [ "MAC_PLATFORM" ] 191 } else { 192 buildos = "windows" 193 defines = [ "WINDOWS_PLATFORM" ] 194 ldflags = [ "-lws2_32" ] 195 } 196 deps = [ 197 "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${buildos}", 198 "//third_party/libxml2:static_libxml2", 199 ] 200 } else { 201 if (is_ohos) { 202 branch_protector_ret = "pac_ret" 203 sanitize = { 204 cfi = true 205 cfi_cross_dso = true 206 debug = false 207 } 208 } 209 deps = [ "//third_party/libxml2:libxml2" ] 210 external_deps = [ 211 "ability_base:zuri", 212 "ability_runtime:dataobs_manager", 213 "c_utils:utils", 214 "hilog:libhilog", 215 "hitrace:hitrace_meter", 216 "ipc:ipc_core", 217 ] 218 } 219 220 public_configs = [ ":native_preferences_public_config" ] 221 222 subsystem_name = "distributeddatamgr" 223 part_name = "preferences" 224} 225