| 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 |
option(LINK_WITH_TRUSTED_STORAGE "Explicitly link mbed TLS library to trusted_storage." OFF) |
| 5 |
|
| 6 |
# Set the project root directory if it's not already defined, as may happen if |
| 7 |
# the library folder is included directly by a parent project, without |
| 8 |
# including the top level CMakeLists.txt. |
| 9 |
if(NOT DEFINED MBEDTLS_DIR) |
| 10 |
set(MBEDTLS_DIR ${CMAKE_SOURCE_DIR}) |
| 11 |
endif() |
| 12 |
|
| 13 |
set(src_crypto |
| 14 |
aes.c |
| 15 |
aesni.c |
| 16 |
arc4.c |
| 17 |
aria.c |
| 18 |
asn1parse.c |
| 19 |
asn1write.c |
| 20 |
base64.c |
| 21 |
bignum.c |
| 22 |
blowfish.c |
| 23 |
camellia.c |
| 24 |
ccm.c |
| 25 |
chacha20.c |
| 26 |
chachapoly.c |
| 27 |
cipher.c |
| 28 |
cipher_wrap.c |
| 29 |
constant_time.c |
| 30 |
cmac.c |
| 31 |
ctr_drbg.c |
| 32 |
des.c |
| 33 |
dhm.c |
| 34 |
ecdh.c |
| 35 |
ecdsa.c |
| 36 |
ecjpake.c |
| 37 |
ecp.c |
| 38 |
ecp_curves.c |
| 39 |
entropy.c |
| 40 |
entropy_poll.c |
| 41 |
error.c |
| 42 |
gcm.c |
| 43 |
havege.c |
| 44 |
hkdf.c |
| 45 |
hmac_drbg.c |
| 46 |
md.c |
| 47 |
md2.c |
| 48 |
md4.c |
| 49 |
md5.c |
| 50 |
memory_buffer_alloc.c |
| 51 |
mps_reader.c |
| 52 |
mps_trace.c |
| 53 |
nist_kw.c |
| 54 |
oid.c |
| 55 |
padlock.c |
| 56 |
pem.c |
| 57 |
pk.c |
| 58 |
pk_wrap.c |
| 59 |
pkcs12.c |
| 60 |
pkcs5.c |
| 61 |
pkparse.c |
| 62 |
pkwrite.c |
| 63 |
platform.c |
| 64 |
platform_util.c |
| 65 |
poly1305.c |
| 66 |
psa_crypto.c |
| 67 |
psa_crypto_aead.c |
| 68 |
psa_crypto_cipher.c |
| 69 |
psa_crypto_client.c |
| 70 |
psa_crypto_driver_wrappers.c |
| 71 |
psa_crypto_ecp.c |
| 72 |
psa_crypto_hash.c |
| 73 |
psa_crypto_mac.c |
| 74 |
psa_crypto_rsa.c |
| 75 |
psa_crypto_se.c |
| 76 |
psa_crypto_slot_management.c |
| 77 |
psa_crypto_storage.c |
| 78 |
psa_its_file.c |
| 79 |
ripemd160.c |
| 80 |
rsa.c |
| 81 |
rsa_internal.c |
| 82 |
sha1.c |
| 83 |
sha256.c |
| 84 |
sha512.c |
| 85 |
threading.c |
| 86 |
timing.c |
| 87 |
version.c |
| 88 |
version_features.c |
| 89 |
xtea.c |
| 90 |
) |
| 91 |
|
| 92 |
list(APPEND src_crypto ${thirdparty_src}) |
| 93 |
|
| 94 |
set(src_x509 |
| 95 |
certs.c |
| 96 |
pkcs11.c |
| 97 |
x509.c |
| 98 |
x509_create.c |
| 99 |
x509_crl.c |
| 100 |
x509_crt.c |
| 101 |
x509_csr.c |
| 102 |
x509write_crt.c |
| 103 |
x509write_csr.c |
| 104 |
) |
| 105 |
|
| 106 |
set(src_tls |
| 107 |
debug.c |
| 108 |
net_sockets.c |
| 109 |
ssl_cache.c |
| 110 |
ssl_ciphersuites.c |
| 111 |
ssl_cli.c |
| 112 |
ssl_cookie.c |
| 113 |
ssl_msg.c |
| 114 |
ssl_srv.c |
| 115 |
ssl_ticket.c |
| 116 |
ssl_tls.c |
| 117 |
ssl_tls13_keys.c |
| 118 |
) |
| 119 |
|
| 120 |
if(CMAKE_COMPILER_IS_GNUCC) |
| 121 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes") |
| 122 |
endif(CMAKE_COMPILER_IS_GNUCC) |
| 123 |
|
| 124 |
if(CMAKE_COMPILER_IS_CLANG) |
| 125 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wunreachable-code") |
| 126 |
endif(CMAKE_COMPILER_IS_CLANG) |
| 127 |
|
| 128 |
if(WIN32) |
| 129 |
set(libs ${libs} ws2_32) |
| 130 |
endif(WIN32) |
| 131 |
|
| 132 |
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 133 |
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>") |
| 134 |
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>") |
| 135 |
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>") |
| 136 |
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>") |
| 137 |
endif() |
| 138 |
|
| 139 |
if(HAIKU) |
| 140 |
set(libs ${libs} network) |
| 141 |
endif(HAIKU) |
| 142 |
|
| 143 |
if(USE_PKCS11_HELPER_LIBRARY) |
| 144 |
set(libs ${libs} pkcs11-helper) |
| 145 |
endif(USE_PKCS11_HELPER_LIBRARY) |
| 146 |
|
| 147 |
if(ENABLE_ZLIB_SUPPORT) |
| 148 |
set(libs ${libs} ${ZLIB_LIBRARIES}) |
| 149 |
endif(ENABLE_ZLIB_SUPPORT) |
| 150 |
|
| 151 |
if(LINK_WITH_PTHREAD) |
| 152 |
set(libs ${libs} pthread) |
| 153 |
endif() |
| 154 |
|
| 155 |
if(LINK_WITH_TRUSTED_STORAGE) |
| 156 |
set(libs ${libs} trusted_storage) |
| 157 |
endif() |
| 158 |
|
| 159 |
if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY) |
| 160 |
message(FATAL_ERROR "Need to choose static or shared mbedtls build!") |
| 161 |
endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY) |
| 162 |
|
| 163 |
set(mbedtls_target "${MBEDTLS_TARGET_PREFIX}mbedtls") |
| 164 |
set(mbedx509_target "${MBEDTLS_TARGET_PREFIX}mbedx509") |
| 165 |
set(mbedcrypto_target "${MBEDTLS_TARGET_PREFIX}mbedcrypto") |
| 166 |
|
| 167 |
set(mbedtls_target ${mbedtls_target} PARENT_SCOPE) |
| 168 |
set(mbedx509_target ${mbedx509_target} PARENT_SCOPE) |
| 169 |
set(mbedcrypto_target ${mbedcrypto_target} PARENT_SCOPE) |
| 170 |
|
| 171 |
if (USE_STATIC_MBEDTLS_LIBRARY) |
| 172 |
set(mbedtls_static_target ${mbedtls_target}) |
| 173 |
set(mbedx509_static_target ${mbedx509_target}) |
| 174 |
set(mbedcrypto_static_target ${mbedcrypto_target}) |
| 175 |
endif() |
| 176 |
|
| 177 |
set(target_libraries ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) |
| 178 |
|
| 179 |
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| 180 |
string(APPEND mbedtls_static_target "_static") |
| 181 |
string(APPEND mbedx509_static_target "_static") |
| 182 |
string(APPEND mbedcrypto_static_target "_static") |
| 183 |
|
| 184 |
list(APPEND target_libraries |
| 185 |
${mbedcrypto_static_target} |
| 186 |
${mbedx509_static_target} |
| 187 |
${mbedtls_static_target}) |
| 188 |
endif() |
| 189 |
|
| 190 |
if(USE_STATIC_MBEDTLS_LIBRARY) |
| 191 |
add_library(${mbedcrypto_static_target} STATIC ${src_crypto}) |
| 192 |
dolphin_disable_warnings(${mbedcrypto_static_target}) |
| 193 |
set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto) |
| 194 |
target_link_libraries(${mbedcrypto_static_target} PUBLIC ${libs}) |
| 195 |
|
| 196 |
add_library(${mbedx509_static_target} STATIC ${src_x509}) |
| 197 |
dolphin_disable_warnings(${mbedx509_static_target}) |
| 198 |
set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) |
| 199 |
target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target}) |
| 200 |
|
| 201 |
add_library(${mbedtls_static_target} STATIC ${src_tls}) |
| 202 |
dolphin_disable_warnings(${mbedtls_static_target}) |
| 203 |
set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) |
| 204 |
target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target}) |
| 205 |
endif(USE_STATIC_MBEDTLS_LIBRARY) |
| 206 |
|
| 207 |
if(USE_SHARED_MBEDTLS_LIBRARY) |
| 208 |
add_library(${mbedcrypto_target} SHARED ${src_crypto}) |
| 209 |
dolphin_disable_warnings(${mbedcrypto_target}) |
| 210 |
set_target_properties(${mbedcrypto_target} PROPERTIES VERSION 2.28.0 SOVERSION 7) |
| 211 |
target_link_libraries(${mbedcrypto_target} PUBLIC ${libs}) |
| 212 |
|
| 213 |
add_library(${mbedx509_target} SHARED ${src_x509}) |
| 214 |
dolphin_disable_warnings(${mbedx509_target}) |
| 215 |
set_target_properties(${mbedx509_target} PROPERTIES VERSION 2.28.0 SOVERSION 1) |
| 216 |
target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target}) |
| 217 |
|
| 218 |
add_library(${mbedtls_target} SHARED ${src_tls}) |
| 219 |
dolphin_disable_warnings(${mbedtls_target}) |
| 220 |
set_target_properties(${mbedtls_target} PROPERTIES VERSION 2.28.0 SOVERSION 14) |
| 221 |
target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target}) |
| 222 |
endif(USE_SHARED_MBEDTLS_LIBRARY) |
| 223 |
|
| 224 |
foreach(target IN LISTS target_libraries) |
| 225 |
add_library(MbedTLS::${target} ALIAS ${target}) # add_subdirectory support |
| 226 |
# Include public header files from /include and other directories |
| 227 |
# declared by /3rdparty/**/CMakeLists.txt. Include private header files |
| 228 |
# from /library and others declared by /3rdparty/**/CMakeLists.txt. |
| 229 |
# /library needs to be listed explicitly when building .c files outside |
| 230 |
# of /library (which currently means: under /3rdparty). |
| 231 |
target_include_directories(${target} |
| 232 |
PUBLIC ${MBEDTLS_DIR}/include/ |
| 233 |
PUBLIC ${thirdparty_inc_public} |
| 234 |
PRIVATE ${MBEDTLS_DIR}/library/ |
| 235 |
PRIVATE ${thirdparty_inc}) |
| 236 |
target_compile_definitions(${target} |
| 237 |
PRIVATE ${thirdparty_def}) |
| 238 |
install(TARGETS ${target} |
| 239 |
DESTINATION ${LIB_INSTALL_DIR} |
| 240 |
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) |
| 241 |
endforeach(target) |
| 242 |
|
| 243 |
set(lib_target "${MBEDTLS_TARGET_PREFIX}lib") |
| 244 |
|
| 245 |
add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) |
| 246 |
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| 247 |
add_dependencies(${lib_target} ${mbedcrypto_static_target} ${mbedx509_static_target} ${mbedtls_static_target}) |
| 248 |
endif() |