Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame^] | 1 | From b8d7d8bd3e447d471f56dc95e0315c965f393edd Mon Sep 17 00:00:00 2001 |
| 2 | From: Gyorgy Szing <Gyorgy.Szing@arm.com> |
| 3 | Date: Tue, 28 Mar 2023 18:20:44 +0200 |
| 4 | Subject: [PATCH 1/1] Add capability to build libmbedcrypto only |
| 5 | |
| 6 | Introduce the CRYPTO_ONLY option which configures cmake to build only |
| 7 | libmbedcrypto. |
| 8 | |
| 9 | Upstream-status: Invalid [other] |
| 10 | - This is a Trusted Services specific change, there is not intention |
| 11 | to upstream this change. |
| 12 | |
| 13 | Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com> |
| 14 | --- |
| 15 | library/CMakeLists.txt | 57 +++++++++++++++++++++++++++++------------- |
| 16 | 1 file changed, 39 insertions(+), 18 deletions(-) |
| 17 | |
| 18 | diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt |
| 19 | index c9714bbfb..d0087c616 100644 |
| 20 | --- a/library/CMakeLists.txt |
| 21 | +++ b/library/CMakeLists.txt |
| 22 | @@ -2,6 +2,7 @@ option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON) |
| 23 | option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF) |
| 24 | option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF) |
| 25 | option(LINK_WITH_TRUSTED_STORAGE "Explicitly link mbed TLS library to trusted_storage." OFF) |
| 26 | +option(CRYPTO_ONLY "Build mbedcrypto linrary only." On) |
| 27 | |
| 28 | # Set the project root directory if it's not already defined, as may happen if |
| 29 | # the library folder is included directly by a parent project, without |
| 30 | @@ -248,18 +249,27 @@ if (USE_STATIC_MBEDTLS_LIBRARY) |
| 31 | set(mbedcrypto_static_target ${mbedcrypto_target}) |
| 32 | endif() |
| 33 | |
| 34 | -set(target_libraries ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) |
| 35 | +set(target_libraries ${mbedcrypto_target}) |
| 36 | + |
| 37 | +if (NOT CRYPTO_ONLY) |
| 38 | + list(APPEND target_libraries ${mbedx509_target} ${mbedtls_target}) |
| 39 | +endif() |
| 40 | |
| 41 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| 42 | string(APPEND mbedtls_static_target "_static") |
| 43 | string(APPEND mbedx509_static_target "_static") |
| 44 | string(APPEND mbedcrypto_static_target "_static") |
| 45 | |
| 46 | + |
| 47 | + list(APPEND target_libraries |
| 48 | + ${mbedcrypto_static_target}) |
| 49 | + |
| 50 | +if (NOT CRYPTO_ONLY) |
| 51 | list(APPEND target_libraries |
| 52 | - ${mbedcrypto_static_target} |
| 53 | ${mbedx509_static_target} |
| 54 | ${mbedtls_static_target}) |
| 55 | endif() |
| 56 | +endif() |
| 57 | |
| 58 | if(USE_STATIC_MBEDTLS_LIBRARY) |
| 59 | add_library(${mbedcrypto_static_target} STATIC ${src_crypto}) |
| 60 | @@ -270,13 +280,15 @@ if(USE_STATIC_MBEDTLS_LIBRARY) |
| 61 | target_link_libraries(${mbedcrypto_static_target} PUBLIC everest) |
| 62 | endif() |
| 63 | |
| 64 | - add_library(${mbedx509_static_target} STATIC ${src_x509}) |
| 65 | - set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) |
| 66 | - target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target}) |
| 67 | + if (NOT CRYPTO_ONLY) |
| 68 | + add_library(${mbedx509_static_target} STATIC ${src_x509}) |
| 69 | + set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) |
| 70 | + target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target}) |
| 71 | |
| 72 | - add_library(${mbedtls_static_target} STATIC ${src_tls}) |
| 73 | - set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) |
| 74 | - target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target}) |
| 75 | + add_library(${mbedtls_static_target} STATIC ${src_tls}) |
| 76 | + set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) |
| 77 | + target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target}) |
| 78 | + endif() |
| 79 | endif(USE_STATIC_MBEDTLS_LIBRARY) |
| 80 | |
| 81 | if(USE_SHARED_MBEDTLS_LIBRARY) |
| 82 | @@ -288,14 +300,15 @@ if(USE_SHARED_MBEDTLS_LIBRARY) |
| 83 | if(TARGET everest) |
| 84 | target_link_libraries(${mbedcrypto_target} PUBLIC everest) |
| 85 | endif() |
| 86 | - |
| 87 | - add_library(${mbedx509_target} SHARED ${src_x509}) |
| 88 | - set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.3.0 SOVERSION 4) |
| 89 | - target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target}) |
| 90 | - |
| 91 | - add_library(${mbedtls_target} SHARED ${src_tls}) |
| 92 | - set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.3.0 SOVERSION 19) |
| 93 | - target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target}) |
| 94 | + if (NOT CRYPTO_ONLY) |
| 95 | + add_library(${mbedx509_target} SHARED ${src_x509}) |
| 96 | + set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.3.0 SOVERSION 4) |
| 97 | + target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target}) |
| 98 | + |
| 99 | + add_library(${mbedtls_target} SHARED ${src_tls}) |
| 100 | + set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.3.0 SOVERSION 19) |
| 101 | + target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target}) |
| 102 | + endif() |
| 103 | endif(USE_SHARED_MBEDTLS_LIBRARY) |
| 104 | |
| 105 | foreach(target IN LISTS target_libraries) |
| 106 | @@ -320,7 +333,15 @@ endforeach(target) |
| 107 | |
| 108 | set(lib_target "${MBEDTLS_TARGET_PREFIX}lib") |
| 109 | |
| 110 | -add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) |
| 111 | +add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target}) |
| 112 | + |
| 113 | +if(NOT CRYPTO_ONLY) |
| 114 | + add_dependencies(${lib_target} ${mbedx509_target} ${mbedtls_target}) |
| 115 | +endif() |
| 116 | + |
| 117 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| 118 | - add_dependencies(${lib_target} ${mbedcrypto_static_target} ${mbedx509_static_target} ${mbedtls_static_target}) |
| 119 | + add_dependencies(${lib_target} ${mbedcrypto_static_target}) |
| 120 | + if(NOT CRYPTO_ONLY) |
| 121 | + add_dependencies(${lib_target} ${mbedx509_static_target} ${mbedtls_static_target}) |
| 122 | + endif() |
| 123 | endif() |
| 124 | -- |
| 125 | 2.39.1.windows.1 |
| 126 | |