| From d225c9ba98e8aafdd462bdff3f8159886a89e1d3 Mon Sep 17 00:00:00 2001 |
| From: Gyorgy Szing <Gyorgy.Szing@arm.com> |
| Date: Tue, 28 Mar 2023 18:20:44 +0200 |
| Subject: [PATCH] Add capability to build libmbedcrypto only |
| |
| Introduce the CRYPTO_ONLY option which configures cmake to build only |
| libmbedcrypto. |
| |
| Upstream-status: Invalid [other] |
| - This is a Trusted Services specific change, there is not intention |
| to upstream this change. |
| |
| Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com> |
| Signed-off-by: Balint Dobszay <balint.dobszay@arm.com> |
| --- |
| library/CMakeLists.txt | 60 ++++++++++++++++++++++++++++-------------- |
| 1 file changed, 40 insertions(+), 20 deletions(-) |
| |
| diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt |
| index 535988303..a70848e82 100644 |
| --- a/library/CMakeLists.txt |
| +++ b/library/CMakeLists.txt |
| @@ -2,6 +2,7 @@ option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON) |
| option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF) |
| option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF) |
| option(LINK_WITH_TRUSTED_STORAGE "Explicitly link mbed TLS library to trusted_storage." OFF) |
| +option(CRYPTO_ONLY "Build mbedcrypto library only." On) |
| |
| # Set the project root directory if it's not already defined, as may happen if |
| # the library folder is included directly by a parent project, without |
| @@ -250,7 +251,11 @@ if (USE_STATIC_MBEDTLS_LIBRARY) |
| set(mbedcrypto_static_target ${mbedcrypto_target}) |
| endif() |
| |
| -set(target_libraries ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) |
| +set(target_libraries ${mbedcrypto_target}) |
| + |
| +if (NOT CRYPTO_ONLY) |
| + list(APPEND target_libraries ${mbedx509_target} ${mbedtls_target}) |
| +endif() |
| |
| if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| string(APPEND mbedtls_static_target "_static") |
| @@ -258,9 +263,13 @@ if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| string(APPEND mbedcrypto_static_target "_static") |
| |
| list(APPEND target_libraries |
| - ${mbedcrypto_static_target} |
| - ${mbedx509_static_target} |
| - ${mbedtls_static_target}) |
| + ${mbedcrypto_static_target}) |
| + |
| + if (NOT CRYPTO_ONLY) |
| + list(APPEND target_libraries |
| + ${mbedx509_static_target} |
| + ${mbedtls_static_target}) |
| + endif() |
| endif() |
| |
| if(USE_STATIC_MBEDTLS_LIBRARY) |
| @@ -272,13 +281,15 @@ if(USE_STATIC_MBEDTLS_LIBRARY) |
| target_link_libraries(${mbedcrypto_static_target} PUBLIC everest) |
| endif() |
| |
| - add_library(${mbedx509_static_target} STATIC ${src_x509}) |
| - set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) |
| - target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target}) |
| + if (NOT CRYPTO_ONLY) |
| + add_library(${mbedx509_static_target} STATIC ${src_x509}) |
| + set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) |
| + target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target}) |
| |
| - add_library(${mbedtls_static_target} STATIC ${src_tls}) |
| - set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) |
| - target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target}) |
| + add_library(${mbedtls_static_target} STATIC ${src_tls}) |
| + set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) |
| + target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target}) |
| + endif() |
| endif(USE_STATIC_MBEDTLS_LIBRARY) |
| |
| if(USE_SHARED_MBEDTLS_LIBRARY) |
| @@ -290,14 +301,15 @@ if(USE_SHARED_MBEDTLS_LIBRARY) |
| if(TARGET everest) |
| target_link_libraries(${mbedcrypto_target} PUBLIC everest) |
| endif() |
| - |
| - add_library(${mbedx509_target} SHARED ${src_x509}) |
| - set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.4.0 SOVERSION 5) |
| - target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target}) |
| - |
| - add_library(${mbedtls_target} SHARED ${src_tls}) |
| - set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.4.0 SOVERSION 19) |
| - target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target}) |
| + if (NOT CRYPTO_ONLY) |
| + add_library(${mbedx509_target} SHARED ${src_x509}) |
| + set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.4.0 SOVERSION 5) |
| + target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target}) |
| + |
| + add_library(${mbedtls_target} SHARED ${src_tls}) |
| + set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.4.0 SOVERSION 19) |
| + target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target}) |
| + endif() |
| endif(USE_SHARED_MBEDTLS_LIBRARY) |
| |
| foreach(target IN LISTS target_libraries) |
| @@ -322,7 +334,15 @@ endforeach(target) |
| |
| set(lib_target "${MBEDTLS_TARGET_PREFIX}lib") |
| |
| -add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) |
| +add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target}) |
| + |
| +if(NOT CRYPTO_ONLY) |
| + add_dependencies(${lib_target} ${mbedx509_target} ${mbedtls_target}) |
| +endif() |
| + |
| if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| - add_dependencies(${lib_target} ${mbedcrypto_static_target} ${mbedx509_static_target} ${mbedtls_static_target}) |
| + add_dependencies(${lib_target} ${mbedcrypto_static_target}) |
| + if(NOT CRYPTO_ONLY) |
| + add_dependencies(${lib_target} ${mbedx509_static_target} ${mbedtls_static_target}) |
| + endif() |
| endif() |
| -- |
| 2.34.1 |