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