Skip to content

Commit

Permalink
[Telink] Adapt Telink platform to common cmake sources
Browse files Browse the repository at this point in the history
Change Telink cmake files to the common sources.
Remove redundant files.

Signed-off-by: ATmobica <[email protected]>
  • Loading branch information
ATmobica committed Mar 13, 2023
1 parent 4ea17c5 commit 0f58595
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 253 deletions.
192 changes: 12 additions & 180 deletions config/telink/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,77 +30,21 @@ include(../../zephyr/ota-image.cmake)
include(../../zephyr/zephyr-util.cmake)
include(generate_factory_data.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 passed to the make_gn_args.py script
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_import FILE)
string(APPEND CHIP_GN_ARGS "--module\n${FILE}\n")
endmacro()

macro(chip_gn_arg_string ARG STRING)
string(APPEND CHIP_GN_ARGS "--arg-string\n${ARG}\n${STRING}\n")
endmacro()

macro(chip_gn_arg_bool ARG)
if (${ARGN})
string(APPEND CHIP_GN_ARGS "--arg\n${ARG}\ntrue\n")
else()
string(APPEND CHIP_GN_ARGS "--arg\n${ARG}\nfalse\n")
endif()
endmacro()

macro(chip_gn_arg_cflags ARG CFLAGS)
string(APPEND CHIP_GN_ARGS "--arg-cflags\n${ARG}\n${CFLAGS}\n")
endmacro()

macro(chip_gn_arg ARG VALUE)
string(APPEND CHIP_GN_ARGS "--arg\n${ARG}\n${VALUE}\n")
endmacro()


# ==============================================================================
# Prepare CHIP configuration based on the project Kconfig configuration
# ==============================================================================

if (NOT CHIP_ROOT)
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH)
endif()
get_filename_component(GN_ROOT_TARGET ${CHIP_ROOT}/config/telink/chip-gn REALPATH)
get_filename_component(COMMON_CMAKE_SOURCE_DIR ${CHIP_ROOT}/config/common/cmake REALPATH)

set(GN_ROOT_TARGET ${CHIP_ROOT}/config/telink/chip-gn)
# Get common Cmake sources

include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake)

# Prepare compiler flags

if (CONFIG_POSIX_API)
list(APPEND CHIP_CFLAGS
Expand All @@ -119,29 +63,6 @@ convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS CHIP_CFLAGS)
convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_C CHIP_CFLAGS_C)
convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_CC CHIP_CFLAGS_CC)

# 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()

# Set up custom OpenThread configuration

if (CONFIG_CHIP_OPENTHREAD_CONFIG)
Expand All @@ -153,40 +74,11 @@ if (CONFIG_CHIP_OPENTHREAD_CONFIG)
zephyr_set_openthread_config(${CHIP_OPENTHREAD_CONFIG})
endif()

# Find required programs

find_program(GN_EXECUTABLE gn)
if (${GN_EXECUTABLE} STREQUAL GN_EXECUTABLE-NOTFOUND)
message(FATAL_ERROR "The 'gn' command was not found. Make sure you have GN installed.")
else()
# Parse the 'gn --version' output to find the installed version.
set(MIN_GN_VERSION 1851)
execute_process(
COMMAND
${GN_EXECUTABLE} --version
OUTPUT_VARIABLE gn_version_output
ERROR_VARIABLE gn_error_output
RESULT_VARIABLE gn_status
)

if(${gn_status} EQUAL 0)
if(gn_version_output VERSION_LESS ${MIN_GN_VERSION})
message(FATAL_ERROR "Found unsuitable version of 'gn'. Required is at least ${MIN_GN_VERSION}")
endif()
else()
message(FATAL_ERROR "Could NOT find working gn: Found gn (${GN_EXECUTABLE}), but failed to load with:\n ${gn_error_output}")
endif()
endif()

find_package(Python3 REQUIRED)

# ==============================================================================
# Generate configuration for CHIP GN build system
# ==============================================================================

chip_gn_arg_cflags("target_cflags" ${CHIP_CFLAGS})
chip_gn_arg_cflags("target_cflags_c" ${CHIP_CFLAGS_C})
chip_gn_arg_cflags("target_cflags_cc" ${CHIP_CFLAGS_CC})
generate_common_configuration()
chip_gn_arg_string("zephyr_ar" ${CMAKE_AR})
chip_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER})
chip_gn_arg_string("zephyr_cxx" ${CMAKE_CXX_COMPILER})
Expand All @@ -197,9 +89,7 @@ chip_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FT
chip_gn_arg_bool ("chip_config_network_layer_ble" CONFIG_BT)
chip_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4)
chip_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR)
chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS)
chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS)
chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL)
chip_gn_arg_bool ("chip_error_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 1)
chip_gn_arg_bool ("chip_progress_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 3)
chip_gn_arg_bool ("chip_detail_logging" CONFIG_MATTER_LOG_LEVEL GREATER_EQUAL 4)
Expand All @@ -221,79 +111,21 @@ if (CONFIG_CHIP_ENABLE_DNSSD_SRP)
chip_gn_arg_string("chip_mdns" "platform")
endif()

if (CHIP_PROJECT_CONFIG)
chip_gn_arg_string("chip_project_config_include" ${CHIP_PROJECT_CONFIG})
chip_gn_arg_string("chip_system_project_config_include" ${CHIP_PROJECT_CONFIG})
endif()

if (CONFIG_CHIP_PW_RPC)
set(PIGWEED_DIR "//third_party/pigweed/repo")
chip_gn_arg_string("pw_assert_BACKEND" ${PIGWEED_DIR}/pw_assert_log:check_backend)
chip_gn_arg_string("pw_log_BACKEND" ${PIGWEED_DIR}/pw_log_basic)
chip_gn_arg("pw_build_LINK_DEPS" [\"${PIGWEED_DIR}/pw_assert:impl\",\ \"${PIGWEED_DIR}/pw_log:impl\"])
endif()

if (CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER)
chip_gn_arg_bool("chip_build_example_providers" "true")
list(APPEND CHIP_LIBRARIES -lMatterDeviceInfoProviderExample)
endif()

file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/args.tmp" CONTENT ${CHIP_GN_ARGS})
generate_args_tmp_file()

# ==============================================================================
# Define 'chip-gn' target that builds CHIP library(ies) with GN build system
# Build chip library
# ==============================================================================
ExternalProject_Add(
chip-gn
PREFIX ${CMAKE_CURRENT_BINARY_DIR}
SOURCE_DIR ${CHIP_ROOT}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_gn_args.py
@args.tmp > args.gn &&
${GN_EXECUTABLE}
--root=${CHIP_ROOT}
--root-target=${GN_ROOT_TARGET}
--dotfile=${GN_ROOT_TARGET}/.gn
--script-executable=${Python3_EXECUTABLE}
--export-compile-commands
gen --check --fail-on-unused-args . &&
ninja
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${CHIP_LIBRARIES}
BUILD_ALWAYS TRUE
USES_TERMINAL_CONFIGURE TRUE
USES_TERMINAL_BUILD TRUE
)
include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake)
add_dependencies(chip-gn kernel)

# ==============================================================================
# Define 'chip' target that exposes CHIP headers & libraries to the application
# ==============================================================================

zephyr_interface_library_named(chip)
target_compile_definitions(chip INTERFACE CHIP_HAVE_CONFIG_H)
target_include_directories(chip INTERFACE
${CHIP_ROOT}/src
${CHIP_ROOT}/src/include
${CHIP_ROOT}/src/lib
${CHIP_ROOT}/third_party/nlassert/repo/include
${CHIP_ROOT}/third_party/nlio/repo/include
${CHIP_ROOT}/zzz_generated/app-common
${CMAKE_CURRENT_BINARY_DIR}/gen/include
)
target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib)
if (CONFIG_CHIP_LIB_SHELL)
target_link_options(chip INTERFACE -Wl,--whole-archive -lCHIPShell -Wl,--no-whole-archive)
endif()

if (CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER)
target_include_directories(chip INTERFACE ${CHIP_ROOT}/examples/providers)
endif()

target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)

add_dependencies(chip chip-gn)
set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS chip)

# ==============================================================================
# Define 'chip-ota-image' target for building CHIP OTA image
Expand Down
73 changes: 0 additions & 73 deletions config/telink/chip-module/make_gn_args.py

This file was deleted.

0 comments on commit 0f58595

Please sign in to comment.