Commit c3f53911 authored by Sebastian Bøe's avatar Sebastian Bøe Committed by Anas Nashif
Browse files

mbedtls: Added support for using an externally built mbedtls



Kbuild supported CONFIG_MBEDTLS_LIBRARY and
CONFIG_MBEDTLS_INSTALL_PATH to allow users to link in an externally
built mbedtls. This was not ported over to CMake, causing build
failures when it was kconfig-enabled.

This patch implements this support. This support has been tested
as well as MBEDTLS_LIBRARY was tested in CI.

Signed-off-by: default avatarSebastian Bøe <sebastian.boe@nordicsemi.no>
Signed-off-by: default avatarDing Tao <miyatsu@qq.com>
parent 61cf3b05
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
add_subdirectory_if_kconfig(tinycrypt)
add_subdirectory_ifdef(CONFIG_MBEDTLS_BUILTIN mbedtls)
add_subdirectory_ifdef(CONFIG_MBEDTLS mbedtls)
+96 −76
Original line number Diff line number Diff line
zephyr_interface_library_named(mbedTLS)

if(CONFIG_MBEDTLS_BUILTIN)
  target_compile_definitions(mbedTLS INTERFACE
	MBEDTLS_CONFIG_FILE="${CONFIG_MBEDTLS_CFG_FILE}"
	)
@@ -8,7 +10,6 @@ target_include_directories(mbedTLS INTERFACE
	configs
	)


  zephyr_library()
  zephyr_library_sources(zephyr_init.c)

@@ -85,5 +86,24 @@ zephyr_library_sources(library/x509write_csr.c)
  zephyr_library_sources(library/xtea.c)

  zephyr_library_link_libraries(mbedTLS)
else()
  assert(CONFIG_MBEDTLS_LIBRARY "MBEDTLS was enabled, but neither BUILTIN or LIBRARY was selected.")

  # NB: CONFIG_MBEDTLS_LIBRARY is not regression tested and is
  # therefore susceptible to bit rot

  target_include_directories(mbedTLS INTERFACE
	${CONFIG_MBEDTLS_INSTALL_PATH}
	)

  zephyr_link_libraries(
    mbedtls_external
    -L${CONFIG_MBEDTLS_INSTALL_PATH}
    gcc
    )
  # Lib mbedtls_external depends on libgcc (I assume?) so to allow
  # mbedtls_external to link with gcc we need to ensure it is placed
  # after mbedtls_external on the linkers command line.
endif()

target_link_libraries(mbedTLS INTERFACE zephyr_interface)