Skip to content

Commit

Permalink
[cmake] Add Matter mbedtls library support option (#27592)
Browse files Browse the repository at this point in the history
Add option to build and use the Matter version of mbedtls
to cmake helpers.

Signed-off-by: ATmobica <artur.tynecki@arm.com>
  • Loading branch information
ATmobica authored and pull[bot] committed Sep 29, 2023
1 parent d07a376 commit 1012958
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
26 changes: 19 additions & 7 deletions config/common/cmake/chip_gn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# @file
# CMake file defining to setup and build the Matter library
# and other optional libraries like unit tests.
# Matter headers and libraries are exposed to the application
# Matter headers and libraries are exposed to the application
# as a specific interface target.
# Since Matter doesn't provide native CMake support, ExternalProject
# module is used to build the required artifacts with GN meta-build
Expand Down Expand Up @@ -57,34 +57,40 @@ endif()
# Macros
# ==============================================================================
# Setup and build the Matter library and other optional libraries like unit tests.
# Expose Matter headers & libraries to the application as specific
# Expose Matter headers & libraries to the application as specific
# interface target.
# [Args]:
# target - interface target name
# Available options are:
# LIB_SHELL Build and add Matter shell library
# LIB_PW_RPC Build and add Matter PW RPC library
# LIB_TESTS Build and add Matter unit tests library
# LIB_MBEDTLS Build and add Matter mbedtls library
# DEVICE_INFO_EXAMPLE_PROVIDER Add example device info provider support
#
# GN_DEPENDENCIES List of targets that should be built before Matter GN project
macro(matter_build target)
set(options)
set(oneValueArgs
LIB_TESTS
LIB_SHELL
LIB_TESTS
LIB_SHELL
LIB_PW_RPC
LIB_MBEDTLS
DEVICE_INFO_EXAMPLE_PROVIDER
)
set(multiValueArgs GN_DEPENDENCIES)

cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(MATTER_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib)

# Prepare Matter libraries that the application should be linked with
set(MATTER_LIBRARIES -lCHIP)

if (ARG_LIB_MBEDTLS)
list(APPEND MATTER_LIBRARIES -lmbedtls)
endif()

if (ARG_LIB_SHELL)
list(APPEND MATTER_LIBRARIES -lCHIPShell)
endif()
Expand Down Expand Up @@ -115,7 +121,7 @@ macro(matter_build target)
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting Matter library build in ${CMAKE_CURRENT_BINARY_DIR}"
COMMAND ${Python3_EXECUTABLE} ${CHIP_ROOT}/config/common/cmake/make_gn_args.py @args.tmp > args.gn.tmp
# Replace the config only if it has changed to avoid triggering unnecessary rebuilds
COMMAND bash -c "(! diff -q args.gn.tmp args.gn && mv args.gn.tmp args.gn) || true"
COMMAND bash -c "(! diff -q args.gn.tmp args.gn && mv args.gn.tmp args.gn) || true"
# Regenerate the ninja build system
COMMAND ${GN_EXECUTABLE}
--root=${CHIP_ROOT}
Expand All @@ -127,7 +133,7 @@ macro(matter_build target)
COMMAND ${CMAKE_COMMAND} -E echo "Matter library build complete"
INSTALL_COMMAND ""
# Byproducts are removed by the clean target removing config and .ninja_deps
# allows a rebuild of the external project after the clean target has been run.
# allows a rebuild of the external project after the clean target has been run.
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/args.gn
${CMAKE_CURRENT_BINARY_DIR}/build.ninja
${CMAKE_CURRENT_BINARY_DIR}/.ninja_deps
Expand Down Expand Up @@ -156,6 +162,12 @@ macro(matter_build target)
${CMAKE_CURRENT_BINARY_DIR}/gen/include
)

if (ARG_LIB_MBEDTLS)
target_include_directories(${target} INTERFACE
${CHIP_ROOT}/third_party/mbedtls/repo/include
)
endif()

# ==============================================================================
# Link required libraries
# ==============================================================================
Expand Down
12 changes: 6 additions & 6 deletions config/common/cmake/chip_gn_args.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#
# @file
# CMake file that allows collecting C/C++ compiler flags passed to
# CMake file that allows collecting C/C++ compiler flags passed to
# the Matter build system.
#

Expand Down Expand Up @@ -165,11 +165,11 @@ endmacro()
macro(matter_common_gn_args)
set(options)
set(oneValueArgs
DEBUG
LIB_TESTS
LIB_SHELL
DEBUG
LIB_TESTS
LIB_SHELL
LIB_PW_RPC
DEVICE_INFO_EXAMPLE_PROVIDER
DEVICE_INFO_EXAMPLE_PROVIDER
PROJECT_CONFIG

)
Expand All @@ -196,7 +196,7 @@ macro(matter_common_gn_args)
matter_add_gn_arg_bool ("is_debug" ${ARG_DEBUG})
matter_add_gn_arg_bool ("chip_build_tests" ${ARG_LIB_TESTS})
matter_add_gn_arg_bool ("chip_build_libshell" ${ARG_LIB_SHELL})

if (ARG_LIB_PW_RPC)
matter_add_gn_arg_bool ("chip_build_pw_rpc_lib" ${ARG_LIB_PW_RPC})
endif() # ARG_LIB_PW_RPC
Expand Down

0 comments on commit 1012958

Please sign in to comment.