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) |
Moshe Shahar | 6763fe4 | 2019-07-24 14:19:35 +0300 | [diff] [blame] | 4 | option(LINK_WITH_TRUSTED_STORAGE "Explicitly link mbed TLS library to trusted_storage." OFF) |
Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 5 | |
Ashley Duncan | d85a7e9 | 2019-04-29 20:35:06 +1200 | [diff] [blame] | 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() |
Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 12 | |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 13 | set(src_crypto |
| 14 | aes.c |
| 15 | aesni.c |
| 16 | arc4.c |
Markku-Juhani O. Saarinen | 3c0b53b | 2017-11-30 16:00:34 +0000 | [diff] [blame] | 17 | aria.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 18 | asn1parse.c |
| 19 | asn1write.c |
| 20 | base64.c |
| 21 | bignum.c |
| 22 | blowfish.c |
| 23 | camellia.c |
| 24 | ccm.c |
Daniel King | 34b822c | 2016-05-15 17:28:08 -0300 | [diff] [blame] | 25 | chacha20.c |
Manuel Pégourié-Gonnard | dca3a5d | 2018-05-07 10:43:27 +0200 | [diff] [blame] | 26 | chachapoly.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 27 | cipher.c |
| 28 | cipher_wrap.c |
Robert Cragie | dc5c7b9 | 2015-12-11 15:49:45 +0000 | [diff] [blame] | 29 | cmac.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 30 | ctr_drbg.c |
| 31 | des.c |
| 32 | dhm.c |
| 33 | ecdh.c |
| 34 | ecdsa.c |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 35 | ecjpake.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 36 | ecp.c |
| 37 | ecp_curves.c |
| 38 | entropy.c |
| 39 | entropy_poll.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 40 | gcm.c |
| 41 | havege.c |
Thomas Fossati | 656864b | 2016-07-17 08:51:22 +0100 | [diff] [blame] | 42 | hkdf.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 43 | hmac_drbg.c |
| 44 | md.c |
| 45 | md2.c |
| 46 | md4.c |
| 47 | md5.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 48 | memory_buffer_alloc.c |
Ron Eldor | cb349ac | 2018-07-15 09:29:47 +0300 | [diff] [blame] | 49 | nist_kw.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 50 | oid.c |
| 51 | padlock.c |
| 52 | pem.c |
| 53 | pk.c |
| 54 | pk_wrap.c |
| 55 | pkcs12.c |
| 56 | pkcs5.c |
| 57 | pkparse.c |
| 58 | pkwrite.c |
| 59 | platform.c |
Andres Amaya Garcia | bc7bdbf | 2018-04-24 08:29:20 -0500 | [diff] [blame] | 60 | platform_util.c |
Daniel King | adc32c0 | 2016-05-16 18:25:45 -0300 | [diff] [blame] | 61 | poly1305.c |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 62 | psa_crypto.c |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 63 | psa_crypto_se.c |
Gilles Peskine | 961849f | 2018-11-30 18:54:54 +0100 | [diff] [blame] | 64 | psa_crypto_slot_management.c |
Darryl Green | db2b8db | 2018-06-15 13:06:04 +0100 | [diff] [blame] | 65 | psa_crypto_storage.c |
Gilles Peskine | 6194dc2 | 2018-11-16 22:24:15 +0100 | [diff] [blame] | 66 | psa_its_file.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 67 | ripemd160.c |
| 68 | rsa.c |
Hanno Becker | a565f54 | 2017-10-11 11:00:19 +0100 | [diff] [blame] | 69 | rsa_internal.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 70 | sha1.c |
| 71 | sha256.c |
| 72 | sha512.c |
| 73 | threading.c |
Manuel Pégourié-Gonnard | 21dcc1e | 2015-06-25 10:59:15 +0200 | [diff] [blame] | 74 | timing.c |
Manuel Pégourié-Gonnard | 463e09d | 2015-06-24 11:54:19 +0200 | [diff] [blame] | 75 | xtea.c |
| 76 | ) |
| 77 | |
Jaeden Amero | 18d4789 | 2019-04-26 12:53:02 +0100 | [diff] [blame] | 78 | # For files generated by the parent project (Mbed TLS) when building Mbed |
| 79 | # Crypto as a submodule, ensure that the parent project instance is used. |
| 80 | if(USE_CRYPTO_SUBMODULE) |
| 81 | set(src_crypto |
| 82 | ${src_crypto} |
Ashley Duncan | d85a7e9 | 2019-04-29 20:35:06 +1200 | [diff] [blame] | 83 | ${MBEDTLS_DIR}/library/version.c |
| 84 | ${MBEDTLS_DIR}/library/version_features.c |
| 85 | ${MBEDTLS_DIR}/library/error.c |
Jaeden Amero | 18d4789 | 2019-04-26 12:53:02 +0100 | [diff] [blame] | 86 | ) |
| 87 | else() |
| 88 | set(src_crypto |
| 89 | ${src_crypto} |
| 90 | version.c |
| 91 | version_features.c |
| 92 | error.c |
| 93 | ) |
| 94 | endif() |
| 95 | |
Christoph M. Wintersteiger | 6ea2dea1 | 2019-01-21 17:26:19 +0000 | [diff] [blame] | 96 | list(APPEND src_crypto ${thirdparty_src}) |
| 97 | |
Paul Bakker | 76f0311 | 2013-11-28 17:20:04 +0100 | [diff] [blame] | 98 | if(CMAKE_COMPILER_IS_GNUCC) |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 99 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes") |
Paul Bakker | 76f0311 | 2013-11-28 17:20:04 +0100 | [diff] [blame] | 100 | endif(CMAKE_COMPILER_IS_GNUCC) |
| 101 | |
Manuel Pégourié-Gonnard | 3185545 | 2014-06-25 15:59:50 +0200 | [diff] [blame] | 102 | if(CMAKE_COMPILER_IS_CLANG) |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 103 | 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] | 104 | endif(CMAKE_COMPILER_IS_CLANG) |
| 105 | |
Gilles Peskine | 1927565 | 2019-01-06 19:48:30 +0000 | [diff] [blame] | 106 | if(UNSAFE_BUILD) |
| 107 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error") |
| 108 | set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -Wno-error") |
| 109 | set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -Wno-error") |
| 110 | endif(UNSAFE_BUILD) |
| 111 | |
Manuel Pégourié-Gonnard | ba2c876 | 2015-06-25 09:35:46 +0200 | [diff] [blame] | 112 | if(WIN32) |
| 113 | set(libs ${libs} ws2_32) |
| 114 | endif(WIN32) |
| 115 | |
Andres Amaya Garcia | bf7fe4f | 2018-06-21 20:21:38 +0100 | [diff] [blame] | 116 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
TabascoEye | 7f3ef27 | 2018-04-27 13:14:59 +0200 | [diff] [blame] | 117 | SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>") |
| 118 | SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>") |
| 119 | SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>") |
| 120 | SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>") |
Andres Amaya Garcia | bf7fe4f | 2018-06-21 20:21:38 +0100 | [diff] [blame] | 121 | endif() |
TabascoEye | 7f3ef27 | 2018-04-27 13:14:59 +0200 | [diff] [blame] | 122 | |
Augustin Cavalier | 60bc47d | 2018-04-11 20:27:32 -0400 | [diff] [blame] | 123 | if(HAIKU) |
Simon Butcher | 6331cb0 | 2018-07-10 11:48:42 +0100 | [diff] [blame] | 124 | set(libs ${libs} network) |
Augustin Cavalier | 60bc47d | 2018-04-11 20:27:32 -0400 | [diff] [blame] | 125 | endif(HAIKU) |
| 126 | |
Manuel Pégourié-Gonnard | ba2c876 | 2015-06-25 09:35:46 +0200 | [diff] [blame] | 127 | if(LINK_WITH_PTHREAD) |
| 128 | set(libs ${libs} pthread) |
| 129 | endif() |
| 130 | |
Moshe Shahar | 7e36765 | 2019-07-15 15:50:19 +0300 | [diff] [blame] | 131 | if(LINK_WITH_TRUSTED_STORAGE) |
| 132 | set(libs ${libs} trusted_storage) |
| 133 | endif() |
| 134 | |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 135 | 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] | 136 | 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] | 137 | endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY) |
Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 138 | |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 139 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 140 | set(mbedcrypto_static_target "mbedcrypto_static") |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 141 | elseif(USE_STATIC_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 142 | set(mbedcrypto_static_target "mbedcrypto") |
hasufell | 3c6409b | 2014-03-06 15:49:08 +0100 | [diff] [blame] | 143 | endif() |
Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 144 | |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 145 | if(USE_STATIC_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 146 | add_library(${mbedcrypto_static_target} STATIC ${src_crypto}) |
| 147 | set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto) |
| 148 | target_link_libraries(${mbedcrypto_static_target} ${libs}) |
Jaeden Amero | c6e4ab0 | 2018-11-01 16:56:08 +0000 | [diff] [blame] | 149 | target_include_directories(${mbedcrypto_static_target} |
Ashley Duncan | d85a7e9 | 2019-04-29 20:35:06 +1200 | [diff] [blame] | 150 | PUBLIC ${MBEDTLS_DIR}/include/ |
| 151 | PUBLIC ${MBEDTLS_DIR}/crypto/include/) |
Paul Bakker | 6c1f69b | 2014-03-17 15:11:13 +0100 | [diff] [blame] | 152 | |
Jaeden Amero | 8298d70 | 2018-11-02 10:11:31 +0000 | [diff] [blame] | 153 | install(TARGETS ${mbedcrypto_static_target} |
| 154 | DESTINATION ${LIB_INSTALL_DIR} |
| 155 | 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] | 156 | endif(USE_STATIC_MBEDTLS_LIBRARY) |
Paul Bakker | 9d3a7e4 | 2011-01-05 15:24:43 +0000 | [diff] [blame] | 157 | |
Manuel Pégourié-Gonnard | 9014b6f | 2015-01-27 15:44:46 +0000 | [diff] [blame] | 158 | if(USE_SHARED_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 159 | add_library(mbedcrypto SHARED ${src_crypto}) |
Janos Follath | 2e9f108 | 2020-01-21 14:08:26 +0000 | [diff] [blame^] | 160 | set_target_properties(mbedcrypto PROPERTIES VERSION 2.20.0 SOVERSION 4) |
Manuel Pégourié-Gonnard | c7781ad | 2015-06-25 09:49:02 +0200 | [diff] [blame] | 161 | target_link_libraries(mbedcrypto ${libs}) |
Jaeden Amero | c6e4ab0 | 2018-11-01 16:56:08 +0000 | [diff] [blame] | 162 | target_include_directories(mbedcrypto |
Ashley Duncan | d85a7e9 | 2019-04-29 20:35:06 +1200 | [diff] [blame] | 163 | PUBLIC ${MBEDTLS_DIR}/include/ |
| 164 | PUBLIC ${MBEDTLS_DIR}/crypto/include/) |
Paul Bakker | 2a5c7a8 | 2012-05-10 21:54:28 +0000 | [diff] [blame] | 165 | |
Jaeden Amero | 8298d70 | 2018-11-02 10:11:31 +0000 | [diff] [blame] | 166 | install(TARGETS mbedcrypto |
| 167 | DESTINATION ${LIB_INSTALL_DIR} |
| 168 | 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] | 169 | endif(USE_SHARED_MBEDTLS_LIBRARY) |
Manuel Pégourié-Gonnard | e1d34d1 | 2015-06-25 14:53:13 +0200 | [diff] [blame] | 170 | |
Jaeden Amero | 5ae1fb6 | 2018-10-29 17:40:05 +0000 | [diff] [blame] | 171 | if(USE_CRYPTO_SUBMODULE) |
| 172 | add_custom_target(crypto_lib DEPENDS mbedcrypto) |
| 173 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| 174 | add_dependencies(crypto_lib mbedcrypto_static) |
| 175 | endif() |
| 176 | else() |
Jaeden Amero | 8298d70 | 2018-11-02 10:11:31 +0000 | [diff] [blame] | 177 | add_custom_target(lib DEPENDS mbedcrypto) |
Jaeden Amero | 5ae1fb6 | 2018-10-29 17:40:05 +0000 | [diff] [blame] | 178 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
Jaeden Amero | 8298d70 | 2018-11-02 10:11:31 +0000 | [diff] [blame] | 179 | add_dependencies(lib mbedcrypto_static) |
Jaeden Amero | 5ae1fb6 | 2018-10-29 17:40:05 +0000 | [diff] [blame] | 180 | endif() |
Manuel Pégourié-Gonnard | e1d34d1 | 2015-06-25 14:53:13 +0200 | [diff] [blame] | 181 | endif() |