| Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 1 | option(USE_STATIC_MBEDTLS_LIBRARY "Build Mbed TLS static library." ON) | 
|  | 2 | option(USE_SHARED_MBEDTLS_LIBRARY "Build Mbed TLS shared library." OFF) | 
|  | 3 | option(LINK_WITH_PTHREAD "Explicitly link Mbed TLS library to pthread." OFF) | 
|  | 4 | option(LINK_WITH_TRUSTED_STORAGE "Explicitly link Mbed TLS library to trusted_storage." OFF) | 
| Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 5 |  | 
| Ashley Duncan | d85a7e9 | 2019-04-29 20:35:06 +1200 | [diff] [blame] | 6 | # Set the project root directory if it's not already defined, as may happen if | 
|  | 7 | # the library folder is included directly by a parent project, without | 
|  | 8 | # including the top level CMakeLists.txt. | 
|  | 9 | if(NOT DEFINED MBEDTLS_DIR) | 
|  | 10 | set(MBEDTLS_DIR ${CMAKE_SOURCE_DIR}) | 
|  | 11 | endif() | 
| Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 12 |  | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 13 | set(src_crypto | 
|  | 14 | aes.c | 
|  | 15 | aesni.c | 
| Jerry Yu | 4923131 | 2023-01-10 16:57:21 +0800 | [diff] [blame] | 16 | aesce.c | 
| Markku-Juhani O. Saarinen | 3c0b53b | 2017-11-30 16:00:34 +0000 | [diff] [blame] | 17 | aria.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 18 | asn1parse.c | 
|  | 19 | asn1write.c | 
|  | 20 | base64.c | 
|  | 21 | bignum.c | 
| Janos Follath | 3ca0775 | 2022-08-09 11:45:47 +0100 | [diff] [blame] | 22 | bignum_core.c | 
| Janos Follath | d1baedb | 2022-08-09 13:44:53 +0100 | [diff] [blame] | 23 | bignum_mod.c | 
| Janos Follath | 138f51c | 2022-08-15 11:38:30 +0100 | [diff] [blame] | 24 | bignum_mod_raw.c | 
| Manuel Pégourié-Gonnard | 2171876 | 2023-11-10 11:21:17 +0100 | [diff] [blame] | 25 | block_cipher.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 26 | camellia.c | 
|  | 27 | ccm.c | 
| Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 28 | chacha20.c | 
| Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 29 | chachapoly.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 30 | cipher.c | 
|  | 31 | cipher_wrap.c | 
| gabor-mezei-arm | d112534 | 2021-07-12 16:31:22 +0200 | [diff] [blame] | 32 | constant_time.c | 
| Robert Cragie | dc5c7b9 | 2015-12-11 15:49:45 +0000 | [diff] [blame] | 33 | cmac.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 34 | ctr_drbg.c | 
|  | 35 | des.c | 
|  | 36 | dhm.c | 
|  | 37 | ecdh.c | 
|  | 38 | ecdsa.c | 
| Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 39 | ecjpake.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 40 | ecp.c | 
|  | 41 | ecp_curves.c | 
| Xiaokang Qian | 4d71051 | 2023-06-13 10:57:43 +0000 | [diff] [blame] | 42 | ecp_curves_new.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 43 | entropy.c | 
|  | 44 | entropy_poll.c | 
|  | 45 | error.c | 
|  | 46 | gcm.c | 
| Thomas Fossati | 656864b | 2016-07-17 08:51:22 +0100 | [diff] [blame] | 47 | hkdf.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 48 | hmac_drbg.c | 
| Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 49 | lmots.c | 
|  | 50 | lms.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 51 | md.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 52 | md5.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 53 | memory_buffer_alloc.c | 
| Ron Eldor | cb349ac | 2018-07-15 09:29:47 +0300 | [diff] [blame] | 54 | nist_kw.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 55 | oid.c | 
|  | 56 | padlock.c | 
|  | 57 | pem.c | 
|  | 58 | pk.c | 
| Valerio Setti | 851f190 | 2024-02-08 09:35:05 +0100 | [diff] [blame] | 59 | pk_ecc.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 60 | pk_wrap.c | 
|  | 61 | pkcs12.c | 
|  | 62 | pkcs5.c | 
|  | 63 | pkparse.c | 
|  | 64 | pkwrite.c | 
|  | 65 | platform.c | 
| Andres Amaya Garcia | bc7bdbf | 2018-04-24 08:29:20 -0500 | [diff] [blame] | 66 | platform_util.c | 
| Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 67 | poly1305.c | 
| Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 68 | psa_crypto.c | 
| Ronald Cron | 7ceee8d | 2021-03-17 16:55:43 +0100 | [diff] [blame] | 69 | psa_crypto_aead.c | 
| Ronald Cron | 0ff5795 | 2021-03-08 16:46:35 +0100 | [diff] [blame] | 70 | psa_crypto_cipher.c | 
| Ronald Cron | d790632 | 2021-01-28 16:07:56 +0100 | [diff] [blame] | 71 | psa_crypto_client.c | 
| Xiaokang Qian | e9c39c4 | 2023-08-09 08:50:19 +0000 | [diff] [blame] | 72 | psa_crypto_driver_wrappers_no_static.c | 
| Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 73 | psa_crypto_ecp.c | 
| Przemek Stekiel | 0dd746d | 2022-12-05 14:17:17 +0100 | [diff] [blame] | 74 | psa_crypto_ffdh.c | 
| Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 75 | psa_crypto_hash.c | 
| Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 76 | psa_crypto_mac.c | 
| Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 77 | psa_crypto_pake.c | 
| Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 78 | psa_crypto_rsa.c | 
| Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 79 | psa_crypto_se.c | 
| Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 80 | psa_crypto_slot_management.c | 
| Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 81 | psa_crypto_storage.c | 
| Gilles Peskine | 6194dc2 | 2018-11-16 22:24:15 +0100 | [diff] [blame] | 82 | psa_its_file.c | 
| Andrzej Kurek | 8a045ce | 2022-12-23 11:00:06 -0500 | [diff] [blame] | 83 | psa_util.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 84 | ripemd160.c | 
|  | 85 | rsa.c | 
| Chris Jones | 66a4cd4 | 2021-03-09 16:04:12 +0000 | [diff] [blame] | 86 | rsa_alt_helpers.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 87 | sha1.c | 
|  | 88 | sha256.c | 
|  | 89 | sha512.c | 
| Pol Henarejos | 0cd1f1c | 2022-05-09 01:04:15 +0200 | [diff] [blame] | 90 | sha3.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 91 | threading.c | 
| Manuel Pégourié-Gonnard | 21dcc1e | 2015-06-25 10:59:15 +0200 | [diff] [blame] | 92 | timing.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 93 | version.c | 
|  | 94 | version_features.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 95 | ) | 
|  | 96 |  | 
|  | 97 | set(src_x509 | 
| Daniel Axtens | aa91d4e | 2020-05-29 00:23:21 +1000 | [diff] [blame] | 98 | pkcs7.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 99 | x509.c | 
|  | 100 | x509_create.c | 
|  | 101 | x509_crl.c | 
|  | 102 | x509_crt.c | 
|  | 103 | x509_csr.c | 
| Andrzej Kurek | c508dc2 | 2023-07-07 08:20:02 -0400 | [diff] [blame] | 104 | x509write.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 105 | x509write_crt.c | 
|  | 106 | x509write_csr.c | 
|  | 107 | ) | 
|  | 108 |  | 
|  | 109 | set(src_tls | 
|  | 110 | debug.c | 
| Gilles Peskine | 89e31ad | 2022-11-26 14:18:45 +0100 | [diff] [blame] | 111 | mps_reader.c | 
|  | 112 | mps_trace.c | 
| Andres AG | 788aa4a | 2016-09-14 14:32:09 +0100 | [diff] [blame] | 113 | net_sockets.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 114 | ssl_cache.c | 
|  | 115 | ssl_ciphersuites.c | 
| Ronald Cron | 3d580bf | 2022-02-18 17:24:56 +0100 | [diff] [blame] | 116 | ssl_client.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 117 | ssl_cookie.c | 
| Gilles Peskine | 898db6b | 2022-11-26 14:15:32 +0100 | [diff] [blame] | 118 | ssl_debug_helpers_generated.c | 
| Hanno Becker | 6e7051a | 2020-02-05 11:33:54 +0000 | [diff] [blame] | 119 | ssl_msg.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 120 | ssl_ticket.c | 
| Hanno Becker | 471c0c9 | 2020-02-05 11:32:03 +0000 | [diff] [blame] | 121 | ssl_tls.c | 
| Ronald Cron | de1adee | 2022-03-07 16:20:30 +0100 | [diff] [blame] | 122 | ssl_tls12_client.c | 
|  | 123 | ssl_tls12_server.c | 
| Hanno Becker | be9d664 | 2020-08-21 13:20:06 +0100 | [diff] [blame] | 124 | ssl_tls13_keys.c | 
| Jerry Yu | 3cc4c2a | 2021-08-06 16:29:08 +0800 | [diff] [blame] | 125 | ssl_tls13_server.c | 
|  | 126 | ssl_tls13_client.c | 
| Jerry Yu | 65dd2cc | 2021-08-18 16:38:40 +0800 | [diff] [blame] | 127 | ssl_tls13_generic.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 128 | ) | 
|  | 129 |  | 
| David Horstmann | a8d1406 | 2021-10-20 17:14:23 +0100 | [diff] [blame] | 130 | if(GEN_FILES) | 
| Manuel Pégourié-Gonnard | e90e405 | 2021-09-08 13:27:09 +0200 | [diff] [blame] | 131 | find_package(Perl REQUIRED) | 
| Manuel Pégourié-Gonnard | cbdedc5 | 2021-05-11 12:47:30 +0200 | [diff] [blame] | 132 |  | 
| Manuel Pégourié-Gonnard | e90e405 | 2021-09-08 13:27:09 +0200 | [diff] [blame] | 133 | file(GLOB error_headers ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/*.h) | 
|  | 134 | add_custom_command( | 
|  | 135 | OUTPUT | 
| Manuel Pégourié-Gonnard | cbdedc5 | 2021-05-11 12:47:30 +0200 | [diff] [blame] | 136 | ${CMAKE_CURRENT_BINARY_DIR}/error.c | 
| Manuel Pégourié-Gonnard | e90e405 | 2021-09-08 13:27:09 +0200 | [diff] [blame] | 137 | COMMAND | 
|  | 138 | ${PERL_EXECUTABLE} | 
|  | 139 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl | 
|  | 140 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls | 
|  | 141 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files | 
|  | 142 | ${CMAKE_CURRENT_BINARY_DIR}/error.c | 
|  | 143 | DEPENDS | 
|  | 144 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl | 
|  | 145 | ${error_headers} | 
|  | 146 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/error.fmt | 
|  | 147 | ) | 
| Manuel Pégourié-Gonnard | cbdedc5 | 2021-05-11 12:47:30 +0200 | [diff] [blame] | 148 |  | 
| Manuel Pégourié-Gonnard | e90e405 | 2021-09-08 13:27:09 +0200 | [diff] [blame] | 149 | add_custom_command( | 
|  | 150 | OUTPUT | 
| Manuel Pégourié-Gonnard | 65a7203 | 2021-05-11 13:02:44 +0200 | [diff] [blame] | 151 | ${CMAKE_CURRENT_BINARY_DIR}/version_features.c | 
| Manuel Pégourié-Gonnard | e90e405 | 2021-09-08 13:27:09 +0200 | [diff] [blame] | 152 | COMMAND | 
|  | 153 | ${PERL_EXECUTABLE} | 
|  | 154 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl | 
|  | 155 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls | 
|  | 156 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files | 
|  | 157 | ${CMAKE_CURRENT_BINARY_DIR}/version_features.c | 
|  | 158 | DEPENDS | 
|  | 159 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl | 
|  | 160 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/mbedtls_config.h | 
|  | 161 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/version_features.fmt | 
|  | 162 | ) | 
| Jerry Yu | eb96fb5 | 2021-12-02 11:03:59 +0800 | [diff] [blame] | 163 |  | 
|  | 164 | add_custom_command( | 
|  | 165 | OUTPUT | 
|  | 166 | ${CMAKE_CURRENT_BINARY_DIR}/ssl_debug_helpers_generated.c | 
|  | 167 | COMMAND | 
|  | 168 | ${MBEDTLS_PYTHON_EXECUTABLE} | 
| Elena Uziunaite | 7f5ec13 | 2024-10-07 17:40:21 +0100 | [diff] [blame] | 169 | ${CMAKE_CURRENT_SOURCE_DIR}/../framework/scripts/generate_ssl_debug_helpers.py | 
| Jerry Yu | e6369b0 | 2021-12-02 13:51:26 +0800 | [diff] [blame] | 170 | --mbedtls-root ${CMAKE_CURRENT_SOURCE_DIR}/.. | 
|  | 171 | ${CMAKE_CURRENT_BINARY_DIR} | 
| Jerry Yu | eb96fb5 | 2021-12-02 11:03:59 +0800 | [diff] [blame] | 172 | DEPENDS | 
| Elena Uziunaite | 7f5ec13 | 2024-10-07 17:40:21 +0100 | [diff] [blame] | 173 | ${CMAKE_CURRENT_SOURCE_DIR}/../framework/scripts/generate_ssl_debug_helpers.py | 
| Jerry Yu | eb96fb5 | 2021-12-02 11:03:59 +0800 | [diff] [blame] | 174 | ${error_headers} | 
|  | 175 | ) | 
| Archana | 6f21e45 | 2021-11-23 14:46:51 +0530 | [diff] [blame] | 176 |  | 
|  | 177 | add_custom_command( | 
|  | 178 | OUTPUT | 
| Xiaokang Qian | fe9666b | 2023-09-11 10:36:20 +0000 | [diff] [blame] | 179 | ${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers.h | 
|  | 180 | ${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers_no_static.c | 
| Archana | 6f21e45 | 2021-11-23 14:46:51 +0530 | [diff] [blame] | 181 | COMMAND | 
|  | 182 | ${MBEDTLS_PYTHON_EXECUTABLE} | 
|  | 183 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_driver_wrappers.py | 
| Archana | e03960e | 2021-12-19 09:17:04 +0530 | [diff] [blame] | 184 | ${CMAKE_CURRENT_BINARY_DIR} | 
| Archana | 6f21e45 | 2021-11-23 14:46:51 +0530 | [diff] [blame] | 185 | DEPENDS | 
|  | 186 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_driver_wrappers.py | 
| Xiaokang Qian | fe9666b | 2023-09-11 10:36:20 +0000 | [diff] [blame] | 187 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja | 
|  | 188 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja | 
| Archana | 6f21e45 | 2021-11-23 14:46:51 +0530 | [diff] [blame] | 189 | ) | 
|  | 190 |  | 
|  | 191 |  | 
| Manuel Pégourié-Gonnard | e90e405 | 2021-09-08 13:27:09 +0200 | [diff] [blame] | 192 | else() | 
|  | 193 | link_to_source(error.c) | 
|  | 194 | link_to_source(version_features.c) | 
| Jerry Yu | eb96fb5 | 2021-12-02 11:03:59 +0800 | [diff] [blame] | 195 | link_to_source(ssl_debug_helpers_generated.c) | 
| Xiaokang Qian | e9c39c4 | 2023-08-09 08:50:19 +0000 | [diff] [blame] | 196 | link_to_source(psa_crypto_driver_wrappers_no_static.c) | 
| Manuel Pégourié-Gonnard | e90e405 | 2021-09-08 13:27:09 +0200 | [diff] [blame] | 197 | endif() | 
| Manuel Pégourié-Gonnard | 65a7203 | 2021-05-11 13:02:44 +0200 | [diff] [blame] | 198 |  | 
| Paul Bakker | 76f0311 | 2013-11-28 17:20:04 +0100 | [diff] [blame] | 199 | if(CMAKE_COMPILER_IS_GNUCC) | 
| Michael Schuster | 4d0d0ec | 2024-06-05 01:45:54 +0200 | [diff] [blame] | 200 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations") | 
| Paul Bakker | 76f0311 | 2013-11-28 17:20:04 +0100 | [diff] [blame] | 201 | endif(CMAKE_COMPILER_IS_GNUCC) | 
|  | 202 |  | 
| Manuel Pégourié-Gonnard | 3185545 | 2014-06-25 15:59:50 +0200 | [diff] [blame] | 203 | if(CMAKE_COMPILER_IS_CLANG) | 
| Michael Schuster | 4d0d0ec | 2024-06-05 01:45:54 +0200 | [diff] [blame] | 204 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code") | 
| Manuel Pégourié-Gonnard | 3185545 | 2014-06-25 15:59:50 +0200 | [diff] [blame] | 205 | endif(CMAKE_COMPILER_IS_CLANG) | 
|  | 206 |  | 
| Krzysztof Stachowiak | de6effa | 2018-10-31 12:46:37 +0100 | [diff] [blame] | 207 | if(CMAKE_COMPILER_IS_MSVC) | 
|  | 208 | option(MSVC_STATIC_RUNTIME "Build the libraries with /MT compiler flag" OFF) | 
|  | 209 | if(MSVC_STATIC_RUNTIME) | 
|  | 210 | foreach(flag_var | 
|  | 211 | CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE | 
|  | 212 | CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO | 
|  | 213 | CMAKE_C_FLAGS_CHECK) | 
|  | 214 | string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") | 
|  | 215 | endforeach(flag_var) | 
|  | 216 | endif() | 
|  | 217 | endif() | 
|  | 218 |  | 
| Manuel Pégourié-Gonnard | ba2c876 | 2015-06-25 09:35:46 +0200 | [diff] [blame] | 219 | if(WIN32) | 
| Simon Butcher | e068aa7 | 2018-03-14 15:10:31 +0000 | [diff] [blame] | 220 | set(libs ${libs} ws2_32 bcrypt) | 
| Manuel Pégourié-Gonnard | ba2c876 | 2015-06-25 09:35:46 +0200 | [diff] [blame] | 221 | endif(WIN32) | 
|  | 222 |  | 
| Signed-off-by: Steven WdV | bcfed50 | 2024-02-29 15:12:36 +0100 | [diff] [blame] | 223 | if(CMAKE_C_COMPILER_ID MATCHES "AppleClang") | 
|  | 224 | set(CMAKE_C_ARCHIVE_CREATE   "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>") | 
| Signed-off-by: Steven WdV | bcfed50 | 2024-02-29 15:12:36 +0100 | [diff] [blame] | 225 | set(CMAKE_C_ARCHIVE_FINISH   "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>") | 
| Steven WdV | 9f0858d | 2024-03-19 11:39:22 +0100 | [diff] [blame] | 226 | endif() | 
|  | 227 | if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") | 
|  | 228 | set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>") | 
| Signed-off-by: Steven WdV | bcfed50 | 2024-02-29 15:12:36 +0100 | [diff] [blame] | 229 | set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>") | 
| Andres Amaya Garcia | bf7fe4f | 2018-06-21 20:21:38 +0100 | [diff] [blame] | 230 | endif() | 
| TabascoEye | 7f3ef27 | 2018-04-27 13:14:59 +0200 | [diff] [blame] | 231 |  | 
| Augustin Cavalier | 60bc47d | 2018-04-11 20:27:32 -0400 | [diff] [blame] | 232 | if(HAIKU) | 
| Simon Butcher | 6331cb0 | 2018-07-10 11:48:42 +0100 | [diff] [blame] | 233 | set(libs ${libs} network) | 
| Augustin Cavalier | 60bc47d | 2018-04-11 20:27:32 -0400 | [diff] [blame] | 234 | endif(HAIKU) | 
|  | 235 |  | 
| Manuel Pégourié-Gonnard | ba2c876 | 2015-06-25 09:35:46 +0200 | [diff] [blame] | 236 | if(LINK_WITH_PTHREAD) | 
| Paul Elliott | 7fd162e | 2024-01-24 18:05:53 +0000 | [diff] [blame] | 237 | set(libs ${libs} ${CMAKE_THREAD_LIBS_INIT}) | 
| Manuel Pégourié-Gonnard | ba2c876 | 2015-06-25 09:35:46 +0200 | [diff] [blame] | 238 | endif() | 
|  | 239 |  | 
| Moshe Shahar | 7e36765 | 2019-07-15 15:50:19 +0300 | [diff] [blame] | 240 | if(LINK_WITH_TRUSTED_STORAGE) | 
|  | 241 | set(libs ${libs} trusted_storage) | 
|  | 242 | endif() | 
|  | 243 |  | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 244 | if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY) | 
| Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 245 | message(FATAL_ERROR "Need to choose static or shared mbedtls build!") | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 246 | endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY) | 
| Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 247 |  | 
| Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 248 | set(mbedtls_target    "${MBEDTLS_TARGET_PREFIX}mbedtls") | 
|  | 249 | set(mbedx509_target   "${MBEDTLS_TARGET_PREFIX}mbedx509") | 
|  | 250 | set(mbedcrypto_target "${MBEDTLS_TARGET_PREFIX}mbedcrypto") | 
|  | 251 |  | 
|  | 252 | set(mbedtls_target    ${mbedtls_target}    PARENT_SCOPE) | 
|  | 253 | set(mbedx509_target   ${mbedx509_target}   PARENT_SCOPE) | 
|  | 254 | set(mbedcrypto_target ${mbedcrypto_target} PARENT_SCOPE) | 
|  | 255 |  | 
|  | 256 | if (USE_STATIC_MBEDTLS_LIBRARY) | 
|  | 257 | set(mbedtls_static_target    ${mbedtls_target}) | 
|  | 258 | set(mbedx509_static_target   ${mbedx509_target}) | 
|  | 259 | set(mbedcrypto_static_target ${mbedcrypto_target}) | 
|  | 260 | endif() | 
|  | 261 |  | 
|  | 262 | set(target_libraries ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) | 
| Gilles Peskine | 3ca8a92 | 2020-07-02 13:07:37 +0200 | [diff] [blame] | 263 |  | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 264 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) | 
| Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 265 | string(APPEND mbedtls_static_target    "_static") | 
|  | 266 | string(APPEND mbedx509_static_target   "_static") | 
|  | 267 | string(APPEND mbedcrypto_static_target "_static") | 
|  | 268 |  | 
| Gilles Peskine | 3ca8a92 | 2020-07-02 13:07:37 +0200 | [diff] [blame] | 269 | list(APPEND target_libraries | 
| Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 270 | ${mbedcrypto_static_target} | 
|  | 271 | ${mbedx509_static_target} | 
|  | 272 | ${mbedtls_static_target}) | 
| hasufell | 3c6409b | 2014-03-06 15:49:08 +0100 | [diff] [blame] | 273 | endif() | 
| Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 274 |  | 
| David Horstmann | de527fb | 2023-09-28 17:52:52 +0100 | [diff] [blame] | 275 | set(p256m_target "${MBEDTLS_TARGET_PREFIX}p256m") | 
|  | 276 | set(everest_target "${MBEDTLS_TARGET_PREFIX}everest") | 
|  | 277 |  | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 278 | if(USE_STATIC_MBEDTLS_LIBRARY) | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 279 | add_library(${mbedcrypto_static_target} STATIC ${src_crypto}) | 
|  | 280 | set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto) | 
| Raef Coles | 4762edd | 2020-10-13 16:31:41 +0100 | [diff] [blame] | 281 | target_link_libraries(${mbedcrypto_static_target} PUBLIC ${libs}) | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 282 |  | 
| David Horstmann | de527fb | 2023-09-28 17:52:52 +0100 | [diff] [blame] | 283 | if(TARGET ${everest_target}) | 
|  | 284 | target_link_libraries(${mbedcrypto_static_target} PUBLIC ${everest_target}) | 
| Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 285 | endif() | 
|  | 286 |  | 
| David Horstmann | de527fb | 2023-09-28 17:52:52 +0100 | [diff] [blame] | 287 | if(TARGET ${p256m_target}) | 
|  | 288 | target_link_libraries(${mbedcrypto_static_target} PUBLIC ${p256m_target}) | 
| Aditya Deshpande | 7b9934d | 2023-04-18 17:00:17 +0100 | [diff] [blame] | 289 | endif() | 
|  | 290 |  | 
| Gilles Peskine | 55d5353 | 2020-03-09 17:48:13 +0100 | [diff] [blame] | 291 | add_library(${mbedx509_static_target} STATIC ${src_x509}) | 
|  | 292 | set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) | 
| Raef Coles | 4762edd | 2020-10-13 16:31:41 +0100 | [diff] [blame] | 293 | target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target}) | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 294 |  | 
| Gilles Peskine | 55d5353 | 2020-03-09 17:48:13 +0100 | [diff] [blame] | 295 | add_library(${mbedtls_static_target} STATIC ${src_tls}) | 
|  | 296 | set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) | 
| Raef Coles | 4762edd | 2020-10-13 16:31:41 +0100 | [diff] [blame] | 297 | target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target}) | 
| Manuel Pégourié-Gonnard | e1d34d1 | 2015-06-25 14:53:13 +0200 | [diff] [blame] | 298 | endif(USE_STATIC_MBEDTLS_LIBRARY) | 
| Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 299 |  | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 300 | if(USE_SHARED_MBEDTLS_LIBRARY) | 
| Ron Eldor | 183264c | 2017-10-09 19:07:26 +0300 | [diff] [blame] | 301 | set(CMAKE_LIBRARY_PATH ${CMAKE_CURRENT_BINARY_DIR}) | 
| Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 302 | add_library(${mbedcrypto_target} SHARED ${src_crypto}) | 
| Minos Galanakis | 5374262 | 2025-06-23 19:01:55 +0100 | [diff] [blame] | 303 | set_target_properties(${mbedcrypto_target} PROPERTIES VERSION 3.6.4 SOVERSION 16) | 
| Raef Coles | 4762edd | 2020-10-13 16:31:41 +0100 | [diff] [blame] | 304 | target_link_libraries(${mbedcrypto_target} PUBLIC ${libs}) | 
| Paul Bakker | 2a5c7a8 | 2012-05-10 21:54:28 +0000 | [diff] [blame] | 305 |  | 
| David Horstmann | de527fb | 2023-09-28 17:52:52 +0100 | [diff] [blame] | 306 | if(TARGET ${everest_target}) | 
|  | 307 | target_link_libraries(${mbedcrypto_target} PUBLIC ${everest_target}) | 
| Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 308 | endif() | 
|  | 309 |  | 
| David Horstmann | de527fb | 2023-09-28 17:52:52 +0100 | [diff] [blame] | 310 | if(TARGET ${p256m_target}) | 
|  | 311 | target_link_libraries(${mbedcrypto_target} PUBLIC ${p256m_target}) | 
| Aditya Deshpande | 7b9934d | 2023-04-18 17:00:17 +0100 | [diff] [blame] | 312 | endif() | 
|  | 313 |  | 
| Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 314 | add_library(${mbedx509_target} SHARED ${src_x509}) | 
| Minos Galanakis | 5374262 | 2025-06-23 19:01:55 +0100 | [diff] [blame] | 315 | set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.6.4 SOVERSION 7) | 
| Raef Coles | 4762edd | 2020-10-13 16:31:41 +0100 | [diff] [blame] | 316 | target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target}) | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 317 |  | 
| Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 318 | add_library(${mbedtls_target} SHARED ${src_tls}) | 
| Minos Galanakis | 5374262 | 2025-06-23 19:01:55 +0100 | [diff] [blame] | 319 | set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.6.4 SOVERSION 21) | 
| Raef Coles | 4762edd | 2020-10-13 16:31:41 +0100 | [diff] [blame] | 320 | target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target}) | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 321 | endif(USE_SHARED_MBEDTLS_LIBRARY) | 
| Manuel Pégourié-Gonnard | e1d34d1 | 2015-06-25 14:53:13 +0200 | [diff] [blame] | 322 |  | 
| Gilles Peskine | 3ca8a92 | 2020-07-02 13:07:37 +0200 | [diff] [blame] | 323 | foreach(target IN LISTS target_libraries) | 
| Robert Shade | 591e729 | 2022-05-12 14:40:16 -0400 | [diff] [blame] | 324 | add_library(MbedTLS::${target} ALIAS ${target})  # add_subdirectory support | 
| Gilles Peskine | 76dd3aa | 2020-07-02 15:58:37 +0200 | [diff] [blame] | 325 | # Include public header files from /include and other directories | 
|  | 326 | # declared by /3rdparty/**/CMakeLists.txt. Include private header files | 
|  | 327 | # from /library and others declared by /3rdparty/**/CMakeLists.txt. | 
|  | 328 | # /library needs to be listed explicitly when building .c files outside | 
|  | 329 | # of /library (which currently means: under /3rdparty). | 
| Gilles Peskine | 3ca8a92 | 2020-07-02 13:07:37 +0200 | [diff] [blame] | 330 | target_include_directories(${target} | 
| Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 331 | PUBLIC $<BUILD_INTERFACE:${MBEDTLS_DIR}/include/> | 
|  | 332 | $<INSTALL_INTERFACE:include/> | 
| David Horstmann | b7b4f23 | 2023-09-27 13:57:11 +0100 | [diff] [blame] | 333 | PRIVATE ${MBEDTLS_DIR}/library/ | 
|  | 334 | # Needed to include psa_crypto_driver_wrappers.h | 
|  | 335 | ${CMAKE_CURRENT_BINARY_DIR}) | 
| David Horstmann | 82f11ff | 2023-01-09 12:41:58 +0000 | [diff] [blame] | 336 | # Pass-through MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE | 
| David Horstmann | 0f1dd57 | 2023-02-15 14:44:25 +0000 | [diff] [blame] | 337 | if(MBEDTLS_CONFIG_FILE) | 
| David Horstmann | 82f11ff | 2023-01-09 12:41:58 +0000 | [diff] [blame] | 338 | target_compile_definitions(${target} | 
|  | 339 | PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}") | 
|  | 340 | endif() | 
| David Horstmann | 0f1dd57 | 2023-02-15 14:44:25 +0000 | [diff] [blame] | 341 | if(MBEDTLS_USER_CONFIG_FILE) | 
| David Horstmann | 82f11ff | 2023-01-09 12:41:58 +0000 | [diff] [blame] | 342 | target_compile_definitions(${target} | 
|  | 343 | PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}") | 
|  | 344 | endif() | 
| Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 345 | install( | 
|  | 346 | TARGETS ${target} | 
|  | 347 | EXPORT MbedTLSTargets | 
| Biswapriyo Nath | d7e0ee4 | 2022-04-22 20:59:50 +0530 | [diff] [blame] | 348 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | 
|  | 349 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | 
|  | 350 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | 
| Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 351 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) | 
| Gilles Peskine | 3ca8a92 | 2020-07-02 13:07:37 +0200 | [diff] [blame] | 352 | endforeach(target) | 
| Manuel Pégourié-Gonnard | e1d34d1 | 2015-06-25 14:53:13 +0200 | [diff] [blame] | 353 |  | 
| Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 354 | set(lib_target "${MBEDTLS_TARGET_PREFIX}lib") | 
|  | 355 |  | 
|  | 356 | add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) | 
| Gilles Peskine | 55d5353 | 2020-03-09 17:48:13 +0100 | [diff] [blame] | 357 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) | 
| Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 358 | add_dependencies(${lib_target} ${mbedcrypto_static_target} ${mbedx509_static_target} ${mbedtls_static_target}) | 
| Manuel Pégourié-Gonnard | e1d34d1 | 2015-06-25 14:53:13 +0200 | [diff] [blame] | 359 | endif() |