• 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_srv.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_srv.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_srv.c" ]
40    MBEDTLS_SOURCES -= [
41      "$MBEDTLSDIR/library/ssl_srv.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    if (ohos_kernel_type == "liteos_m") {
50      defines += [
51        "__unix__",
52        "MBEDTLS_CONFIG_FILE=<../port/config/config_liteos_m.h>",
53      ]
54    }
55    if (ohos_kernel_type == "liteos_a") {
56      defines += [
57        "__unix__",
58        "MBEDTLS_CONFIG_FILE=<../port/config/config_liteos_a.h>",
59      ]
60    }
61  }
62
63  lite_library("mbedtls_shared") {
64    target_type = "shared_library"
65    public_configs = [ ":mbedtls_config" ]
66    output_name = "mbedtls"
67    sources = MBEDTLS_SOURCES
68  }
69
70  lite_library("mbedtls_static") {
71    target_type = "static_library"
72    public_configs = [ ":mbedtls_config" ]
73    output_name = "mbedtls"
74    sources = MBEDTLS_SOURCES
75  }
76
77  group("mbedtls") {
78    if (ohos_kernel_type == "liteos_m") {
79      if (ohos_security_huks_mbedtls_porting_path != "") {
80        public_deps = [ ohos_security_huks_mbedtls_porting_path ]
81      } else {
82        public_deps = [ ":mbedtls_static" ]
83      }
84    } else {
85      public_deps = [ ":mbedtls_shared" ]
86    }
87  }
88
89  ndk_lib("mbedtls_ndk") {
90    if (ohos_kernel_type == "liteos_m") {
91      lib_extension = ".a"
92    } else {
93      lib_extension = ".so"
94    }
95    deps = [ ":mbedtls" ]
96    head_files = [ "include" ]
97  }
98
99  # for test: test profile
100  if (ohos_build_type == "debug" && ohos_kernel_type != "liteos_m") {
101    config("mbedtls_profile_test") {
102      include_dirs = [
103        "./include",
104        "./configs",  # The directory where the custom configuration file is
105                      # located
106      ]
107      defines = [
108        "MBEDTLS_CONFIG_FILE=<config_rsa_aes_cbc.h>",
109        "__unix__",
110      ]
111      ldflags = [
112        "-s",
113        "-w",
114      ]
115    }
116
117    static_library("mbedtls_gt") {
118      sources = MBEDTLS_SOURCES
119      output_name = "mbedtls_gt"
120      public_configs = [ ":mbedtls_profile_test" ]
121    }
122  }
123} else {
124  import("//build/ohos.gni")
125  config("mbedtls_config") {
126    include_dirs = MBEDTLS_INLCUDE_DIRS
127  }
128
129  ohos_shared_library("mbedtls_shared") {
130    public_configs = [ ":mbedtls_config" ]
131    output_name = "mbedtls"
132    subsystem_name = "thirdparty"
133    innerapi_tags = [
134      "platformsdk_indirect",
135      "sasdk",
136    ]
137    part_name = "mbedtls"
138    sources = MBEDTLS_SOURCES
139    install_images = [
140      "system",
141      "updater",
142    ]
143  }
144
145  group("mbedtls") {
146    public_deps = [ ":mbedtls_shared" ]
147  }
148}
149