Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame^] | 1 | # |
| 2 | # SPDX-License-Identifier: BSD-3-Clause |
| 3 | # SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | # |
| 5 | |
| 6 | #[=======================================================================[.rst: |
| 7 | FindMbedTLS |
| 8 | =========== |
| 9 | |
| 10 | TODO: documentation. |
| 11 | #]=======================================================================] |
| 12 | |
| 13 | include(FindPackageHandleStandardArgs) |
| 14 | |
| 15 | find_path(MbedTLS_INCLUDE_DIR |
| 16 | NAMES "mbedtls/build_info.h") |
| 17 | |
| 18 | if(MbedTLS_INCLUDE_DIR) |
| 19 | mark_as_advanced(MbedTLS_INCLUDE_DIR) |
| 20 | |
| 21 | set(MbedTLS_FOUND TRUE) |
| 22 | endif() |
| 23 | |
| 24 | find_library(MbedTLS_Crypto_LIBRARY "mbedcrypto" PATHS "library" "lib") |
| 25 | find_library(MbedTLS_TLS_LIBRARY "mbedtls" PATHS "library" "lib") |
| 26 | find_library(MbedTLS_X509_LIBRARY "mbedx509" PATHS "library" "lib") |
| 27 | |
| 28 | foreach(component IN ITEMS Crypto TLS X509) |
| 29 | if(MbedTLS_${component}_LIBRARY) |
| 30 | mark_as_advanced(MbedTLS_${component}_LIBRARY) |
| 31 | |
| 32 | set(MbedTLS_${component}_FOUND TRUE) |
| 33 | endif() |
| 34 | endforeach() |
| 35 | |
| 36 | find_package_handle_standard_args(MbedTLS HANDLE_COMPONENTS |
| 37 | REQUIRED_VARS MbedTLS_FOUND MbedTLS_INCLUDE_DIR) |
| 38 | |
| 39 | if(MbedTLS_FOUND) |
| 40 | add_library(MbedTLS INTERFACE) |
| 41 | |
| 42 | target_include_directories(MbedTLS |
| 43 | INTERFACE "${MbedTLS_INCLUDE_DIR}" |
| 44 | "${RMM_SOURCE_DIR}/configs/mbedtls") |
| 45 | |
| 46 | target_compile_definitions(MbedTLS |
| 47 | INTERFACE "MBEDTLS_CONFIG_FILE=<mbedtls_config.h>") |
| 48 | |
| 49 | foreach(component IN ITEMS Crypto TLS X509) |
| 50 | if(MbedTLS_${component}_LIBRARY) |
| 51 | add_library(MbedTLS::${component} UNKNOWN IMPORTED) |
| 52 | |
| 53 | set_target_properties(MbedTLS::${component} |
| 54 | PROPERTIES IMPORTED_LOCATION "${MbedTLS_${component}_LIBRARY}") |
| 55 | |
| 56 | target_link_libraries(MbedTLS::${component} |
| 57 | INTERFACE MbedTLS) |
| 58 | endif() |
| 59 | endforeach() |
| 60 | endif() |