Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Gn #2321

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions config/nrfconnect/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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

# Allow loading paths relative to //gn.
secondary_source = "//third_party/connectedhomeip/gn/"

default_args = {
# We don't want the build scripts to inject any additional CPU related compiler flags,
# because those are supplied from cmake.
target_cpu = "zephyr"
target_os = "zephyr"

import("//args.gni")
}
44 changes: 44 additions & 0 deletions config/nrfconnect/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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("//${chip_root}/gn/chip/tests.gni")
import("//build_overrides/chip.gni")

assert(current_os == "zephyr")

group("nrfconnect") {
deps = [ "${chip_root}/src/lib" ]
}

if (chip_build_tests) {
import("//${chip_root}/gn/chip/chip_test_group.gni")

group("check") {
deps = [ ":tests_run" ]
}

chip_test_group("tests") {
deps = [
"${chip_root}/src/ble/tests",
"${chip_root}/src/crypto/tests",
"${chip_root}/src/inet/tests",
"${chip_root}/src/lib/core/tests",
"${chip_root}/src/lib/support/tests",
"${chip_root}/src/platform/tests",
"${chip_root}/src/setup_payload/tests",
"${chip_root}/src/system/tests",
"${chip_root}/src/transport/tests",
]
}
}
34 changes: 34 additions & 0 deletions config/nrfconnect/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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")

nrfconnect_target = get_label_info(":nrfconnect", "label_no_toolchain")

chip_device_platform = "nrfconnect"
chip_logging_style = "external"

chip_ble_project_config_include = "<CHIPProjectConfig.h>"
chip_device_project_config_include = "<CHIPProjectConfig.h>"
chip_project_config_include = "<CHIPProjectConfig.h>"
chip_inet_project_config_include = "<CHIPProjectConfig.h>"
chip_system_project_config_include = "<CHIPProjectConfig.h>"

chip_build_tests = false
chip_inet_config_enable_tun_endpoint = chip_build_tests
chip_inet_config_enable_raw_endpoint = chip_build_tests
chip_inet_config_enable_tcp_endpoint = chip_build_tests
chip_inet_config_enable_dns_resolver = chip_build_tests
chip_inet_config_enable_ipv4 = chip_build_tests
custom_toolchain = "//toolchain:zephyr"
1 change: 1 addition & 0 deletions config/nrfconnect/build_overrides
94 changes: 47 additions & 47 deletions config/nrfconnect/chip-lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ macro(append_if_not VAR CONDITION)
endif()
endmacro()

macro(chip_gn_arg_bool_if CONDITION ARGSTRING GN_VARNAME)
if (${${CONDITION}})
string(APPEND ${ARGSTRING} "${GN_VARNAME} = true\n")
else ()
string(APPEND ${ARGSTRING} "${GN_VARNAME} = false\n")
endif()
endmacro()

macro(chip_gn_arg_string ARGSTRING GN_STRING)
string(APPEND ${ARGSTRING} "${GN_STRING}\n")
endmacro()

# Function to retrieve Zephyr compilation flags for the given language (C or CXX)
function(zephyr_get_compile_flags VAR LANG)
zephyr_get_include_directories_for_lang(${LANG} INCLUDES)
Expand All @@ -61,80 +73,65 @@ endfunction()
# ==================================================

function(chip_configure TARGET_NAME)
cmake_parse_arguments(CHIP
cmake_parse_arguments(CHIP
"BUILD_TESTS"
"ARCH;PROJECT_CONFIG"
"CFLAGS;CXXFLAGS"
"CFLAGS;CXXFLAGS"
${ARGN})

# Prepare CFLAGS & CXXFLAGS
zephyr_get_compile_flags(CHIP_CFLAGS C)
list(APPEND CHIP_CFLAGS -I${ZEPHYR_BASE}/../mbedtls/include)
list(APPEND CHIP_CFLAGS -I${CMAKE_CURRENT_SOURCE_DIR}/main/include)
convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS CHIP_CFLAGS)

zephyr_get_compile_flags(CHIP_CXXFLAGS CXX)
list(FILTER CHIP_CXXFLAGS EXCLUDE REGEX -std.*) # CHIP adds gnu++11 anyway...
list(FILTER CHIP_CXXFLAGS EXCLUDE REGEX -Wno-deprecated-copy)
list(FILTER CHIP_CXXFLAGS EXCLUDE REGEX -Wno-cast-function-type)
list(FILTER CHIP_CXXFLAGS EXCLUDE REGEX -Werror)
list(APPEND CHIP_CXXFLAGS -I${ZEPHYR_BASE}/../mbedtls/include)
list(APPEND CHIP_CXXFLAGS -I${CMAKE_CURRENT_SOURCE_DIR}/main/include)
convert_list_of_flags_to_string_of_flags(CHIP_CXXFLAGS CHIP_CXXFLAGS)

# Prepare command line arguments passed to the CHIP's ./configure script
set(CHIP_CONFIGURE_ARGS
AR=${CMAKE_AR}
AS=${CMAKE_AS}
CC=${CMAKE_C_COMPILER}
CXX=${CMAKE_CXX_COMPILER}
LD=${CMAKE_LINKER}
OBJCOPY=${CMAKE_OBJCOPY}
RANLIB=${CMAKE_RANLIB}
CFLAGS=${CHIP_CFLAGS}
CXXFLAGS=${CHIP_CXXFLAGS}
--prefix=${CHIP_OUTPUT_DIR}
--exec-prefix=${CHIP_OUTPUT_DIR}
--host=${CHIP_ARCH}
--with-device-layer=nrfconnect
--with-network-layer=all
--with-target-network=sockets
--with-inet-endpoint=udp
--with-logging-style=external
--with-target-style=embedded
--with-chip-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-system-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-inet-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-ble-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-warm-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-device-project-includes=${CHIP_PROJECT_CONFIG}
--enable-debug
--enable-optimization=no
--disable-tools
--disable-docs
--disable-java
--disable-device-manager
--with-mbedtls=${ZEPHYR_BASE}/../modules/crypto/mbedtls
--with-crypto=mbedtls
)

append_if(CHIP_CONFIGURE_ARGS CONFIG_NET_L2_OPENTHREAD --with-openthread=${ZEPHYR_BASE}/../modules/lib/openthread)
append_if_not(CHIP_CONFIGURE_ARGS CHIP_BUILD_TESTS --disable-tests)
append_if_not(CHIP_CONFIGURE_ARGS CONFIG_NET_IPV4 --disable-ipv4)
set(GN_ARGS "")
chip_gn_arg_string(GN_ARGS "target_cflags_c = string_split(\"${CHIP_CFLAGS}\")")
chip_gn_arg_string(GN_ARGS "target_cflags_cc = string_split(\"${CHIP_CXXFLAGS}\")")
chip_gn_arg_string(GN_ARGS "ar_ext = \"${CMAKE_AR}\"")
chip_gn_arg_string(GN_ARGS "cc_ext = \"${CMAKE_C_COMPILER}\"")
chip_gn_arg_string(GN_ARGS "cxx_ext = \"${CMAKE_CXX_COMPILER}\"")

chip_gn_arg_bool_if(CONFIG_BT GN_ARGS "chip_config_network_layer_ble")
chip_gn_arg_bool_if(CONFIG_NET_L2_OPENTHREAD GN_ARGS "chip_enable_openthread")
chip_gn_arg_bool_if(BUILD_TESTING GN_ARGS "chip_build_tests")

message("-- GN arguments:\n${GN_ARGS}")

file(
GENERATE OUTPUT ${CHIP_OUTPUT_DIR}/args.gn
CONTENT "${GN_ARGS}"
)
# Define target
ExternalProject_Add(
${TARGET_NAME}
PREFIX ${CHIP_OUTPUT_DIR}
SOURCE_DIR ${CHIP_ROOT}
BINARY_DIR ${CHIP_OUTPUT_DIR}
CONFIGURE_COMMAND ${CHIP_ROOT}/configure ${CHIP_CONFIGURE_ARGS}
CONFIGURE_COMMAND gn --root=${CHIP_ROOT}/config/nrfconnect gen ${CHIP_OUTPUT_DIR}
BUILD_COMMAND ""
INSTALL_COMMAND ""
BUILD_ALWAYS TRUE
USES_TERMINAL_CONFIGURE TRUE
)
endfunction()

# ==================================================
# Define chip build target
# ==================================================
# ==================================================

function(chip_build TARGET_NAME BASE_TARGET_NAME)
cmake_parse_arguments(CHIP "" "" "BUILD_COMMAND;BUILD_ARTIFACTS" ${ARGN})

# Define build target
ExternalProject_Add(
${TARGET_NAME}Build
Expand All @@ -146,6 +143,7 @@ function(chip_build TARGET_NAME BASE_TARGET_NAME)
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${CHIP_BUILD_ARTIFACTS}
BUILD_ALWAYS TRUE
USES_TERMINAL_BUILD TRUE
)

# Define interface library containing desired CHIP byproducts
Expand All @@ -155,12 +153,14 @@ function(chip_build TARGET_NAME BASE_TARGET_NAME)
${CHIP_ROOT}/src/lib
${CHIP_ROOT}/src/lib/core
${CHIP_ROOT}/src/include
${CHIP_OUTPUT_DIR}/include
${CHIP_OUTPUT_DIR}/src/include
${CHIP_ROOT}/third_party/nlassert/repo/include
${CHIP_OUTPUT_DIR}/gen/include
${CHIP_OUTPUT_DIR}/gen/third_party/connectedhomeip/src/lib/support/include
${CHIP_OUTPUT_DIR}/gen/third_party/connectedhomeip/src/app/include
)
target_link_directories(${TARGET_NAME} INTERFACE ${CHIP_OUTPUT_DIR}/lib)
target_link_libraries(${TARGET_NAME} INTERFACE -Wl,--start-group ${CHIP_BUILD_ARTIFACTS} -Wl,--end-group)

add_dependencies(${TARGET_NAME}Build ${BASE_TARGET_NAME})
add_dependencies(${TARGET_NAME} ${TARGET_NAME}Build)
endfunction()
endfunction()
12 changes: 3 additions & 9 deletions config/nrfconnect/nrfconnect-app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,27 @@ set(CHIP_COMMON_FLAGS

set(CHIP_OUTPUT_LIBRARIES
${CHIP_OUTPUT_DIR}/lib/libCHIP.a
${CHIP_OUTPUT_DIR}/lib/libInetLayer.a
${CHIP_OUTPUT_DIR}/lib/libSystemLayer.a
${CHIP_OUTPUT_DIR}/lib/libSupportLayer.a
${CHIP_OUTPUT_DIR}/lib/libBleLayer.a
${CHIP_OUTPUT_DIR}/lib/libDeviceLayer.a
${CHIP_OUTPUT_DIR}/lib/libCHIPDataModel.a
)

# ==================================================
# Setup CHIP build
# ==================================================

chip_configure(ChipConfig
chip_configure(ChipConfig
ARCH arm-none-eabi
CFLAGS ${CHIP_COMMON_FLAGS} --specs=nosys.specs
CXXFLAGS ${CHIP_COMMON_FLAGS}
PROJECT_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/main/include/CHIPProjectConfig.h
)

chip_build(ChipLib ChipConfig
BUILD_COMMAND make --no-print-directory install V=${CMAKE_AUTOGEN_VERBOSE}
BUILD_COMMAND ninja
BUILD_ARTIFACTS ${CHIP_OUTPUT_LIBRARIES}
)

# ==================================================
# Configure application
# ==================================================

target_compile_definitions(app PRIVATE HAVE_CONFIG_H)
target_link_libraries(app PUBLIC -Wl,--start-group ChipLib -Wl,--end-group)
target_compile_definitions(app PRIVATE CHIP_SEPARATE_CONFIG_H)
1 change: 1 addition & 0 deletions config/nrfconnect/third_party/connectedhomeip
33 changes: 33 additions & 0 deletions config/nrfconnect/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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/toolchain/arm_gcc/arm_toolchain.gni")
import("//build_overrides/chip.gni")

declare_args() {
ar_ext = ""
cc_ext = ""
cxx_ext = ""
}

gcc_toolchain("zephyr") {
ar = ar_ext
cc = cc_ext
cxx = cxx_ext

toolchain_args = {
current_os = "zephyr"
is_clang = false
}
}
1 change: 0 additions & 1 deletion examples/lock-app/nrfconnect/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <logging/log.h>

#include <BuildConfig.h>
#include <platform/CHIPDeviceLayer.h>

LOG_MODULE_REGISTER(app);
Expand Down
8 changes: 5 additions & 3 deletions gn/chip/chip_test.gni
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ template("chip_test") {
_test_output_dir = invoker.output_dir
}

executable(_test_name) {
forward_variables_from(invoker, "*", [ "output_dir" ])
output_dir = _test_output_dir
if (current_os != "zephyr") {
executable(_test_name) {
forward_variables_from(invoker, "*", [ "output_dir" ])
output_dir = _test_output_dir
}
}

# Only execute tests when current_os == host_os
Expand Down
4 changes: 4 additions & 0 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ void ChipDeviceController::OnMessageReceived(const MessageHeader & header, Trans
}
}

#if CONFIG_NETWORK_LAYER_BLE

void ChipDeviceController::OnBLEConnectionError(BLE_ERROR err)
{
if (mOnError)
Expand Down Expand Up @@ -521,5 +523,7 @@ void ChipDeviceController::OnBLEPacketReceived(PacketBuffer * buffer)
}
}

#endif // CONFIG_NETWORK_LAYER_BLE

} // namespace DeviceController
} // namespace chip
Loading