Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2020 Project CHIP Authors |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | # |
| 18 | # @file |
| 19 | # CMake sub-project defining 'chip' target which represents CHIP library |
| 20 | # and other optional libraries like unit tests, built with 'mbed' |
| 21 | # platform. |
| 22 | # Since CHIP doesn't provide native CMake support, ExternalProject |
| 23 | # module is used to build the required artifacts with GN meta-build |
| 24 | # system. |
| 25 | # |
| 26 | |
| 27 | include(ExternalProject) |
| 28 | include(mbed-util.cmake) |
| 29 | |
| 30 | # ============================================================================== |
| 31 | # Declare configuration variables and define constants |
| 32 | # ============================================================================== |
| 33 | # C/C++ compiler flags passed to CHIP build system |
| 34 | list(APPEND CHIP_CFLAGS) |
| 35 | |
| 36 | # C compiler flags passed to CHIP build system |
| 37 | list(APPEND CHIP_CFLAGS_C) |
| 38 | |
| 39 | # C++ compiler flags passed to CHIP build system |
| 40 | list(APPEND CHIP_CFLAGS_CC) |
| 41 | |
| 42 | # CHIP libraries that the application should be linked with |
| 43 | list(APPEND CHIP_LIBRARIES) |
| 44 | |
| 45 | # GN meta-build system arguments in the form of 'key1 = value1\nkey2 = value2...' string |
| 46 | string(APPEND CHIP_GN_ARGS) |
| 47 | |
| 48 | # C/C++ compiler flags which should not be forwarded to CHIP |
| 49 | # build system (e.g. because CHIP configures them on its own) |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 50 | set(CHIP_CFLAG_EXCLUDES |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 51 | "-fno-asynchronous-unwind-tables" |
| 52 | "-fno-common" |
| 53 | "-fno-defer-pop" |
| 54 | "-fno-reorder-functions" |
| 55 | "-ffunction-sections" |
| 56 | "-fdata-sections" |
| 57 | "-g*" |
| 58 | "-O*" |
| 59 | "-W*" |
| 60 | ) |
| 61 | |
| 62 | # ============================================================================== |
| 63 | # Helper macros |
| 64 | # ============================================================================== |
| 65 | |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 66 | macro(chip_gn_arg_import FILE) |
| 67 | string(APPEND CHIP_GN_ARGS "import(\"${FILE}\")\n") |
| 68 | endmacro() |
| 69 | |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 70 | macro(chip_gn_arg_string ARG STRING) |
| 71 | string(APPEND CHIP_GN_ARGS "${ARG} = \"${STRING}\"\n") |
| 72 | endmacro() |
| 73 | |
| 74 | macro(chip_gn_arg_bool ARG BOOLEAN) |
| 75 | if (${BOOLEAN}) |
| 76 | string(APPEND CHIP_GN_ARGS "${ARG} = true\n") |
| 77 | else() |
| 78 | string(APPEND CHIP_GN_ARGS "${ARG} = false\n") |
| 79 | endif() |
| 80 | endmacro() |
| 81 | |
| 82 | macro(chip_gn_arg_flags ARG CFLAGS) |
| 83 | list(SORT CFLAGS) |
| 84 | string(APPEND CHIP_GN_ARGS "${ARG} = [${CFLAGS}]\n") |
| 85 | endmacro() |
| 86 | |
| 87 | macro(chip_gn_arg_lang_flags ARG CFLAGS) |
| 88 | list(SORT CFLAGS) |
| 89 | list(SORT CHIP_CFLAG_EXCLUDES) |
| 90 | set(CFLAG_EXCLUDES "[") |
| 91 | foreach(cflag ${CHIP_CFLAG_EXCLUDES}) |
| 92 | string(APPEND CFLAG_EXCLUDES "\"${cflag}\", ") |
| 93 | endforeach() |
| 94 | string(APPEND CFLAG_EXCLUDES "]") |
| 95 | string(APPEND CHIP_GN_ARGS "${ARG} = filter_exclude(string_split(\"${CFLAGS}\"), ${CFLAG_EXCLUDES})\n") |
| 96 | endmacro() |
| 97 | |
| 98 | macro(mbed_interface_library_named name) |
| 99 | add_library(${name} INTERFACE) |
| 100 | endmacro() |
| 101 | |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 102 | # Select gnu++<YY> standard based on project configuration |
| 103 | macro(mbed_get_gnu_cpp_standard VAR) |
| 104 | if (CONFIG_STD_CPP11) |
| 105 | list(APPEND ${VAR} -std=gnu++11) |
| 106 | elseif (CONFIG_STD_CPP14) |
| 107 | list(APPEND ${VAR} -std=gnu++14) |
| 108 | elseif (CONFIG_STD_CPP17) |
| 109 | list(APPEND ${VAR} -std=gnu++17) |
| 110 | elseif (CONFIG_STD_CPP2A) |
| 111 | list(APPEND ${VAR} -std=gnu++20) |
| 112 | endif() |
| 113 | endmacro() |
| 114 | |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 115 | # ============================================================================== |
| 116 | # Prepare CHIP configuration based on the project configuration |
| 117 | # ============================================================================== |
| 118 | # Read configuration file and parse it content to create cmake variable |
| 119 | file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/config ConfigContents) |
| 120 | foreach(NameAndValue ${ConfigContents}) |
| 121 | # Strip leading spaces |
| 122 | string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) |
| 123 | # Find variable name |
| 124 | string(REGEX MATCH "^[^=]+" Name ${NameAndValue}) |
| 125 | # Find the value |
| 126 | string(REPLACE "${Name}=" "" Value ${NameAndValue}) |
| 127 | # Set the variable |
| 128 | set(${Name} "${Value}") |
| 129 | endforeach() |
| 130 | |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 131 | if (CONFIG_CHIP_PW_RPC) |
| 132 | set(CONFIG_STD_CPP17 y) |
| 133 | endif() |
| 134 | |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 135 | if (NOT CHIP_ROOT) |
| 136 | get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../.. REALPATH) |
| 137 | endif() |
| 138 | |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 139 | set(GN_ROOT_TARGET ${CHIP_ROOT}/config/mbed/chip-gn) |
| 140 | |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 141 | # Prepare compiler flags |
| 142 | |
| 143 | mbed_get_target_common_compile_flags(CHIP_CFLAGS mbed-core) |
| 144 | mbed_get_lang_compile_flags(CHIP_CFLAGS_C mbed-core C) |
| 145 | list(APPEND CHIP_CFLAGS_C ${CMAKE_C_FLAGS_INIT}) |
| 146 | mbed_get_lang_compile_flags(CHIP_CFLAGS_CC mbed-core CXX) |
| 147 | list(APPEND CHIP_CFLAGS_CC ${CMAKE_CXX_FLAGS_INIT}) |
| 148 | |
Artur Tynecki | 35fb13e | 2021-10-12 18:23:45 +0200 | [diff] [blame] | 149 | mbed_get_target_common_compile_flags(CHIP_MBEDCMSISCM_CFLAGS mbed-cmsis-cortex-m) |
| 150 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDCMSISCM_CFLAGS}) |
| 151 | if(MBED_TARGET STREQUAL "CY8CPROTO_062_4343W") |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 152 | mbed_get_target_common_compile_flags(CHIP_MBEDCMSISCY8_CFLAGS mbed-cy8cproto-062-4343w) |
Artur Tynecki | 35fb13e | 2021-10-12 18:23:45 +0200 | [diff] [blame] | 153 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDCMSISCY8_CFLAGS}) |
| 154 | mbed_get_target_common_compile_flags(CHIP_MBEDPSOC6_CFLAGS mbed-psoc6) |
| 155 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDPSOC6_CFLAGS}) |
| 156 | mbed_get_target_common_compile_flags(CHIP_MBEDCAT1_CFLAGS mbed-cat1a) |
| 157 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDCAT1_CFLAGS}) |
| 158 | mbed_get_target_common_compile_flags(CHIP_MBEDCMSISCY8MODUS_CFLAGS mbed-cy8cproto-062-4343w-bsp-design-modus) |
| 159 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDCMSISCY8MODUS_CFLAGS}) |
| 160 | endif() |
| 161 | |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 162 | # Add support for Mbed Posix Socket |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 163 | mbed_get_target_common_compile_flags(CHIP_MBEDPOSIXSOCKET_CFLAGS mbed-os-posix-socket) |
| 164 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDPOSIXSOCKET_CFLAGS}) |
| 165 | |
| 166 | # Add support for Mbed BLE |
| 167 | mbed_get_target_common_compile_flags(CHIP_MBEDBLE_CFLAGS mbed-ble) |
| 168 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDBLE_CFLAGS}) |
| 169 | |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 170 | # Add support for Mbed event |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 171 | mbed_get_target_common_compile_flags(CHIP_MBEDEVENTS_CFLAGS mbed-events) |
| 172 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDEVENTS_CFLAGS}) |
| 173 | |
| 174 | # Add support for Mbed rtos |
| 175 | mbed_get_target_common_compile_flags(CHIP_MBEDRTOS_CFLAGS mbed-rtos) |
| 176 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDRTOS_CFLAGS}) |
| 177 | |
| 178 | # Add support for Mbed storage |
| 179 | mbed_get_target_common_compile_flags(CHIP_MBEDSTORAGE_CFLAGS mbed-storage-kv-global-api) |
| 180 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDSTORAGE_CFLAGS}) |
| 181 | |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 182 | # Add support for Mbed Socket |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 183 | mbed_get_target_common_compile_flags(CHIP_MBEDNETSOCKET_CFLAGS mbed-netsocket) |
| 184 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDNETSOCKET_CFLAGS}) |
| 185 | |
| 186 | if (CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS) |
| 187 | mbed_get_target_common_compile_flags(CHIP_MBEDTLS_CFLAGS mbed-mbedtls) |
| 188 | list(APPEND CHIP_CFLAGS ${CHIP_MBEDTLS_CFLAGS}) |
| 189 | endif() |
| 190 | |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 191 | mbed_get_gnu_cpp_standard(CHIP_CFLAGS_CC) |
| 192 | |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 193 | list(APPEND CHIP_CFLAGS |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 194 | \"-D__LINUX_ERRNO_EXTENSIONS__=1\" |
| 195 | ) |
| 196 | |
Andrei Litvin | adc7a84 | 2022-03-12 16:21:12 -0500 | [diff] [blame] | 197 | list(APPEND CHIP_CFLAGS |
| 198 | \"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>\" |
| 199 | ) |
| 200 | |
ATmobica | f0ae9d8 | 2021-09-02 05:47:22 +0200 | [diff] [blame] | 201 | if (CONFIG_MBED_BSD_SOCKET_TRACE) |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 202 | list(APPEND CHIP_CFLAGS |
ATmobica | f0ae9d8 | 2021-09-02 05:47:22 +0200 | [diff] [blame] | 203 | \"-DMBED_BSD_SOCKET_TRACE=1\" |
| 204 | ) |
| 205 | endif() |
| 206 | |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 207 | # CFLAGS are put in random order, sort them before converting them to a string |
| 208 | list(SORT CHIP_CFLAGS) |
| 209 | list(SORT CHIP_CFLAGS_C) |
| 210 | list(SORT CHIP_CFLAGS_CC) |
| 211 | |
| 212 | set(SEPARATOR ",") |
| 213 | convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS CHIP_CFLAGS ${SEPARATOR}) |
| 214 | set(SEPARATOR " ") |
| 215 | convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_C CHIP_CFLAGS_C ${SEPARATOR}) |
| 216 | convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_CC CHIP_CFLAGS_CC ${SEPARATOR}) |
| 217 | |
| 218 | # Prepare CHIP libraries that the application should be linked with |
| 219 | |
| 220 | if (NOT CHIP_LIBRARIES) |
| 221 | set(CHIP_LIBRARIES -lCHIP) |
| 222 | endif() |
| 223 | |
| 224 | if (CONFIG_CHIP_LIB_SHELL) |
| 225 | list(APPEND CHIP_LIBRARIES -lCHIPShell) |
| 226 | endif() |
| 227 | |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 228 | if (CONFIG_CHIP_PW_RPC) |
| 229 | list(APPEND CHIP_LIBRARIES -lPwRpc) |
| 230 | if (${APP_TARGET} MATCHES "pigweed-app") |
| 231 | set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "y") |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 232 | elseif (${APP_TARGET} MATCHES "lighting-app") |
| 233 | set(CONFIG_CHIP_PW_RPC_COMMON_PROTO "y") |
| 234 | set(CONFIG_CHIP_PW_RPC_LIGHTING_PROTO "y") |
| 235 | elseif (${APP_TARGET} MATCHES "lock-app") |
| 236 | set(CONFIG_CHIP_PW_RPC_COMMON_PROTO "y") |
| 237 | set(CONFIG_CHIP_PW_RPC_LOCKING_PROTO "y") |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 238 | endif() |
| 239 | endif(CONFIG_CHIP_PW_RPC) |
| 240 | |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 241 | # Set up CHIP project configuration file |
| 242 | |
| 243 | set(CHIP_DEFAULT_CONFIG_FILE "<${CHIP_ROOT}/config/mbed/CHIPProjectConfig.h>") |
| 244 | set(CHIP_PROJECT_CONFIG ${CHIP_DEFAULT_CONFIG_FILE}) |
| 245 | |
| 246 | if (CONFIG_CHIP_PROJECT_CONFIG) |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 247 | get_filename_component(CHIP_PROJECT_CONFIG |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 248 | ${CONFIG_CHIP_PROJECT_CONFIG} |
| 249 | REALPATH |
| 250 | BASE_DIR ${CMAKE_SOURCE_DIR} |
| 251 | ) |
| 252 | set(CHIP_PROJECT_CONFIG "<${CHIP_PROJECT_CONFIG}>") |
| 253 | endif() |
| 254 | |
| 255 | if (${CMAKE_BUILD_TYPE} STREQUAL "debug") |
| 256 | set(CONFIG_DEBUG "y") |
| 257 | endif() |
| 258 | |
| 259 | # ============================================================================== |
| 260 | # Generate configuration for CHIP GN build system |
| 261 | # ============================================================================== |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 262 | if (CONFIG_CHIP_PW_RPC) |
| 263 | chip_gn_arg_import("${GN_ROOT_TARGET}/lib/pw_rpc/pw_rpc.gni") |
| 264 | endif() |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 265 | |
| 266 | chip_gn_arg_flags("target_cflags" ${CHIP_CFLAGS}) |
| 267 | chip_gn_arg_lang_flags("target_cflags_c" ${CHIP_CFLAGS_C}) |
| 268 | chip_gn_arg_lang_flags("target_cflags_cc" ${CHIP_CFLAGS_CC}) |
| 269 | chip_gn_arg_string("mbed_ar" ${CMAKE_AR}) |
| 270 | chip_gn_arg_string("mbed_cc" ${CMAKE_C_COMPILER}) |
| 271 | chip_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER}) |
| 272 | chip_gn_arg_string("chip_project_config_include" "${CHIP_PROJECT_CONFIG}") |
| 273 | chip_gn_arg_bool ("is_debug" CONFIG_DEBUG) |
| 274 | chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS) |
Vincent Coubard | d48d754 | 2021-10-06 22:35:20 +0100 | [diff] [blame] | 275 | chip_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TESTS) |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 276 | chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL) |
| 277 | chip_gn_arg_bool ("chip_with_platform_mbedtls" CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS) |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 278 | chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC) |
Artur Tynecki | b4921fc | 2022-02-21 17:44:34 +0100 | [diff] [blame] | 279 | chip_gn_arg_bool ("chip_enable_data_model" CONFIG_CHIP_DATA_MODEL) |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 280 | if (CONFIG_CHIP_PW_RPC) |
| 281 | chip_gn_arg_bool ("chip_build_pw_rpc_echo_proto" CONFIG_CHIP_PW_RPC_ECHO_PROTO) |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 282 | chip_gn_arg_bool ("chip_build_pw_rpc_common_proto" CONFIG_CHIP_PW_RPC_COMMON_PROTO) |
| 283 | chip_gn_arg_bool ("chip_build_pw_rpc_lighting_proto" CONFIG_CHIP_PW_RPC_LIGHTING_PROTO) |
| 284 | chip_gn_arg_bool ("chip_build_pw_rpc_locking_proto" CONFIG_CHIP_PW_RPC_LOCKING_PROTO) |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 285 | endif(CONFIG_CHIP_PW_RPC) |
Artur Tynecki | 42a7b0a | 2022-01-26 05:46:24 +0100 | [diff] [blame] | 286 | if (CONFIG_CHIP_OTA_REQUESTOR) |
| 287 | chip_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR) |
| 288 | endif(CONFIG_CHIP_OTA_REQUESTOR) |
| 289 | |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 290 | |
| 291 | file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS}) |
| 292 | |
| 293 | # ============================================================================== |
| 294 | # Define 'chip-gn' target that builds CHIP library(ies) with GN build system |
| 295 | # ============================================================================== |
| 296 | ExternalProject_Add( |
| 297 | chip-gn |
| 298 | PREFIX ${CMAKE_CURRENT_BINARY_DIR} |
| 299 | SOURCE_DIR ${CHIP_ROOT} |
| 300 | BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 301 | CONFIGURE_COMMAND gn --root=${GN_ROOT_TARGET} gen --export-compile-commands --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR} |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 302 | BUILD_COMMAND ninja |
| 303 | INSTALL_COMMAND "" |
| 304 | BUILD_BYPRODUCTS ${CHIP_LIBRARIES} |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 305 | CONFIGURE_ALWAYS TRUE |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 306 | BUILD_ALWAYS TRUE |
| 307 | USES_TERMINAL_CONFIGURE TRUE |
| 308 | USES_TERMINAL_BUILD TRUE |
| 309 | ) |
| 310 | |
| 311 | # ============================================================================== |
| 312 | # Define 'chip' target that exposes CHIP headers & libraries to the application |
| 313 | # ============================================================================== |
| 314 | mbed_interface_library_named(chip) |
| 315 | target_compile_definitions(chip INTERFACE CHIP_HAVE_CONFIG_H) |
| 316 | target_include_directories(chip INTERFACE |
| 317 | ${CHIP_ROOT}/src |
| 318 | ${CHIP_ROOT}/src/include |
| 319 | ${CHIP_ROOT}/src/lib |
| 320 | ${CHIP_ROOT}/third_party/nlassert/repo/include |
| 321 | ${CMAKE_CURRENT_BINARY_DIR}/gen/include |
| 322 | ) |
| 323 | target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib) |
| 324 | target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group) |
| 325 | add_dependencies(chip chip-gn) |
| 326 | |
| 327 | # ============================================================================== |
| 328 | # Define mbed target configuration according to CHIP component usage |
| 329 | # ============================================================================== |
| 330 | # CHIP includes path |
| 331 | list(APPEND CHIP_INCLUDES) |
| 332 | |
| 333 | # CHIP defines |
| 334 | list(APPEND CHIP_DEFINES) |
| 335 | |
Artur Tynecki | 42a7b0a | 2022-01-26 05:46:24 +0100 | [diff] [blame] | 336 | # Target specific configuration |
| 337 | if("capsense" IN_LIST MBED_TARGET_LABELS) |
| 338 | add_subdirectory(${CHIP_ROOT}/third_party/mbed-os-cypress-capsense-button/repo ${CMAKE_BINARY_DIR}/capsense_build) |
| 339 | target_link_libraries(${APP_TARGET} capsense) |
| 340 | endif() |
| 341 | |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 342 | list(APPEND CHIP_INCLUDES |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 343 | ${CHIP_ROOT}/config/mbed/mbedtls |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 344 | ) |
| 345 | |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 346 | list(APPEND CHIP_DEFINES |
Vincent Coubard | cc13560 | 2021-06-29 16:58:47 +0100 | [diff] [blame] | 347 | __LINUX_ERRNO_EXTENSIONS__=1 |
| 348 | ) |
| 349 | |
Andrei Litvin | adc7a84 | 2022-03-12 16:21:12 -0500 | [diff] [blame] | 350 | list(APPEND CHIP_DEFINES |
| 351 | CHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h> |
| 352 | ) |
| 353 | |
ATmobica | f0ae9d8 | 2021-09-02 05:47:22 +0200 | [diff] [blame] | 354 | if (CONFIG_MBED_BSD_SOCKET_TRACE) |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 355 | list(APPEND CHIP_DEFINES |
ATmobica | f0ae9d8 | 2021-09-02 05:47:22 +0200 | [diff] [blame] | 356 | MBED_BSD_SOCKET_TRACE=1 |
| 357 | ) |
| 358 | endif() |
| 359 | |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 360 | if (CONFIG_CHIP_PW_RPC) |
| 361 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17" PARENT_SCOPE) |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 362 | list(APPEND CHIP_DEFINES |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 363 | CHIP_PW_RPC=1 |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 364 | ) |
| 365 | endif() |
| 366 | |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 367 | if (CONFIG_CHIP_PW_RPC) |
| 368 | |
| 369 | set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo") |
| 370 | |
| 371 | target_sources(${APP_TARGET} PRIVATE |
| 372 | ${CHIP_ROOT}/examples/common/pigweed/RpcService.cpp |
| 373 | ${CHIP_ROOT}/examples/common/pigweed/mbed/PigweedLoggerMutex.cpp |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 374 | ${CHIP_ROOT}/examples/common/pigweed/mbed/Rpc.cpp |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 375 | ${MBED_COMMON}/util/PigweedLogger.cpp |
| 376 | ) |
| 377 | |
rgoliver | eb3ac83 | 2022-05-31 16:02:41 -0400 | [diff] [blame] | 378 | list(APPEND CHIP_DEFINES |
| 379 | PW_RPC_USE_GLOBAL_MUTEX=0 |
| 380 | ) |
| 381 | |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 382 | target_include_directories(${APP_TARGET} PRIVATE |
| 383 | ${PIGWEED_ROOT}/pw_sys_io/public |
| 384 | ${PIGWEED_ROOT}/pw_assert/public |
rgoliver | ea17779 | 2022-03-04 08:30:03 -0500 | [diff] [blame] | 385 | ${PIGWEED_ROOT}/pw_assert/assert_lite_public_overrides |
rgoliver | dcec35a | 2022-06-15 10:50:26 -0400 | [diff] [blame] | 386 | ${PIGWEED_ROOT}/pw_assert_log/assert_backend_public_overrides |
| 387 | ${PIGWEED_ROOT}/pw_assert_log/check_backend_public_overrides |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 388 | ${PIGWEED_ROOT}/pw_assert_log/public |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 389 | ${PIGWEED_ROOT}/pw_bytes/public |
| 390 | ${PIGWEED_ROOT}/pw_checksum/public |
| 391 | ${PIGWEED_ROOT}/pw_containers/public |
| 392 | ${PIGWEED_ROOT}/pw_hdlc/public |
| 393 | ${PIGWEED_ROOT}/pw_log/public |
| 394 | ${PIGWEED_ROOT}/pw_log_basic/public |
| 395 | ${PIGWEED_ROOT}/pw_log_basic/public_overrides |
| 396 | ${PIGWEED_ROOT}/pw_span/public_overrides |
| 397 | ${PIGWEED_ROOT}/pw_span/public |
rgoliver | 53a5d1e | 2021-12-01 12:59:29 -0500 | [diff] [blame] | 398 | ${PIGWEED_ROOT}/pw_sync/public |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 399 | ${PIGWEED_ROOT}/pw_polyfill/public |
| 400 | ${PIGWEED_ROOT}/pw_polyfill/standard_library_public |
| 401 | ${PIGWEED_ROOT}/pw_polyfill/public_overrides |
| 402 | ${PIGWEED_ROOT}/pw_rpc/public |
| 403 | ${PIGWEED_ROOT}/pw_rpc/nanopb/public |
| 404 | ${PIGWEED_ROOT}/pw_rpc/raw/public |
| 405 | ${PIGWEED_ROOT}/pw_protobuf/public |
| 406 | ${PIGWEED_ROOT}/pw_status/public |
| 407 | ${PIGWEED_ROOT}/pw_stream/public |
| 408 | ${PIGWEED_ROOT}/pw_result/public |
| 409 | ${PIGWEED_ROOT}/pw_varint/public |
| 410 | ${PIGWEED_ROOT}/pw_function/public |
| 411 | ${PIGWEED_ROOT}/pw_preprocessor/public |
| 412 | ${PIGWEED_ROOT}/pw_rpc/system_server/public |
| 413 | ${CHIP_ROOT}/third_party/nanopb/repo |
| 414 | |
| 415 | ${CHIP_ROOT}/examples/common |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 416 | ${CHIP_ROOT}/examples/common/pigweed |
| 417 | ${CHIP_ROOT}/examples/common/pigweed/mbed |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 418 | ${MBED_COMMON}/pw_sys_io/public |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 419 | |
| 420 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/pwpb |
| 421 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_protobuf/common_protos.proto_library/nanopb |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 422 | ) |
| 423 | |
| 424 | if (CONFIG_CHIP_PW_RPC_ECHO_PROTO) |
| 425 | target_include_directories(${APP_TARGET} PRIVATE |
| 426 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb_rpc |
| 427 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 428 | ) |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 429 | list(APPEND CHIP_DEFINES |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 430 | CHIP_PW_RPC_ECHO_PROTO=1 |
Artur Tynecki | c9e35ba | 2021-10-22 18:23:19 +0200 | [diff] [blame] | 431 | ) |
| 432 | endif(CONFIG_CHIP_PW_RPC_ECHO_PROTO) |
| 433 | |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 434 | if (CONFIG_CHIP_PW_RPC_COMMON_PROTO) |
| 435 | target_include_directories(${APP_TARGET} PRIVATE |
| 436 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/button_service.proto_library/nanopb |
| 437 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/button_service.proto_library/nanopb_rpc |
| 438 | |
| 439 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/device_service.proto_library/nanopb |
| 440 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/device_service.proto_library/nanopb_rpc |
| 441 | ) |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 442 | list(APPEND CHIP_DEFINES |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 443 | CHIP_PW_RPC_COMMON_PROTO=1 |
| 444 | ) |
| 445 | endif(CONFIG_CHIP_PW_RPC_COMMON_PROTO) |
| 446 | |
| 447 | if (CONFIG_CHIP_PW_RPC_LIGHTING_PROTO) |
| 448 | target_include_directories(${APP_TARGET} PRIVATE |
| 449 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/lighting_service.proto_library/nanopb |
| 450 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/lighting_service.proto_library/nanopb_rpc |
| 451 | ) |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 452 | list(APPEND CHIP_DEFINES |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 453 | CHIP_PW_RPC_LIGHTING_PROTO=1 |
| 454 | ) |
| 455 | endif(CONFIG_CHIP_PW_RPC_LIGHTING_PROTO) |
| 456 | |
| 457 | if (CONFIG_CHIP_PW_RPC_LOCKING_PROTO) |
| 458 | target_include_directories(${APP_TARGET} PRIVATE |
| 459 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/locking_service.proto_library/nanopb |
| 460 | ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/locking_service.proto_library/nanopb_rpc |
| 461 | ) |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 462 | list(APPEND CHIP_DEFINES |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 463 | CHIP_PW_RPC_LOCKING_PROTO=1 |
| 464 | ) |
| 465 | endif(CONFIG_CHIP_PW_RPC_LOCKING_PROTO) |
| 466 | |
| 467 | endif(CONFIG_CHIP_PW_RPC) |
| 468 | |
Artur Tynecki | 42a7b0a | 2022-01-26 05:46:24 +0100 | [diff] [blame] | 469 | if (CONFIG_CHIP_OTA_REQUESTOR) |
| 470 | target_include_directories(${APP_TARGET} PRIVATE |
Carol Yang | 31cf572 | 2022-03-08 21:55:42 -0800 | [diff] [blame] | 471 | ${CHIP_ROOT}/examples/platform/mbed/ota/ |
Artur Tynecki | 42a7b0a | 2022-01-26 05:46:24 +0100 | [diff] [blame] | 472 | ${CHIP_ROOT}/src/app/clusters/ota-requestor |
| 473 | ${CHIP_ROOT}/src/platform |
| 474 | ${CHIP_ROOT}/src/platform/mbed |
| 475 | ${CHIP_ROOT}/src/include/platform |
| 476 | ) |
| 477 | |
| 478 | target_sources(${APP_TARGET} PRIVATE |
Carol Yang | 535c6c8 | 2022-03-08 09:44:03 -0800 | [diff] [blame] | 479 | ${CHIP_ROOT}/examples/platform/mbed/ota/OTARequestorDriverImpl.cpp |
Carol Yang | 5b62cea | 2022-04-04 17:48:08 -0700 | [diff] [blame] | 480 | ${CHIP_ROOT}/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp |
Carol Yang | 04f1acd | 2022-04-05 01:44:44 -0700 | [diff] [blame] | 481 | ${CHIP_ROOT}/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp |
Damian Królik | aa17b2f | 2022-03-09 14:13:29 +0100 | [diff] [blame] | 482 | ${CHIP_ROOT}/src/app/clusters/ota-requestor/DefaultOTARequestorStorage.cpp |
Artur Tynecki | 42a7b0a | 2022-01-26 05:46:24 +0100 | [diff] [blame] | 483 | ${CHIP_ROOT}/src/app/clusters/ota-requestor/BDXDownloader.cpp |
Artur Tynecki | 42a7b0a | 2022-01-26 05:46:24 +0100 | [diff] [blame] | 484 | ${CHIP_ROOT}/src/platform/mbed/OTAImageProcessorImpl.cpp |
| 485 | ) |
| 486 | |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 487 | if (NOT ${APP_TARGET} MATCHES "shell") |
| 488 | target_sources(${APP_TARGET} PRIVATE |
| 489 | ${CHIP_ROOT}/src/app/clusters/ota-requestor/ota-requestor-server.cpp |
| 490 | ) |
| 491 | else() |
| 492 | include(${CHIP_ROOT}/src/app/chip_data_model.cmake) |
| 493 | chip_configure_data_model(${APP_TARGET} |
| 494 | ZAP_FILE ${CHIP_ROOT}/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.zap |
| 495 | GEN_DIR ${CHIP_ROOT}/zzz_generated/ota-requestor-app/zap-generated |
| 496 | ) |
| 497 | target_include_directories(${APP_TARGET} PRIVATE |
| 498 | ${GEN_DIR}/ota-requestor-app |
| 499 | ) |
| 500 | target_sources(${APP_TARGET} PRIVATE |
| 501 | ${GEN_DIR}//ota-requestor-app/zap-generated/callback-stub.cpp |
| 502 | ${GEN_DIR}/ota-requestor-app/zap-generated/IMClusterCommandHandler.cpp |
| 503 | ) |
| 504 | endif() |
| 505 | |
| 506 | list(APPEND CHIP_DEFINES |
Artur Tynecki | 42a7b0a | 2022-01-26 05:46:24 +0100 | [diff] [blame] | 507 | CHIP_OTA_REQUESTOR=1 |
| 508 | ) |
| 509 | endif(CONFIG_CHIP_OTA_REQUESTOR) |
| 510 | |
| 511 | if(BOOT_ENABLED) |
| 512 | add_subdirectory(${MCUBOOT_PATH}/boot/bootutil/ ${CMAKE_BINARY_DIR}/mbed_mcu_boot_util_build) |
| 513 | add_subdirectory(${MCUBOOT_PATH}/boot/mbed/ ${CMAKE_BINARY_DIR}/mbed_mcu_boot_build) |
| 514 | |
| 515 | target_include_directories(${APP_TARGET} PRIVATE |
| 516 | ${MCUBOOT_PATH}/boot/mbed/include |
| 517 | ) |
| 518 | |
| 519 | target_sources(${APP_TARGET} PRIVATE |
| 520 | ${CHIP_ROOT}/examples/platform/mbed/bootloader/default_bd.cpp |
| 521 | ) |
| 522 | |
| 523 | target_include_directories(bootutil PUBLIC |
| 524 | ${CHIP_ROOT}/config/mbed/mbedtls |
| 525 | ) |
| 526 | |
| 527 | target_link_libraries(${APP_TARGET} mbed-mcuboot bootutil) |
| 528 | |
| 529 | file(READ ${APP_PATH}/mbed_app.json mbedAppJson) |
| 530 | string(JSON PRIMARY_SLOT_ADDRESS GET "${mbedAppJson}" target_overrides ${MBED_TARGET} mcuboot.primary-slot-address) |
| 531 | string(JSON HEADER_SIZE GET "${mbedAppJson}" target_overrides ${MBED_TARGET} mcuboot.header-size) |
| 532 | string(JSON SLOT_SIZE GET "${mbedAppJson}" target_overrides ${MBED_TARGET} mcuboot.slot-size) |
| 533 | math(EXPR APP_START "${PRIMARY_SLOT_ADDRESS} + ${HEADER_SIZE}" OUTPUT_FORMAT HEXADECIMAL) |
| 534 | math(EXPR APP_SIZE "${SLOT_SIZE} - 2 * ${HEADER_SIZE}" OUTPUT_FORMAT HEXADECIMAL) |
| 535 | target_compile_definitions(mbed-core |
| 536 | INTERFACE |
| 537 | "-DMBED_APP_START=${APP_START}" |
| 538 | "-DMBED_APP_SIZE=${APP_SIZE}" |
| 539 | ) |
| 540 | |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 541 | list(APPEND CHIP_DEFINES |
Artur Tynecki | 42a7b0a | 2022-01-26 05:46:24 +0100 | [diff] [blame] | 542 | BOOT_ENABLED=1 |
| 543 | ) |
| 544 | endif() |
| 545 | |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 546 | |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 547 | target_include_directories(${APP_TARGET} PRIVATE |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 548 | ${CHIP_INCLUDES} |
| 549 | ) |
| 550 | |
| 551 | target_compile_definitions(${APP_TARGET} PRIVATE |
Artur Tynecki | fbf8bab | 2022-02-16 06:36:17 +0100 | [diff] [blame] | 552 | ${CHIP_DEFINES} |
Artur Tynecki | 582d97a | 2021-10-27 20:38:24 +0200 | [diff] [blame] | 553 | ) |