Skip to content

Commit

Permalink
Merge pull request #974 from bettio/static-mbedtls
Browse files Browse the repository at this point in the history
Also build x86_64 artifact with builtin (static linked) mbedtls.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
  • Loading branch information
bettio committed Dec 9, 2023
2 parents 008fe12 + db86ddc commit 5b144a5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build-linux-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ jobs:
tag: "22.04"
cflags: ""

- arch: "x86_64"
build_name: "linux-x86_64-static-mbedtls"
docker_image: "ubuntu"
platform: "amd64"
tag: "18.04"
cflags: ""
cmake_opts: "-DAVM_STATIC_MBEDTLS=ON"
install_deps: |
apt update &&
apt install -y file gcc g++ binutils make doxygen gperf zlib1g-dev libmbedtls-dev wget tzdata &&
apt purge -y cmake &&
wget https://cmake.org/files/v3.13/cmake-3.13.5-Linux-x86_64.tar.gz &&
tar xf cmake-3.13.5-Linux-x86_64.tar.gz &&
mv cmake-3.13.5-Linux-x86_64 /opt/cmake-3.13.5 &&
ln -sf /opt/cmake-3.13.5/bin/* /usr/bin/
- arch: "x86_64"
build_name: "linux-x86_64"
docker_image: "ubuntu"
Expand Down
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 5b144a5

Please sign in to comment.