• 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    target_type = "static_library"
73    public_configs = [ ":mbedtls_config" ]
74    output_name = "mbedtls"
75    sources = MBEDTLS_SOURCES
76  }
77
78  group("mbedtls") {
79    if (ohos_kernel_type == "liteos_m") {
80      if (ohos_security_huks_mbedtls_porting_path != "") {
81        public_deps = [ ohos_security_huks_mbedtls_porting_path ]
82      } else {
83        public_deps = [ ":mbedtls_static" ]
84      }
85    } else {
86      public_deps = [ ":mbedtls_shared" ]
87    }
88  }
89
90  ndk_lib("mbedtls_ndk") {
91    if (ohos_kernel_type == "liteos_m") {
92      lib_extension = ".a"
93    } else {
94      lib_extension = ".so"
95    }
96    deps = [ ":mbedtls" ]
97    head_files = [ "include" ]
98  }
99
100  # for test: test profile
101  if (ohos_build_type == "debug" && ohos_kernel_type != "liteos_m") {
102    config("mbedtls_profile_test") {
103      include_dirs = [
104        "./include",
105        "./configs",  # The directory where the custom configuration file is
106                      # located
107      ]
108      defines = [
109        "MBEDTLS_CONFIG_FILE=<config_rsa_aes_cbc.h>",
110        "__unix__",
111      ]
112      ldflags = [
113        "-s",
114        "-w",
115      ]
116    }
117
118    static_library("mbedtls_gt") {
119      sources = MBEDTLS_SOURCES
120      output_name = "mbedtls_gt"
121      public_configs = [ ":mbedtls_profile_test" ]
122    }
123  }
124} else {
125  import("//build/ohos.gni")
126  config("mbedtls_config") {
127    include_dirs = MBEDTLS_INLCUDE_DIRS
128  }
129
130  ohos_shared_library("mbedtls_shared") {
131    public_configs = [ ":mbedtls_config" ]
132    output_name = "mbedtls"
133    subsystem_name = "thirdparty"
134    innerapi_tags = [
135      "platformsdk_indirect",
136      "sasdk",
137    ]
138    external_deps = [ "bounds_checking_function:libsec_static" ]
139    part_name = "mbedtls"
140    sources = MBEDTLS_SOURCES
141    install_images = [
142      "system",
143      "updater",
144    ]
145  }
146
147  ohos_static_library("mbedtls_static") {
148    sources = MBEDTLS_SOURCES
149    public_configs = [ ":mbedtls_config" ]
150    external_deps = [ "bounds_checking_function:libsec_static" ]
151    part_name = "mbedtls"
152    subsystem_name = "thirdparty"
153  }
154
155  group("mbedtls") {
156    public_deps = [ ":mbedtls_shared" ]
157  }
158}
159