1# Copyright (C) 2021-2024 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.
13
14import("//base/security/device_auth/deps_adapter/deviceauth_hals.gni")
15import("//build/ohos.gni")
16import("deviceauth.gni")
17
18config("deviceauth_config") {
19  include_dirs = [ "//base/security/device_auth/interfaces/inner_api" ]
20}
21include_dirs = inc_path + hals_inc_path
22if (os_level == "mini" || os_level == "small") {
23  static_library("deviceauth") {
24    public_configs = [ ":deviceauth_config" ]
25    include_dirs += [
26      "//third_party/cJSON",
27      "//commonlibrary/utils_lite/include",
28      "//third_party/bounds_checking_function/include",
29      "//foundation/communication/dsoftbus/interfaces/kits/common",
30      "//foundation/communication/dsoftbus/interfaces/kits/transport",
31      "//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
32      "${dev_frameworks_path}/inc/hiview_adapter",
33    ]
34    sources = deviceauth_files
35    defines = [ "HILOG_ENABLE" ]
36    defines += deviceauth_defines
37
38    sources += identity_manager_files
39    include_dirs += identity_manager_inc
40
41    deps = [
42      "${deps_adapter_path}:${hal_module_name}",
43      "//build/lite/config/component/cJSON:cjson_shared",
44      "//commonlibrary/utils_lite:utils",
45    ]
46    if (device_auth_enable_soft_bus_channel) {
47      deps += [ "//foundation/communication/dsoftbus/sdk:softbus_client" ]
48    }
49    if (enable_extend_plugin) {
50      defines += [ "DEV_AUTH_PLUGIN_ENABLE" ]
51      if (os_level == "mini") {
52        sources += [
53          "${dev_frameworks_path}/src/plugin_adapter/static_plugin_adapter.c",
54        ]
55      } else {
56        sources += [
57          "${dev_frameworks_path}/src/plugin_adapter/dynamic_plugin_adapter.c",
58          "${dev_frameworks_path}/src/plugin_adapter/ext_part/account_lifecycle_plugin_proxy.c",
59          "${dev_frameworks_path}/src/plugin_adapter/ext_part/ext_part_proxy.c",
60        ]
61      }
62    }
63    if (board_toolchain_type == "iccarm" && os_level == "mini") {
64      cflags = [
65        "--diag_suppress",
66        "Pe546,Pe223,Pe111,Pe188",
67      ]
68    } else {
69      cflags = build_flags
70    }
71    cflags += [
72      "-DDEV_AUTH_WORK_THREAD_STACK_SIZE=${device_auth_hichain_thread_stack_size}",
73      "-DMAX_AUTH_SESSION_COUNT=${max_auth_session_count}",
74    ]
75    if (ohos_kernel_type == "linux" || ohos_kernel_type == "liteos_a") {
76      include_dirs +=
77          [ "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog" ]
78      deps += [
79        "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
80        "//third_party/bounds_checking_function:libsec_shared",
81      ]
82    } else {
83      include_dirs +=
84          [ "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite" ]
85      deps += [ "//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite" ]
86    }
87  }
88
89  if (os_level == "mini") {
90    group("deviceauth_sdk") {
91    }
92    group("deviceauth_service") {
93    }
94  }
95
96  if (ohos_kernel_type == "linux" || ohos_kernel_type == "liteos_a") {
97    executable("deviceauth_service") {
98      include_dirs += [
99        "//third_party/cJSON",
100        "//commonlibrary/utils_lite/include",
101        "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
102        "//third_party/bounds_checking_function/include",
103        "${frameworks_path}/inc/lite",
104        "//foundation/systemabilitymgr/samgr_lite/interfaces/kits/samgr",
105        "${dev_frameworks_path}/inc/hiview_adapter",
106      ]
107
108      sources = deviceauth_ipc_files
109      sources += [
110        "${frameworks_path}/src/ipc_service.c",
111        "${frameworks_path}/src/lite/ipc_service_init.c",
112      ]
113
114      defines = [ "HILOG_ENABLE" ]
115      if (ohos_kernel_type == "linux") {
116        defines += [ "__LINUX__" ]
117      }
118      ldflags = [ "-pthread" ]
119
120      deps = [
121        ":deviceauth",
122        "${deps_adapter_path}:${hal_module_name}",
123        "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
124        "//build/lite/config/component/cJSON:cjson_shared",
125        "//commonlibrary/utils_lite:utils",
126        "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single",
127        "//foundation/systemabilitymgr/samgr_lite/samgr:samgr",
128        "//third_party/bounds_checking_function:libsec_shared",
129      ]
130    }
131
132    shared_library("deviceauth_sdk") {
133      public_configs = [ ":deviceauth_config" ]
134      include_dirs += [
135        "//third_party/cJSON",
136        "//commonlibrary/utils_lite/include",
137        "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
138        "//third_party/bounds_checking_function/include",
139        "${frameworks_path}/inc/lite",
140        "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include",
141        "//foundation/systemabilitymgr/samgr_lite/interfaces/kits/samgr",
142        "${dev_frameworks_path}/inc/hiview_adapter",
143      ]
144
145      sources = deviceauth_ipc_files
146      sources += [ "${frameworks_path}/src/ipc_sdk.c" ]
147
148      defines = [ "HILOG_ENABLE" ]
149      if (ohos_kernel_type == "linux") {
150        defines += [ "__LINUX__" ]
151      }
152      cflags = build_flags
153      cflags += [ "-fPIC" ]
154
155      deps = [
156        "${deps_adapter_path}:${hal_module_name}",
157        "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
158        "//commonlibrary/utils_lite:utils",
159        "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single",
160        "//foundation/systemabilitymgr/samgr_lite/samgr:samgr",
161        "//third_party/bounds_checking_function:libsec_shared",
162      ]
163    }
164  }
165} else {
166  ohos_static_library("deviceauth") {
167    subsystem_name = "security"
168    part_name = "device_auth"
169    include_dirs += [
170      "${frameworks_path}/inc/standard",
171      "${dev_frameworks_path}/inc/hiview_adapter",
172    ]
173
174    if (support_os_account) {
175      include_dirs += [ "${dev_frameworks_path}/inc/account_subscriber" ]
176      include_dirs += [ "${dev_frameworks_path}/inc/sa_subscriber" ]
177    }
178
179    sources = deviceauth_files
180    if (support_os_account) {
181      sources += account_subscriber_files
182      sources += sa_subscriber_files
183    }
184    sources += hiview_adapter_files
185    defines = deviceauth_defines
186    defines += [ "HILOG_ENABLE" ]
187    defines += [ "DEV_AUTH_HIVIEW_ENABLE" ]
188    cflags = build_flags
189    cflags += [
190      "-DDEV_AUTH_WORK_THREAD_STACK_SIZE=${device_auth_hichain_thread_stack_size}",
191      "-DMAX_AUTH_SESSION_COUNT=${max_auth_session_count}",
192    ]
193    if (target_cpu == "arm") {
194      cflags += [ "-DBINDER_IPC_32BIT" ]
195    }
196    if (enable_extend_plugin) {
197      defines += [ "DEV_AUTH_PLUGIN_ENABLE" ]
198      sources += [
199        "${dev_frameworks_path}/src/plugin_adapter/dynamic_plugin_adapter.c",
200        "${dev_frameworks_path}/src/plugin_adapter/ext_part/account_lifecycle_plugin_proxy.c",
201        "${dev_frameworks_path}/src/plugin_adapter/ext_part/ext_part_proxy.c",
202      ]
203    }
204
205    sources += identity_manager_files
206    include_dirs += identity_manager_inc
207
208    branch_protector_ret = "pac_ret"
209    sanitize = {
210      cfi = true
211      cfi_cross_dso = true
212      integer_overflow = true
213      boundary_sanitize = true
214      ubsan = true
215      debug = false
216    }
217
218    deps = [ "${deps_adapter_path}:${hal_module_name}" ]
219
220    external_deps = [
221      "bounds_checking_function:libsec_shared",
222      "cJSON:cjson",
223      "c_utils:utils",
224      "dsoftbus:softbus_client",
225      "hilog:libhilog",
226      "hisysevent:libhisysevent",
227      "hitrace:hitrace_meter",
228    ]
229    if (support_os_account) {
230      external_deps += [
231        "ability_base:want",
232        "common_event_service:cesfwk_innerkits",
233        "ipc:ipc_single",
234        "os_account:os_account_innerkits",
235        "samgr:samgr_proxy",
236      ]
237    }
238  }
239
240  ohos_prebuilt_etc("auth_service.rc") {
241    source = "${frameworks_path}/src/standard/deviceauth_service.cfg"
242    relative_install_dir = "init"
243    subsystem_name = "security"
244    part_name = "device_auth"
245  }
246
247  group("etc") {
248    deps = [ ":auth_service.rc" ]
249  }
250
251  ohos_executable("deviceauth_service") {
252    subsystem_name = "security"
253    part_name = "device_auth"
254    install_enable = true
255
256    include_dirs += [
257      "${frameworks_path}/inc/standard",
258      "${dev_frameworks_path}/inc/permission_adapter",
259      "${dev_frameworks_path}/inc/hiview_adapter",
260    ]
261
262    sources = deviceauth_ipc_files
263    sources += permission_adapter_files
264    sources += [ "${frameworks_path}/src/ipc_service.c" ]
265
266    defines = [ "HILOG_ENABLE" ]
267    defines += [ "DEV_AUTH_HIVIEW_ENABLE" ]
268    defines += [ "DEV_AUTH_SERVICE_BUILD" ]
269    cflags = build_flags
270    if (target_cpu == "arm") {
271      cflags += [ "-DBINDER_IPC_32BIT" ]
272    }
273
274    branch_protector_ret = "pac_ret"
275    sanitize = {
276      cfi = true
277      cfi_cross_dso = true
278      integer_overflow = true
279      boundary_sanitize = true
280      ubsan = true
281      debug = false
282    }
283
284    deps = [
285      ":auth_service.rc",
286      ":deviceauth",
287      "${deps_adapter_path}:${hal_module_name}",
288    ]
289
290    external_deps = [
291      "access_token:libaccesstoken_sdk",
292      "bounds_checking_function:libsec_shared",
293      "cJSON:cjson",
294      "c_utils:utils",
295      "hilog:libhilog",
296      "init:libbegetutil",
297      "ipc:ipc_single",
298      "samgr:samgr_proxy",
299    ]
300  }
301
302  ohos_shared_library("deviceauth_sdk") {
303    subsystem_name = "security"
304    part_name = "device_auth"
305    innerapi_tags = [ "platformsdk" ]
306    version_script = "device_auth.map"
307    public_configs = [ ":deviceauth_config" ]
308
309    include_dirs += [
310      "${frameworks_path}/inc/standard",
311      "${dev_frameworks_path}/inc/permission_adapter",
312      "${dev_frameworks_path}/inc/hiview_adapter",
313    ]
314
315    sources = deviceauth_ipc_files
316    sources += permission_adapter_files
317    sources += [ "${frameworks_path}/src/ipc_sdk.c" ]
318
319    defines = [
320      "__LINUX__",
321      "HILOG_ENABLE",
322    ]
323    cflags = build_flags
324    cflags += [ "-fPIC" ]
325    if (target_cpu == "arm") {
326      cflags += [ "-DBINDER_IPC_32BIT" ]
327    }
328
329    branch_protector_ret = "pac_ret"
330    sanitize = {
331      cfi = true
332      cfi_cross_dso = true
333      integer_overflow = true
334      boundary_sanitize = true
335      ubsan = true
336      debug = false
337    }
338
339    deps = [ "${deps_adapter_path}:${hal_module_name}" ]
340
341    external_deps = [
342      "access_token:libaccesstoken_sdk",
343      "bounds_checking_function:libsec_shared",
344      "cJSON:cjson",
345      "c_utils:utils",
346      "hilog:libhilog",
347      "hisysevent:libhisysevent",
348      "hitrace:hitrace_meter",
349      "init:libbegetutil",
350      "ipc:ipc_single",
351      "samgr:samgr_proxy",
352    ]
353  }
354}
355