@@ -20,8 +20,132 @@ add_subdirectory(nlohmann_json EXCLUDE_FROM_ALL)
2020
2121add_subdirectory (whereami EXCLUDE_FROM_ALL )
2222
23- if (EXISTS "${PICO_SDK_PATH} /lib/mbedtls/CMakeLists.txt" )
24- option (ENABLE_PROGRAMS "Build Mbed TLS programs." OFF )
25- option (ENABLE_TESTING "Build Mbed TLS tests." OFF )
26- add_subdirectory (${PICO_SDK_PATH} /lib/mbedtls mbedtls EXCLUDE_FROM_ALL )
23+ # Taken from pico-sdk/src/rp2_common/pico_mbedtls/CMakeLists.txt
24+ if (DEFINED ENV{PICO_MBEDTLS_PATH} AND (NOT PICO_MBEDTLS_PATH))
25+ set (PICO_MBEDTLS_PATH $ENV{PICO_MBEDTLS_PATH} )
26+ message ("Using PICO_MBEDTLS_PATH from environment ('${PICO_MBEDTLS_PATH} ')" )
27+ endif ()
28+
29+ set (MBEDTLS_TEST_PATH "library/aes.c" )
30+ if (NOT PICO_MBEDTLS_PATH)
31+ set (PICO_MBEDTLS_PATH ${PICO_SDK_PATH} /lib/mbedtls)
32+ elseif (NOT EXISTS "${PICO_MBEDTLS_PATH} /${MBEDTLS_TEST_PATH} " )
33+ message (WARNING "PICO_MBEDTLS_PATH specified but content not present." )
34+ endif ()
35+
36+ if (EXISTS "${PICO_MBEDTLS_PATH} /${MBEDTLS_TEST_PATH} " )
37+ # Support version 2.28.8 or 3.6.2
38+ if (EXISTS ${PICO_MBEDTLS_PATH} /library/ssl_cli.c)
39+ set (MBEDTLS_VERSION_MAJOR 2)
40+ elseif (EXISTS ${PICO_MBEDTLS_PATH} /library/ssl_client.c)
41+ set (MBEDTLS_VERSION_MAJOR 3)
42+ else ()
43+ message (WARNING "Cannot determine the version of mbedtls" )
44+ endif ()
45+
46+ function (src_crypto_list)
47+ set (src_crypto
48+ aes.c
49+ aesni.c
50+ aria.c
51+ asn1parse.c
52+ asn1write.c
53+ base64.c
54+ bignum.c
55+ camellia.c
56+ ccm.c
57+ chacha20.c
58+ chachapoly.c
59+ cipher.c
60+ cipher_wrap.c
61+ constant_time.c
62+ cmac.c
63+ ctr_drbg.c
64+ des.c
65+ dhm.c
66+ ecdh.c
67+ ecdsa.c
68+ ecjpake.c
69+ ecp.c
70+ ecp_curves.c
71+ entropy.c
72+ entropy_poll.c
73+ error.c
74+ gcm.c
75+ hkdf.c
76+ hmac_drbg.c
77+ md .c
78+ md5.c
79+ memory_buffer_alloc.c
80+ mps_reader.c
81+ mps_trace.c
82+ nist_kw.c
83+ oid.c
84+ padlock.c
85+ pem.c
86+ pk.c
87+ pk_wrap.c
88+ pkcs12.c
89+ pkcs5.c
90+ pkparse.c
91+ pkwrite.c
92+ platform.c
93+ platform_util.c
94+ poly1305.c
95+ psa_crypto.c
96+ psa_crypto_aead.c
97+ psa_crypto_cipher.c
98+ psa_crypto_client.c
99+ psa_crypto_ecp.c
100+ psa_crypto_hash.c
101+ psa_crypto_mac.c
102+ psa_crypto_rsa.c
103+ psa_crypto_se.c
104+ psa_crypto_slot_management.c
105+ psa_crypto_storage.c
106+ psa_its_file.c
107+ ripemd160.c
108+ rsa.c
109+ sha1.c
110+ sha256.c
111+ sha512.c
112+ threading.c
113+ timing.c
114+ version .c
115+ version_features.c
116+ )
117+ if (MBEDTLS_VERSION_MAJOR EQUAL 2)
118+ list (APPEND src_crypto
119+ arc4.c
120+ blowfish.c
121+ havege.c
122+ md2.c
123+ md4.c
124+ psa_crypto_driver_wrappers.c
125+ rsa_internal.c xtea.c
126+ )
127+ elseif (MBEDTLS_VERSION_MAJOR EQUAL 3)
128+ list (APPEND src_crypto
129+ bignum_core.c
130+ rsa_alt_helpers.c
131+ pk_ecc.c
132+ )
133+ endif ()
134+ list (TRANSFORM src_crypto PREPEND ${PICO_MBEDTLS_PATH} /library/)
135+ set (src_crypto ${src_crypto} PARENT_SCOPE)
136+ endfunction ()
137+
138+ src_crypto_list()
139+
140+
141+ # Create library
142+ add_library (mbedtls STATIC ${src_crypto} )
143+
144+ if (WIN32 )
145+ target_link_libraries (mbedtls ws2_32 bcrypt)
146+ endif (WIN32 )
147+
148+ target_compile_definitions (mbedtls PUBLIC MBEDTLS_CONFIG_FILE="picotool_mbedtls_config.h" )
149+ target_include_directories (mbedtls SYSTEM PUBLIC ${PICO_MBEDTLS_PATH} /include )
150+ target_include_directories (mbedtls PUBLIC ${CMAKE_CURRENT_LIST_DIR} /include )
27151endif ()
0 commit comments