diff --git a/CMakeLists.txt b/CMakeLists.txt index 89e5cce60..cd9d093d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,15 +108,6 @@ endif() list(APPEND OT_PRIVATE_DEFINES ${OT_PLATFORM_DEFINES}) -if(OT_BUILTIN_MBEDTLS) - list(APPEND OT_PRIVATE_INCLUDES ${PROJECT_SOURCE_DIR}/third_party/mbedtls) - list(APPEND OT_PRIVATE_INCLUDES ${PROJECT_SOURCE_DIR}/third_party/mbedtls/repo/include) - - list(APPEND OT_PRIVATE_DEFINES - "MBEDTLS_CONFIG_FILE=\"mbedtls-config.h\"" - ) -endif() - if(OT_PLATFORM STREQUAL "posix-host") add_subdirectory(src/posix) elseif(NOT OT_PLATFORM MATCHES "none") diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index 81b58a3e3..aee9ee01d 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -201,3 +201,10 @@ if(OT_BUILTIN_MBEDTLS) else() list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=0") endif() + +option(OT_BUILTIN_MBEDTLS_MANAGEMENT "enable builtin mbedtls management" ON) +if(OT_BUILTIN_MBEDTLS_MANAGEMENT) + list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT=1") +else() + list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT=0") +endif() diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 55dc8b785..da05c9aa7 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -78,3 +78,13 @@ target_include_directories(openthread-cli-mtd PUBLIC ${OT_PUBLIC_INCLUDES} PRIVA target_sources(openthread-cli-ftd PRIVATE ${COMMON_SOURCES}) target_sources(openthread-cli-mtd PRIVATE ${COMMON_SOURCES}) + +target_link_libraries(openthread-cli-ftd + PUBLIC + openthread-ftd +) + +target_link_libraries(openthread-cli-mtd + PUBLIC + openthread-mtd +) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 848ae7294..b27eb01d5 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -232,3 +232,13 @@ target_sources(openthread-radio PRIVATE thread/link_quality.cpp utils/parse_cmdline.cpp ) + +target_link_libraries(openthread-ftd + PUBLIC + mbedcrypto +) + +target_link_libraries(openthread-mtd + PUBLIC + mbedcrypto +) diff --git a/src/core/api/link_raw_api.cpp b/src/core/api/link_raw_api.cpp index bd2ec2662..53606e614 100644 --- a/src/core/api/link_raw_api.cpp +++ b/src/core/api/link_raw_api.cpp @@ -42,7 +42,6 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" #include "common/random.hpp" -#include "mac/mac.hpp" #include "mac/mac_frame.hpp" #include "utils/parse_cmdline.hpp" diff --git a/src/core/common/instance.cpp b/src/core/common/instance.cpp index 90e9b9d03..9dde4ff77 100644 --- a/src/core/common/instance.cpp +++ b/src/core/common/instance.cpp @@ -37,7 +37,6 @@ #include "common/logging.hpp" #include "common/new.hpp" -#include "thread/router_table.hpp" namespace ot { diff --git a/src/core/mac/link_raw.cpp b/src/core/mac/link_raw.cpp index fdf01c7d3..aa806b4d2 100644 --- a/src/core/mac/link_raw.cpp +++ b/src/core/mac/link_raw.cpp @@ -42,7 +42,6 @@ #include "common/locator-getters.hpp" #include "common/logging.hpp" #include "common/random.hpp" -#include "mac/mac.hpp" #include "mac/mac_frame.hpp" #if OPENTHREAD_RADIO || OPENTHREAD_CONFIG_LINK_RAW_ENABLE diff --git a/src/core/mac/mac_frame.cpp b/src/core/mac/mac_frame.cpp index 732ee672c..5028fc503 100644 --- a/src/core/mac/mac_frame.cpp +++ b/src/core/mac/mac_frame.cpp @@ -37,8 +37,11 @@ #include "common/code_utils.hpp" #include "common/debug.hpp" + +#if OPENTHREAD_MTD || OPENTHREAD_FTD #include "crypto/aes_ccm.hpp" #include "thread/key_manager.hpp" +#endif namespace ot { namespace Mac { diff --git a/src/core/mac/sub_mac_callbacks.cpp b/src/core/mac/sub_mac_callbacks.cpp index 10145941e..add39ac22 100644 --- a/src/core/mac/sub_mac_callbacks.cpp +++ b/src/core/mac/sub_mac_callbacks.cpp @@ -36,7 +36,10 @@ #include "common/code_utils.hpp" #include "common/instance.hpp" #include "common/locator-getters.hpp" + +#if OPENTHREAD_FTD || OPENTHREAD_MTD #include "mac/mac.hpp" +#endif namespace ot { namespace Mac { diff --git a/src/ncp/CMakeLists.txt b/src/ncp/CMakeLists.txt index c887c9a87..eedb17c79 100644 --- a/src/ncp/CMakeLists.txt +++ b/src/ncp/CMakeLists.txt @@ -93,17 +93,26 @@ target_sources(openthread-ncp-ftd PRIVATE ${COMMON_SOURCES}) target_sources(openthread-ncp-mtd PRIVATE ${COMMON_SOURCES}) target_sources(openthread-rcp PRIVATE ${COMMON_SOURCES}) -target_link_libraries(openthread-ncp-ftd PRIVATE - openthread-hdlc - openthread-spinel-ncp +target_link_libraries(openthread-ncp-ftd + PUBLIC + openthread-ftd + PRIVATE + openthread-hdlc + openthread-spinel-ncp ) -target_link_libraries(openthread-ncp-mtd PRIVATE - openthread-hdlc - openthread-spinel-ncp +target_link_libraries(openthread-ncp-mtd + PUBLIC + openthread-mtd + PRIVATE + openthread-hdlc + openthread-spinel-ncp ) -target_link_libraries(openthread-rcp PRIVATE - openthread-hdlc - openthread-spinel-rcp +target_link_libraries(openthread-rcp + PUBLIC + openthread-radio + PRIVATE + openthread-hdlc + openthread-spinel-rcp ) diff --git a/src/posix/platform/CMakeLists.txt b/src/posix/platform/CMakeLists.txt index eef952411..d9c4d10f8 100644 --- a/src/posix/platform/CMakeLists.txt +++ b/src/posix/platform/CMakeLists.txt @@ -63,8 +63,11 @@ target_link_libraries(openthread-posix PUBLIC ) target_compile_definitions(openthread-posix - PUBLIC ${OT_PLATFORM_DEFINES} - PRIVATE ${OT_PRIVATE_DEFINES} + PUBLIC + ${OT_PUBLIC_DEFINES} + PRIVATE + ${OT_PLATFORM_DEFINES} + ${OT_PRIVATE_DEFINES} ) target_compile_options(openthread-posix PRIVATE diff --git a/third_party/mbedtls/CMakeLists.txt b/third_party/mbedtls/CMakeLists.txt index 00ca41610..63c9accf8 100644 --- a/third_party/mbedtls/CMakeLists.txt +++ b/third_party/mbedtls/CMakeLists.txt @@ -28,16 +28,33 @@ add_library(mbedcrypto) -target_compile_definitions(mbedcrypto PRIVATE - ${OT_PRIVATE_DEFINES} +set(OT_MBEDTLS_DEFAULT_CONFIG_FILE "\"mbedtls-config.h\"") + +set(OT_MBEDTLS_CONFIG_FILE "" CACHE STRING "The mbedTLS config file") + +target_compile_definitions(mbedcrypto + PUBLIC + "MBEDTLS_CONFIG_FILE=$,${OT_MBEDTLS_CONFIG_FILE},${OT_MBEDTLS_DEFAULT_CONFIG_FILE}>" + PRIVATE + ${OT_PRIVATE_DEFINES} ) -target_include_directories(mbedcrypto PRIVATE - ${OT_PUBLIC_INCLUDES} - ${OT_PRIVATE_INCLUDES} - ${PROJECT_SOURCE_DIR}/src/core +target_include_directories(mbedcrypto + PUBLIC + ${PROJECT_SOURCE_DIR}/third_party/mbedtls/repo/include + PRIVATE + ${OT_PUBLIC_INCLUDES} + ${OT_PRIVATE_INCLUDES} ) +if (NOT OT_MBEDTLS_CONFIG_FILE) + target_include_directories(mbedcrypto + PUBLIC + ${PROJECT_SOURCE_DIR}/src/core + ${PROJECT_SOURCE_DIR}/third_party/mbedtls + ) +endif() + target_sources(mbedcrypto PRIVATE repo/library/aes.c repo/library/asn1parse.c @@ -75,6 +92,7 @@ target_sources(mbedcrypto PRIVATE repo/library/ssl_ticket.c repo/library/ssl_tls.c repo/library/threading.c + repo/library/timing.c repo/library/x509.c repo/library/x509_crt.c )