From 62139bf0ab19c4c5d0b8a4d2282a6b8cf3405aac Mon Sep 17 00:00:00 2001 From: dinabenamar <108664279+dinabenamar@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:01:50 +0200 Subject: [PATCH] [NXP][config] Adding CMake support to build CHIP libs for NXP FreeRTOS platforms (#34901) * [NXP][config][freertos] Adding support to build Matter lib and port files with cmake on NXP freertos platforms Signed-off-by: Dina Benamar * [NXP][config][common] Create common .cmake file to include common configs between freertos & zephyr Signed-off-by: Dina Benamar * [NXP][config][zephyr] Include common.cmake which adds common options to zephyr & freertos Signed-off-by: Dina Benamar * [NXP][config][freertos] Updates to align with new flag introduction "chip_enable_secure_whole_factory_data" Signed-off-by: Dina Benamar * [NXP][config][freertos] Set build_matter_standalone_lib to true to support building CHIP libs with CMake in matter-over-thread configuration Signed-off-by: Dina Benamar --------- Signed-off-by: Dina Benamar --- config/nxp/chip-cmake-freertos/CMakeLists.txt | 62 +++++++++++++++++ config/nxp/chip-gn-freertos/.gn | 29 ++++++++ config/nxp/chip-gn-freertos/BUILD.gn | 42 +++++++++++ config/nxp/chip-gn-freertos/args.gni | 31 +++++++++ config/nxp/chip-module/CMakeLists.txt | 42 +---------- config/nxp/cmake/common.cmake | 69 +++++++++++++++++++ 6 files changed, 234 insertions(+), 41 deletions(-) create mode 100644 config/nxp/chip-cmake-freertos/CMakeLists.txt create mode 100644 config/nxp/chip-gn-freertos/.gn create mode 100644 config/nxp/chip-gn-freertos/BUILD.gn create mode 100644 config/nxp/chip-gn-freertos/args.gni create mode 100644 config/nxp/cmake/common.cmake diff --git a/config/nxp/chip-cmake-freertos/CMakeLists.txt b/config/nxp/chip-cmake-freertos/CMakeLists.txt new file mode 100644 index 00000000000000..b639e23ff65034 --- /dev/null +++ b/config/nxp/chip-cmake-freertos/CMakeLists.txt @@ -0,0 +1,62 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include(ExternalProject) + +if(NOT CHIP_ROOT) + get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH) +endif() + +get_filename_component(GN_ROOT_TARGET ${CHIP_ROOT}/config/nxp/chip-gn-freertos REALPATH) + +include(${CHIP_ROOT}/config/nxp/cmake/common.cmake) +include(${CHIP_ROOT}/src/app/chip_data_model.cmake) + +# Prepare compiler flags +matter_add_cflags(${CMAKE_C_FLAGS}) +matter_add_cxxflags(${CMAKE_CXX_FLAGS}) + +matter_get_compiler_flags_from_targets("${CONFIG_CHIP_EXTERNAL_TARGETS}") + +# ============================================================================== +# Generate configuration for CHIP GN build system +# ============================================================================== +matter_add_gn_arg_string("nxp_nvm_component" ${CONFIG_CHIP_NVM_COMPONENT}) +matter_add_gn_arg_string("nxp_platform" ${CONFIG_CHIP_NXP_PLATFORM}) +matter_add_gn_arg("chip_with_factory_data" ${CONFIG_CHIP_FACTORY_DATA}) +matter_add_gn_arg("chip_enable_secure_dac_private_key_storage" ${CONFIG_CHIP_SECURE_DAC_PRIVATE_KEY_STORAGE}) +matter_add_gn_arg("chip_enable_secure_whole_factory_data" ${CONFIG_CHIP_ENABLE_SECURE_WHOLE_FACTORY_DATA}) + +matter_common_gn_args( + DEBUG CONFIG_DEBUG + LIB_SHELL CONFIG_CHIP_LIB_SHELL + LIB_TESTS CONFIG_CHIP_BUILD_TESTS + PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG} + PROJECT_CONFIG_INC_DIR ${CONFIG_CHIP_PROJECT_CONFIG_INCLUDE_DIRS} + DEVICE_INFO_EXAMPLE_PROVIDER CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER +) + +matter_generate_args_tmp_file() + +# ============================================================================== +# Build chip library +# ============================================================================== +matter_build(chip + LIB_SHELL ${CONFIG_CHIP_LIB_SHELL} + LIB_TESTS ${CONFIG_CHIP_BUILD_TESTS} + DEVICE_INFO_EXAMPLE_PROVIDER ${CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER} + GN_DEPENDENCIES ${CONFIG_GN_DEPENDENCIES} +) diff --git a/config/nxp/chip-gn-freertos/.gn b/config/nxp/chip-gn-freertos/.gn new file mode 100644 index 00000000000000..15dde062d89de3 --- /dev/null +++ b/config/nxp/chip-gn-freertos/.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2024 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +# The location of the build configuration file. +buildconfig = "//build/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +default_args = { + target_cpu = "arm" + target_os = "freertos" + + import("${chip_root}/config/nxp/chip-gn-freertos/args.gni") +} diff --git a/config/nxp/chip-gn-freertos/BUILD.gn b/config/nxp/chip-gn-freertos/BUILD.gn new file mode 100644 index 00000000000000..3c508666c833d1 --- /dev/null +++ b/config/nxp/chip-gn-freertos/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2024 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +import("${chip_root}/build/chip/tests.gni") + +assert(current_os == "freertos") + +declare_args() { + chip_build_example_providers = false + chip_enable_ethernet = false + chip_malloc_sys_heap = false +} + +group("nxp_freertos") { + deps = [ "${chip_root}/src/lib" ] + + if (chip_build_tests) { + deps += [ "${chip_root}/src:tests" ] + } + + if (chip_build_example_providers) { + deps += [ "${chip_root}/examples/providers:device_info_provider" ] + } +} + +group("default") { + deps = [ ":nxp_freertos" ] +} diff --git a/config/nxp/chip-gn-freertos/args.gni b/config/nxp/chip-gn-freertos/args.gni new file mode 100644 index 00000000000000..be31f22fcbdcf1 --- /dev/null +++ b/config/nxp/chip-gn-freertos/args.gni @@ -0,0 +1,31 @@ +# Copyright (c) 2024 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/chip.gni") +import("//build_overrides/nxp_sdk.gni") + +nxp_external_sdk = true +nxp_build_matter_standalone_lib = true +chip_device_platform = "nxp" +lwip_platform = "nxp" + +# project config files +chip_device_project_config_include = "" +chip_project_config_include = "" +chip_inet_project_config_include = "" +chip_system_project_config_include = "" +chip_ble_project_config_include = "" + +# mbedtls is built as part of the NXP SDK build process +mbedtls_target = "${nxp_sdk_build_root}:nxp_mbedtls" diff --git a/config/nxp/chip-module/CMakeLists.txt b/config/nxp/chip-module/CMakeLists.txt index 6b8266970dc883..32a85a606c71e0 100644 --- a/config/nxp/chip-module/CMakeLists.txt +++ b/config/nxp/chip-module/CMakeLists.txt @@ -42,12 +42,8 @@ if (NOT CHIP_ROOT) get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH) endif() get_filename_component(GN_ROOT_TARGET ${CHIP_ROOT}/config/nxp/chip-gn REALPATH) -get_filename_component(COMMON_CMAKE_SOURCE_DIR ${CHIP_ROOT}/config/common/cmake REALPATH) -# Get common Cmake sources - -include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) -include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) +include(${CHIP_ROOT}/config/nxp/cmake/common.cmake) # Prepare compiler flags if (CHIP_CFLAGS) @@ -109,30 +105,6 @@ matter_common_gn_args( matter_add_gn_arg_string("zephyr_ar" ${CMAKE_AR}) matter_add_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER}) matter_add_gn_arg_string("zephyr_cxx" ${CMAKE_CXX_COMPILER}) -matter_add_gn_arg_bool ("chip_logging" CONFIG_LOG) -matter_add_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD) -matter_add_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD) -matter_add_gn_arg_bool ("chip_config_network_layer_ble" CONFIG_BT) -matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_CHIP_IPV4) -matter_add_gn_arg_bool ("chip_persist_subscriptions" CONFIG_CHIP_PERSISTENT_SUBSCRIPTIONS) -matter_add_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TESTS) -matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) -matter_add_gn_arg_bool ("chip_error_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 1) -matter_add_gn_arg_bool ("chip_progress_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 3) -matter_add_gn_arg_bool ("chip_detail_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 4) -matter_add_gn_arg_bool ("chip_automation_logging" FALSE) -matter_add_gn_arg_bool ("chip_malloc_sys_heap" CONFIG_CHIP_MALLOC_SYS_HEAP) -matter_add_gn_arg_bool ("chip_enable_wifi" CONFIG_CHIP_WIFI) -matter_add_gn_arg_bool ("chip_system_config_provide_statistics" CONFIG_CHIP_STATISTICS) -matter_add_gn_arg_bool ("chip_enable_icd_server" CONFIG_CHIP_ENABLE_ICD_SUPPORT) -matter_add_gn_arg_bool ("enable_eventlist_attribute" TRUE) -matter_add_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) - -if(CONFIG_DEBUG) - matter_add_gn_arg_bool("optimize_debug" true) - matter_add_gn_arg_string("optimize_debug_level" "0") - matter_add_gn_arg_string("symbol_level" "2") -endif() if (CONFIG_CHIP_FACTORY_DATA) matter_add_gn_arg_bool("chip_use_transitional_commissionable_data_provider" FALSE) @@ -141,11 +113,6 @@ elseif (CONFIG_CHIP_FACTORY_DATA_CUSTOM_BACKEND) matter_add_gn_arg_bool("chip_use_transitional_commissionable_data_provider" FALSE) endif() -if (CONFIG_CHIP_ROTATING_DEVICE_ID) - matter_add_gn_arg_bool("chip_enable_rotating_device_id" TRUE) - matter_add_gn_arg_bool("chip_enable_additional_data_advertising" TRUE) -endif() - if (CONFIG_NET_L2_OPENTHREAD) matter_add_gn_arg_string("chip_mdns" "platform") elseif(CONFIG_WIFI_NXP) @@ -154,9 +121,6 @@ else() matter_add_gn_arg_string("chip_mdns" "none") endif() -if (CONFIG_CHIP_CRYPTO_PSA) - matter_add_gn_arg_string("chip_crypto" "psa") -endif() # if (BOARD STREQUAL "native_posix") # matter_add_gn_arg_string("target_cpu" "x86") @@ -164,10 +128,6 @@ endif() # matter_add_gn_arg_string("target_cpu" "x64") # endif() -if (NOT CONFIG_CHIP_DEBUG_SYMBOLS) - matter_add_gn_arg_string("symbol_level" "0") -endif() - # if (CHIP_COMPILER_LAUNCHER) # matter_add_gn_arg_string("pw_command_launcher" ${CHIP_COMPILER_LAUNCHER}) # endif() diff --git a/config/nxp/cmake/common.cmake b/config/nxp/cmake/common.cmake new file mode 100644 index 00000000000000..8b0f379f502d09 --- /dev/null +++ b/config/nxp/cmake/common.cmake @@ -0,0 +1,69 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# @file +# CMake for CHIP library configuration common to NXP platforms +# + +include(${CHIP_ROOT}/config/nxp/chip-module/generate_factory_data.cmake) + +get_filename_component(COMMON_CMAKE_SOURCE_DIR ${CHIP_ROOT}/config/common/cmake REALPATH) + +# Get common Cmake sources +include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) +include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) + +# ============================================================================== +# Generate configuration for CHIP GN build system +# ============================================================================== +matter_add_gn_arg_bool ("chip_logging" CONFIG_LOG) +matter_add_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD) +matter_add_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD) +matter_add_gn_arg_bool ("chip_config_network_layer_ble" CONFIG_BT) +matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_CHIP_IPV4) +matter_add_gn_arg_bool ("chip_persist_subscriptions" CONFIG_CHIP_PERSISTENT_SUBSCRIPTIONS) +matter_add_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TESTS) +matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) +matter_add_gn_arg_bool ("chip_error_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 1) +matter_add_gn_arg_bool ("chip_progress_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 3) +matter_add_gn_arg_bool ("chip_detail_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 4) +matter_add_gn_arg_bool ("chip_automation_logging" FALSE) +matter_add_gn_arg_bool ("chip_malloc_sys_heap" CONFIG_CHIP_MALLOC_SYS_HEAP) +matter_add_gn_arg_bool ("chip_enable_wifi" CONFIG_CHIP_WIFI) +matter_add_gn_arg_bool ("chip_system_config_provide_statistics" CONFIG_CHIP_STATISTICS) +matter_add_gn_arg_bool ("chip_enable_icd_server" CONFIG_CHIP_ENABLE_ICD_SUPPORT) +matter_add_gn_arg_bool ("enable_eventlist_attribute" TRUE) +matter_add_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) + +if(CONFIG_DEBUG) + matter_add_gn_arg_bool("optimize_debug" true) + matter_add_gn_arg_string("optimize_debug_level" "0") + matter_add_gn_arg_string("symbol_level" "2") +endif() + +if (CONFIG_CHIP_ROTATING_DEVICE_ID) + matter_add_gn_arg_bool("chip_enable_rotating_device_id" TRUE) + matter_add_gn_arg_bool("chip_enable_additional_data_advertising" TRUE) +endif() + +if (CONFIG_CHIP_CRYPTO_PSA) + matter_add_gn_arg_string("chip_crypto" "psa") +endif() + +if (NOT CONFIG_CHIP_DEBUG_SYMBOLS) + matter_add_gn_arg_string("symbol_level" "0") +endif()