blob: f721cd957193fd0b4f14b16ffe0c5ddff47a42a4 [file] [log] [blame]
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +00001option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
2option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF)
Manuel Pégourié-Gonnardcfa9a452015-01-23 13:33:31 +00003option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF)
Paul Bakker9d3a7e42011-01-05 15:24:43 +00004
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +02005set(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 ecp.c
24 ecp_curves.c
25 entropy.c
26 entropy_poll.c
27 error.c
28 gcm.c
29 havege.c
30 hmac_drbg.c
31 md.c
32 md2.c
33 md4.c
34 md5.c
35 md_wrap.c
36 memory_buffer_alloc.c
37 oid.c
38 padlock.c
39 pem.c
40 pk.c
41 pk_wrap.c
42 pkcs12.c
43 pkcs5.c
44 pkparse.c
45 pkwrite.c
46 platform.c
47 ripemd160.c
48 rsa.c
49 sha1.c
50 sha256.c
51 sha512.c
52 threading.c
53 version.c
54 version_features.c
55 xtea.c
56)
57
58set(src_x509
59 certs.c
60 pkcs11.c
61 x509.c
62 x509_create.c
63 x509_crl.c
64 x509_crt.c
65 x509_csr.c
66 x509write_crt.c
67 x509write_csr.c
68)
69
70set(src_tls
71 debug.c
72 net.c
73 ssl_cache.c
74 ssl_ciphersuites.c
75 ssl_cli.c
76 ssl_cookie.c
77 ssl_srv.c
78 ssl_ticket.c
79 ssl_tls.c
80 timing.c
81)
82
Paul Bakker9d3a7e42011-01-05 15:24:43 +000083set(src
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020084 ${src_crypto}
85 ${src_x509}
86 ${src_tls}
Paul Bakker367dae42009-06-28 21:50:27 +000087)
Paul Bakker547f73d2011-01-05 15:07:54 +000088
Paul Bakker2a5c7a82012-05-10 21:54:28 +000089if(WIN32)
90set(libs ws2_32)
91endif(WIN32)
92
Paul Bakker76f03112013-11-28 17:20:04 +010093if(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard98aa1912014-11-14 16:34:36 +010094 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
Paul Bakker76f03112013-11-28 17:20:04 +010095endif(CMAKE_COMPILER_IS_GNUCC)
96
Manuel Pégourié-Gonnard31855452014-06-25 15:59:50 +020097if(CMAKE_COMPILER_IS_CLANG)
Manuel Pégourié-Gonnardedb7ed32015-01-20 16:45:20 +000098 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
Manuel Pégourié-Gonnard31855452014-06-25 15:59:50 +020099endif(CMAKE_COMPILER_IS_CLANG)
100
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000101if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
102 message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
103endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
Paul Bakker9d3a7e42011-01-05 15:24:43 +0000104
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000105if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
hasufell3c6409b2014-03-06 15:49:08 +0100106 # if we build both static an shared, then let
107 # tests and programs link to the shared lib target
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000108 set(mbedtls_static_target "mbedtls_static")
109elseif(USE_STATIC_MBEDTLS_LIBRARY)
110 set(mbedtls_static_target "mbedtls")
hasufell3c6409b2014-03-06 15:49:08 +0100111endif()
Paul Bakker9d3a7e42011-01-05 15:24:43 +0000112
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000113if(USE_STATIC_MBEDTLS_LIBRARY)
114 add_library(${mbedtls_static_target} STATIC ${src})
115 set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
116 target_link_libraries(${mbedtls_static_target} ${libs})
Paul Bakker6c1f69b2014-03-17 15:11:13 +0100117
118 if(ZLIB_FOUND)
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000119 target_link_libraries(${mbedtls_static_target} ${ZLIB_LIBRARIES})
Paul Bakker6c1f69b2014-03-17 15:11:13 +0100120 endif(ZLIB_FOUND)
121
Paul Bakkerd6917f02014-06-09 23:46:41 +0200122 if(LINK_WITH_PTHREAD)
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000123 target_link_libraries(${mbedtls_static_target} pthread)
Paul Bakkerd6917f02014-06-09 23:46:41 +0200124 endif()
Paul Bakker9d3a7e42011-01-05 15:24:43 +0000125
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000126 install(TARGETS ${mbedtls_static_target}
hasufell3c6409b2014-03-06 15:49:08 +0100127 DESTINATION ${LIB_INSTALL_DIR}
128 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
129endif()
Paul Bakker9d3a7e42011-01-05 15:24:43 +0000130
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000131if(USE_SHARED_MBEDTLS_LIBRARY)
132 add_library(mbedtls SHARED ${src})
Manuel Pégourié-Gonnard2a0718d2015-01-29 11:29:12 +0000133 set_target_properties(mbedtls PROPERTIES VERSION 1.4.0 SOVERSION 8)
Paul Bakker9d3a7e42011-01-05 15:24:43 +0000134
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000135 target_link_libraries(mbedtls ${libs})
Paul Bakker2a5c7a82012-05-10 21:54:28 +0000136
hasufell3c6409b2014-03-06 15:49:08 +0100137 if(ZLIB_FOUND)
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000138 target_link_libraries(mbedtls ${ZLIB_LIBRARIES})
hasufell3c6409b2014-03-06 15:49:08 +0100139 endif(ZLIB_FOUND)
Steffan Kargerc2458342013-11-14 10:34:46 +0100140
Paul Bakkerd6917f02014-06-09 23:46:41 +0200141 if(LINK_WITH_PTHREAD)
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000142 target_link_libraries(mbedtls pthread)
Paul Bakkerd6917f02014-06-09 23:46:41 +0200143 endif()
144
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000145 install(TARGETS mbedtls
hasufell3c6409b2014-03-06 15:49:08 +0100146 DESTINATION ${LIB_INSTALL_DIR}
147 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000148endif(USE_SHARED_MBEDTLS_LIBRARY)