• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (c) 2020-2023 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16import("//third_party/mbedtls/mbedtls.gni")
17
18MBEDTLS_SOURCES += [
19  "library/debug.c",
20  "library/ssl_cache.c",
21  "library/ssl_cookie.c",
22  "library/ssl_tls12_server.c",
23  "library/ssl_ticket.c",
24  "library/x509_create.c",
25  "library/x509_csr.c",
26  "library/x509write_crt.c",
27  "library/x509write_csr.c",
28]
29
30if (defined(ohos_lite)) {
31  MBEDTLS_SOURCES -= [ "library/ssl_tls12_server.c" ]
32}
33
34if (defined(ohos_lite)) {
35  import("//build/lite/config/component/lite_component.gni")
36  import("//build/lite/ndk/ndk.gni")
37
38  if (ohos_kernel_type != "liteos_m") {
39    MBEDTLS_SOURCES += [ "library/ssl_tls12_server.c" ]
40    MBEDTLS_SOURCES -= [
41      "$MBEDTLSDIR/library/ssl_tls12_server.c",
42      "$MBEDTLSDIR/port/src/tls_client.c",
43      "$MBEDTLSDIR/port/src/tls_certificate.c",
44    ]
45  }
46
47  config("mbedtls_config") {
48    include_dirs = MBEDTLS_INLCUDE_DIRS
49    include_dirs += [ "//third_party/bounds_checking_function/include" ]
50    if (ohos_kernel_type == "liteos_m") {
51      defines += [
52        "__unix__",
53        "MBEDTLS_CONFIG_FILE=<../port/config/config_liteos_m.h>",
54      ]
55    }
56    if (ohos_kernel_type == "liteos_a") {
57      defines += [
58        "__unix__",
59        "MBEDTLS_CONFIG_FILE=<../port/config/config_liteos_a.h>",
60      ]
61    }
62  }
63
64  lite_library("mbedtls_shared") {
65    target_type = "shared_library"
66    public_configs = [ ":mbedtls_config" ]
67    output_name = "mbedtls"
68    sources = MBEDTLS_SOURCES
69  }
70
71  lite_library("mbedtls_static") {
72    if (board_toolchain_type == "clang") {
73      cflags = [
74        "-Wno-error=parentheses-equality",
75        "-Wno-error=implicit-function-declaration",
76      ]
77    }
78    target_type = "static_library"
79    public_configs = [ ":mbedtls_config" ]
80    output_name = "mbedtls"
81    sources = MBEDTLS_SOURCES
82  }
83
84  group("mbedtls") {
85    if (ohos_kernel_type == "liteos_m") {
86      if (mbedtls_porting_path != "") {
87        public_deps = [ mbedtls_porting_path ]
88      } else {
89        public_deps = [ ":mbedtls_static" ]
90      }
91    } else {
92      public_deps = [ ":mbedtls_shared" ]
93    }
94  }
95
96  ndk_lib("mbedtls_ndk") {
97    if (ohos_kernel_type == "liteos_m") {
98      lib_extension = ".a"
99    } else {
100      lib_extension = ".so"
101    }
102    deps = [ ":mbedtls" ]
103    head_files = [ "include" ]
104  }
105
106  # for test: test profile
107  if (ohos_build_type == "debug" && ohos_kernel_type != "liteos_m") {
108    config("mbedtls_profile_test") {
109      include_dirs = [
110        "./include",
111        "./configs",  # The directory where the custom configuration file is
112                      # located
113      ]
114      defines = [
115        "MBEDTLS_CONFIG_FILE=<config_rsa_aes_cbc.h>",
116        "__unix__",
117      ]
118      ldflags = [
119        "-s",
120        "-w",
121      ]
122    }
123
124    static_library("mbedtls_gt") {
125      sources = MBEDTLS_SOURCES
126      output_name = "mbedtls_gt"
127      public_configs = [ ":mbedtls_profile_test" ]
128    }
129  }
130} else {
131  import("//build/ohos.gni")
132  config("mbedtls_config") {
133    include_dirs = MBEDTLS_INLCUDE_DIRS
134  }
135
136  ohos_shared_library("mbedtls_shared") {
137    if (mbedtls_enable_ssl_srv == true) {
138      defines = [
139        "MBEDTLS_KEY_EXCHANGE_PSK_ENABLED",
140        "MBEDTLS_SSL_SRV_C",
141      ]
142    }
143
144    branch_protector_ret = "pac_ret"
145    public_configs = [ ":mbedtls_config" ]
146    output_name = "mbedtls"
147    subsystem_name = "thirdparty"
148    version_script = "libmbedtls.map"
149    innerapi_tags = [
150      "chipsetsdk",
151      "platformsdk_indirect",
152      "sasdk",
153    ]
154    external_deps = [ "bounds_checking_function:libsec_static" ]
155    part_name = "mbedtls"
156    sources = MBEDTLS_SOURCES
157    install_images = [
158      "system",
159      "updater",
160    ]
161  }
162
163  ohos_static_library("mbedtls_static") {
164    sources = MBEDTLS_SOURCES
165    public_configs = [ ":mbedtls_config" ]
166    external_deps = [ "bounds_checking_function:libsec_static" ]
167    part_name = "mbedtls"
168    subsystem_name = "thirdparty"
169  }
170
171  group("mbedtls") {
172    public_deps = [ ":mbedtls_shared" ]
173  }
174}
175