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 |
| 51 | sha1.c |
| 52 | sha256.c |
| 53 | sha512.c |
| 54 | threading.c |
Manuel Pégourié-Gonnard | 21dcc1e | 2015-06-25 10:59:15 +0200 | [diff] [blame] | 55 | timing.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 56 | version.c |
| 57 | version_features.c |
| 58 | xtea.c |
| 59 | ) |
| 60 | |
| 61 | set(src_x509 |
| 62 | certs.c |
| 63 | pkcs11.c |
| 64 | x509.c |
| 65 | x509_create.c |
| 66 | x509_crl.c |
| 67 | x509_crt.c |
| 68 | x509_csr.c |
| 69 | x509write_crt.c |
| 70 | x509write_csr.c |
| 71 | ) |
| 72 | |
| 73 | set(src_tls |
| 74 | debug.c |
Andres AG | 788aa4a | 2016-09-14 14:32:09 +0100 | [diff] [blame] | 75 | net_sockets.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 76 | ssl_cache.c |
| 77 | ssl_ciphersuites.c |
| 78 | ssl_cli.c |
| 79 | ssl_cookie.c |
| 80 | ssl_srv.c |
| 81 | ssl_ticket.c |
| 82 | ssl_tls.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 83 | ) |
| 84 | |
Paul Bakker | 76f0311 | 2013-11-28 17:20:04 +0100 | [diff] [blame] | 85 | if(CMAKE_COMPILER_IS_GNUCC) |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 86 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes") |
Paul Bakker | 76f0311 | 2013-11-28 17:20:04 +0100 | [diff] [blame] | 87 | endif(CMAKE_COMPILER_IS_GNUCC) |
| 88 | |
Manuel Pégourié-Gonnard | 3185545 | 2014-06-25 15:59:50 +0200 | [diff] [blame] | 89 | if(CMAKE_COMPILER_IS_CLANG) |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 90 | 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] | 91 | endif(CMAKE_COMPILER_IS_CLANG) |
| 92 | |
Manuel Pégourié-Gonnard | ba2c876 | 2015-06-25 09:35:46 +0200 | [diff] [blame] | 93 | if(WIN32) |
| 94 | set(libs ${libs} ws2_32) |
| 95 | endif(WIN32) |
| 96 | |
| 97 | if(USE_PKCS11_HELPER_LIBRARY) |
| 98 | set(libs ${libs} pkcs11-helper) |
| 99 | endif(USE_PKCS11_HELPER_LIBRARY) |
| 100 | |
| 101 | if(ENABLE_ZLIB_SUPPORT) |
| 102 | set(libs ${libs} ${ZLIB_LIBRARIES}) |
| 103 | endif(ENABLE_ZLIB_SUPPORT) |
| 104 | |
| 105 | if(LINK_WITH_PTHREAD) |
| 106 | set(libs ${libs} pthread) |
| 107 | endif() |
| 108 | |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 109 | 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] | 110 | 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] | 111 | endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY) |
Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 112 | |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 113 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 114 | set(mbedtls_static_target "mbedtls_static") |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 115 | set(mbedx509_static_target "mbedx509_static") |
| 116 | set(mbedcrypto_static_target "mbedcrypto_static") |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 117 | elseif(USE_STATIC_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 118 | set(mbedtls_static_target "mbedtls") |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 119 | set(mbedx509_static_target "mbedx509") |
| 120 | set(mbedcrypto_static_target "mbedcrypto") |
hasufell | 3c6409b | 2014-03-06 15:49:08 +0100 | [diff] [blame] | 121 | endif() |
Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 122 | |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 123 | if(USE_STATIC_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 124 | add_library(${mbedcrypto_static_target} STATIC ${src_crypto}) |
| 125 | set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto) |
| 126 | target_link_libraries(${mbedcrypto_static_target} ${libs}) |
Paul Bakker | 6c1f69b | 2014-03-17 15:11:13 +0100 | [diff] [blame] | 127 | |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 128 | add_library(${mbedx509_static_target} STATIC ${src_x509}) |
| 129 | set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) |
| 130 | target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target}) |
| 131 | |
| 132 | add_library(${mbedtls_static_target} STATIC ${src_tls}) |
| 133 | set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) |
| 134 | target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target}) |
| 135 | |
Manuel Pégourié-Gonnard | 6f42417 | 2015-07-24 16:53:46 +0200 | [diff] [blame] | 136 | 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] | 137 | DESTINATION ${LIB_INSTALL_DIR} |
| 138 | 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] | 139 | endif(USE_STATIC_MBEDTLS_LIBRARY) |
Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 140 | |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 141 | if(USE_SHARED_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 142 | add_library(mbedcrypto SHARED ${src_crypto}) |
Janos Follath | 4f09291 | 2017-10-06 15:55:32 +0100 | [diff] [blame] | 143 | set_target_properties(mbedcrypto PROPERTIES VERSION 2.6.1 SOVERSION 0) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 144 | target_link_libraries(mbedcrypto ${libs}) |
Paul Bakker | 2a5c7a8 | 2012-05-10 21:54:28 +0000 | [diff] [blame] | 145 | |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 146 | add_library(mbedx509 SHARED ${src_x509}) |
Janos Follath | 4f09291 | 2017-10-06 15:55:32 +0100 | [diff] [blame] | 147 | set_target_properties(mbedx509 PROPERTIES VERSION 2.6.1 SOVERSION 0) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 148 | target_link_libraries(mbedx509 ${libs} mbedcrypto) |
| 149 | |
| 150 | add_library(mbedtls SHARED ${src_tls}) |
Janos Follath | 4f09291 | 2017-10-06 15:55:32 +0100 | [diff] [blame] | 151 | set_target_properties(mbedtls PROPERTIES VERSION 2.6.1 SOVERSION 10) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 152 | target_link_libraries(mbedtls ${libs} mbedx509) |
| 153 | |
| 154 | install(TARGETS mbedtls mbedx509 mbedcrypto |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 155 | DESTINATION ${LIB_INSTALL_DIR} |
| 156 | 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] | 157 | endif(USE_SHARED_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | e1d34d1 | 2015-06-25 14:53:13 +0200 | [diff] [blame] | 158 | |
| 159 | add_custom_target(lib DEPENDS mbedcrypto mbedx509 mbedtls) |
| 160 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| 161 | add_dependencies(lib mbedcrypto_static mbedx509_static mbedtls_static) |
| 162 | endif() |