Skip to content

Commit

Permalink
[NXP][config] Adding CMake support to build CHIP libs for NXP FreeRTO…
Browse files Browse the repository at this point in the history
…S platforms (project-chip#34901)

* [NXP][config][freertos] Adding support to build Matter lib and port files with cmake on NXP freertos platforms

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>

* [NXP][config][common] Create common .cmake file to include common configs between freertos & zephyr

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>

* [NXP][config][zephyr] Include common.cmake which adds common options to zephyr & freertos

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>

* [NXP][config][freertos] Updates to align with new flag introduction "chip_enable_secure_whole_factory_data"

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>

* [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 <dina.benamarelmaaroufi@nxp.com>

---------

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
  • Loading branch information
dinabenamar authored Aug 13, 2024
1 parent 13c45d5 commit 62139bf
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 41 deletions.
62 changes: 62 additions & 0 deletions config/nxp/chip-cmake-freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
29 changes: 29 additions & 0 deletions config/nxp/chip-gn-freertos/.gn
Original file line number Diff line number Diff line change
@@ -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")
}
42 changes: 42 additions & 0 deletions config/nxp/chip-gn-freertos/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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" ]
}
31 changes: 31 additions & 0 deletions config/nxp/chip-gn-freertos/args.gni
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 1 addition & 41 deletions config/nxp/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -154,20 +121,13 @@ 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")
# elseif (BOARD STREQUAL "native_posix_64")
# 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()
Expand Down
69 changes: 69 additions & 0 deletions config/nxp/cmake/common.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 62139bf

Please sign in to comment.