forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
477 lines (399 loc) · 17.7 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# The compile flags written args.gn come from chip.c and chip.cpp.
# Any build specifications (include dirs, compile flags, definitions, etc)
# that is set in the component will be reflected in
# the output args.gn. By default, all components inherit build-level
# specifications stored as idf-build-properties as done in
# tools/cmake/build.cmake.
#
# Adding REQUIRES/PRIV_REQUIRES will also propagate the
# appropriate build specifications from the required component.
idf_build_get_property(idf_path IDF_PATH)
if(NOT CHIP_ROOT)
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../.. REALPATH)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/ota-image.cmake)
set(CHIP_REQUIRE_COMPONENTS esp_eth freertos lwip bt mbedtls fatfs app_update console openthread nvs_flash spi_flash mdns)
if (NOT CMAKE_BUILD_EARLY_EXPANSION)
if (CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE)
set(is_debug TRUE)
else()
set(is_debug FALSE)
endif()
endif()
idf_component_register(SRCS chip.c chip.cpp
PRIV_REQUIRES ${CHIP_REQUIRE_COMPONENTS})
# Prepare initial args file (lacking compile flags)
# This will be saved as args.gn.in
set(chip_gn_args "import(\"//args.gni\")\n")
macro(chip_gn_arg_append arg val)
string(APPEND chip_gn_args "${arg} = ${val}\n")
endmacro()
macro(chip_gn_arg_bool arg boolean)
if (${boolean})
string(APPEND chip_gn_args "${arg} = true\n")
else()
string(APPEND chip_gn_args "${arg} = false\n")
endif()
endmacro()
# ESP-IDF lets user set software version string by two ways:
# 1. Project's CMakeLists.txt file and 2. Config option
# It depends on CONFIG_APP_PROJECT_VER_FROM_CONFIG option
# So, below makes the same provision for software version number
if (CONFIG_APP_PROJECT_VER_FROM_CONFIG)
chip_gn_arg_append("chip_config_software_version_number" ${CONFIG_DEVICE_SOFTWARE_VERSION_NUMBER})
elseif (DEFINED PROJECT_VER_NUMBER)
chip_gn_arg_append("chip_config_software_version_number" ${PROJECT_VER_NUMBER})
else()
chip_gn_arg_append("chip_config_software_version_number" 0)
endif()
chip_gn_arg_append("esp32_ar" "\"${CMAKE_AR}\"")
chip_gn_arg_append("esp32_cc" "\"${CMAKE_C_COMPILER}\"")
chip_gn_arg_append("esp32_cxx" "\"${CMAKE_CXX_COMPILER}\"")
chip_gn_arg_append("esp32_cpu" "\"esp32\"")
chip_gn_arg_bool("is_debug" ${is_debug})
if (CONFIG_CHIP_CONFIG_IM_PRETTY_PRINT)
chip_gn_arg_bool("enable_im_pretty_print" "true")
endif()
# Config the chip log level by IDF menuconfig
if (CONFIG_CHIP_LOG_DEFAULT_LEVEL GREATER_EQUAL 1)
chip_gn_arg_bool ("chip_error_logging" "true")
else()
chip_gn_arg_bool ("chip_error_logging" "false")
endif()
if (CONFIG_CHIP_LOG_DEFAULT_LEVEL GREATER_EQUAL 3)
chip_gn_arg_bool ("chip_progress_logging" "true")
else()
chip_gn_arg_bool ("chip_progress_logging" "false")
endif()
if (CONFIG_CHIP_LOG_DEFAULT_LEVEL GREATER_EQUAL 4)
chip_gn_arg_bool ("chip_detail_logging" "true")
else()
chip_gn_arg_bool ("chip_detail_logging" "false")
endif()
if (CONFIG_CHIP_LOG_DEFAULT_LEVEL GREATER_EQUAL 5)
chip_gn_arg_bool ("chip_automation_logging" "true")
else()
chip_gn_arg_bool ("chip_automation_logging" "false")
endif()
if(CONFIG_ENABLE_CHIPOBLE)
chip_gn_arg_append("chip_config_network_layer_ble" "true")
else()
chip_gn_arg_append("chip_config_network_layer_ble" "false")
endif()
if(CONFIG_DISABLE_IPV4)
if(NOT CONFIG_LWIP_IPV4)
chip_gn_arg_append("chip_inet_config_enable_ipv4" "false")
else()
message(FATAL_ERROR "Please also disable config option CONFIG_LWIP_IPV4")
endif()
endif()
if(CONFIG_DISABLE_READ_CLIENT)
chip_gn_arg_append("chip_enable_read_client" "false")
endif()
if(CHIP_CODEGEN_PREGEN_DIR)
chip_gn_arg_append("chip_code_pre_generated_directory" "\"${CHIP_CODEGEN_PREGEN_DIR}\"")
endif()
if(CONFIG_ENABLE_ICD_SERVER)
chip_gn_arg_append("chip_enable_icd_server" "true")
if(CONFIG_ICD_REPORT_ON_ACTIVE_MODE)
chip_gn_arg_append("chip_icd_report_on_active_mode" "true")
endif()
if(CONFIG_ENABLE_ICD_LIT)
chip_gn_arg_append("chip_enable_icd_lit" "true")
if(CONFIG_ENABLE_ICD_CIP)
chip_gn_arg_append("chip_enable_icd_checkin" "true")
else()
chip_gn_arg_append("chip_enable_icd_checkin" "false")
endif()
if(CONFIG_ENABLE_ICD_USER_ACTIVE_MODE_TRIGGER)
chip_gn_arg_append("chip_enable_icd_user_active_mode_trigger" "true")
else()
chip_gn_arg_append("chip_enable_icd_user_active_mode_trigger" "false")
endif()
endif()
endif()
if(CONFIG_CHIP_MEM_ALLOC_MODE_INTERNAL)
chip_gn_arg_append("chip_memory_alloc_mode" "\"internal\"")
elseif(CONFIG_CHIP_MEM_ALLOC_MODE_EXTERNAL)
chip_gn_arg_append("chip_memory_alloc_mode" "\"external\"")
elseif(CONFIG_CHIP_MEM_ALLOC_MODE_DEFAULT)
chip_gn_arg_append("chip_memory_alloc_mode" "\"default\"")
endif()
if(CONFIG_ENABLE_PW_RPC)
string(APPEND chip_gn_args "import(\"//build_overrides/pigweed.gni\")\n")
chip_gn_arg_append("remove_default_configs" "[\"//third_party/connectedhomeip/third_party/pigweed/repo/pw_build:toolchain_cpp_standard\"]")
chip_gn_arg_append("chip_build_pw_rpc_lib" "true")
chip_gn_arg_append("pw_log_BACKEND" "\"//third_party/connectedhomeip/third_party/pigweed/repo/pw_log_basic\"")
chip_gn_arg_append("pw_assert_BACKEND" "\"//third_party/connectedhomeip/third_party/pigweed/repo/pw_assert_log:check_backend\"")
chip_gn_arg_append("pw_sys_io_BACKEND" "\"//third_party/connectedhomeip/examples/platform/esp32/pw_sys_io:pw_sys_io_esp32\"")
chip_gn_arg_append("dir_pw_third_party_nanopb" "\"//third_party/connectedhomeip/third_party/nanopb/repo\"")
chip_gn_arg_append("pw_build_LINK_DEPS" "[\"\$dir_pw_assert:impl\", \"\$dir_pw_log:impl\"]")
chip_gn_arg_append("pw_rpc_CONFIG" "\"//third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc:disable_global_mutex\"")
endif()
if (CONFIG_BUILD_CHIP_TESTS)
chip_gn_arg_bool("chip_build_tests" "true")
endif()
if (CONFIG_IM_PRETTY_PRINT)
chip_gn_arg_bool("enable_im_pretty_print" "true")
endif()
if (NOT CONFIG_USE_MINIMAL_MDNS)
chip_gn_arg_append("chip_mdns" "\"platform\"")
else()
chip_gn_arg_append("chip_mdns" "\"minimal\"")
endif()
if (CONFIG_ENABLE_CHIP_SHELL)
chip_gn_arg_append("chip_build_libshell" "true")
endif()
if (CONFIG_ENABLE_CHIP_CONTROLLER_BUILD)
chip_gn_arg_append("chip_build_controller" "true")
endif()
if (CONFIG_ENABLE_WIFI_STATION OR CONFIG_ENABLE_WIFI_AP)
chip_gn_arg_append("chip_enable_wifi" "true")
else()
chip_gn_arg_append("chip_enable_wifi" "false")
endif()
if (CONFIG_ENABLE_CHIPOBLE)
chip_gn_arg_append("chip_enable_chipoble" "true")
endif()
if ((CONFIG_BT_ENABLED) AND (CONFIG_ENABLE_CHIPOBLE))
if (CONFIG_BT_NIMBLE_ENABLED)
chip_gn_arg_append("chip_bt_nimble_enabled" "true")
else()
chip_gn_arg_append("chip_bt_bluedroid_enabled" "true")
endif()
endif()
if (CONFIG_ENABLE_PERSIST_SUBSCRIPTIONS)
chip_gn_arg_append("chip_persist_subscriptions" "true")
else()
chip_gn_arg_append("chip_persist_subscriptions" "false")
endif()
if (CONFIG_ENABLE_ESP32_BLE_CONTROLLER)
chip_gn_arg_append("chip_enable_ble_controller" "true")
endif()
if (CONFIG_ENABLE_ETHERNET_TELEMETRY)
chip_gn_arg_append("chip_enable_ethernet" "true")
endif()
if (CONFIG_ENABLE_MATTER_OVER_THREAD)
chip_gn_arg_append("chip_enable_openthread" "true")
if (CONFIG_THREAD_NETWORK_COMMISSIONING_DRIVER)
chip_gn_arg_append("chip_device_config_thread_network_endpoint_id" ${CONFIG_THREAD_NETWORK_ENDPOINT_ID})
endif()
else()
chip_gn_arg_append("chip_enable_openthread" "false")
endif()
if (CONFIG_OPENTHREAD_FTD)
chip_gn_arg_append("chip_openthread_ftd" "true")
else()
chip_gn_arg_append("chip_openthread_ftd" "false")
endif()
if (CONFIG_OPENTHREAD_BORDER_ROUTER)
chip_gn_arg_append("chip_openthread_border_router" "true")
else()
chip_gn_arg_append("chip_openthread_border_router" "false")
endif()
if (CONFIG_ENABLE_OTA_REQUESTOR)
chip_gn_arg_append("chip_enable_ota_requestor" "true")
endif()
if (CONFIG_ENABLE_ROTATING_DEVICE_ID)
chip_gn_arg_append("chip_enable_additional_data_advertising" "true")
chip_gn_arg_append("chip_enable_rotating_device_id" "true")
endif()
if (CONFIG_ENABLE_ROUTE_HOOK)
chip_gn_arg_append("chip_enable_route_hook" "true")
endif()
if (CONFIG_CHIP_ENABLE_EXTERNAL_PLATFORM)
chip_gn_arg_append("chip_device_platform" "\"external\"")
if (CONFIG_ENABLE_CHIP_SHELL)
chip_gn_arg_append("chip_shell_platform" "\"esp32\"")
endif()
chip_gn_arg_append("chip_platform_target" "\"//${CONFIG_CHIP_EXTERNAL_PLATFORM_DIR}\"")
chip_gn_arg_append("chip_external_platform_include_dir" "\"//${CONFIG_CHIP_EXTERNAL_PLATFORM_INCLUDE_DIR}\"")
endif()
# Set up CHIP project configuration file
if (CONFIG_CHIP_PROJECT_CONFIG)
get_filename_component(CHIP_PROJECT_CONFIG
${CONFIG_CHIP_PROJECT_CONFIG}
REALPATH
BASE_DIR ${CMAKE_SOURCE_DIR}
)
set(CHIP_PROJECT_CONFIG "<${CHIP_PROJECT_CONFIG}>")
else()
set(CHIP_PROJECT_CONFIG "")
endif()
if (CHIP_PROJECT_CONFIG)
chip_gn_arg_append("chip_project_config_include" "\"${CHIP_PROJECT_CONFIG}\"")
chip_gn_arg_append("chip_system_project_config_include" "\"${CHIP_PROJECT_CONFIG}\"")
endif()
if (CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER)
chip_gn_arg_append("chip_use_transitional_commissionable_data_provider" "false")
chip_gn_arg_append("chip_use_factory_data_provider" "true")
endif()
if (CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER)
chip_gn_arg_append("chip_use_device_info_provider" "true")
endif()
if (CONFIG_SEC_CERT_DAC_PROVIDER)
chip_gn_arg_append("chip_use_secure_cert_dac_provider" "true")
endif()
if (CONFIG_ENABLE_ESP_INSIGHTS_TRACE)
chip_gn_arg_bool("matter_enable_tracing_support" "true")
chip_gn_arg_append("matter_trace_config" "\"${CHIP_ROOT}/src/tracing/esp32_trace:esp32_trace_tracing\"")
endif()
if (CONFIG_ENABLE_ESP_INSIGHTS_SYSTEM_STATS)
chip_gn_arg_append("matter_enable_esp_insights_system_stats" "true")
endif()
if (CONFIG_USE_ESP32_ECDSA_PERIPHERAL)
chip_gn_arg_append("chip_use_esp32_ecdsa_peripheral" "true")
endif()
if (CONFIG_ENABLE_ESP_INSIGHTS_TRACE)
target_include_directories(${COMPONENT_LIB} INTERFACE "${CHIP_ROOT}/src/tracing/esp32_trace/include")
endif()
if (CONFIG_CHIP_DEVICE_ENABLE_DYNAMIC_SERVER)
chip_gn_arg_append("chip_build_controller_dynamic_server" "true")
endif()
if (CONFIG_ICD_MAX_NOTIFICATION_SUBSCRIBERS)
chip_gn_arg_append("icd_max_notification_subscribers" ${CONFIG_ICD_MAX_NOTIFICATION_SUBSCRIBERS})
endif()
set(args_gn_input "${CMAKE_CURRENT_BINARY_DIR}/args.gn.in")
file(GENERATE OUTPUT "${args_gn_input}" CONTENT "${chip_gn_args}")
# This generates the final args.in file to be fed to
# CHIP build using GN build system. The necessary compile_commands.json
# and args.gn.in input file should exist by the time this is invoked,
# since these requirements ar generated at the parent project's
# GENERATE phase.
idf_build_get_property(idf_ver IDF_VER)
set(filter_out "-DHAVE_CONFIG_H" "-DIDF_VER=\\\"${idf_ver}\\\"" )
# CMake adds config include dir relative to build directory.
# Make sure full path is given to CHIP build.
list(APPEND filter_out "-Iconfig")
idf_build_get_property(config_dir CONFIG_DIR)
target_compile_options(${COMPONENT_LIB} PRIVATE "-I${config_dir}")
if(filter_out)
set(filter_arg "--filter-out=${filter_out}")
endif()
set(args_gn "${CMAKE_CURRENT_BINARY_DIR}/args.gn")
add_custom_command(OUTPUT "${args_gn}"
COMMAND ${python}
${CMAKE_CURRENT_LIST_DIR}/create_args_gn.py
"${CMAKE_BINARY_DIR}"
"${idf_path}"
"${CMAKE_CURRENT_LIST_DIR}/chip.c"
"${CMAKE_CURRENT_LIST_DIR}/chip.cpp"
"${args_gn_input}"
"${args_gn}"
"${filter_arg}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS "${CMAKE_BINARY_DIR}/compile_commands.json"
VERBATIM)
add_custom_target(args_gn DEPENDS "${args_gn}")
# CHIP build as an external project.
find_program(GN_EXECUTABLE gn)
if (${GN_EXECUTABLE} STREQUAL GN_EXECUTABLE-NOTFOUND)
message(FATAL_ERROR "The 'gn' command was not found. Make sure you have GN installed."
"Or have followed necessary build preparations stated in BUILDING.md.")
endif()
set(GN_ROOT_TARGET ${CHIP_ROOT}/config/esp32)
set(chip_libraries "${CMAKE_CURRENT_BINARY_DIR}/lib/libCHIP.a")
if(CONFIG_ENABLE_PW_RPC)
list(APPEND chip_libraries "${CMAKE_CURRENT_BINARY_DIR}/lib/libPwRpc.a")
endif()
if (CONFIG_ENABLE_ESP_INSIGHTS_TRACE)
list(APPEND chip_libraries "${CMAKE_CURRENT_BINARY_DIR}/lib/libEsp32TracingBackend.a")
endif()
# When using the pregenerated files, there is a edge case where an error appears for
# undeclared argument chip_code_pre_generated_directory. To get around with it we are
# disabling the --fail-on-unused-args flag.
# For more, see: https://github.com/project-chip/connectedhomeip/issues/27636
if (CHIP_CODEGEN_PREGEN_DIR)
set(GN_CONFIGURE_COMMAND ${GN_EXECUTABLE} --root=${GN_ROOT_TARGET} gen --check ${CMAKE_CURRENT_BINARY_DIR})
else ()
set(GN_CONFIGURE_COMMAND ${GN_EXECUTABLE} --root=${GN_ROOT_TARGET} gen --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR})
endif ()
externalproject_add(
chip_gn
SOURCE_DIR ${CHIP_ROOT}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
CONFIGURE_COMMAND ${GN_CONFIGURE_COMMAND}
BUILD_COMMAND ninja "esp32"
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${chip_libraries}
DEPENDS args_gn
BUILD_ALWAYS 1
)
idf_component_get_property(freertos_dir freertos COMPONENT_DIR)
# ESP-IDF components usually need 'freertos/<header.h>', while
# CHIP might include do 'header.h'.
# In IDF V5.0, this path has been moved to
# '${freertos_component}/FreeRTOS-Kernel/include/freertos'
target_include_directories(${COMPONENT_LIB} PRIVATE
"${freertos_dir}/include/freertos"
"${freertos_dir}/FreeRTOS-Kernel/include/freertos")
target_include_directories(${COMPONENT_LIB} INTERFACE
"${CHIP_ROOT}/src/platform/ESP32"
"${CHIP_ROOT}/src/platform/OpenThread"
"${CHIP_ROOT}/src/include"
"${CHIP_ROOT}/src/lib"
"${CHIP_ROOT}/src"
"${CHIP_ROOT}/zzz_generated/app-common"
"${CHIP_ROOT}/examples/platform/esp32"
"${CHIP_ROOT}/third_party/nlassert/repo/include"
"${CHIP_ROOT}/third_party/nlio/repo/include"
"${CMAKE_CURRENT_BINARY_DIR}/src/include"
"${CMAKE_CURRENT_BINARY_DIR}/include"
"${CMAKE_CURRENT_BINARY_DIR}/gen/include"
"${CHIP_ROOT}/config/esp32/${CONFIG_CHIP_EXTERNAL_PLATFORM_DIR}"
"${CHIP_ROOT}/config/esp32/${CONFIG_CHIP_EXTERNAL_PLATFORM_DIR}/../../"
)
set(matter_requires lwip freertos console bt)
idf_build_get_property(build_components BUILD_COMPONENTS)
if("espressif__mdns" IN_LIST build_components)
list(APPEND matter_requires espressif__mdns)
elseif("mdns" IN_LIST build_components)
list(APPEND matter_requires mdns)
endif()
if (CONFIG_OPENTHREAD_BORDER_ROUTER)
list(APPEND matter_requires espressif__esp_rcp_update)
endif()
if (CONFIG_SEC_CERT_DAC_PROVIDER)
list(APPEND matter_requires espressif__esp_secure_cert_mgr)
endif()
if (CONFIG_ENABLE_ENCRYPTED_OTA)
list(APPEND matter_requires espressif__esp_encrypted_img)
endif()
add_prebuilt_library(matterlib "${CMAKE_CURRENT_BINARY_DIR}/lib/libCHIP.a"
REQUIRES ${matter_requires})
target_link_libraries(${COMPONENT_LIB} INTERFACE -Wl,--start-group
${chip_libraries}
matterlib
-Wl,--end-group)
# Make the component dependent on our CHIP build
add_dependencies(${COMPONENT_LIB} chip_gn)
if(CONFIG_ENABLE_PW_RPC)
set(WRAP_FUNCTIONS esp_log_write esp_log_writev)
foreach(func ${WRAP_FUNCTIONS})
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${func}")
endforeach()
endif()
# Build Matter OTA image
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
chip_ota_image(chip-ota-image
INPUT_FILES ${BUILD_DIR}/${CMAKE_PROJECT_NAME}.bin
OUTPUT_FILE ${BUILD_DIR}/${CMAKE_PROJECT_NAME}-ota.bin
)
# Adding dependecy as app target so that this runs after images are ready
add_dependencies(chip-ota-image app)
endif()