From 509807e3772ad69e01a3cbacf8ad3b3a6f719257 Mon Sep 17 00:00:00 2001 From: kangping Date: Wed, 29 Apr 2020 02:28:09 +0800 Subject: [PATCH] [cmake] enable user specified mbedtls target (#4812) This commit allows users to specify the mbedtls target by a OT_EXTERNAL_MBEDTLS option. The native cmake build system of mbedtls is not so "modern" (for backward compatibility, it maybe hard to change it soon) and applications using mbedtls are likely to write wrapper cmake files and targets by themselves. --- CMakeLists.txt | 2 +- etc/cmake/options.cmake | 4 +++- examples/platforms/cc1352/CMakeLists.txt | 2 +- examples/platforms/cc2650/CMakeLists.txt | 2 +- examples/platforms/cc2652/CMakeLists.txt | 2 +- examples/platforms/qpg6095/CMakeLists.txt | 2 +- examples/platforms/samr21/CMakeLists.txt | 2 +- src/cli/CMakeLists.txt | 4 ++-- src/core/CMakeLists.txt | 4 ++-- src/ncp/CMakeLists.txt | 4 ++-- tests/unit/CMakeLists.txt | 2 +- third_party/CMakeLists.txt | 3 ++- 12 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29f83eb7e..119401e43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,8 @@ cmake_minimum_required(VERSION 3.13.1) project(openthread) option(OT_BUILD_EXECUTABLES "Build executables" ON) -option(OT_BUILTIN_MBEDTLS "Enable builtin mbedTLS" ON) option(OT_COVERAGE "enable coverage" OFF) +set(OT_EXTERNAL_MBEDTLS "" CACHE STRING "Specify external mbedtls library") include(TestBigEndian) TEST_BIG_ENDIAN(OT_BIG_ENDIAN) diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index bd16a3ce1..75ba98e34 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -41,9 +41,11 @@ if(OT_BORDER_ROUTER) list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE=1") endif() -if(OT_BUILTIN_MBEDTLS) +if(NOT OT_EXTERNAL_MBEDTLS) + set(OT_MBEDTLS mbedtls) list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=1") else() + set(OT_MBEDTLS ${OT_EXTERNAL_MBEDTLS}) list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=0") endif() diff --git a/examples/platforms/cc1352/CMakeLists.txt b/examples/platforms/cc1352/CMakeLists.txt index a0f350503..aa53693d7 100644 --- a/examples/platforms/cc1352/CMakeLists.txt +++ b/examples/platforms/cc1352/CMakeLists.txt @@ -70,7 +70,7 @@ set_property(TARGET openthread-cc1352 PROPERTY C_STANDARD 99) target_link_libraries(openthread-cc1352 PRIVATE "${PROJECT_SOURCE_DIR}/third_party/ti/devices/cc13x2_cc26x2/driverlib/bin/gcc/driverlib.a" - mbedtls + ${OT_MBEDTLS} ) target_link_options(openthread-cc1352 PUBLIC diff --git a/examples/platforms/cc2650/CMakeLists.txt b/examples/platforms/cc2650/CMakeLists.txt index c731eecb0..045506e0a 100644 --- a/examples/platforms/cc2650/CMakeLists.txt +++ b/examples/platforms/cc2650/CMakeLists.txt @@ -71,7 +71,7 @@ target_link_libraries(openthread-cc2650 PUBLIC cc26x0-driver PRIVATE - mbedtls + ${OT_MBEDTLS} openthread-platform-utils ) diff --git a/examples/platforms/cc2652/CMakeLists.txt b/examples/platforms/cc2652/CMakeLists.txt index 447e50c7b..0e89de051 100644 --- a/examples/platforms/cc2652/CMakeLists.txt +++ b/examples/platforms/cc2652/CMakeLists.txt @@ -70,7 +70,7 @@ set_property(TARGET openthread-cc2652 PROPERTY C_STANDARD 99) target_link_libraries(openthread-cc2652 PRIVATE "${PROJECT_SOURCE_DIR}/third_party/ti/devices/cc13x2_cc26x2/driverlib/bin/gcc/driverlib.a" - mbedtls + ${OT_MBEDTLS} ) target_link_options(openthread-cc2652 PUBLIC diff --git a/examples/platforms/qpg6095/CMakeLists.txt b/examples/platforms/qpg6095/CMakeLists.txt index a9e6126b3..2153045f0 100644 --- a/examples/platforms/qpg6095/CMakeLists.txt +++ b/examples/platforms/qpg6095/CMakeLists.txt @@ -72,7 +72,7 @@ set_property(TARGET openthread-qpg6095 PROPERTY C_STANDARD 99) target_link_libraries(openthread-qpg6095 PRIVATE qpg6095-driver - mbedtls + ${OT_MBEDTLS} ) target_link_options(openthread-qpg6095 diff --git a/examples/platforms/samr21/CMakeLists.txt b/examples/platforms/samr21/CMakeLists.txt index 38f92df86..a3066ac57 100644 --- a/examples/platforms/samr21/CMakeLists.txt +++ b/examples/platforms/samr21/CMakeLists.txt @@ -70,7 +70,7 @@ target_link_libraries(openthread-samr21 PUBLIC samr21-driver PRIVATE - mbedtls + ${OT_MBEDTLS} ) target_link_options(openthread-samr21 diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 6a7e28a14..15aed4304 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -83,12 +83,12 @@ target_link_libraries(openthread-cli-ftd PUBLIC openthread-ftd PRIVATE - mbedtls + ${OT_MBEDTLS} ) target_link_libraries(openthread-cli-mtd PUBLIC openthread-mtd PRIVATE - mbedtls + ${OT_MBEDTLS} ) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 3a4c3b092..8d72e81ae 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -245,10 +245,10 @@ target_sources(openthread-radio PRIVATE target_link_libraries(openthread-ftd PRIVATE - mbedtls + ${OT_MBEDTLS} ) target_link_libraries(openthread-mtd PRIVATE - mbedtls + ${OT_MBEDTLS} ) diff --git a/src/ncp/CMakeLists.txt b/src/ncp/CMakeLists.txt index 154f5ae25..885902aff 100644 --- a/src/ncp/CMakeLists.txt +++ b/src/ncp/CMakeLists.txt @@ -105,7 +105,7 @@ target_link_libraries(openthread-ncp-ftd PUBLIC openthread-ftd PRIVATE - mbedtls + ${OT_MBEDTLS} openthread-hdlc openthread-spinel-ncp ) @@ -114,7 +114,7 @@ target_link_libraries(openthread-ncp-mtd PUBLIC openthread-mtd PRIVATE - mbedtls + ${OT_MBEDTLS} openthread-hdlc openthread-spinel-ncp ) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 04bbab036..981892c48 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -34,7 +34,7 @@ set(COMMON_SOURCES set(COMMON_LIBS openthread-ftd openthread-ncp-ftd - mbedtls + ${OT_MBEDTLS} util ) diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index aea072458..055cf1442 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -26,9 +26,10 @@ # POSSIBILITY OF SUCH DAMAGE. # -if(OT_BUILTIN_MBEDTLS) +if(NOT OT_EXTERNAL_MBEDTLS) add_subdirectory(mbedtls) endif() + if(OT_PLATFORM STREQUAL "kw41z") add_subdirectory(nxp) elseif(OT_PLATFORM STREQUAL "cc2650")