blob: 3041ac64763b2889267830601236569c34bcdb9d [file] [log] [blame]
Balint Dobszay21ce26e2023-05-19 10:12:49 +02001From d225c9ba98e8aafdd462bdff3f8159886a89e1d3 Mon Sep 17 00:00:00 2001
Gyorgy Szing9c8daca2023-03-28 17:09:33 +02002From: Gyorgy Szing <Gyorgy.Szing@arm.com>
3Date: Tue, 28 Mar 2023 18:20:44 +0200
Balint Dobszay21ce26e2023-05-19 10:12:49 +02004Subject: [PATCH] Add capability to build libmbedcrypto only
Gyorgy Szing9c8daca2023-03-28 17:09:33 +02005
6Introduce the CRYPTO_ONLY option which configures cmake to build only
7libmbedcrypto.
8
9Upstream-status: Invalid [other]
10 - This is a Trusted Services specific change, there is not intention
11 to upstream this change.
12
13Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
Balint Dobszay21ce26e2023-05-19 10:12:49 +020014Signed-off-by: Balint Dobszay <balint.dobszay@arm.com>
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020015---
Balint Dobszay21ce26e2023-05-19 10:12:49 +020016 library/CMakeLists.txt | 60 ++++++++++++++++++++++++++++--------------
17 1 file changed, 40 insertions(+), 20 deletions(-)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020018
19diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
Balint Dobszay21ce26e2023-05-19 10:12:49 +020020index 535988303..a70848e82 100644
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020021--- a/library/CMakeLists.txt
22+++ b/library/CMakeLists.txt
23@@ -2,6 +2,7 @@ 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)
Balint Dobszay21ce26e2023-05-19 10:12:49 +020027+option(CRYPTO_ONLY "Build mbedcrypto library only." On)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020028
29 # Set the project root directory if it's not already defined, as may happen if
30 # the library folder is included directly by a parent project, without
Balint Dobszay21ce26e2023-05-19 10:12:49 +020031@@ -250,7 +251,11 @@ if (USE_STATIC_MBEDTLS_LIBRARY)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020032 set(mbedcrypto_static_target ${mbedcrypto_target})
33 endif()
34
35-set(target_libraries ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target})
36+set(target_libraries ${mbedcrypto_target})
37+
38+if (NOT CRYPTO_ONLY)
39+ list(APPEND target_libraries ${mbedx509_target} ${mbedtls_target})
40+endif()
41
42 if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
43 string(APPEND mbedtls_static_target "_static")
Balint Dobszay21ce26e2023-05-19 10:12:49 +020044@@ -258,9 +263,13 @@ if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020045 string(APPEND mbedcrypto_static_target "_static")
46
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020047 list(APPEND target_libraries
48- ${mbedcrypto_static_target}
Balint Dobszay21ce26e2023-05-19 10:12:49 +020049- ${mbedx509_static_target}
50- ${mbedtls_static_target})
51+ ${mbedcrypto_static_target})
52+
53+ if (NOT CRYPTO_ONLY)
54+ list(APPEND target_libraries
55+ ${mbedx509_static_target}
56+ ${mbedtls_static_target})
57+ endif()
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020058 endif()
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020059
60 if(USE_STATIC_MBEDTLS_LIBRARY)
Balint Dobszay21ce26e2023-05-19 10:12:49 +020061@@ -272,13 +281,15 @@ if(USE_STATIC_MBEDTLS_LIBRARY)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020062 target_link_libraries(${mbedcrypto_static_target} PUBLIC everest)
63 endif()
64
65- add_library(${mbedx509_static_target} STATIC ${src_x509})
66- set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
67- target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target})
68+ if (NOT CRYPTO_ONLY)
69+ add_library(${mbedx509_static_target} STATIC ${src_x509})
70+ set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
71+ target_link_libraries(${mbedx509_static_target} PUBLIC ${libs} ${mbedcrypto_static_target})
72
73- add_library(${mbedtls_static_target} STATIC ${src_tls})
74- set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
75- target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target})
76+ add_library(${mbedtls_static_target} STATIC ${src_tls})
77+ set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
78+ target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target})
79+ endif()
80 endif(USE_STATIC_MBEDTLS_LIBRARY)
81
82 if(USE_SHARED_MBEDTLS_LIBRARY)
Balint Dobszay21ce26e2023-05-19 10:12:49 +020083@@ -290,14 +301,15 @@ if(USE_SHARED_MBEDTLS_LIBRARY)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020084 if(TARGET everest)
85 target_link_libraries(${mbedcrypto_target} PUBLIC everest)
86 endif()
87-
88- add_library(${mbedx509_target} SHARED ${src_x509})
Balint Dobszay21ce26e2023-05-19 10:12:49 +020089- set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.4.0 SOVERSION 5)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020090- target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target})
91-
92- add_library(${mbedtls_target} SHARED ${src_tls})
Balint Dobszay21ce26e2023-05-19 10:12:49 +020093- set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.4.0 SOVERSION 19)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020094- target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target})
95+ if (NOT CRYPTO_ONLY)
96+ add_library(${mbedx509_target} SHARED ${src_x509})
Balint Dobszay21ce26e2023-05-19 10:12:49 +020097+ set_target_properties(${mbedx509_target} PROPERTIES VERSION 3.4.0 SOVERSION 5)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +020098+ target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target})
99+
100+ add_library(${mbedtls_target} SHARED ${src_tls})
Balint Dobszay21ce26e2023-05-19 10:12:49 +0200101+ set_target_properties(${mbedtls_target} PROPERTIES VERSION 3.4.0 SOVERSION 19)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +0200102+ target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target})
103+ endif()
104 endif(USE_SHARED_MBEDTLS_LIBRARY)
105
106 foreach(target IN LISTS target_libraries)
Balint Dobszay21ce26e2023-05-19 10:12:49 +0200107@@ -322,7 +334,15 @@ endforeach(target)
Gyorgy Szing9c8daca2023-03-28 17:09:33 +0200108
109 set(lib_target "${MBEDTLS_TARGET_PREFIX}lib")
110
111-add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target} ${mbedx509_target} ${mbedtls_target})
112+add_custom_target(${lib_target} DEPENDS ${mbedcrypto_target})
113+
114+if(NOT CRYPTO_ONLY)
115+ add_dependencies(${lib_target} ${mbedx509_target} ${mbedtls_target})
116+endif()
117+
118 if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
119- add_dependencies(${lib_target} ${mbedcrypto_static_target} ${mbedx509_static_target} ${mbedtls_static_target})
120+ add_dependencies(${lib_target} ${mbedcrypto_static_target})
121+ if(NOT CRYPTO_ONLY)
122+ add_dependencies(${lib_target} ${mbedx509_static_target} ${mbedtls_static_target})
123+ endif()
124 endif()
125--
Balint Dobszay21ce26e2023-05-19 10:12:49 +02001262.34.1