Balint Dobszay | 3c52ce6 | 2021-05-10 16:27:18 +0200 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Gyorgy Szing | 28bca0b | 2023-02-15 11:17:07 +0100 | [diff] [blame] | 2 | # Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved. |
Balint Dobszay | 3c52ce6 | 2021-05-10 16:27:18 +0200 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
Balint Dobszay | ddcca1e | 2023-01-11 13:27:52 +0100 | [diff] [blame] | 8 | set(MBEDTLS_URL "https://github.com/Mbed-TLS/mbedtls.git" |
Gyorgy Szing | afb3c6e | 2021-12-08 04:20:34 +0100 | [diff] [blame] | 9 | CACHE STRING "Mbed TLS repository URL") |
Imre Kis | 8a86a00 | 2024-01-22 15:43:11 +0100 | [diff] [blame] | 10 | set(MBEDTLS_REFSPEC "mbedtls-3.5.1" |
Gyorgy Szing | afb3c6e | 2021-12-08 04:20:34 +0100 | [diff] [blame] | 11 | CACHE STRING "Mbed TLS git refspec") |
| 12 | set(MBEDTLS_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/mbedtls-src" |
| 13 | CACHE PATH "MbedTLS source directory") |
| 14 | set(MBEDTLS_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/mbedtls_install" |
| 15 | CACHE PATH "Mbed TLS installation directory") |
Gyorgy Szing | 34aaf21 | 2022-10-20 07:26:23 +0200 | [diff] [blame] | 16 | set(MBEDTLS_BUILD_TYPE "Release" CACHE STRING "Mbed TLS build type") |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 17 | |
Balint Dobszay | ff8e0cd | 2022-08-11 15:07:52 +0200 | [diff] [blame] | 18 | find_package(Python3 REQUIRED COMPONENTS Interpreter) |
| 19 | |
| 20 | # Mbed TLS has a custom config script that must be ran before invoking CMake. |
| 21 | # This script configures which components of the project will get built, in our |
| 22 | # use case only mbedcrypto is necessary. LazyFetch has a PATCH_COMMAND option |
| 23 | # that was intended to be used for patching the repo after fetch, but before |
| 24 | # running CMake. However, it can be "misused" in this case to run the Mbed TLS |
| 25 | # config script. |
| 26 | set(GIT_OPTIONS |
| 27 | GIT_REPOSITORY ${MBEDTLS_URL} |
| 28 | GIT_TAG ${MBEDTLS_REFSPEC} |
| 29 | GIT_SHALLOW FALSE |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 30 | PATCH_COMMAND |
| 31 | git stash |
| 32 | COMMAND git branch -f bf-am |
Julian Hall | 29620bf | 2022-06-09 10:26:37 +0100 | [diff] [blame] | 33 | COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0001-Add-capability-to-selectively-build-libraries.patch |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 34 | COMMAND git reset bf-am |
| 35 | COMMAND ${Python3_EXECUTABLE} scripts/config.py crypto |
Balint Dobszay | 3c52ce6 | 2021-05-10 16:27:18 +0200 | [diff] [blame] | 36 | ) |
| 37 | |
Balint Dobszay | ff8e0cd | 2022-08-11 15:07:52 +0200 | [diff] [blame] | 38 | # Only pass libc settings to Mbed TLS if needed. For environments where the standard |
| 39 | # library is not overridden, this is not needed. |
| 40 | if(TARGET stdlib::c) |
Gyorgy Szing | eb0507d | 2022-03-05 01:11:27 +0000 | [diff] [blame] | 41 | include(${TS_ROOT}/tools/cmake/common/PropertyCopy.cmake) |
Balint Dobszay | ff8e0cd | 2022-08-11 15:07:52 +0200 | [diff] [blame] | 42 | # Save libc settings |
| 43 | save_interface_target_properties(TGT stdlib::c PREFIX LIBC) |
| 44 | # Translate libc settings to CMake code fragment. Will be inserted into |
| 45 | # mbedtls-init-cache.cmake.in when LazyFetch configures the file. |
| 46 | translate_interface_target_properties(PREFIX LIBC RES _cmake_fragment) |
| 47 | unset_saved_properties(LIBC) |
Balint Dobszay | 3c52ce6 | 2021-05-10 16:27:18 +0200 | [diff] [blame] | 48 | endif() |
| 49 | |
Balint Dobszay | ff8e0cd | 2022-08-11 15:07:52 +0200 | [diff] [blame] | 50 | include(${TS_ROOT}/tools/cmake/common/LazyFetch.cmake REQUIRED) |
| 51 | LazyFetch_MakeAvailable(DEP_NAME MbedTLS |
| 52 | FETCH_OPTIONS ${GIT_OPTIONS} |
| 53 | INSTALL_DIR ${MBEDTLS_INSTALL_DIR} |
Balint Dobszay | 21ce26e | 2023-05-19 10:12:49 +0200 | [diff] [blame] | 54 | PACKAGE_DIR ${MBEDTLS_INSTALL_DIR} |
Balint Dobszay | ff8e0cd | 2022-08-11 15:07:52 +0200 | [diff] [blame] | 55 | CACHE_FILE "${TS_ROOT}/external/MbedTLS/mbedtls-init-cache.cmake.in" |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 56 | SOURCE_DIR "${MBEDTLS_SOURCE_DIR}" |
Balint Dobszay | ff8e0cd | 2022-08-11 15:07:52 +0200 | [diff] [blame] | 57 | ) |
| 58 | unset(_cmake_fragment) |
Gyorgy Szing | 2d92413 | 2022-09-15 18:55:30 +0200 | [diff] [blame] | 59 | |
Balint Dobszay | ff8e0cd | 2022-08-11 15:07:52 +0200 | [diff] [blame] | 60 | # Link the libraries created by Mbed TLS to libc if needed. For environments where the standard |
| 61 | # library is not overridden, this is not needed. |
Gyorgy Szing | 28bca0b | 2023-02-15 11:17:07 +0100 | [diff] [blame] | 62 | if(TARGET stdlib::c) |
Gyorgy Szing | 9c8daca | 2023-03-28 17:09:33 +0200 | [diff] [blame] | 63 | foreach(_mbedtls_tgt IN ITEMS "MbedTLS::mbedcrypto") |
Balint Dobszay | ff8e0cd | 2022-08-11 15:07:52 +0200 | [diff] [blame] | 64 | target_link_libraries(${_mbedtls_tgt} INTERFACE stdlib::c) |
| 65 | endforeach() |
| 66 | unset(_mbedtls_tgt) |
| 67 | endif() |
| 68 | |
Balint Dobszay | abec464 | 2024-01-16 10:51:51 +0100 | [diff] [blame^] | 69 | # Advertise Mbed TLS provided psa crypto api header file. Can be used with #include MBEDTLS_PSA_CRYPTO_H |
| 70 | # when it is necessary to explicitly include the mbedtls provided version of psa/crypto.h. |
| 71 | add_compile_definitions(MBEDTLS_PSA_CRYPTO_H="${MBEDTLS_INSTALL_DIR}/include/psa/crypto.h") |
| 72 | |
| 73 | # Advertise the public interface path to allow a deployment to determine what scope to give it |
| 74 | set(MBEDTLS_PUBLIC_INCLUDE_PATH "${MBEDTLS_INSTALL_DIR}/include" CACHE STRING "Mbedtls public include path") |