blob: 337020b56c3d62c8dd358be018f326f555936960 [file] [log] [blame]
Vincent Coubardcc135602021-06-29 16:58:47 +01001#
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
27include(ExternalProject)
28include(mbed-util.cmake)
29
30# ==============================================================================
31# Declare configuration variables and define constants
32# ==============================================================================
33# C/C++ compiler flags passed to CHIP build system
34list(APPEND CHIP_CFLAGS)
35
36# C compiler flags passed to CHIP build system
37list(APPEND CHIP_CFLAGS_C)
38
39# C++ compiler flags passed to CHIP build system
40list(APPEND CHIP_CFLAGS_CC)
41
42# CHIP libraries that the application should be linked with
43list(APPEND CHIP_LIBRARIES)
44
45# GN meta-build system arguments in the form of 'key1 = value1\nkey2 = value2...' string
46string(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 Tyneckifbf8bab2022-02-16 06:36:17 +010050set(CHIP_CFLAG_EXCLUDES
Vincent Coubardcc135602021-06-29 16:58:47 +010051 "-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 Tyneckic9e35ba2021-10-22 18:23:19 +020066macro(chip_gn_arg_import FILE)
67 string(APPEND CHIP_GN_ARGS "import(\"${FILE}\")\n")
68endmacro()
69
Vincent Coubardcc135602021-06-29 16:58:47 +010070macro(chip_gn_arg_string ARG STRING)
71 string(APPEND CHIP_GN_ARGS "${ARG} = \"${STRING}\"\n")
72endmacro()
73
74macro(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()
80endmacro()
81
82macro(chip_gn_arg_flags ARG CFLAGS)
83 list(SORT CFLAGS)
84 string(APPEND CHIP_GN_ARGS "${ARG} = [${CFLAGS}]\n")
85endmacro()
86
87macro(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")
96endmacro()
97
98macro(mbed_interface_library_named name)
99 add_library(${name} INTERFACE)
100endmacro()
101
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200102# Select gnu++<YY> standard based on project configuration
103macro(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()
113endmacro()
114
Vincent Coubardcc135602021-06-29 16:58:47 +0100115# ==============================================================================
116# Prepare CHIP configuration based on the project configuration
117# ==============================================================================
118# Read configuration file and parse it content to create cmake variable
119file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/config ConfigContents)
120foreach(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}")
129endforeach()
130
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200131if (CONFIG_CHIP_PW_RPC)
132 set(CONFIG_STD_CPP17 y)
133endif()
134
Vincent Coubardcc135602021-06-29 16:58:47 +0100135if (NOT CHIP_ROOT)
136 get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../.. REALPATH)
137endif()
138
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200139set(GN_ROOT_TARGET ${CHIP_ROOT}/config/mbed/chip-gn)
140
Vincent Coubardcc135602021-06-29 16:58:47 +0100141# Prepare compiler flags
142
143mbed_get_target_common_compile_flags(CHIP_CFLAGS mbed-core)
144mbed_get_lang_compile_flags(CHIP_CFLAGS_C mbed-core C)
145list(APPEND CHIP_CFLAGS_C ${CMAKE_C_FLAGS_INIT})
146mbed_get_lang_compile_flags(CHIP_CFLAGS_CC mbed-core CXX)
147list(APPEND CHIP_CFLAGS_CC ${CMAKE_CXX_FLAGS_INIT})
148
Artur Tynecki35fb13e2021-10-12 18:23:45 +0200149mbed_get_target_common_compile_flags(CHIP_MBEDCMSISCM_CFLAGS mbed-cmsis-cortex-m)
150list(APPEND CHIP_CFLAGS ${CHIP_MBEDCMSISCM_CFLAGS})
151if(MBED_TARGET STREQUAL "CY8CPROTO_062_4343W")
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100152 mbed_get_target_common_compile_flags(CHIP_MBEDCMSISCY8_CFLAGS mbed-cy8cproto-062-4343w)
Artur Tynecki35fb13e2021-10-12 18:23:45 +0200153 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})
160endif()
161
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100162# Add support for Mbed Posix Socket
Vincent Coubardcc135602021-06-29 16:58:47 +0100163mbed_get_target_common_compile_flags(CHIP_MBEDPOSIXSOCKET_CFLAGS mbed-os-posix-socket)
164list(APPEND CHIP_CFLAGS ${CHIP_MBEDPOSIXSOCKET_CFLAGS})
165
166# Add support for Mbed BLE
167mbed_get_target_common_compile_flags(CHIP_MBEDBLE_CFLAGS mbed-ble)
168list(APPEND CHIP_CFLAGS ${CHIP_MBEDBLE_CFLAGS})
169
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100170# Add support for Mbed event
Vincent Coubardcc135602021-06-29 16:58:47 +0100171mbed_get_target_common_compile_flags(CHIP_MBEDEVENTS_CFLAGS mbed-events)
172list(APPEND CHIP_CFLAGS ${CHIP_MBEDEVENTS_CFLAGS})
173
174# Add support for Mbed rtos
175mbed_get_target_common_compile_flags(CHIP_MBEDRTOS_CFLAGS mbed-rtos)
176list(APPEND CHIP_CFLAGS ${CHIP_MBEDRTOS_CFLAGS})
177
178# Add support for Mbed storage
179mbed_get_target_common_compile_flags(CHIP_MBEDSTORAGE_CFLAGS mbed-storage-kv-global-api)
180list(APPEND CHIP_CFLAGS ${CHIP_MBEDSTORAGE_CFLAGS})
181
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100182# Add support for Mbed Socket
Vincent Coubardcc135602021-06-29 16:58:47 +0100183mbed_get_target_common_compile_flags(CHIP_MBEDNETSOCKET_CFLAGS mbed-netsocket)
184list(APPEND CHIP_CFLAGS ${CHIP_MBEDNETSOCKET_CFLAGS})
185
186if (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})
189endif()
190
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200191mbed_get_gnu_cpp_standard(CHIP_CFLAGS_CC)
192
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100193list(APPEND CHIP_CFLAGS
Vincent Coubardcc135602021-06-29 16:58:47 +0100194 \"-D__LINUX_ERRNO_EXTENSIONS__=1\"
195)
196
Andrei Litvinadc7a842022-03-12 16:21:12 -0500197list(APPEND CHIP_CFLAGS
198 \"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>\"
199)
200
ATmobicaf0ae9d82021-09-02 05:47:22 +0200201if (CONFIG_MBED_BSD_SOCKET_TRACE)
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100202 list(APPEND CHIP_CFLAGS
ATmobicaf0ae9d82021-09-02 05:47:22 +0200203 \"-DMBED_BSD_SOCKET_TRACE=1\"
204 )
205endif()
206
Vincent Coubardcc135602021-06-29 16:58:47 +0100207# CFLAGS are put in random order, sort them before converting them to a string
208list(SORT CHIP_CFLAGS)
209list(SORT CHIP_CFLAGS_C)
210list(SORT CHIP_CFLAGS_CC)
211
212set(SEPARATOR ",")
213convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS CHIP_CFLAGS ${SEPARATOR})
214set(SEPARATOR " ")
215convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_C CHIP_CFLAGS_C ${SEPARATOR})
216convert_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
220if (NOT CHIP_LIBRARIES)
221 set(CHIP_LIBRARIES -lCHIP)
222endif()
223
224if (CONFIG_CHIP_LIB_SHELL)
225 list(APPEND CHIP_LIBRARIES -lCHIPShell)
226endif()
227
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200228if (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 Tynecki582d97a2021-10-27 20:38:24 +0200232 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 Tyneckic9e35ba2021-10-22 18:23:19 +0200238 endif()
239endif(CONFIG_CHIP_PW_RPC)
240
Vincent Coubardcc135602021-06-29 16:58:47 +0100241# Set up CHIP project configuration file
242
243set(CHIP_DEFAULT_CONFIG_FILE "<${CHIP_ROOT}/config/mbed/CHIPProjectConfig.h>")
244set(CHIP_PROJECT_CONFIG ${CHIP_DEFAULT_CONFIG_FILE})
245
246if (CONFIG_CHIP_PROJECT_CONFIG)
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100247 get_filename_component(CHIP_PROJECT_CONFIG
Vincent Coubardcc135602021-06-29 16:58:47 +0100248 ${CONFIG_CHIP_PROJECT_CONFIG}
249 REALPATH
250 BASE_DIR ${CMAKE_SOURCE_DIR}
251 )
252 set(CHIP_PROJECT_CONFIG "<${CHIP_PROJECT_CONFIG}>")
253endif()
254
255if (${CMAKE_BUILD_TYPE} STREQUAL "debug")
256 set(CONFIG_DEBUG "y")
257endif()
258
259# ==============================================================================
260# Generate configuration for CHIP GN build system
261# ==============================================================================
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200262if (CONFIG_CHIP_PW_RPC)
263 chip_gn_arg_import("${GN_ROOT_TARGET}/lib/pw_rpc/pw_rpc.gni")
264endif()
Vincent Coubardcc135602021-06-29 16:58:47 +0100265
266chip_gn_arg_flags("target_cflags" ${CHIP_CFLAGS})
267chip_gn_arg_lang_flags("target_cflags_c" ${CHIP_CFLAGS_C})
268chip_gn_arg_lang_flags("target_cflags_cc" ${CHIP_CFLAGS_CC})
269chip_gn_arg_string("mbed_ar" ${CMAKE_AR})
270chip_gn_arg_string("mbed_cc" ${CMAKE_C_COMPILER})
271chip_gn_arg_string("mbed_cxx" ${CMAKE_CXX_COMPILER})
272chip_gn_arg_string("chip_project_config_include" "${CHIP_PROJECT_CONFIG}")
273chip_gn_arg_bool ("is_debug" CONFIG_DEBUG)
274chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS)
Vincent Coubardd48d7542021-10-06 22:35:20 +0100275chip_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TESTS)
Vincent Coubardcc135602021-06-29 16:58:47 +0100276chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL)
277chip_gn_arg_bool ("chip_with_platform_mbedtls" CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS)
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200278chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC)
Artur Tyneckib4921fc2022-02-21 17:44:34 +0100279chip_gn_arg_bool ("chip_enable_data_model" CONFIG_CHIP_DATA_MODEL)
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200280if (CONFIG_CHIP_PW_RPC)
281 chip_gn_arg_bool ("chip_build_pw_rpc_echo_proto" CONFIG_CHIP_PW_RPC_ECHO_PROTO)
Artur Tynecki582d97a2021-10-27 20:38:24 +0200282 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 Tyneckic9e35ba2021-10-22 18:23:19 +0200285endif(CONFIG_CHIP_PW_RPC)
Artur Tynecki42a7b0a2022-01-26 05:46:24 +0100286if (CONFIG_CHIP_OTA_REQUESTOR)
287 chip_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR)
288endif(CONFIG_CHIP_OTA_REQUESTOR)
289
Vincent Coubardcc135602021-06-29 16:58:47 +0100290
291file(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# ==============================================================================
296ExternalProject_Add(
297 chip-gn
298 PREFIX ${CMAKE_CURRENT_BINARY_DIR}
299 SOURCE_DIR ${CHIP_ROOT}
300 BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200301 CONFIGURE_COMMAND gn --root=${GN_ROOT_TARGET} gen --export-compile-commands --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR}
Vincent Coubardcc135602021-06-29 16:58:47 +0100302 BUILD_COMMAND ninja
303 INSTALL_COMMAND ""
304 BUILD_BYPRODUCTS ${CHIP_LIBRARIES}
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100305 CONFIGURE_ALWAYS TRUE
Vincent Coubardcc135602021-06-29 16:58:47 +0100306 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# ==============================================================================
314mbed_interface_library_named(chip)
315target_compile_definitions(chip INTERFACE CHIP_HAVE_CONFIG_H)
316target_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)
323target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib)
324target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)
325add_dependencies(chip chip-gn)
326
327# ==============================================================================
328# Define mbed target configuration according to CHIP component usage
329# ==============================================================================
330# CHIP includes path
331list(APPEND CHIP_INCLUDES)
332
333# CHIP defines
334list(APPEND CHIP_DEFINES)
335
Artur Tynecki42a7b0a2022-01-26 05:46:24 +0100336# Target specific configuration
337if("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)
340endif()
341
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100342list(APPEND CHIP_INCLUDES
Vincent Coubardcc135602021-06-29 16:58:47 +0100343 ${CHIP_ROOT}/config/mbed/mbedtls
Vincent Coubardcc135602021-06-29 16:58:47 +0100344)
345
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100346list(APPEND CHIP_DEFINES
Vincent Coubardcc135602021-06-29 16:58:47 +0100347 __LINUX_ERRNO_EXTENSIONS__=1
348)
349
Andrei Litvinadc7a842022-03-12 16:21:12 -0500350list(APPEND CHIP_DEFINES
351 CHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>
352)
353
ATmobicaf0ae9d82021-09-02 05:47:22 +0200354if (CONFIG_MBED_BSD_SOCKET_TRACE)
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100355 list(APPEND CHIP_DEFINES
ATmobicaf0ae9d82021-09-02 05:47:22 +0200356 MBED_BSD_SOCKET_TRACE=1
357 )
358endif()
359
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200360if (CONFIG_CHIP_PW_RPC)
361 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17" PARENT_SCOPE)
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100362 list(APPEND CHIP_DEFINES
Artur Tynecki582d97a2021-10-27 20:38:24 +0200363 CHIP_PW_RPC=1
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200364 )
365endif()
366
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200367if (CONFIG_CHIP_PW_RPC)
368
369set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
370
371target_sources(${APP_TARGET} PRIVATE
372 ${CHIP_ROOT}/examples/common/pigweed/RpcService.cpp
373 ${CHIP_ROOT}/examples/common/pigweed/mbed/PigweedLoggerMutex.cpp
Artur Tynecki582d97a2021-10-27 20:38:24 +0200374 ${CHIP_ROOT}/examples/common/pigweed/mbed/Rpc.cpp
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200375 ${MBED_COMMON}/util/PigweedLogger.cpp
376)
377
rgolivereb3ac832022-05-31 16:02:41 -0400378list(APPEND CHIP_DEFINES
379 PW_RPC_USE_GLOBAL_MUTEX=0
380)
381
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200382target_include_directories(${APP_TARGET} PRIVATE
383 ${PIGWEED_ROOT}/pw_sys_io/public
384 ${PIGWEED_ROOT}/pw_assert/public
rgoliverea177792022-03-04 08:30:03 -0500385 ${PIGWEED_ROOT}/pw_assert/assert_lite_public_overrides
rgoliverdcec35a2022-06-15 10:50:26 -0400386 ${PIGWEED_ROOT}/pw_assert_log/assert_backend_public_overrides
387 ${PIGWEED_ROOT}/pw_assert_log/check_backend_public_overrides
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200388 ${PIGWEED_ROOT}/pw_assert_log/public
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200389 ${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
rgoliver53a5d1e2021-12-01 12:59:29 -0500398 ${PIGWEED_ROOT}/pw_sync/public
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200399 ${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 Tynecki582d97a2021-10-27 20:38:24 +0200416 ${CHIP_ROOT}/examples/common/pigweed
417 ${CHIP_ROOT}/examples/common/pigweed/mbed
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200418 ${MBED_COMMON}/pw_sys_io/public
Artur Tynecki582d97a2021-10-27 20:38:24 +0200419
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 Tyneckic9e35ba2021-10-22 18:23:19 +0200422)
423
424if (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 Tynecki582d97a2021-10-27 20:38:24 +0200428 )
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100429 list(APPEND CHIP_DEFINES
Artur Tynecki582d97a2021-10-27 20:38:24 +0200430 CHIP_PW_RPC_ECHO_PROTO=1
Artur Tyneckic9e35ba2021-10-22 18:23:19 +0200431 )
432endif(CONFIG_CHIP_PW_RPC_ECHO_PROTO)
433
Artur Tynecki582d97a2021-10-27 20:38:24 +0200434if (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 Tyneckifbf8bab2022-02-16 06:36:17 +0100442 list(APPEND CHIP_DEFINES
Artur Tynecki582d97a2021-10-27 20:38:24 +0200443 CHIP_PW_RPC_COMMON_PROTO=1
444 )
445endif(CONFIG_CHIP_PW_RPC_COMMON_PROTO)
446
447if (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 Tyneckifbf8bab2022-02-16 06:36:17 +0100452 list(APPEND CHIP_DEFINES
Artur Tynecki582d97a2021-10-27 20:38:24 +0200453 CHIP_PW_RPC_LIGHTING_PROTO=1
454 )
455endif(CONFIG_CHIP_PW_RPC_LIGHTING_PROTO)
456
457if (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 Tyneckifbf8bab2022-02-16 06:36:17 +0100462 list(APPEND CHIP_DEFINES
Artur Tynecki582d97a2021-10-27 20:38:24 +0200463 CHIP_PW_RPC_LOCKING_PROTO=1
464 )
465endif(CONFIG_CHIP_PW_RPC_LOCKING_PROTO)
466
467endif(CONFIG_CHIP_PW_RPC)
468
Artur Tynecki42a7b0a2022-01-26 05:46:24 +0100469if (CONFIG_CHIP_OTA_REQUESTOR)
470 target_include_directories(${APP_TARGET} PRIVATE
Carol Yang31cf5722022-03-08 21:55:42 -0800471 ${CHIP_ROOT}/examples/platform/mbed/ota/
Artur Tynecki42a7b0a2022-01-26 05:46:24 +0100472 ${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 Yang535c6c82022-03-08 09:44:03 -0800479 ${CHIP_ROOT}/examples/platform/mbed/ota/OTARequestorDriverImpl.cpp
Carol Yang5b62cea2022-04-04 17:48:08 -0700480 ${CHIP_ROOT}/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
Carol Yang04f1acd2022-04-05 01:44:44 -0700481 ${CHIP_ROOT}/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp
Damian Królikaa17b2f2022-03-09 14:13:29 +0100482 ${CHIP_ROOT}/src/app/clusters/ota-requestor/DefaultOTARequestorStorage.cpp
Artur Tynecki42a7b0a2022-01-26 05:46:24 +0100483 ${CHIP_ROOT}/src/app/clusters/ota-requestor/BDXDownloader.cpp
Artur Tynecki42a7b0a2022-01-26 05:46:24 +0100484 ${CHIP_ROOT}/src/platform/mbed/OTAImageProcessorImpl.cpp
485 )
486
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100487if (NOT ${APP_TARGET} MATCHES "shell")
488 target_sources(${APP_TARGET} PRIVATE
489 ${CHIP_ROOT}/src/app/clusters/ota-requestor/ota-requestor-server.cpp
490 )
491else()
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 )
504endif()
505
506 list(APPEND CHIP_DEFINES
Artur Tynecki42a7b0a2022-01-26 05:46:24 +0100507 CHIP_OTA_REQUESTOR=1
508 )
509endif(CONFIG_CHIP_OTA_REQUESTOR)
510
511if(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 Tyneckifbf8bab2022-02-16 06:36:17 +0100541 list(APPEND CHIP_DEFINES
Artur Tynecki42a7b0a2022-01-26 05:46:24 +0100542 BOOT_ENABLED=1
543 )
544endif()
545
Artur Tynecki582d97a2021-10-27 20:38:24 +0200546
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100547target_include_directories(${APP_TARGET} PRIVATE
Artur Tynecki582d97a2021-10-27 20:38:24 +0200548 ${CHIP_INCLUDES}
549)
550
551target_compile_definitions(${APP_TARGET} PRIVATE
Artur Tyneckifbf8bab2022-02-16 06:36:17 +0100552 ${CHIP_DEFINES}
Artur Tynecki582d97a2021-10-27 20:38:24 +0200553)