blob: 15443259bc082474b6abeec7055f33fdd119edd1 [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
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +00009 aria.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020010 asn1parse.c
11 asn1write.c
12 base64.c
13 bignum.c
14 blowfish.c
15 camellia.c
16 ccm.c
Daniel King34b822c2016-05-15 17:28:08 -030017 chacha20.c
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020018 chachapoly.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020019 cipher.c
20 cipher_wrap.c
Robert Cragiedc5c7b92015-12-11 15:49:45 +000021 cmac.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020022 ctr_drbg.c
23 des.c
24 dhm.c
25 ecdh.c
26 ecdsa.c
Manuel Pégourié-Gonnard4d8685b2015-08-05 15:44:42 +020027 ecjpake.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020028 ecp.c
29 ecp_curves.c
30 entropy.c
31 entropy_poll.c
32 error.c
33 gcm.c
34 havege.c
Thomas Fossati656864b2016-07-17 08:51:22 +010035 hkdf.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020036 hmac_drbg.c
37 md.c
38 md2.c
39 md4.c
40 md5.c
41 md_wrap.c
42 memory_buffer_alloc.c
Ron Eldorcb349ac2018-07-15 09:29:47 +030043 nist_kw.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020044 oid.c
45 padlock.c
46 pem.c
47 pk.c
48 pk_wrap.c
49 pkcs12.c
50 pkcs5.c
51 pkparse.c
52 pkwrite.c
53 platform.c
Andres Amaya Garciabc7bdbf2018-04-24 08:29:20 -050054 platform_util.c
Daniel Kingadc32c02016-05-16 18:25:45 -030055 poly1305.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020056 ripemd160.c
57 rsa.c
Hanno Beckera565f542017-10-11 11:00:19 +010058 rsa_internal.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020059 sha1.c
60 sha256.c
61 sha512.c
62 threading.c
Manuel Pégourié-Gonnard21dcc1e2015-06-25 10:59:15 +020063 timing.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020064 version.c
65 version_features.c
66 xtea.c
67)
68
Christoph M. Wintersteiger655ddab2019-01-21 17:26:19 +000069list(APPEND src_crypto ${thirdparty_src})
70
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020071set(src_x509
72 certs.c
73 pkcs11.c
74 x509.c
75 x509_create.c
76 x509_crl.c
77 x509_crt.c
78 x509_csr.c
79 x509write_crt.c
80 x509write_csr.c
81)
82
83set(src_tls
84 debug.c
Andres AG788aa4a2016-09-14 14:32:09 +010085 net_sockets.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020086 ssl_cache.c
87 ssl_ciphersuites.c
88 ssl_cli.c
89 ssl_cookie.c
Hanno Becker6e7051a2020-02-05 11:33:54 +000090 ssl_msg.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020091 ssl_srv.c
92 ssl_ticket.c
Hanno Becker471c0c92020-02-05 11:32:03 +000093 ssl_tls.c
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020094)
95
Paul Bakker76f03112013-11-28 17:20:04 +010096if(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard216a1832015-06-25 09:20:03 +020097 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
Paul Bakker76f03112013-11-28 17:20:04 +010098endif(CMAKE_COMPILER_IS_GNUCC)
99
Manuel Pégourié-Gonnard31855452014-06-25 15:59:50 +0200100if(CMAKE_COMPILER_IS_CLANG)
Manuel Pégourié-Gonnard216a1832015-06-25 09:20:03 +0200101 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 +0200102endif(CMAKE_COMPILER_IS_CLANG)
103
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000104if(UNSAFE_BUILD)
105 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
106 set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -Wno-error")
107 set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -Wno-error")
108endif(UNSAFE_BUILD)
109
Manuel Pégourié-Gonnardba2c8762015-06-25 09:35:46 +0200110if(WIN32)
111 set(libs ${libs} ws2_32)
112endif(WIN32)
113
Andres Amaya Garciabf7fe4f2018-06-21 20:21:38 +0100114if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
TabascoEye7f3ef272018-04-27 13:14:59 +0200115 SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
116 SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
117 SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
118 SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
Andres Amaya Garciabf7fe4f2018-06-21 20:21:38 +0100119endif()
TabascoEye7f3ef272018-04-27 13:14:59 +0200120
Augustin Cavalier60bc47d2018-04-11 20:27:32 -0400121if(HAIKU)
Simon Butcher6331cb02018-07-10 11:48:42 +0100122 set(libs ${libs} network)
Augustin Cavalier60bc47d2018-04-11 20:27:32 -0400123endif(HAIKU)
124
Manuel Pégourié-Gonnardba2c8762015-06-25 09:35:46 +0200125if(USE_PKCS11_HELPER_LIBRARY)
126 set(libs ${libs} pkcs11-helper)
127endif(USE_PKCS11_HELPER_LIBRARY)
128
129if(ENABLE_ZLIB_SUPPORT)
130 set(libs ${libs} ${ZLIB_LIBRARIES})
131endif(ENABLE_ZLIB_SUPPORT)
132
133if(LINK_WITH_PTHREAD)
134 set(libs ${libs} pthread)
135endif()
136
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000137if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
Manuel Pégourié-Gonnard216a1832015-06-25 09:20:03 +0200138 message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000139endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
Paul Bakker9d3a7e42011-01-05 15:24:43 +0000140
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000141if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
Manuel Pégourié-Gonnard216a1832015-06-25 09:20:03 +0200142 set(mbedtls_static_target "mbedtls_static")
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200143 set(mbedx509_static_target "mbedx509_static")
144 set(mbedcrypto_static_target "mbedcrypto_static")
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000145elseif(USE_STATIC_MBEDTLS_LIBRARY)
Manuel Pégourié-Gonnard216a1832015-06-25 09:20:03 +0200146 set(mbedtls_static_target "mbedtls")
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200147 set(mbedx509_static_target "mbedx509")
148 set(mbedcrypto_static_target "mbedcrypto")
hasufell3c6409b2014-03-06 15:49:08 +0100149endif()
Paul Bakker9d3a7e42011-01-05 15:24:43 +0000150
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000151if(USE_STATIC_MBEDTLS_LIBRARY)
Paul Bakker6c1f69b2014-03-17 15:11:13 +0100152
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200153 add_library(${mbedx509_static_target} STATIC ${src_x509})
154 set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
155 target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target})
Jaeden Amero30b340a2018-10-25 17:37:00 +0100156 target_include_directories(${mbedx509_static_target}
Ashley Duncaneb339782019-04-29 20:35:06 +1200157 PUBLIC ${MBEDTLS_DIR}/include/
158 PUBLIC ${MBEDTLS_DIR}/crypto/include/)
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200159
160 add_library(${mbedtls_static_target} STATIC ${src_tls})
161 set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
162 target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target})
Jaeden Amero30b340a2018-10-25 17:37:00 +0100163 target_include_directories(${mbedtls_static_target}
Ashley Duncaneb339782019-04-29 20:35:06 +1200164 PUBLIC ${MBEDTLS_DIR}/include/
165 PUBLIC ${MBEDTLS_DIR}/crypto/include/
Jaeden Amero30b340a2018-10-25 17:37:00 +0100166 )
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200167
Andrzej Kurek346747c2019-04-17 04:19:37 -0400168
169 install(TARGETS ${mbedtls_static_target} ${mbedx509_static_target}
170 DESTINATION ${LIB_INSTALL_DIR}
171 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
172
Manuel Pégourié-Gonnarde1d34d12015-06-25 14:53:13 +0200173endif(USE_STATIC_MBEDTLS_LIBRARY)
Paul Bakker9d3a7e42011-01-05 15:24:43 +0000174
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000175if(USE_SHARED_MBEDTLS_LIBRARY)
Paul Bakker2a5c7a82012-05-10 21:54:28 +0000176
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200177 add_library(mbedx509 SHARED ${src_x509})
Janos Follath83f33d32020-01-20 14:52:29 +0000178 set_target_properties(mbedx509 PROPERTIES VERSION 2.20.0 SOVERSION 1)
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200179 target_link_libraries(mbedx509 ${libs} mbedcrypto)
Jaeden Amero30b340a2018-10-25 17:37:00 +0100180 target_include_directories(mbedx509
Ashley Duncaneb339782019-04-29 20:35:06 +1200181 PUBLIC ${MBEDTLS_DIR}/include/
182 PUBLIC ${MBEDTLS_DIR}/crypto/include/)
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200183
184 add_library(mbedtls SHARED ${src_tls})
Janos Follath83f33d32020-01-20 14:52:29 +0000185 set_target_properties(mbedtls PROPERTIES VERSION 2.20.0 SOVERSION 13)
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200186 target_link_libraries(mbedtls ${libs} mbedx509)
Jaeden Amero30b340a2018-10-25 17:37:00 +0100187 target_include_directories(mbedtls
Ashley Duncaneb339782019-04-29 20:35:06 +1200188 PUBLIC ${MBEDTLS_DIR}/include/
189 PUBLIC ${MBEDTLS_DIR}/crypto/include/)
Manuel Pégourié-Gonnardc7781ad2015-06-25 09:49:02 +0200190
Andrzej Kurek346747c2019-04-17 04:19:37 -0400191 install(TARGETS mbedtls mbedx509
192 DESTINATION ${LIB_INSTALL_DIR}
193 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
194
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000195endif(USE_SHARED_MBEDTLS_LIBRARY)
Manuel Pégourié-Gonnarde1d34d12015-06-25 14:53:13 +0200196
Andrzej Kurek346747c2019-04-17 04:19:37 -0400197add_custom_target(lib DEPENDS mbedx509 mbedtls)
198if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
199 add_dependencies(lib mbedx509_static mbedtls_static)
Manuel Pégourié-Gonnarde1d34d12015-06-25 14:53:13 +0200200endif()