Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 1 | From 009b346144f4efd6c7f6ca0ceaead89e7333bba7 Mon Sep 17 00:00:00 2001 |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 2 | From: Gyorgy Szing <Gyorgy.Szing@arm.com> |
| 3 | Date: Tue, 28 Mar 2023 18:20:44 +0200 |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 4 | Subject: [PATCH] Add capability to selectively build libraries |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 5 | |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 6 | Introduce the BUILD_X509 and BUILD_TLS options which allows disabling |
| 7 | or enabling building of these libraries. |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 8 | |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 9 | Uptream-status: Invalid [other] |
| 10 | - This is a Trusted Services specific change, there is no intention |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 11 | to upstream this change. |
| 12 | |
| 13 | Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com> |
Imre Kis | 8a86a00 | 2024-01-22 15:43:11 +0100 | [diff] [blame] | 14 | Signed-off-by: Imre Kis <imre.kis@arm.com> |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 15 | --- |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 16 | library/CMakeLists.txt | 77 +++++++++++++++++++++++++++++++----------- |
| 17 | 1 file changed, 57 insertions(+), 20 deletions(-) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 18 | |
| 19 | diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 20 | index e6705de55..3244bd086 100644 |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 21 | --- a/library/CMakeLists.txt |
| 22 | +++ b/library/CMakeLists.txt |
Imre Kis | 8a86a00 | 2024-01-22 15:43:11 +0100 | [diff] [blame] | 23 | @@ -2,6 +2,8 @@ option(USE_STATIC_MBEDTLS_LIBRARY "Build Mbed TLS static library." ON) |
| 24 | option(USE_SHARED_MBEDTLS_LIBRARY "Build Mbed TLS shared library." OFF) |
| 25 | option(LINK_WITH_PTHREAD "Explicitly link Mbed TLS library to pthread." OFF) |
| 26 | option(LINK_WITH_TRUSTED_STORAGE "Explicitly link Mbed TLS library to trusted_storage." OFF) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 27 | +option(BUIILD_X509 "Build x509 library too." ON) |
| 28 | +option(BUILD_TLS "Build TLS library too" OFF) |
| 29 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 30 | # Set the project root directory if it's not already defined, as may happen if |
| 31 | # the library folder is included directly by a parent project, without |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 32 | @@ -257,7 +259,15 @@ if (USE_STATIC_MBEDTLS_LIBRARY) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 33 | set(mbedcrypto_static_target ${mbedcrypto_target}) |
| 34 | endif() |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 35 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 36 | -set(target_libraries ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) |
| 37 | +set(target_libraries ${mbedcrypto_target}) |
| 38 | + |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 39 | +if (BUIILD_X509) |
| 40 | + list(APPEND target_libraries ${mbedx509_target}) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 41 | +endif() |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 42 | + |
| 43 | +if (BUILD_TLS) |
| 44 | + list(APPEND target_libraries ${mbedtls_target}) |
| 45 | +endif() |
| 46 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 47 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| 48 | string(APPEND mbedtls_static_target "_static") |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 49 | @@ -265,9 +275,15 @@ if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 50 | string(APPEND mbedcrypto_static_target "_static") |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 51 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 52 | list(APPEND target_libraries |
| 53 | - ${mbedcrypto_static_target} |
Balint Dobszay | 21ce26e | 2023-05-19 10:12:49 +0200 | [diff] [blame] | 54 | - ${mbedx509_static_target} |
| 55 | - ${mbedtls_static_target}) |
| 56 | + ${mbedcrypto_static_target}) |
Imre Kis | 8a86a00 | 2024-01-22 15:43:11 +0100 | [diff] [blame] | 57 | + |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 58 | + if (BUIILD_X509 OR BUIILD_TLS) |
| 59 | + list(APPEND target_libraries ${mbedx509_static_target}) |
| 60 | + endif() |
Balint Dobszay | 21ce26e | 2023-05-19 10:12:49 +0200 | [diff] [blame] | 61 | + |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 62 | + if (BUILD_TLS) |
| 63 | + list(APPEND target_libraries ${mbedtls_static_target}) |
Balint Dobszay | 21ce26e | 2023-05-19 10:12:49 +0200 | [diff] [blame] | 64 | + endif() |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 65 | endif() |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 66 | |
Imre Kis | 8a86a00 | 2024-01-22 15:43:11 +0100 | [diff] [blame] | 67 | set(p256m_target "${MBEDTLS_TARGET_PREFIX}p256m") |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 68 | @@ -286,13 +302,17 @@ if(USE_STATIC_MBEDTLS_LIBRARY) |
Imre Kis | 8a86a00 | 2024-01-22 15:43:11 +0100 | [diff] [blame] | 69 | target_link_libraries(${mbedcrypto_static_target} PUBLIC ${p256m_target}) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 70 | endif() |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 71 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 72 | - add_library(${mbedx509_static_target} STATIC ${src_x509}) |
| 73 | - set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) |
| 74 | - target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target}) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 75 | + if (BUIILD_X509 OR BUIILD_TLS) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 76 | + add_library(${mbedx509_static_target} STATIC ${src_x509}) |
| 77 | + set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509) |
| 78 | + target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target}) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 79 | + endif() |
| 80 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 81 | - add_library(${mbedtls_static_target} STATIC ${src_tls}) |
| 82 | - set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) |
| 83 | - target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target}) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 84 | + if (BUILD_TLS) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 85 | + add_library(${mbedtls_static_target} STATIC ${src_tls}) |
| 86 | + set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls) |
| 87 | + target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target}) |
| 88 | + endif() |
| 89 | endif(USE_STATIC_MBEDTLS_LIBRARY) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 90 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 91 | if(USE_SHARED_MBEDTLS_LIBRARY) |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 92 | @@ -308,14 +328,16 @@ if(USE_SHARED_MBEDTLS_LIBRARY) |
Imre Kis | 8a86a00 | 2024-01-22 15:43:11 +0100 | [diff] [blame] | 93 | if(TARGET ${p256m_target}) |
| 94 | target_link_libraries(${mbedcrypto_target} PUBLIC ${p256m_target}) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 95 | endif() |
| 96 | - |
| 97 | - add_library(${mbedx509_target} SHARED ${src_x509}) |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 98 | - set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.6.0 SOVERSION 7) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 99 | - target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target}) |
| 100 | - |
| 101 | - add_library(${mbedtls_target} SHARED ${src_tls}) |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 102 | - set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.6.0 SOVERSION 21) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 103 | - target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target}) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 104 | + if (BUIILD_X509 OR BUILD_TLS) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 105 | + add_library(${mbedx509_target} SHARED ${src_x509}) |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 106 | + set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.6.0 SOVERSION 7) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 107 | + target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target}) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 108 | + endif() |
| 109 | + if (BUILD_TLS) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 110 | + add_library(${mbedtls_target} SHARED ${src_tls}) |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 111 | + set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.6.0 SOVERSION 21) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 112 | + target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target}) |
| 113 | + endif() |
| 114 | endif(USE_SHARED_MBEDTLS_LIBRARY) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 115 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 116 | foreach(target IN LISTS target_libraries) |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 117 | @@ -351,7 +373,22 @@ endforeach(target) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 118 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 119 | set(lib_target "${MBEDTLS_TARGET_PREFIX}lib") |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 120 | |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 121 | -add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target}) |
| 122 | +add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target}) |
| 123 | + |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 124 | +if(BUIILD_X509 OR BUIILD_TLS) |
| 125 | + add_dependencies(${lib_target} ${mbedx509_target}) |
| 126 | +endif() |
| 127 | + |
| 128 | +if(BUIILD_TLS) |
| 129 | + add_dependencies(${lib_target} ${mbedtls_target}) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 130 | +endif() |
| 131 | + |
| 132 | if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY) |
| 133 | - add_dependencies(${lib_target} ${mbedcrypto_static_target} ${mbedx509_static_target} ${mbedtls_static_target}) |
| 134 | + add_dependencies(${lib_target} ${mbedcrypto_static_target}) |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 135 | + if(BUIILD_X509 OR BUIILD_TLS) |
| 136 | + add_dependencies(${lib_target} ${mbedx509_static_target}) |
| 137 | + endif() |
| 138 | + if(BUIILD_TLS) |
| 139 | + add_dependencies(${lib_target} ${mbedtls_static_target}) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 140 | + endif() |
| 141 | endif() |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 142 | -- |
Imre Kis | 3767626 | 2024-06-05 11:53:03 +0200 | [diff] [blame] | 143 | 2.25.1 |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 144 | |