Skip to content

Commit

Permalink
cmake: allow using static (.a) mbedtls
Browse files Browse the repository at this point in the history
This option will be used when building Linux artifacts that are
published later on GitHub releases.

Signed-off-by: Davide Bettio <davide@uninstall.it>
  • Loading branch information
bettio committed Dec 8, 2023
1 parent 008fe12 commit 5b4cf54
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions CMakeModules/MbedTLS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@
# If it doesn't work, search for MBEDTLS_VERSION_NUMBER symbol as well as
# the three libraries we need with check_symbol_exists and find_library

option(AVM_STATIC_MBEDTLS "Static link Mbed-TLS." OFF)

if (MBEDTLS_ROOT_DIR)
set(MbedTLS_FOUND TRUE)
if (NOT MBEDTLS_LIBRARIES_DIR)
set(MBEDTLS_LIBRARIES_DIR ${MBEDTLS_ROOT_DIR}/lib)
endif()
message(STATUS "Will use MbedTLS from ${MBEDTLS_ROOT_DIR} and ${MBEDTLS_LIBRARIES_DIR}")

if (AVM_STATIC_MBEDTLS)
message(FATAL_ERROR "AVM_STATIC_MBEDTLS not supported with MbedTLS root dir option")
endif()

add_library(MbedTLS::mbedcrypto SHARED IMPORTED)
set_target_properties(MbedTLS::mbedcrypto PROPERTIES
IMPORTED_LOCATION "${MBEDTLS_LIBRARIES_DIR}/libmbedcrypto${CMAKE_SHARED_LIBRARY_SUFFIX}"
Expand All @@ -64,12 +70,26 @@ else()
find_package(MbedTLS QUIET)
if (MbedTLS_FOUND)
message(STATUS "Found MbedTLS package ${MbedTLS_FOUND}")

if (AVM_STATIC_MBEDTLS)
message(FATAL_ERROR "AVM_STATIC_MBEDTLS not supported with MbedTLS cmake package")
endif()
else()
if (AVM_STATIC_MBEDTLS)
set(MBEDCRYPTO_LIB_NAME "libmbedcrypto.a")
set(MBEDX509_LIB "libmbedx509.a")
set(MBEDTLS_LIB "libmbedtls.a")
else()
set(MBEDCRYPTO_LIB_NAME "mbedcrypto")
set(MBEDX509_LIB "mbedx509")
set(MBEDTLS_LIB "mbedtls")
endif()

include(CheckSymbolExists)
check_symbol_exists(MBEDTLS_VERSION_NUMBER "mbedtls/version.h" HAVE_MBEDTLS_VERSION_NUMBER)
find_library(MBEDCRYPTO mbedcrypto)
find_library(MBEDX509 mbedx509)
find_library(MBEDTLS mbedtls)
find_library(MBEDCRYPTO NAMES ${MBEDCRYPTO_LIB_NAME})
find_library(MBEDX509 NAMES ${MBEDX509_LIB})
find_library(MBEDTLS NAMES ${MBEDTLS_LIB})
if (HAVE_MBEDTLS_VERSION_NUMBER
AND NOT ${MBEDCRYPTO} STREQUAL "MBEDCRYPTO-NOTFOUND"
AND NOT ${MBEDX509} STREQUAL "MBEDX509-NOTFOUND"
Expand Down

0 comments on commit 5b4cf54

Please sign in to comment.