forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request project-chip#13 from ARMmbed/chip-mbed-integration-at
Chip SHELL mbed integration
- Loading branch information
Showing
43 changed files
with
3,377 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
# | ||
# Copyright (c) 2020 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 sub-project defining 'chip' target which represents CHIP library | ||
# and other optional libraries like unit tests, built with 'mbed' | ||
# platform. | ||
# Since CHIP doesn't provide native CMake support, ExternalProject | ||
# module is used to build the required artifacts with GN meta-build | ||
# system. | ||
# | ||
|
||
include(ExternalProject) | ||
include(mbed-util.cmake) | ||
|
||
# ============================================================================== | ||
# Declare configuration variables and define constants | ||
# ============================================================================== | ||
# C/C++ compiler flags passed to CHIP build system | ||
list(APPEND CHIP_CFLAGS) | ||
|
||
# C compiler flags passed to CHIP build system | ||
list(APPEND CHIP_CFLAGS_C) | ||
|
||
# C++ compiler flags passed to CHIP build system | ||
list(APPEND CHIP_CFLAGS_CC) | ||
|
||
# CHIP libraries that the application should be linked with | ||
list(APPEND CHIP_LIBRARIES) | ||
|
||
# GN meta-build system arguments in the form of 'key1 = value1\nkey2 = value2...' string | ||
string(APPEND CHIP_GN_ARGS) | ||
|
||
# C/C++ compiler flags which should not be forwarded to CHIP | ||
# build system (e.g. because CHIP configures them on its own) | ||
set(CHIP_CFLAG_EXCLUDES | ||
"-fno-asynchronous-unwind-tables" | ||
"-fno-common" | ||
"-fno-defer-pop" | ||
"-fno-reorder-functions" | ||
"-ffunction-sections" | ||
"-fdata-sections" | ||
"-g*" | ||
"-O*" | ||
"-W*" | ||
) | ||
|
||
# ============================================================================== | ||
# Helper macros | ||
# ============================================================================== | ||
|
||
macro(chip_gn_arg_string ARG STRING) | ||
string(APPEND CHIP_GN_ARGS "${ARG} = \"${STRING}\"\n") | ||
endmacro() | ||
|
||
macro(chip_gn_arg_bool ARG BOOLEAN) | ||
if (${BOOLEAN}) | ||
string(APPEND CHIP_GN_ARGS "${ARG} = true\n") | ||
else() | ||
string(APPEND CHIP_GN_ARGS "${ARG} = false\n") | ||
endif() | ||
endmacro() | ||
|
||
macro(chip_gn_arg_flags ARG CFLAGS) | ||
string(APPEND CHIP_GN_ARGS "${ARG} = [${CFLAGS}]\n") | ||
endmacro() | ||
|
||
macro(chip_gn_arg_lang_flags ARG CFLAGS) | ||
set(CFLAG_EXCLUDES "[") | ||
foreach(cflag ${CHIP_CFLAG_EXCLUDES}) | ||
string(APPEND CFLAG_EXCLUDES "\"${cflag}\", ") | ||
endforeach() | ||
string(APPEND CFLAG_EXCLUDES "]") | ||
string(APPEND CHIP_GN_ARGS "${ARG} = filter_exclude(string_split(\"${CFLAGS}\"), ${CFLAG_EXCLUDES})\n") | ||
endmacro() | ||
|
||
macro(mbed_interface_library_named name) | ||
add_library(${name} INTERFACE) | ||
set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS ${name}) | ||
endmacro() | ||
|
||
# ============================================================================== | ||
# Prepare CHIP configuration based on the project configuration | ||
# ============================================================================== | ||
# Read configuration file and parse it content to create cmake variable | ||
file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/config ConfigContents) | ||
foreach(NameAndValue ${ConfigContents}) | ||
# Strip leading spaces | ||
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) | ||
# Find variable name | ||
string(REGEX MATCH "^[^=]+" Name ${NameAndValue}) | ||
# Find the value | ||
string(REPLACE "${Name}=" "" Value ${NameAndValue}) | ||
# Set the variable | ||
set(${Name} "${Value}") | ||
endforeach() | ||
|
||
if (NOT CHIP_ROOT) | ||
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../.. REALPATH) | ||
endif() | ||
|
||
# Prepare compiler flags | ||
|
||
mbed_get_common_compile_flags(CHIP_CFLAGS) | ||
mbed_get_lang_compile_flags(CHIP_CFLAGS_C C) | ||
list(APPEND CHIP_CFLAGS_C ${CMAKE_C_FLAGS_INIT}) | ||
mbed_get_lang_compile_flags(CHIP_CFLAGS_CC CXX) | ||
list(APPEND CHIP_CFLAGS_CC ${CMAKE_CXX_FLAGS_INIT}) | ||
|
||
set(SEPARATOR ",") | ||
convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS CHIP_CFLAGS ${SEPARATOR}) | ||
set(SEPARATOR " ") | ||
convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_C CHIP_CFLAGS_C ${SEPARATOR}) | ||
convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_CC CHIP_CFLAGS_CC ${SEPARATOR}) | ||
|
||
# Prepare CHIP libraries that the application should be linked with | ||
|
||
if (NOT CHIP_LIBRARIES) | ||
set(CHIP_LIBRARIES -lCHIP) | ||
endif() | ||
|
||
if (CONFIG_CHIP_LIB_SHELL) | ||
list(APPEND CHIP_LIBRARIES -lCHIPShell) | ||
endif() | ||
|
||
# Set up CHIP project configuration file | ||
|
||
if (CONFIG_CHIP_PROJECT_CONFIG) | ||
get_filename_component(CHIP_PROJECT_CONFIG | ||
${CONFIG_CHIP_PROJECT_CONFIG} | ||
REALPATH | ||
BASE_DIR ${CMAKE_SOURCE_DIR} | ||
) | ||
set(CHIP_PROJECT_CONFIG "<${CHIP_PROJECT_CONFIG}>") | ||
else() | ||
set(CHIP_PROJECT_CONFIG "") | ||
endif() | ||
|
||
if (${CMAKE_BUILD_TYPE} STREQUAL "debug") | ||
set(CONFIG_DEBUG "y") | ||
endif() | ||
|
||
# ============================================================================== | ||
# Generate configuration for CHIP GN build system | ||
# ============================================================================== | ||
|
||
chip_gn_arg_flags("target_cflags" ${CHIP_CFLAGS}) | ||
chip_gn_arg_lang_flags("target_cflags_c" ${CHIP_CFLAGS_C}) | ||
chip_gn_arg_lang_flags("target_cflags_cc" ${CHIP_CFLAGS_CC}) | ||
chip_gn_arg_string("mbed_ar" ${CMAKE_AR}) | ||
chip_gn_arg_string("mbed_cc" ${CMAKE_C_COMPILER}) | ||
chip_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER}) | ||
chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) | ||
chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS) | ||
chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL) | ||
chip_gn_arg_bool ("chip_with_lwip" CONFIG_CHIP_WITH_LWIP) | ||
|
||
if (BOARD STREQUAL "native_posix") | ||
chip_gn_arg_string("target_cpu" "x86") | ||
elseif (BOARD STREQUAL "native_posix_64") | ||
chip_gn_arg_string("target_cpu" "x64") | ||
endif() | ||
|
||
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS}) | ||
|
||
# ============================================================================== | ||
# Define 'chip-gn' target that builds CHIP library(ies) with GN build system | ||
# ============================================================================== | ||
ExternalProject_Add( | ||
chip-gn | ||
PREFIX ${CMAKE_CURRENT_BINARY_DIR} | ||
SOURCE_DIR ${CHIP_ROOT} | ||
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} | ||
CONFIGURE_COMMAND gn --root=${CHIP_ROOT}/config/mbed/chip-gn gen --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR} | ||
BUILD_COMMAND ninja | ||
INSTALL_COMMAND "" | ||
BUILD_BYPRODUCTS ${CHIP_LIBRARIES} | ||
BUILD_ALWAYS TRUE | ||
USES_TERMINAL_CONFIGURE TRUE | ||
USES_TERMINAL_BUILD TRUE | ||
) | ||
|
||
# ============================================================================== | ||
# Define 'chip' target that exposes CHIP headers & libraries to the application | ||
# ============================================================================== | ||
mbed_interface_library_named(chip) | ||
target_compile_definitions(chip INTERFACE CHIP_HAVE_CONFIG_H) | ||
target_include_directories(chip INTERFACE | ||
${CHIP_ROOT}/src | ||
${CHIP_ROOT}/src/app/server | ||
${CHIP_ROOT}/src/app/util | ||
${CHIP_ROOT}/src/include | ||
${CHIP_ROOT}/src/lib | ||
${CHIP_ROOT}/src/lib/core | ||
${CHIP_ROOT}/third_party/nlassert/repo/include | ||
${CMAKE_CURRENT_BINARY_DIR}/gen/include | ||
${CMAKE_CURRENT_BINARY_DIR}/gen/third_party/connectedhomeip/src/app/include | ||
) | ||
target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib) | ||
target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group) | ||
add_dependencies(chip chip-gn) | ||
|
||
# ============================================================================== | ||
# Define mbed target configuration according to CHIP component usage | ||
# ============================================================================== | ||
# CHIP includes path | ||
list(APPEND CHIP_INCLUDES) | ||
|
||
# CHIP defines | ||
list(APPEND CHIP_DEFINES) | ||
|
||
if (${CONFIG_CHIP_WITH_LWIP}) | ||
list(APPEND CHIP_INCLUDES | ||
${CHIP_ROOT}/third_party/lwip/repo/lwip/src/include | ||
${CHIP_ROOT}/src/lwip/mbed | ||
) | ||
list(APPEND CHIP_DEFINES | ||
"LWIP_NO_STDINT_H=1" | ||
"IN_ADDR_T_DEFINED=1" | ||
) | ||
endif() | ||
|
||
target_include_directories(${APP_TARGET} PRIVATE | ||
${CHIP_INCLUDES} | ||
) | ||
|
||
target_compile_definitions(${APP_TARGET} PRIVATE | ||
${CHIP_DEFINES} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) 2020 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. | ||
|
||
# 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 = "mbed" | ||
|
||
import("//args.gni") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright (c) 2020 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("//${chip_root}/build/chip/tests.gni") | ||
import("//build_overrides/mbedtls.gni") | ||
import("${mbedtls_root}/mbedtls.gni") | ||
|
||
assert(current_os == "mbed") | ||
|
||
declare_args() { | ||
chip_build_libshell = false | ||
} | ||
|
||
group("mbed") { | ||
deps = [ "${chip_root}/src/lib" ] | ||
|
||
if (chip_build_libshell) { | ||
deps += [ "${chip_root}/src/lib/shell" ] | ||
} | ||
} | ||
|
||
group("default") { | ||
deps = [ ":mbed" ] | ||
} | ||
|
||
mbedtls_target("mbedtls") { | ||
include_dirs = [ | ||
"mbedtls" | ||
] | ||
|
||
defines = [ | ||
"MBEDTLS_CONFIG_FILE=<mbed_tls_mbed_stub_config.h>" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) 2020 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") | ||
|
||
chip_device_platform = "mbed" | ||
|
||
chip_project_config_include = "" | ||
chip_system_project_config_include = "" | ||
chip_ble_project_config_include = "" | ||
|
||
custom_toolchain = "//toolchain:mbed" | ||
mbedtls_target = "//:mbedtls" | ||
|
||
treat_warnings_as_errors = false | ||
lwip_platform = "mbed" | ||
chip_system_config_use_sockets=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../examples/build_overrides/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
#define MBEDTLS_NO_PLATFORM_ENTROPY | ||
#undef MBEDTLS_FS_IO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../ |
Oops, something went wrong.