| 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 |
|
|---|
| 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
|
|---|
| 18 | ctr_drbg.c
|
|---|
| 19 | des.c
|
|---|
| 20 | dhm.c
|
|---|
| 21 | ecdh.c
|
|---|
| 22 | ecdsa.c
|
|---|
| 23 | ecjpake.c
|
|---|
| 24 | ecp.c
|
|---|
| 25 | ecp_curves.c
|
|---|
| 26 | entropy.c
|
|---|
| 27 | entropy_poll.c
|
|---|
| 28 | error.c
|
|---|
| 29 | gcm.c
|
|---|
| 30 | havege.c
|
|---|
| 31 | hmac_drbg.c
|
|---|
| 32 | md.c
|
|---|
| 33 | md2.c
|
|---|
| 34 | md4.c
|
|---|
| 35 | md5.c
|
|---|
| 36 | md_wrap.c
|
|---|
| 37 | memory_buffer_alloc.c
|
|---|
| 38 | oid.c
|
|---|
| 39 | padlock.c
|
|---|
| 40 | pem.c
|
|---|
| 41 | pk.c
|
|---|
| 42 | pk_wrap.c
|
|---|
| 43 | pkcs12.c
|
|---|
| 44 | pkcs5.c
|
|---|
| 45 | pkparse.c
|
|---|
| 46 | pkwrite.c
|
|---|
| 47 | platform.c
|
|---|
| 48 | ripemd160.c
|
|---|
| 49 | rsa.c
|
|---|
| 50 | sha1.c
|
|---|
| 51 | sha256.c
|
|---|
| 52 | sha512.c
|
|---|
| 53 | threading.c
|
|---|
| 54 | timing.c
|
|---|
| 55 | version.c
|
|---|
| 56 | version_features.c
|
|---|
| 57 | xtea.c
|
|---|
| 58 | )
|
|---|
| 59 |
|
|---|
| 60 | set(src_x509
|
|---|
| 61 | certs.c
|
|---|
| 62 | pkcs11.c
|
|---|
| 63 | x509.c
|
|---|
| 64 | x509_create.c
|
|---|
| 65 | x509_crl.c
|
|---|
| 66 | x509_crt.c
|
|---|
| 67 | x509_csr.c
|
|---|
| 68 | x509write_crt.c
|
|---|
| 69 | x509write_csr.c
|
|---|
| 70 | )
|
|---|
| 71 |
|
|---|
| 72 | set(src_tls
|
|---|
| 73 | debug.c
|
|---|
| 74 | net.c
|
|---|
| 75 | ssl_cache.c
|
|---|
| 76 | ssl_ciphersuites.c
|
|---|
| 77 | ssl_cli.c
|
|---|
| 78 | ssl_cookie.c
|
|---|
| 79 | ssl_srv.c
|
|---|
| 80 | ssl_ticket.c
|
|---|
| 81 | ssl_tls.c
|
|---|
| 82 | )
|
|---|
| 83 |
|
|---|
| 84 | if(CMAKE_COMPILER_IS_GNUCC)
|
|---|
| 85 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
|
|---|
| 86 | endif(CMAKE_COMPILER_IS_GNUCC)
|
|---|
| 87 |
|
|---|
| 88 | if(CMAKE_COMPILER_IS_CLANG)
|
|---|
| 89 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
|
|---|
| 90 | endif(CMAKE_COMPILER_IS_CLANG)
|
|---|
| 91 |
|
|---|
| 92 | if(WIN32)
|
|---|
| 93 | set(libs ${libs} ws2_32)
|
|---|
| 94 | endif(WIN32)
|
|---|
| 95 |
|
|---|
| 96 | if(USE_PKCS11_HELPER_LIBRARY)
|
|---|
| 97 | set(libs ${libs} pkcs11-helper)
|
|---|
| 98 | endif(USE_PKCS11_HELPER_LIBRARY)
|
|---|
| 99 |
|
|---|
| 100 | if(ENABLE_ZLIB_SUPPORT)
|
|---|
| 101 | set(libs ${libs} ${ZLIB_LIBRARIES})
|
|---|
| 102 | endif(ENABLE_ZLIB_SUPPORT)
|
|---|
| 103 |
|
|---|
| 104 | if(LINK_WITH_PTHREAD)
|
|---|
| 105 | set(libs ${libs} pthread)
|
|---|
| 106 | endif()
|
|---|
| 107 |
|
|---|
| 108 | if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
|
|---|
| 109 | message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
|
|---|
| 110 | endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
|
|---|
| 111 |
|
|---|
| 112 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
|
|---|
| 113 | set(mbedtls_static_target "mbedtls_static")
|
|---|
| 114 | set(mbedx509_static_target "mbedx509_static")
|
|---|
| 115 | set(mbedcrypto_static_target "mbedcrypto_static")
|
|---|
| 116 | elseif(USE_STATIC_MBEDTLS_LIBRARY)
|
|---|
| 117 | set(mbedtls_static_target "mbedtls")
|
|---|
| 118 | set(mbedx509_static_target "mbedx509")
|
|---|
| 119 | set(mbedcrypto_static_target "mbedcrypto")
|
|---|
| 120 | endif()
|
|---|
| 121 |
|
|---|
| 122 | if(USE_STATIC_MBEDTLS_LIBRARY)
|
|---|
| 123 | add_library(${mbedcrypto_static_target} STATIC ${src_crypto})
|
|---|
| 124 | set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
|
|---|
| 125 | target_link_libraries(${mbedcrypto_static_target} ${libs})
|
|---|
| 126 |
|
|---|
| 127 | add_library(${mbedx509_static_target} STATIC ${src_x509})
|
|---|
| 128 | set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
|
|---|
| 129 | target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target})
|
|---|
| 130 |
|
|---|
| 131 | add_library(${mbedtls_static_target} STATIC ${src_tls})
|
|---|
| 132 | set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
|
|---|
| 133 | target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target})
|
|---|
| 134 |
|
|---|
| 135 | install(TARGETS ${mbedtls_static_target} ${mbedx509_static_target} ${mbedcrypto_static_target}
|
|---|
| 136 | DESTINATION ${LIB_INSTALL_DIR}
|
|---|
| 137 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
|---|
| 138 | endif(USE_STATIC_MBEDTLS_LIBRARY)
|
|---|
| 139 |
|
|---|
| 140 | if(USE_SHARED_MBEDTLS_LIBRARY)
|
|---|
| 141 | add_library(mbedcrypto SHARED ${src_crypto})
|
|---|
| 142 | set_target_properties(mbedcrypto PROPERTIES VERSION 2.2.1 SOVERSION 0)
|
|---|
| 143 | target_link_libraries(mbedcrypto ${libs})
|
|---|
| 144 |
|
|---|
| 145 | add_library(mbedx509 SHARED ${src_x509})
|
|---|
| 146 | set_target_properties(mbedx509 PROPERTIES VERSION 2.2.1 SOVERSION 0)
|
|---|
| 147 | target_link_libraries(mbedx509 ${libs} mbedcrypto)
|
|---|
| 148 |
|
|---|
| 149 | add_library(mbedtls SHARED ${src_tls})
|
|---|
| 150 | set_target_properties(mbedtls PROPERTIES VERSION 2.2.1 SOVERSION 10)
|
|---|
| 151 | target_link_libraries(mbedtls ${libs} mbedx509)
|
|---|
| 152 |
|
|---|
| 153 | install(TARGETS mbedtls mbedx509 mbedcrypto
|
|---|
| 154 | DESTINATION ${LIB_INSTALL_DIR}
|
|---|
| 155 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
|---|
| 156 | endif(USE_SHARED_MBEDTLS_LIBRARY)
|
|---|
| 157 |
|
|---|
| 158 | add_custom_target(lib DEPENDS mbedcrypto mbedx509 mbedtls)
|
|---|
| 159 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
|
|---|
| 160 | add_dependencies(lib mbedcrypto_static mbedx509_static mbedtls_static)
|
|---|
| 161 | endif()
|
|---|