diff --git a/config/common/cmake/chip_gn.cmake b/config/common/cmake/chip_gn.cmake index 28a49376d7d86c..bfaa91ab28200b 100644 --- a/config/common/cmake/chip_gn.cmake +++ b/config/common/cmake/chip_gn.cmake @@ -16,45 +16,26 @@ # # @file -# CMake file defining 'chip' target which represents CHIP library -# and other optional libraries like unit tests, built with specific -# platform. -# Since CHIP doesn't provide native CMake support, ExternalProject +# CMake file defining to setup and build the Matter library +# and other optional libraries like unit tests. +# Matter headers and libraries are exposed to the application +# as a specific interface target. +# Since Matter doesn't provide native CMake support, ExternalProject # module is used to build the required artifacts with GN meta-build # system. # -# Check or set paths +# ============================================================================== +# Validate paths +# ============================================================================== if (NOT GN_ROOT_TARGET) - message(FATAL_ERROR "GN_ROOT_TARGET not defined. Please provide the path to your CHIP GN project.") + message(FATAL_ERROR "GN_ROOT_TARGET not defined. Please provide the path to your Matter GN project.") endif() if (NOT CHIP_ROOT) - get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH) + get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../.. REALPATH) endif() -set(CHIP_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib) - -# Prepare CHIP libraries that the application should be linked with -list(APPEND CHIP_LIBRARIES -lCHIP) - -if (CONFIG_CHIP_LIB_SHELL) - list(APPEND CHIP_LIBRARIES -lCHIPShell) -endif() - -if (CONFIG_CHIP_LIB_PW_RPC) - list(APPEND CHIP_LIBRARIES -lPwRpc) -endif(CONFIG_CHIP_LIB_PW_RPC) - -if (CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER) - list(APPEND CHIP_LIBRARIES -lMatterDeviceInfoProviderExample) -endif() - -list(TRANSFORM CHIP_LIBRARIES REPLACE - "-l(.*)" - "${CHIP_LIB_DIR}/lib\\1.a" -) - # ============================================================================== # Find required programs # ============================================================================== @@ -73,73 +54,123 @@ if (GN_VERSION VERSION_LESS MIN_GN_VERSION) endif() # ============================================================================== -# Define 'chip-gn' target that builds CHIP library(ies) with GN build system +# Macros # ============================================================================== -ExternalProject_Add( - chip-gn - PREFIX ${CMAKE_CURRENT_BINARY_DIR} - SOURCE_DIR ${CHIP_ROOT} - BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} - CONFIGURE_COMMAND "" - CONFIGURE_HANDLED_BY_BUILD TRUE - BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting Matter library build in ${CMAKE_CURRENT_BINARY_DIR}" - COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/make_gn_args.py @args.tmp > args.gn.tmp - # Replace the config only if it has changed to avoid triggering unnecessary rebuilds - COMMAND bash -c "(! diff -q args.gn.tmp args.gn && mv args.gn.tmp args.gn) || true" - # Regenerate the ninja build system - COMMAND ${GN_EXECUTABLE} - --root=${CHIP_ROOT} - --root-target=${GN_ROOT_TARGET} - --dotfile=${GN_ROOT_TARGET}/.gn - --script-executable=${Python3_EXECUTABLE} - gen --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ninja - COMMAND ${CMAKE_COMMAND} -E echo "Matter library build complete" - INSTALL_COMMAND "" - # Byproducts are removed by the clean target removing config and .ninja_deps - # allows a rebuild of the external project after the clean target has been run. - BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/args.gn - ${CMAKE_CURRENT_BINARY_DIR}/build.ninja - ${CMAKE_CURRENT_BINARY_DIR}/.ninja_deps - ${CMAKE_CURRENT_BINARY_DIR}/build.ninja.stamp - ${CHIP_LIBRARIES} - BUILD_ALWAYS TRUE - USES_TERMINAL_CONFIGURE TRUE - USES_TERMINAL_BUILD TRUE -) - -# ============================================================================== -# Define 'chip' target that exposes CHIP headers & libraries to the application -# ============================================================================== -add_library(chip INTERFACE) -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 -) - -# Link required CHIP libraries -if (CONFIG_CHIP_LIB_SHELL) - target_link_options(chip INTERFACE -Wl,--whole-archive ${CHIP_LIB_DIR}/libCHIPShell.a -Wl,--no-whole-archive) -endif() - -if (CONFIG_CHIP_BUILD_TESTS) - target_link_options(chip INTERFACE -Wl,--whole-archive ${CHIP_LIB_DIR}/libCHIP_tests.a -Wl,--no-whole-archive) -endif() - -if (CONFIG_CHIP_LIB_PW_RPC) - target_link_options(chip INTERFACE -Wl,--whole-archive ${CHIP_LIB_DIR}/libPwRpc.a -Wl,--no-whole-archive) -endif(CONFIG_CHIP_LIB_PW_RPC) - -if (CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER) - target_include_directories(chip INTERFACE ${CHIP_ROOT}/examples/providers) -endif() - -target_link_directories(chip INTERFACE ${CHIP_LIB_DIR}) -target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group) -add_dependencies(chip chip-gn) +# Setup and build the Matter library and other optional libraries like unit tests. +# Expose Matter headers & libraries to the application as specific +# interface target. +# [Args]: +# target - interface target name +# Available options are: +# LIB_SHELL Build and add Matter shell library +# LIB_PW_RPC Build and add Matter PW RPC library +# LIB_TESTS Build and add Matter unit tests library +# DEVICE_INFO_EXAMPLE_PROVIDER Add example device info provider support +# +# GN_DEPENDENCIES List of targets that should be built before Matter GN project +macro(matter_build target) + set(options) + set(oneValueArgs + LIB_TESTS + LIB_SHELL + LIB_PW_RPC + DEVICE_INFO_EXAMPLE_PROVIDER + ) + set(multiValueArgs GN_DEPENDENCIES) + + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(MATTER_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib) + + # Prepare Matter libraries that the application should be linked with + set(MATTER_LIBRARIES -lCHIP) + + if (ARG_LIB_SHELL) + list(APPEND MATTER_LIBRARIES -lCHIPShell) + endif() + + if (ARG_LIB_PW_RPC) + list(APPEND MATTER_LIBRARIES -lPwRpc) + endif() + + if (ARG_DEVICE_INFO_EXAMPLE_PROVIDER) + list(APPEND MATTER_LIBRARIES -lMatterDeviceInfoProviderExample) + endif() + + list(TRANSFORM MATTER_LIBRARIES REPLACE + "-l(.*)" + "${MATTER_LIB_DIR}/lib\\1.a" + ) + + # ============================================================================== + # 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 "" + CONFIGURE_HANDLED_BY_BUILD TRUE + BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting Matter library build in ${CMAKE_CURRENT_BINARY_DIR}" + COMMAND ${Python3_EXECUTABLE} ${CHIP_ROOT}/config/common/cmake/make_gn_args.py @args.tmp > args.gn.tmp + # Replace the config only if it has changed to avoid triggering unnecessary rebuilds + COMMAND bash -c "(! diff -q args.gn.tmp args.gn && mv args.gn.tmp args.gn) || true" + # Regenerate the ninja build system + COMMAND ${GN_EXECUTABLE} + --root=${CHIP_ROOT} + --root-target=${GN_ROOT_TARGET} + --dotfile=${GN_ROOT_TARGET}/.gn + --script-executable=${Python3_EXECUTABLE} + gen --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ninja + COMMAND ${CMAKE_COMMAND} -E echo "Matter library build complete" + INSTALL_COMMAND "" + # Byproducts are removed by the clean target removing config and .ninja_deps + # allows a rebuild of the external project after the clean target has been run. + BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/args.gn + ${CMAKE_CURRENT_BINARY_DIR}/build.ninja + ${CMAKE_CURRENT_BINARY_DIR}/.ninja_deps + ${CMAKE_CURRENT_BINARY_DIR}/build.ninja.stamp + ${MATTER_LIBRARIES} + BUILD_ALWAYS TRUE + USES_TERMINAL_CONFIGURE TRUE + USES_TERMINAL_BUILD TRUE + ) + + if(ARG_GN_DEPENDENCIES) + add_dependencies(chip-gn ${ARG_GN_DEPENDENCIES}) + endif() + + # ============================================================================== + # Define target that exposes Matter headers & libraries to the application + # ============================================================================== + add_library(${target} INTERFACE) + target_compile_definitions(${target} INTERFACE CHIP_HAVE_CONFIG_H) + target_include_directories(${target} INTERFACE + ${CHIP_ROOT}/src + ${CHIP_ROOT}/src/include + ${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 + ) + + # ============================================================================== + # Link required libraries + # ============================================================================== + target_link_libraries(${target} INTERFACE -Wl,--start-group ${MATTER_LIBRARIES} -Wl,--end-group) + add_dependencies(${target} chip-gn) + + if (ARG_LIB_SHELL) + target_link_options(${target} INTERFACE -Wl,--whole-archive ${MATTER_LIB_DIR}/libCHIPShell.a -Wl,--no-whole-archive) + endif() + + if (ARG_LIB_TESTS) + target_link_options(${target} INTERFACE -Wl,--whole-archive ${MATTER_LIB_DIR}/libCHIP_tests.a -Wl,--no-whole-archive) + endif() + + if (ARG_DEVICE_INFO_EXAMPLE_PROVIDER) + target_include_directories(${target} INTERFACE ${CHIP_ROOT}/examples/providers) + endif() +endmacro() diff --git a/config/common/cmake/chip_gn_args.cmake b/config/common/cmake/chip_gn_args.cmake index 2bc0ed12a0a88f..2fb99ff325941e 100644 --- a/config/common/cmake/chip_gn_args.cmake +++ b/config/common/cmake/chip_gn_args.cmake @@ -17,133 +17,188 @@ # # @file # CMake file that allows collecting C/C++ compiler flags passed to -# the CHIP build system. +# the Matter build system. # +include(${CMAKE_CURRENT_LIST_DIR}/util.cmake) + # ============================================================================== # Configuration variables and define constants # ============================================================================== -# C/C++ compiler flags passed to CHIP build system -if (NOT CHIP_CFLAGS) - set(CHIP_CFLAGS PARENT_SCOPE) +# C/C++ compiler flags passed to the Matter build system +if (NOT MATTER_CFLAGS) + set(MATTER_CFLAGS PARENT_SCOPE) endif() -# C compiler flags passed to CHIP build system -if (NOT CHIP_CFLAGS_C) - set(CHIP_CFLAGS_C PARENT_SCOPE) +# C compiler flags passed to the Matter build system +if (NOT MATTER_CFLAGS_C) + set(MATTER_CFLAGS_C PARENT_SCOPE) endif() -# C++ compiler flags passed to CHIP build system -if (NOT CHIP_CFLAGS_CC) - set(CHIP_CFLAGS_CC PARENT_SCOPE) +# C++ compiler flags passed to the Matter build system +if (NOT MATTER_CFLAGS_CC) + set(MATTER_CFLAGS_CC PARENT_SCOPE) endif() # GN meta-build system arguments in the form of 'key1 = value1\nkey2 = value2...' string -if (NOT CHIP_GN_ARGS) - set(CHIP_GN_ARGS PARENT_SCOPE) +if (NOT MATTER_GN_ARGS) + set(MATTER_GN_ARGS PARENT_SCOPE) endif() # ============================================================================== -# Helper macros +# Macros # ============================================================================== -macro(chip_gn_arg_import FILE) - string(APPEND CHIP_GN_ARGS "--module\n${FILE}\n") +# Add import GN argument +# [Args]: +# file - path to file that should be imported +macro(matter_add_gn_arg_import file) + string(APPEND MATTER_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") +# Add string GN argument +# [Args]: +# key - key name +# value - string value +macro(matter_add_gn_arg_string key value) + string(APPEND MATTER_GN_ARGS "--arg-string\n${key}\n${value}\n") endmacro() -macro(chip_gn_arg_bool ARG) +# Add bool GN argument +# [Args]: +# key - bool variable +macro(matter_add_gn_arg_bool key) if (${ARGN}) - string(APPEND CHIP_GN_ARGS "--arg\n${ARG}\ntrue\n") + string(APPEND MATTER_GN_ARGS "--arg\n${key}\ntrue\n") else() - string(APPEND CHIP_GN_ARGS "--arg\n${ARG}\nfalse\n") + string(APPEND MATTER_GN_ARGS "--arg\n${key}\nfalse\n") endif() endmacro() -macro(chip_gn_arg_cflags ARG CFLAGS) - string(APPEND CHIP_GN_ARGS "--arg-cflags\n${ARG}\n${CFLAGS}\n") +# Add compiler flag GN argument +# [Args]: +# key - key name +# value - compiler flag value +macro(matter_add_gn_arg_cflags key value) + string(APPEND MATTER_GN_ARGS "--arg-cflags\n${key}\n${value}\n") endmacro() -macro(chip_gn_arg ARG VALUE) - string(APPEND CHIP_GN_ARGS "--arg\n${ARG}\n${VALUE}\n") +# Add simple variable GN argument +# [Args]: +# key - variable name +# value - variable value +macro(matter_add_gn_arg key value) + string(APPEND MATTER_GN_ARGS "--arg\n${key}\n${value}\n") endmacro() -# ============================================================================== -# Functions -# ============================================================================== +# Add items to Matter common compiler flags +# [Args]: +# flags - flags to add +macro(matter_add_flags flags) + list(APPEND MATTER_CFLAGS ${flags}) +endmacro() + +# Add items to Matter C compiler flags +# [Args]: +# flags - flags to add +macro(matter_add_cflags flags) + list(APPEND MATTER_CFLAGS_C ${flags}) +endmacro() + +# Add items to Matter CXX compiler flags +# [Args]: +# flags - flags to add +macro(matter_add_cxxflags flags) + list(APPEND MATTER_CFLAGS_CC ${flags}) +endmacro() + +# Add GNU CPP standard flag to Matter CXX compiler flags +# [Args]: +# std_version - standard version number e.g. 17 for C++17 +macro(matter_add_gnu_cpp_standard std_version) + list(APPEND MATTER_CFLAGS_CC -std=gnu++${std_version}) +endmacro() # Get compiler flags from listed targets. -# Collect common compile flags and save them in CHIP_CFLAGS -# Collect C/CXX compile flags and save them in CHIP_CFLAGS_C/CHIP_CFLAGS_CXX +# Collect common compile flags and save them in MATTER_CFLAGS +# Collect C/CXX compile flags and save them in MATTER_CFLAGS_C/MATTER_CFLAGS_CXX # [Args]: # targets - list of targets -function(get_compiler_flags_from_targets targets) +macro(matter_get_compiler_flags_from_targets targets) foreach(target ${targets}) get_target_common_compile_flags(EXTERNAL_TARGET_CFLAGS ${target}) get_lang_compile_flags(EXTERNAL_TARGET_CFLAGS_C ${target} C) get_lang_compile_flags(EXTERNAL_TARGET_CFLAGS_CXX ${target} CXX) - list(APPEND CHIP_CFLAGS ${EXTERNAL_TARGET_CFLAGS}) - list(APPEND CHIP_CFLAGS_C ${EXTERNAL_TARGET_CFLAGS_C}) - list(APPEND CHIP_CFLAGS_CC ${EXTERNAL_TARGET_CFLAGS_CXX}) + list(APPEND MATTER_CFLAGS ${EXTERNAL_TARGET_CFLAGS}) + list(APPEND MATTER_CFLAGS_C ${EXTERNAL_TARGET_CFLAGS_C}) + list(APPEND MATTER_CFLAGS_CC ${EXTERNAL_TARGET_CFLAGS_CXX}) # Reset between targets set(EXTERNAL_TARGET_CFLAGS "") set(EXTERNAL_TARGET_CFLAGS_C "") set(EXTERNAL_TARGET_CFLAGS_CXX "") endforeach() - set(CHIP_CFLAGS ${CHIP_CFLAGS} PARENT_SCOPE) - set(CHIP_CFLAGS_C ${CHIP_CFLAGS_C} PARENT_SCOPE) - set(CHIP_CFLAGS_CC ${CHIP_CFLAGS_CC} PARENT_SCOPE) -endfunction() - -# Generate the common GN configuration -function(generate_common_configuration) - # Set up CHIP project configuration file - if (CONFIG_CHIP_PROJECT_CONFIG) - get_filename_component(CHIP_PROJECT_CONFIG - ${CONFIG_CHIP_PROJECT_CONFIG} +endmacro() + +# Generate the common Matter GN arguments. +# Pass all compilation flags to GN build. +# Available options are: +# DEBUG Debug build +# LIB_SHELL Add Matter shell library +# LIB_PW_RPC Add Matter PW RPC library +# LIB_TESTS Add Matter unit tests library +# DEVICE_INFO_EXAMPLE_PROVIDER Add example device info provider support +# PROJECT_CONFIG Path to the project-specific configuration file +# +macro(matter_common_gn_args) + set(options) + set(oneValueArgs + DEBUG + LIB_TESTS + LIB_SHELL + LIB_PW_RPC + DEVICE_INFO_EXAMPLE_PROVIDER + PROJECT_CONFIG + ) + set(multiValueArgs) + + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + convert_list_of_flags_to_string_of_flags(MATTER_CFLAGS MATTER_CFLAGS) + convert_list_of_flags_to_string_of_flags(MATTER_CFLAGS_C MATTER_CFLAGS_C) + convert_list_of_flags_to_string_of_flags(MATTER_CFLAGS_CC MATTER_CFLAGS_CC) + + if (MATTER_CFLAGS) + matter_add_gn_arg_cflags ("target_cflags" ${MATTER_CFLAGS}) + endif() # MATTER_CFLAGS + if (MATTER_CFLAGS_C) + matter_add_gn_arg_cflags ("target_cflags_c" ${MATTER_CFLAGS_C}) + endif() # MATTER_CFLAGS_C + if (MATTER_CFLAGS_CC) + matter_add_gn_arg_cflags ("target_cflags_cc" ${MATTER_CFLAGS_CC}) + endif() # MATTER_CFLAGS_CC + + matter_add_gn_arg_bool ("is_debug" ${ARG_DEBUG}) + matter_add_gn_arg_bool ("chip_build_tests" ${ARG_LIB_TESTS}) + matter_add_gn_arg_bool ("chip_build_libshell" ${ARG_LIB_SHELL}) + + if (ARG_LIB_PW_RPC) + matter_add_gn_arg_bool ("chip_build_pw_rpc_lib" ${ARG_LIB_PW_RPC}) + endif() # ARG_LIB_PW_RPC + if (ARG_DEVICE_INFO_EXAMPLE_PROVIDER) + matter_add_gn_arg_bool ("chip_build_example_providers" ${ARG_DEVICE_INFO_EXAMPLE_PROVIDER}) + endif() # ARG_DEVICE_INFO_EXAMPLE_PROVIDER + if (ARG_PROJECT_CONFIG) + get_filename_component(PROJECT_CONFIG + ${ARG_PROJECT_CONFIG} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR} ) - set(CHIP_PROJECT_CONFIG "<${CHIP_PROJECT_CONFIG}>") - else() - set(CHIP_PROJECT_CONFIG "") - endif() - - if (CHIP_CFLAGS) - chip_gn_arg_cflags ("target_cflags" ${CHIP_CFLAGS}) - endif() # CHIP_CFLAGS - if (CHIP_CFLAGS_C) - chip_gn_arg_cflags ("target_cflags_c" ${CHIP_CFLAGS_C}) - endif() # CHIP_CFLAGS_C - if (CHIP_CFLAGS_CC) - chip_gn_arg_cflags ("target_cflags_cc" ${CHIP_CFLAGS_CC}) - endif() # CHIP_CFLAGS_CC - if (DEFINED CONFIG_CHIP_DEBUG) - chip_gn_arg_bool ("is_debug" CONFIG_CHIP_DEBUG) - endif() # CONFIG_CHIP_DEBUG - if (DEFINED CONFIG_CHIP_BUILD_TESTS) - chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS) - endif() # CONFIG_CHIP_BUILD_TESTS - if (DEFINED CONFIG_CHIP_LIB_SHELL) - chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL) - endif() # CONFIG_CHIP_LIB_SHELL - if (DEFINED CONFIG_CHIP_LIB_PW_RPC) - chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_LIB_PW_RPC) - endif() # CONFIG_CHIP_LIB_PW_RPC - if (CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER) - chip_gn_arg_bool("chip_build_example_providers" TRUE) - endif() # CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER - 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}) + matter_add_gn_arg_string("chip_project_config_include" "<${PROJECT_CONFIG}>") + matter_add_gn_arg_string("chip_system_project_config_include" "<${PROJECT_CONFIG}>") endif() # CHIP_PROJECT_CONFIG - set(CHIP_GN_ARGS ${CHIP_GN_ARGS} PARENT_SCOPE) -endfunction() +endmacro() -# Generate the temporary GUN arguments file from the settings -function(generate_args_tmp_file) - file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/args.tmp" CONTENT ${CHIP_GN_ARGS}) -endfunction() \ No newline at end of file +# Generate the temporary GN arguments file from the settings +macro(matter_generate_args_tmp_file) + file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/args.tmp" CONTENT ${MATTER_GN_ARGS}) +endmacro() \ No newline at end of file diff --git a/config/common/cmake/make_gn_args.py b/config/common/cmake/make_gn_args.py index 0215a649b078b4..c6282bc0f8b451 100755 --- a/config/common/cmake/make_gn_args.py +++ b/config/common/cmake/make_gn_args.py @@ -42,9 +42,9 @@ def write_gn_args(args): sys.stdout.write('{} = {}\n'.format(key, value)) for key, value in args.arg_string: - # Fix " and ' + # Escaped quote and dollar sign characters filtered_value = value.replace('"', '\\"') - filtered_value = value.replace("'", '"') + filtered_value = filtered_value.replace('$', '\\$') sys.stdout.write('{} = "{}"\n'.format(key, filtered_value)) cflag_excludes = ', '.join(['"{}"'.format(exclude) @@ -52,17 +52,16 @@ def write_gn_args(args): for key, value in args.arg_cflags: filtered_value = value.split(" -") - # Remove empty include paths and defines + # Remove empty include paths and defines caused by Cmake generator expressions filtered_value = filter(lambda v: v != "D", filtered_value) filtered_value = filter(lambda v: v != "isystem", filtered_value) - # Fix " and ' and whitespaces + # Escaped quote and dollar sign characters filtered_value = map(lambda v: v.replace('"', '\\"'), filtered_value) - filtered_value = map(lambda v: v.replace("'", '"'), filtered_value) + filtered_value = map(lambda v: v.replace('$', '\\$'), filtered_value) + # Remove white spaces around the argument and remove internal whitespace + # for correct splitting in string_split() function filtered_value = map(lambda v: v.strip(), filtered_value) - # Fix 'imacros' exception - filtered_value = [v.replace(" ", "") if "imacros" in v else v for v in filtered_value] - # Fix 'include' exception - filtered_value = [v.replace(" ", "") if "include" in v else v for v in filtered_value] + filtered_value = map(lambda v: v.replace(' ', ''), filtered_value) # Remove duplicates filtered_value = list(dict.fromkeys(filtered_value)) diff --git a/config/common/cmake/util.cmake b/config/common/cmake/util.cmake index 375b359ae75a16..91988e946fc64b 100644 --- a/config/common/cmake/util.cmake +++ b/config/common/cmake/util.cmake @@ -19,25 +19,6 @@ # CMake utilities for managing and retrieving build configuration # -# ============================================================================== -# Macros -# ============================================================================== - -# Select gnu++ standard based on project configuration -# [Args]: -# VAR - name of list variable to be appended with the selected "-std=gnu++" flag -macro(get_gnu_cpp_standard VAR) - if (CONFIG_STD_CPP11) - list(APPEND ${VAR} -std=gnu++11) - elseif (CONFIG_STD_CPP14) - list(APPEND ${VAR} -std=gnu++14) - elseif (CONFIG_STD_CPP17) - list(APPEND ${VAR} -std=gnu++17) - elseif (CONFIG_STD_CPP2A) - list(APPEND ${VAR} -std=gnu++20) - endif() -endmacro() - # ============================================================================== # Functions # ============================================================================== diff --git a/config/mbed/CMakeLists.txt b/config/mbed/CMakeLists.txt index ce824a9294a2f5..2a0eb84dda52b3 100644 --- a/config/mbed/CMakeLists.txt +++ b/config/mbed/CMakeLists.txt @@ -34,6 +34,7 @@ get_filename_component(COMMON_CMAKE_SOURCE_DIR ${CHIP_ROOT}/config/common/cmake # Get common Cmake sources include(${COMMON_CMAKE_SOURCE_DIR}/util.cmake) include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) +include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) # Mbed targets passed to CHIP build set(CONFIG_CHIP_EXTERNAL_TARGETS) @@ -50,13 +51,6 @@ foreach(NameAndValue ${ConfigContents}) # Set the variable set(${Name} "${Value}") endforeach() - -# Additional configuration -if (CONFIG_CHIP_PW_RPC) - set(CONFIG_STD_CPP17 YES) - set(CONFIG_CHIP_LIB_PW_RPC YES) -endif() - if (CONFIG_CHIP_PW_RPC) if (${APP_TARGET} MATCHES "pigweed-app") set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "y") @@ -69,13 +63,15 @@ if (CONFIG_CHIP_PW_RPC) endif() endif(CONFIG_CHIP_PW_RPC) -if (${CMAKE_BUILD_TYPE} STREQUAL "debug") - set(CONFIG_CHIP_DEBUG "y") +if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") + set(CONFIG_CHIP_DEBUG YES) +else() + set(CONFIG_CHIP_DEBUG NO) endif() # Prepare compiler flags -list(APPEND CHIP_CFLAGS_C ${CMAKE_C_FLAGS_INIT}) -list(APPEND CHIP_CFLAGS_CC ${CMAKE_CXX_FLAGS_INIT}) +matter_add_cflags(${CMAKE_C_FLAGS_INIT}) +matter_add_cxxflags(${CMAKE_CXX_FLAGS_INIT}) # Create a list of external targets passed to CHIP build list(APPEND CONFIG_CHIP_EXTERNAL_TARGETS @@ -104,55 +100,59 @@ if(MBED_TARGET STREQUAL "CY8CPROTO_062_4343W") endif() # Get compiler flags from external targets -get_compiler_flags_from_targets("${CONFIG_CHIP_EXTERNAL_TARGETS}") +matter_get_compiler_flags_from_targets("${CONFIG_CHIP_EXTERNAL_TARGETS}") # Additional settings -list(APPEND CHIP_CFLAGS - -D__LINUX_ERRNO_EXTENSIONS__=1 - -DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER= -) +matter_add_flags(-D__LINUX_ERRNO_EXTENSIONS__=1) +matter_add_flags(-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=) -if (CONFIG_MBED_BSD_SOCKET_TRACE) - list(APPEND CHIP_CFLAGS - -DMBED_BSD_SOCKET_TRACE=1 - ) +if (CONFIG_CHIP_PW_RPC) + matter_add_gnu_cpp_standard("17") endif() -get_gnu_cpp_standard(CHIP_CFLAGS_CC) - -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) +if (CONFIG_MBED_BSD_SOCKET_TRACE) + matter_add_flags(-DMBED_BSD_SOCKET_TRACE=1) +endif() # ============================================================================== # Generate configuration for CHIP GN build system # ============================================================================== -generate_common_configuration() +matter_common_gn_args( + DEBUG CONFIG_CHIP_DEBUG + LIB_SHELL CONFIG_CHIP_LIB_SHELL + LIB_TESTS CONFIG_CHIP_BUILD_TESTS + LIB_PW_RPC CONFIG_CHIP_PW_RPC + PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG} +) if (CONFIG_CHIP_PW_RPC) - chip_gn_arg_import("${GN_ROOT_TARGET}/lib/pw_rpc/pw_rpc.gni") + matter_add_gn_arg_import("${GN_ROOT_TARGET}/lib/pw_rpc/pw_rpc.gni") endif() -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 ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TESTS) -chip_gn_arg_bool ("chip_with_platform_mbedtls" CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS) -chip_gn_arg_bool ("chip_enable_data_model" CONFIG_CHIP_DATA_MODEL) +matter_add_gn_arg_string("mbed_ar" ${CMAKE_AR}) +matter_add_gn_arg_string("mbed_cc" ${CMAKE_C_COMPILER}) +matter_add_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER}) +matter_add_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TESTS) +matter_add_gn_arg_bool ("chip_with_platform_mbedtls" CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS) +matter_add_gn_arg_bool ("chip_enable_data_model" CONFIG_CHIP_DATA_MODEL) if (CONFIG_CHIP_PW_RPC) - chip_gn_arg_bool ("chip_build_pw_rpc_echo_proto" CONFIG_CHIP_PW_RPC_ECHO_PROTO) - chip_gn_arg_bool ("chip_build_pw_rpc_common_proto" CONFIG_CHIP_PW_RPC_COMMON_PROTO) - chip_gn_arg_bool ("chip_build_pw_rpc_lighting_proto" CONFIG_CHIP_PW_RPC_LIGHTING_PROTO) - chip_gn_arg_bool ("chip_build_pw_rpc_locking_proto" CONFIG_CHIP_PW_RPC_LOCKING_PROTO) + matter_add_gn_arg_bool ("chip_build_pw_rpc_echo_proto" CONFIG_CHIP_PW_RPC_ECHO_PROTO) + matter_add_gn_arg_bool ("chip_build_pw_rpc_common_proto" CONFIG_CHIP_PW_RPC_COMMON_PROTO) + matter_add_gn_arg_bool ("chip_build_pw_rpc_lighting_proto" CONFIG_CHIP_PW_RPC_LIGHTING_PROTO) + matter_add_gn_arg_bool ("chip_build_pw_rpc_locking_proto" CONFIG_CHIP_PW_RPC_LOCKING_PROTO) endif(CONFIG_CHIP_PW_RPC) if (CONFIG_CHIP_OTA_REQUESTOR) - chip_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) + matter_add_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) endif(CONFIG_CHIP_OTA_REQUESTOR) -generate_args_tmp_file() +matter_generate_args_tmp_file() # ============================================================================== # Build chip library # ============================================================================== -include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) +matter_build(chip + LIB_SHELL ${CONFIG_CHIP_LIB_SHELL} + LIB_TESTS ${CONFIG_CHIP_BUILD_TESTS} + LIB_PW_RPC ${CONFIG_CHIP_PW_RPC} +) # ============================================================================== # Define mbed target configuration according to CHIP component usage diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt index d05d8773f810a3..09ae1ac37f16d8 100644 --- a/config/nrfconnect/chip-module/CMakeLists.txt +++ b/config/nrfconnect/chip-module/CMakeLists.txt @@ -47,22 +47,18 @@ get_filename_component(COMMON_CMAKE_SOURCE_DIR ${CHIP_ROOT}/config/common/cmake # Get common Cmake sources include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) +include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) # Prepare compiler flags - -list(APPEND CHIP_CFLAGS -D_DEFAULT_SOURCE) +matter_add_flags(-D_DEFAULT_SOURCE) if (CONFIG_ARM) - list(APPEND CHIP_CFLAGS_C - --specs=nosys.specs - ) + matter_add_cflags(--specs=nosys.specs) endif() if (CONFIG_POSIX_API) - list(APPEND CHIP_CFLAGS - -D_SYS__PTHREADTYPES_H_ - -isystem${ZEPHYR_BASE}/include/zephyr/posix - ) + matter_add_flags(-D_SYS__PTHREADTYPES_H_) + matter_add_flags(-isystem${ZEPHYR_BASE}/include/zephyr/posix) endif() if (CONFIG_NORDIC_SECURITY_BACKEND) @@ -71,7 +67,7 @@ if (CONFIG_NORDIC_SECURITY_BACKEND) if(TARGET platform_cc3xx) zephyr_include_directories($) endif() - list(APPEND CHIP_CFLAGS -DMBEDTLS_CONFIG_FILE=) + matter_add_flags(-DMBEDTLS_CONFIG_FILE=) elseif(CONFIG_MBEDTLS) zephyr_include_directories($) zephyr_compile_definitions($) @@ -81,13 +77,12 @@ if (CONFIG_NRF_802154_RADIO_DRIVER) zephyr_include_directories($) endif() -zephyr_get_compile_flags(CHIP_CFLAGS_C C) -zephyr_get_compile_flags(CHIP_CFLAGS_CC CXX) -zephyr_get_gnu_cpp_standard(CHIP_CFLAGS_CC) - -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) +zephyr_get_compile_flags(ZEPHYR_CFLAGS_C C) +matter_add_cflags("${ZEPHYR_CFLAGS_C}") +zephyr_get_compile_flags(ZEPHYR_CFLAGS_CC CXX) +matter_add_cxxflags("${ZEPHYR_CFLAGS_CC}") +zephyr_get_gnu_cpp_standard(ZEPHYR_GNU_CPP_STD) +matter_add_cxxflags(${ZEPHYR_GNU_CPP_STD}) # Set up custom OpenThread configuration @@ -114,81 +109,90 @@ get_property(CHIP_COMPILER_LAUNCHER GLOBAL PROPERTY RULE_LAUNCH_COMPILE) # Generate configuration for CHIP GN build system # ============================================================================== -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}) -chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) -chip_gn_arg_bool ("chip_logging" CONFIG_LOG) -chip_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD) -chip_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD) -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_nfc" CONFIG_CHIP_NFC_COMMISSIONING) -chip_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) -chip_gn_arg_bool ("chip_persist_subscriptions" CONFIG_CHIP_PERSISTENT_SUBSCRIPTIONS) -chip_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TESTS) -chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) -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) -chip_gn_arg_bool ("chip_automation_logging" FALSE) -chip_gn_arg_bool ("chip_malloc_sys_heap" CONFIG_CHIP_MALLOC_SYS_HEAP) -chip_gn_arg_bool ("chip_enable_wifi" CONFIG_WIFI_NRF700X) +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} + DEVICE_INFO_EXAMPLE_PROVIDER CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER +) +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_NET_IPV4) +matter_add_gn_arg_bool ("chip_enable_nfc" CONFIG_CHIP_NFC_COMMISSIONING) +matter_add_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) +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_WIFI_NRF700X) if (CONFIG_CHIP_FACTORY_DATA) - chip_gn_arg_bool("chip_use_transitional_commissionable_data_provider" FALSE) - chip_gn_arg_bool("chip_enable_factory_data" TRUE) + matter_add_gn_arg_bool("chip_use_transitional_commissionable_data_provider" FALSE) + matter_add_gn_arg_bool("chip_enable_factory_data" TRUE) elseif (CONFIG_CHIP_FACTORY_DATA_CUSTOM_BACKEND) - chip_gn_arg_bool("chip_use_transitional_commissionable_data_provider" FALSE) + matter_add_gn_arg_bool("chip_use_transitional_commissionable_data_provider" FALSE) endif() if (CONFIG_CHIP_ROTATING_DEVICE_ID) - chip_gn_arg_bool("chip_enable_rotating_device_id" TRUE) - chip_gn_arg_bool("chip_enable_additional_data_advertising" TRUE) + 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) - chip_gn_arg_string("chip_mdns" "platform") + matter_add_gn_arg_string("chip_mdns" "platform") elseif(CONFIG_WIFI_NRF700X) - chip_gn_arg_string("chip_mdns" "minimal") + matter_add_gn_arg_string("chip_mdns" "minimal") else() - chip_gn_arg_string("chip_mdns" "none") + matter_add_gn_arg_string("chip_mdns" "none") endif() if (CONFIG_CHIP_CRYPTO_PSA) - chip_gn_arg_string("chip_crypto" "psa") + matter_add_gn_arg_string("chip_crypto" "psa") endif() if (BOARD STREQUAL "native_posix") - chip_gn_arg_string("target_cpu" "x86") + matter_add_gn_arg_string("target_cpu" "x86") elseif (BOARD STREQUAL "native_posix_64") - chip_gn_arg_string("target_cpu" "x64") + matter_add_gn_arg_string("target_cpu" "x64") endif() if (NOT CONFIG_CHIP_DEBUG_SYMBOLS) - chip_gn_arg_string("symbol_level" "0") + matter_add_gn_arg_string("symbol_level" "0") endif() if (CHIP_COMPILER_LAUNCHER) - chip_gn_arg_string("pw_command_launcher" ${CHIP_COMPILER_LAUNCHER}) + matter_add_gn_arg_string("pw_command_launcher" ${CHIP_COMPILER_LAUNCHER}) 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\"]) + matter_add_gn_arg_string("pw_assert_BACKEND" ${PIGWEED_DIR}/pw_assert_log:check_backend) + matter_add_gn_arg_string("pw_log_BACKEND" ${PIGWEED_DIR}/pw_log_basic) + matter_add_gn_arg("pw_build_LINK_DEPS" [\"${PIGWEED_DIR}/pw_assert:impl\",\ \"${PIGWEED_DIR}/pw_log:impl\"]) endif() -generate_args_tmp_file() +matter_generate_args_tmp_file() # ============================================================================== # Build chip library # ============================================================================== -include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) -add_dependencies(chip-gn kernel) +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 kernel +) set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS chip) target_compile_definitions(chip INTERFACE _DEFAULT_SOURCE) diff --git a/config/openiotsdk/CMakeLists.txt b/config/openiotsdk/CMakeLists.txt index c5461f119f0a33..7f559587a88a66 100644 --- a/config/openiotsdk/CMakeLists.txt +++ b/config/openiotsdk/CMakeLists.txt @@ -34,45 +34,49 @@ get_filename_component(COMMON_CMAKE_SOURCE_DIR ${CHIP_ROOT}/config/common/cmake # Get common Cmake sources include(${COMMON_CMAKE_SOURCE_DIR}/util.cmake) include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) +include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) # Prepare compiler flags -list(APPEND CHIP_CFLAGS_C ${CMAKE_C_FLAGS}) -list(APPEND CHIP_CFLAGS_CC ${CMAKE_CXX_FLAGS}) - -get_compiler_flags_from_targets("${CONFIG_CHIP_EXTERNAL_TARGETS}") +matter_add_cflags(${CMAKE_C_FLAGS}) +matter_add_cxxflags(${CMAKE_CXX_FLAGS}) -get_gnu_cpp_standard(CHIP_CFLAGS_CC) - -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) +matter_get_compiler_flags_from_targets("${CONFIG_CHIP_EXTERNAL_TARGETS}") # ============================================================================== # Generate configuration for CHIP GN build system # ============================================================================== -generate_common_configuration() -chip_gn_arg_string("target_cpu" "${CMAKE_SYSTEM_PROCESSOR}") -chip_gn_arg_string("openiotsdk_ar" ${CMAKE_AR}) -chip_gn_arg_string("openiotsdk_cc" ${CMAKE_C_COMPILER}) -chip_gn_arg_string("openiotsdk_cxx" ${CMAKE_CXX_COMPILER}) -chip_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TESTS) -chip_gn_arg_bool ("chip_detail_logging" CONFIG_CHIP_DETAIL_LOGGING) -chip_gn_arg_bool ("chip_progress_logging" CONFIG_CHIP_PROGRESS_LOGGING) -chip_gn_arg_bool ("chip_automation_logging" CONFIG_CHIP_AUTOMATION_LOGGING) -chip_gn_arg_bool ("chip_error_logging" CONFIG_CHIP_ERROR_LOGGING) -chip_gn_arg_bool ("chip_openiotsdk_use_tfm" TFM_SUPPORT) -chip_gn_arg_bool ("chip_openiotsdk_use_psa_ps" CONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS) +matter_common_gn_args( + DEBUG CONFIG_CHIP_DEBUG + LIB_SHELL CONFIG_CHIP_LIB_SHELL + LIB_TESTS CONFIG_CHIP_LIB_TESTS + PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG} +) +matter_add_gn_arg_string("target_cpu" "${CMAKE_SYSTEM_PROCESSOR}") +matter_add_gn_arg_string("openiotsdk_ar" ${CMAKE_AR}) +matter_add_gn_arg_string("openiotsdk_cc" ${CMAKE_C_COMPILER}) +matter_add_gn_arg_string("openiotsdk_cxx" ${CMAKE_CXX_COMPILER}) +matter_add_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_LIB_TESTS) +matter_add_gn_arg_bool ("chip_detail_logging" CONFIG_CHIP_DETAIL_LOGGING) +matter_add_gn_arg_bool ("chip_progress_logging" CONFIG_CHIP_PROGRESS_LOGGING) +matter_add_gn_arg_bool ("chip_automation_logging" CONFIG_CHIP_AUTOMATION_LOGGING) +matter_add_gn_arg_bool ("chip_error_logging" CONFIG_CHIP_ERROR_LOGGING) +matter_add_gn_arg_bool ("chip_openiotsdk_use_tfm" TFM_SUPPORT) +matter_add_gn_arg_bool ("chip_openiotsdk_use_psa_ps" CONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS) if (TARGET cmsis-rtos-api) - chip_gn_arg_string("target_os" "cmsis-rtos") + matter_add_gn_arg_string("target_os" "cmsis-rtos") endif() -chip_gn_arg_string("optimize_debug_level" "s") +matter_add_gn_arg_string("optimize_debug_level" "s") -generate_args_tmp_file() +matter_generate_args_tmp_file() # ============================================================================== # Build chip library # ============================================================================== -include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) +matter_build(chip + LIB_SHELL ${CONFIG_CHIP_LIB_SHELL} + LIB_TESTS ${CONFIG_CHIP_LIB_TESTS} +) + target_link_libraries(chip INTERFACE ${CONFIG_CHIP_EXTERNAL_TARGETS} ) diff --git a/config/openiotsdk/chip-gn/args.gni b/config/openiotsdk/chip-gn/args.gni index a468c14510aad9..fd9edf986f8ee7 100644 --- a/config/openiotsdk/chip-gn/args.gni +++ b/config/openiotsdk/chip-gn/args.gni @@ -19,6 +19,7 @@ import("${chip_root}/src/crypto/crypto.gni") chip_device_platform = "openiotsdk" chip_build_tests = false +chip_build_libshell = false chip_project_config_include = "" chip_system_project_config_include = "" diff --git a/config/openiotsdk/cmake/chip.cmake b/config/openiotsdk/cmake/chip.cmake index 885958f0fa6432..bdef5870433d23 100644 --- a/config/openiotsdk/cmake/chip.cmake +++ b/config/openiotsdk/cmake/chip.cmake @@ -23,7 +23,7 @@ get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH) # Default CHIP build configuration set(CONFIG_CHIP_PROJECT_CONFIG "main/include/CHIPProjectConfig.h" CACHE STRING "") -set(CONFIG_CHIP_BUILD_TESTS NO CACHE BOOL "") +set(CONFIG_CHIP_LIB_TESTS NO CACHE BOOL "") set(CONFIG_CHIP_LIB_SHELL NO CACHE BOOL "") set(CONFIG_CHIP_DETAIL_LOGGING YES CACHE BOOL "Enable logging at detail level") @@ -39,6 +39,8 @@ endif() if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") set(CONFIG_CHIP_DEBUG YES) +else() + set(CONFIG_CHIP_DEBUG NO) endif() # Add CHIP sources diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 6dc061ddabfbc3..e1953b324d3c07 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -43,25 +43,23 @@ get_filename_component(COMMON_CMAKE_SOURCE_DIR ${CHIP_ROOT}/config/common/cmake # Get common Cmake sources include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) +include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) # Prepare compiler flags if (CONFIG_POSIX_API) - list(APPEND CHIP_CFLAGS - -D_SYS__PTHREADTYPES_H_ - -isystem${ZEPHYR_BASE}/include/zephyr/posix - ) + matter_add_flags(-D_SYS__PTHREADTYPES_H_) + matter_add_flags(-isystem${ZEPHYR_BASE}/include/zephyr/posix) endif() zephyr_include_directories(${CHIP_ROOT}/src/platform/telink/) -zephyr_get_compile_flags(CHIP_CFLAGS_C C) -zephyr_get_compile_flags(CHIP_CFLAGS_CC CXX) -zephyr_get_gnu_cpp_standard(CHIP_CFLAGS_CC) - -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) +zephyr_get_compile_flags(ZEPHYR_CFLAGS_C C) +matter_add_cflags("${ZEPHYR_CFLAGS_C}") +zephyr_get_compile_flags(ZEPHYR_CFLAGS_CC CXX) +matter_add_cxxflags("${ZEPHYR_CFLAGS_CC}") +zephyr_get_gnu_cpp_standard(ZEPHYR_GNU_CPP_STD) +matter_add_cxxflags(${ZEPHYR_GNU_CPP_STD}) # Set up custom OpenThread configuration @@ -78,53 +76,61 @@ endif() # Generate configuration for CHIP GN build system # ============================================================================== -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}) -chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) -chip_gn_arg_bool ("chip_logging" CONFIG_LOG) -chip_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD) -chip_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD) -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_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) -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) -chip_gn_arg_bool ("chip_automation_logging" FALSE) +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} + DEVICE_INFO_EXAMPLE_PROVIDER CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER +) +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_NET_IPV4) +matter_add_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) +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) if (CONFIG_CHIP_FACTORY_DATA) - chip_gn_arg_bool ("chip_use_transitional_commissionable_data_provider" "false") - chip_gn_arg_bool ("chip_enable_factory_data" "true") + matter_add_gn_arg_bool ("chip_use_transitional_commissionable_data_provider" "false") + matter_add_gn_arg_bool ("chip_enable_factory_data" "true") elseif (CONFIG_CHIP_FACTORY_DATA_CUSTOM_BACKEND) - chip_gn_arg_bool ("chip_use_transitional_commissionable_data_provider" "false") + matter_add_gn_arg_bool ("chip_use_transitional_commissionable_data_provider" "false") endif() if (CONFIG_CHIP_ROTATING_DEVICE_ID) - chip_gn_arg_bool("chip_enable_rotating_device_id" "true") - chip_gn_arg_bool("chip_enable_additional_data_advertising" "true") + 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_ENABLE_DNSSD_SRP) - chip_gn_arg_string("chip_mdns" "platform") + matter_add_gn_arg_string("chip_mdns" "platform") 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\"]) + matter_add_gn_arg_string("pw_assert_BACKEND" ${PIGWEED_DIR}/pw_assert_log:check_backend) + matter_add_gn_arg_string("pw_log_BACKEND" ${PIGWEED_DIR}/pw_log_basic) + matter_add_gn_arg("pw_build_LINK_DEPS" [\"${PIGWEED_DIR}/pw_assert:impl\",\ \"${PIGWEED_DIR}/pw_log:impl\"]) endif() -generate_args_tmp_file() +matter_generate_args_tmp_file() # ============================================================================== # Build chip library # ============================================================================== -include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) -add_dependencies(chip-gn kernel) +matter_build(chip + LIB_SHELL ${CONFIG_CHIP_LIB_SHELL} + DEVICE_INFO_EXAMPLE_PROVIDER ${CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER} + GN_DEPENDENCIES kernel +) set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS chip) # ============================================================================== diff --git a/config/zephyr/chip-module/CMakeLists.txt b/config/zephyr/chip-module/CMakeLists.txt index f90e0f8373d2a6..6d84a962a69cc0 100644 --- a/config/zephyr/chip-module/CMakeLists.txt +++ b/config/zephyr/chip-module/CMakeLists.txt @@ -46,24 +46,22 @@ endif() # Get common Cmake sources include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) +include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) # Prepare compiler flags +matter_add_flags(-isystem${ZEPHYR_BASE}/../modules/crypto/mbedtls/include/) + if (CONFIG_POSIX_API) - list(APPEND CHIP_CFLAGS - -D_SYS__PTHREADTYPES_H_ - -isystem${ZEPHYR_BASE}/include/zephyr/posix - ) + matter_add_flags(-D_SYS__PTHREADTYPES_H_) + matter_add_flags(-isystem${ZEPHYR_BASE}/include/zephyr/posix) endif() -list(APPEND CHIP_CFLAGS -isystem${ZEPHYR_BASE}/../modules/crypto/mbedtls/include/) - -zephyr_get_compile_flags(CHIP_CFLAGS_C C) -zephyr_get_compile_flags(CHIP_CFLAGS_CC CXX) -zephyr_get_gnu_cpp_standard(CHIP_CFLAGS_CC) - -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) +zephyr_get_compile_flags(ZEPHYR_CFLAGS_C C) +matter_add_cflags(${ZEPHYR_CFLAGS_C}) +zephyr_get_compile_flags(ZEPHYR_CFLAGS_CC CXX) +matter_add_cxxflags(${ZEPHYR_CFLAGS_CC}) +zephyr_get_gnu_cpp_standard(ZEPHYR_GNU_CPP_STD) +matter_add_cxxflags(${ZEPHYR_GNU_CPP_STD}) # Set up custom OpenThread configuration @@ -79,27 +77,36 @@ endif() # ============================================================================== # Generate configuration for CHIP GN build system # ============================================================================== -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}) -chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) -chip_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD) -chip_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD) -chip_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4) -chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) +matter_common_gn_args( + DEBUG CONFIG_DEBUG + LIB_SHELL CONFIG_CHIP_LIB_SHELL + LIB_TESTS CONFIG_CHIP_BUILD_TESTS + LIB_PW_RPC CONFIG_CHIP_PW_RPC + PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG} +) +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_enable_openthread" CONFIG_NET_L2_OPENTHREAD) +matter_add_gn_arg_bool ("chip_openthread_ftd" CONFIG_OPENTHREAD_FTD) +matter_add_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4) +matter_add_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) if (CONFIG_CHIP_ENABLE_DNSSD_SRP) - chip_gn_arg_string("chip_mdns" "platform") + matter_add_gn_arg_string("chip_mdns" "platform") endif() -generate_args_tmp_file() +matter_generate_args_tmp_file() # ============================================================================== # Build chip library # ============================================================================== -include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) -add_dependencies(chip-gn kernel) +matter_build(chip + LIB_SHELL ${CONFIG_CHIP_LIB_SHELL} + LIB_PW_RPC ${CONFIG_CHIP_PW_RPC} + LIB_TESTS ${CONFIG_CHIP_BUILD_TESTS} + GN_DEPENDENCIES kernel +) set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS chip) endif() # CONFIG_CHIP \ No newline at end of file diff --git a/examples/common/pigweed/mbed/Rpc.cpp b/examples/common/pigweed/mbed/Rpc.cpp index 65e9d48824160a..79940b005eba06 100644 --- a/examples/common/pigweed/mbed/Rpc.cpp +++ b/examples/common/pigweed/mbed/Rpc.cpp @@ -28,7 +28,7 @@ #include "pw_sys_io/sys_io.h" #include "pw_sys_io_mbed/init.h" -#include +#include #ifdef CHIP_PW_RPC_ECHO_PROTO #include "pw_rpc/echo_service_nanopb.h" diff --git a/src/platform/mbed/Logging.h b/src/platform/mbed/Logging.h index ce1ce9c8c2a2c5..df327141945fba 100644 --- a/src/platform/mbed/Logging.h +++ b/src/platform/mbed/Logging.h @@ -23,7 +23,7 @@ #pragma once -#include +#include namespace chip { namespace Logging { diff --git a/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt b/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt index 5d526bfedd4801..e9c0f48953cfde 100644 --- a/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt +++ b/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt @@ -23,7 +23,7 @@ get_filename_component(OPEN_IOT_SDK_EXAMPLE_COMMON ${CHIP_ROOT}/examples/platfor list(APPEND CMAKE_MODULE_PATH ${OPEN_IOT_SDK_CONFIG}/cmake) # Application CHIP build configuration -set(CONFIG_CHIP_BUILD_TESTS YES) +set(CONFIG_CHIP_LIB_TESTS YES) set(CONFIG_CHIP_DETAIL_LOGGING NO) set(CONFIG_CHIP_PROGRESS_LOGGING NO) set(CONFIG_CHIP_AUTOMATION_LOGGING YES)