| 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) | 
| Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 4 |  | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 5 | set(src_crypto | 
|  | 6 | aes.c | 
|  | 7 | aesni.c | 
|  | 8 | arc4.c | 
|  | 9 | asn1parse.c | 
|  | 10 | asn1write.c | 
|  | 11 | base64.c | 
|  | 12 | bignum.c | 
|  | 13 | blowfish.c | 
|  | 14 | camellia.c | 
|  | 15 | ccm.c | 
|  | 16 | cipher.c | 
|  | 17 | cipher_wrap.c | 
| Robert Cragie | dc5c7b9 | 2015-12-11 15:49:45 +0000 | [diff] [blame] | 18 | cmac.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 19 | ctr_drbg.c | 
|  | 20 | des.c | 
|  | 21 | dhm.c | 
|  | 22 | ecdh.c | 
|  | 23 | ecdsa.c | 
| Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 24 | ecjpake.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 25 | ecp.c | 
|  | 26 | ecp_curves.c | 
|  | 27 | entropy.c | 
|  | 28 | entropy_poll.c | 
|  | 29 | error.c | 
|  | 30 | gcm.c | 
|  | 31 | havege.c | 
|  | 32 | hmac_drbg.c | 
|  | 33 | md.c | 
|  | 34 | md2.c | 
|  | 35 | md4.c | 
|  | 36 | md5.c | 
|  | 37 | md_wrap.c | 
|  | 38 | memory_buffer_alloc.c | 
|  | 39 | oid.c | 
|  | 40 | padlock.c | 
|  | 41 | pem.c | 
|  | 42 | pk.c | 
|  | 43 | pk_wrap.c | 
|  | 44 | pkcs12.c | 
|  | 45 | pkcs5.c | 
|  | 46 | pkparse.c | 
|  | 47 | pkwrite.c | 
|  | 48 | platform.c | 
|  | 49 | ripemd160.c | 
|  | 50 | rsa.c | 
| Hanno Becker | a565f54 | 2017-10-11 11:00:19 +0100 | [diff] [blame] | 51 | rsa_internal.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 52 | sha1.c | 
|  | 53 | sha256.c | 
|  | 54 | sha512.c | 
|  | 55 | threading.c | 
| Manuel Pégourié-Gonnard | 21dcc1e | 2015-06-25 10:59:15 +0200 | [diff] [blame] | 56 | timing.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 57 | version.c | 
|  | 58 | version_features.c | 
|  | 59 | xtea.c | 
|  | 60 | ) | 
|  | 61 |  | 
|  | 62 | set(src_x509 | 
|  | 63 | certs.c | 
|  | 64 | pkcs11.c | 
|  | 65 | x509.c | 
|  | 66 | x509_create.c | 
|  | 67 | x509_crl.c | 
|  | 68 | x509_crt.c | 
|  | 69 | x509_csr.c | 
|  | 70 | x509write_crt.c | 
|  | 71 | x509write_csr.c | 
|  | 72 | ) | 
|  | 73 |  | 
|  | 74 | set(src_tls | 
|  | 75 | debug.c | 
| Andres AG | 788aa4a | 2016-09-14 14:32:09 +0100 | [diff] [blame] | 76 | net_sockets.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 77 | ssl_cache.c | 
|  | 78 | ssl_ciphersuites.c | 
|  | 79 | ssl_cli.c | 
|  | 80 | ssl_cookie.c | 
|  | 81 | ssl_srv.c | 
|  | 82 | ssl_ticket.c | 
|  | 83 | ssl_tls.c | 
| Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 84 | ) | 
|  | 85 |  | 
| Paul Bakker | 76f0311 | 2013-11-28 17:20:04 +0100 | [diff] [blame] | 86 | if(CMAKE_COMPILER_IS_GNUCC) | 
| Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 87 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes") | 
| Paul Bakker | 76f0311 | 2013-11-28 17:20:04 +0100 | [diff] [blame] | 88 | endif(CMAKE_COMPILER_IS_GNUCC) | 
|  | 89 |  | 
| Manuel Pégourié-Gonnard | 3185545 | 2014-06-25 15:59:50 +0200 | [diff] [blame] | 90 | if(CMAKE_COMPILER_IS_CLANG) | 
| Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 91 | 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] | 92 | endif(CMAKE_COMPILER_IS_CLANG) | 
|  | 93 |  | 
| Gilles Peskine | 4e7b323 | 2019-01-06 19:48:30 +0000 | [diff] [blame] | 94 | if(UNSAFE_BUILD) | 
|  | 95 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error") | 
|  | 96 | set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -Wno-error") | 
|  | 97 | set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -Wno-error") | 
|  | 98 | endif(UNSAFE_BUILD) | 
|  | 99 |  | 
| Manuel Pégourié-Gonnard | ba2c876 | 2015-06-25 09:35:46 +0200 | [diff] [blame] | 100 | if(WIN32) | 
|  | 101 | set(libs ${libs} ws2_32) | 
|  | 102 | endif(WIN32) | 
|  | 103 |  | 
|  | 104 | if(USE_PKCS11_HELPER_LIBRARY) | 
|  | 105 | set(libs ${libs} pkcs11-helper) | 
|  | 106 | endif(USE_PKCS11_HELPER_LIBRARY) | 
|  | 107 |  | 
|  | 108 | if(ENABLE_ZLIB_SUPPORT) | 
|  | 109 | set(libs ${libs} ${ZLIB_LIBRARIES}) | 
|  | 110 | endif(ENABLE_ZLIB_SUPPORT) | 
|  | 111 |  | 
|  | 112 | if(LINK_WITH_PTHREAD) | 
|  | 113 | set(libs ${libs} pthread) | 
|  | 114 | endif() | 
|  | 115 |  | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 116 | 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] | 117 | 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] | 118 | endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY) | 
| Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 119 |  | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 120 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) | 
| Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 121 | set(mbedtls_static_target "mbedtls_static") | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 122 | set(mbedx509_static_target "mbedx509_static") | 
|  | 123 | set(mbedcrypto_static_target "mbedcrypto_static") | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 124 | elseif(USE_STATIC_MBEDTLS_LIBRARY) | 
| Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 125 | set(mbedtls_static_target "mbedtls") | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 126 | set(mbedx509_static_target "mbedx509") | 
|  | 127 | set(mbedcrypto_static_target "mbedcrypto") | 
| hasufell | 3c6409b | 2014-03-06 15:49:08 +0100 | [diff] [blame] | 128 | endif() | 
| Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 129 |  | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 130 | if(USE_STATIC_MBEDTLS_LIBRARY) | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 131 | add_library(${mbedcrypto_static_target} STATIC ${src_crypto}) | 
|  | 132 | set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto) | 
|  | 133 | target_link_libraries(${mbedcrypto_static_target} ${libs}) | 
| Paul Bakker | 6c1f69b | 2014-03-17 15:11:13 +0100 | [diff] [blame] | 134 |  | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 135 | add_library(${mbedx509_static_target} STATIC ${src_x509}) | 
|  | 136 | set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) | 
|  | 137 | target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target}) | 
|  | 138 |  | 
|  | 139 | add_library(${mbedtls_static_target} STATIC ${src_tls}) | 
|  | 140 | set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) | 
|  | 141 | target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target}) | 
|  | 142 |  | 
| Manuel Pégourié-Gonnard | 6f42417 | 2015-07-24 16:53:46 +0200 | [diff] [blame] | 143 | install(TARGETS ${mbedtls_static_target} ${mbedx509_static_target} ${mbedcrypto_static_target} | 
| Manuel Pégourié-Gonnard | ba2c876 | 2015-06-25 09:35:46 +0200 | [diff] [blame] | 144 | DESTINATION ${LIB_INSTALL_DIR} | 
|  | 145 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) | 
| Manuel Pégourié-Gonnard | e1d34d1 | 2015-06-25 14:53:13 +0200 | [diff] [blame] | 146 | endif(USE_STATIC_MBEDTLS_LIBRARY) | 
| Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 147 |  | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 148 | if(USE_SHARED_MBEDTLS_LIBRARY) | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 149 | add_library(mbedcrypto SHARED ${src_crypto}) | 
| Janos Follath | ee88f81 | 2020-01-20 14:28:41 +0000 | [diff] [blame] | 150 | set_target_properties(mbedcrypto PROPERTIES VERSION 2.7.13 SOVERSION 2) | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 151 | target_link_libraries(mbedcrypto ${libs}) | 
| Paul Bakker | 2a5c7a8 | 2012-05-10 21:54:28 +0000 | [diff] [blame] | 152 |  | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 153 | add_library(mbedx509 SHARED ${src_x509}) | 
| Janos Follath | ee88f81 | 2020-01-20 14:28:41 +0000 | [diff] [blame] | 154 | set_target_properties(mbedx509 PROPERTIES VERSION 2.7.13 SOVERSION 0) | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 155 | target_link_libraries(mbedx509 ${libs} mbedcrypto) | 
|  | 156 |  | 
|  | 157 | add_library(mbedtls SHARED ${src_tls}) | 
| Janos Follath | ee88f81 | 2020-01-20 14:28:41 +0000 | [diff] [blame] | 158 | set_target_properties(mbedtls PROPERTIES VERSION 2.7.13 SOVERSION 10) | 
| Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 159 | target_link_libraries(mbedtls ${libs} mbedx509) | 
|  | 160 |  | 
|  | 161 | install(TARGETS mbedtls mbedx509 mbedcrypto | 
| Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 162 | DESTINATION ${LIB_INSTALL_DIR} | 
|  | 163 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) | 
| Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 164 | endif(USE_SHARED_MBEDTLS_LIBRARY) | 
| Manuel Pégourié-Gonnard | e1d34d1 | 2015-06-25 14:53:13 +0200 | [diff] [blame] | 165 |  | 
|  | 166 | add_custom_target(lib DEPENDS mbedcrypto mbedx509 mbedtls) | 
|  | 167 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) | 
|  | 168 | add_dependencies(lib mbedcrypto_static mbedx509_static mbedtls_static) | 
|  | 169 | endif() |