blob: 54abef97926e04fc5046c5c34df3cb7165cd27b1 [file] [log] [blame]
Michael Spange772be02021-04-09 14:03:22 -04001# Copyright (c) 2021 Project CHIP Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Michael Spang446e7ad2021-06-14 14:55:51 -040015import("//build_overrides/build.gni")
Michael Spange772be02021-04-09 14:03:22 -040016import("//build_overrides/chip.gni")
Andrei Litvin559c7d52022-10-21 13:38:11 -040017import("${chip_root}/build/chip/chip_codegen.gni")
Karsten Sperling567b7972023-05-13 02:22:28 +120018import("${chip_root}/src/lib/core/core.gni")
Markus Beckereddf2b42021-12-02 08:16:46 +010019import("${chip_root}/src/platform/python.gni")
Michael Spange772be02021-04-09 14:03:22 -040020
Michael Spange772be02021-04-09 14:03:22 -040021_app_root = get_path_info(".", "abspath")
22
23# Defines a source_set for CHIP data model.
24#
25# Arguments:
26# zap_pregenerated_dir
27# Path to the ZAP "gen" dir.
28#
Michael Spang9e282882021-04-26 15:54:03 -040029# zap_file
30# Path to the ZAP input file.
31#
Andrei Litvin559c7d52022-10-21 13:38:11 -040032# idl
33# Path to the .matter IDL corresponding to the zap file. This is for
34# dependencies on build-time code generation.
35#
Michael Spange772be02021-04-09 14:03:22 -040036# Forwards all the remaining variables to the source_set.
37#
38template("chip_data_model") {
39 _data_model_name = target_name
40
Boris Zbarsky3f0e0432023-03-31 15:00:36 -040041 declare_args() {
42 # Allow building ota-requestor-app with a non-spec-compliant floor
43 # (i.e. smaller than 2 minutes) for action delays.
44 non_spec_compliant_ota_action_delay_floor = -1
C Freeman2e97ec02023-08-21 17:31:51 -040045 time_sync_enable_tsc_feature = 1
Boris Zbarsky3f0e0432023-03-31 15:00:36 -040046 }
47
Andrei Litvin559c7d52022-10-21 13:38:11 -040048 if (defined(invoker.idl)) {
49 _idl = invoker.idl
50 } else {
51 # Assume that IDL name is the same as the zap file name, but instead of
52 # '.zap' use '.matter' as extension. This is currently the case in the
53 # sample apps, but may change in the future
Andrei Litvin559c7d52022-10-21 13:38:11 -040054 _idl = string_replace(invoker.zap_file, ".zap", ".matter")
55 }
56
Michael Spange772be02021-04-09 14:03:22 -040057 config("${_data_model_name}_config") {
58 include_dirs = []
59
60 if (defined(invoker.zap_pregenerated_dir)) {
61 include_dirs += [ "${invoker.zap_pregenerated_dir}/.." ]
62 }
63 }
64
Andrei Litvin89c6fb62023-01-17 21:29:11 -050065 chip_zapgen("${_data_model_name}_zapgen") {
66 input = rebase_path(invoker.zap_file)
67 generator = "app-templates"
68
69 outputs = [
70 "zap-generated/access.h",
71 "zap-generated/gen_config.h",
72 "zap-generated/endpoint_config.h",
Andrei Litvin89c6fb62023-01-17 21:29:11 -050073 ]
74
75 if (chip_code_pre_generated_directory == "") {
76 prune_outputs = []
77 }
78
79 if (chip_controller) {
80 outputs += [ "zap-generated/CHIPClusters.h" ]
81 } else {
82 if (defined(prune_outputs)) {
83 prune_outputs += [ "zap-generated/CHIPClusters.h" ]
84 }
85 }
86
87 # TODO: It is unclear here why `zap_pregenerated_dir` has any relevance
88 # in including IMClusterCommandHandler or not.
89 #
90 # This logic has been carried over from previous code during compile
91 # time codegen addition, however the rationale of why pregenerated
92 # dir controls IMClusterCommandHandler needs to be explained and
93 # potentially controlled by a clearer variable (is this for controllers?
94 # is this during app compile but not others? I am unclear what
95 # zap_pregenerated_dir is supposed to convey. Existence of a directory
96 # does not obviously map to "need command handler cpp compiled in").
97 if (defined(invoker.zap_pregenerated_dir)) {
98 outputs += [ "zap-generated/IMClusterCommandHandler.cpp" ]
99 } else {
100 if (defined(prune_outputs)) {
101 prune_outputs += [ "zap-generated/IMClusterCommandHandler.cpp" ]
102 }
103 }
104
105 public_configs = [ ":${_data_model_name}_config" ]
106
107 if (!defined(deps)) {
108 deps = []
109 }
110
111 deps += [ "${chip_root}/src/app" ]
112 }
113
Andrei Litvina7158842022-11-30 10:11:41 -0500114 chip_codegen("${_data_model_name}_codegen") {
115 input = _idl
116 generator = "cpp-app"
117
118 outputs = [
119 "app/PluginApplicationCallbacks.h",
120 "app/callback-stub.cpp",
121 ]
122
123 public_configs = [ ":${_data_model_name}_config" ]
124
125 if (!defined(deps)) {
126 deps = []
127 }
128
Andrei Litvin89c6fb62023-01-17 21:29:11 -0500129 deps += [
130 ":${_data_model_name}_zapgen",
131 "${chip_root}/src/app/common:cluster-objects",
132 ]
Andrei Litvina7158842022-11-30 10:11:41 -0500133 }
134
Michael Spange772be02021-04-09 14:03:22 -0400135 source_set(_data_model_name) {
136 forward_variables_from(invoker,
137 "*",
138 [
139 "zap_pregenerated_dir",
Michael Spang9e282882021-04-26 15:54:03 -0400140 "zap_file",
Vivien Nicolas92e36832021-05-01 00:38:25 +0200141 "is_server",
Damian Królik2cb314a2023-07-12 22:16:49 +0200142 "external_clusters",
Michael Spange772be02021-04-09 14:03:22 -0400143 ])
144
145 if (!defined(sources)) {
146 sources = []
147 }
148
Andrei Litvin89c6fb62023-01-17 21:29:11 -0500149 if (!defined(is_server)) {
150 is_server = false
Andrei Litvina7158842022-11-30 10:11:41 -0500151 }
Andrei Litvin559c7d52022-10-21 13:38:11 -0400152
Michael Spange772be02021-04-09 14:03:22 -0400153 sources += [
154 "${_app_root}/clusters/barrier-control-server/barrier-control-server.h",
Boris Zbarsky04c20f62022-12-18 10:09:13 -0500155 "${_app_root}/clusters/basic-information/basic-information.h",
Michael Spange772be02021-04-09 14:03:22 -0400156 "${_app_root}/clusters/color-control-server/color-control-server.h",
157 "${_app_root}/clusters/door-lock-server/door-lock-server.h",
158 "${_app_root}/clusters/groups-server/groups-server.h",
mkardous-silabs1fa214d2023-05-16 16:51:28 -0400159 "${_app_root}/clusters/icd-management-server/icd-management-server.h",
eve-cxrpa3e30a32021-09-23 18:31:36 +0200160 "${_app_root}/clusters/identify-server/identify-server.h",
Michael Spange772be02021-04-09 14:03:22 -0400161 "${_app_root}/clusters/level-control/level-control.h",
Michael Spange772be02021-04-09 14:03:22 -0400162 "${_app_root}/clusters/on-off-server/on-off-server.h",
lpbeliveau-silabs5dea83e2023-05-30 19:23:04 -0400163 "${_app_root}/clusters/scenes-server/ExtensionFieldSets.h",
164 "${_app_root}/clusters/scenes-server/ExtensionFieldSetsImpl.h",
165 "${_app_root}/clusters/scenes-server/SceneTable.h",
166 "${_app_root}/clusters/scenes-server/SceneTableImpl.h",
167 "${_app_root}/clusters/scenes-server/scenes-server.h",
Damian Królikdada1be2021-04-12 22:56:05 +0200168 "${_app_root}/util/DataModelHandler.cpp",
Michael Spang35b5ce32021-06-16 10:05:06 -0400169 "${_app_root}/util/attribute-size-util.cpp",
Michael Spange772be02021-04-09 14:03:22 -0400170 "${_app_root}/util/attribute-storage.cpp",
171 "${_app_root}/util/attribute-table.cpp",
172 "${_app_root}/util/binding-table.cpp",
Jiacheng Guof8f54e92022-02-22 03:35:48 +0800173 "${_app_root}/util/binding-table.h",
Michael Spange772be02021-04-09 14:03:22 -0400174 "${_app_root}/util/ember-compatibility-functions.cpp",
Andrei Litvin5030df42022-11-02 14:02:46 -0400175 "${_app_root}/util/generic-callback-stubs.cpp",
Michael Spange772be02021-04-09 14:03:22 -0400176 "${_app_root}/util/message.cpp",
Marc Lepagec7b49132022-03-23 17:28:47 -0400177 "${_app_root}/util/privilege-storage.cpp",
Michael Spange772be02021-04-09 14:03:22 -0400178 "${_app_root}/util/util.cpp",
Andrei Litvin1ae045e2021-08-25 11:56:29 -0400179 "${chip_root}/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp",
Michael Spange772be02021-04-09 14:03:22 -0400180 ]
181
Andrei Litvin0e082652022-07-22 10:23:35 -0400182 if (defined(invoker.zap_file)) {
Karsten Sperling567b7972023-05-13 02:22:28 +1200183 _zap_file = rebase_path(invoker.zap_file, root_build_dir)
Damian Królik2cb314a2023-07-12 22:16:49 +0200184 _script_args = [
185 "--zap_file",
186 _zap_file,
187 ]
188 if (defined(invoker.external_clusters)) {
189 _script_args += [ "--external-clusters" ]
190 _script_args += invoker.external_clusters
191 }
Karsten Sperling567b7972023-05-13 02:22:28 +1200192 _cluster_sources = exec_script("${_app_root}/zap_cluster_list.py",
Damian Królik2cb314a2023-07-12 22:16:49 +0200193 _script_args,
Michael Spang9e282882021-04-26 15:54:03 -0400194 "list lines",
195 [ invoker.zap_file ])
196 }
197
Junior Martineze6f610b2023-07-17 21:04:30 -0400198 if (!defined(deps)) {
199 deps = []
200 }
201
C Freeman2e97ec02023-08-21 17:31:51 -0400202 if (!defined(cflags)) {
203 cflags = []
204 }
205
C Freeman9853ecf2023-09-26 15:02:44 -0400206 if (!defined(defines)) {
207 defines = []
208 }
209
Michael Spang9e282882021-04-26 15:54:03 -0400210 foreach(cluster, _cluster_sources) {
Damian Królik2cb314a2023-07-12 22:16:49 +0200211 if (cluster == "door-lock-server") {
Erwin Pand64b0fd2022-07-12 20:57:47 +0800212 sources += [
213 "${_app_root}/clusters/${cluster}/door-lock-server-callback.cpp",
214 "${_app_root}/clusters/${cluster}/door-lock-server.cpp",
215 ]
du48s0309ba9fb2021-10-29 17:41:53 -0700216 } else if (cluster == "mode-select-server") {
217 sources += [
218 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
du48s03ca811e02021-11-09 13:48:48 -0800219 "${_app_root}/clusters/${cluster}/supported-modes-manager.h",
du48s0309ba9fb2021-10-29 17:41:53 -0700220 ]
Rohit Jadhav701fcb22023-07-19 14:18:26 +0530221 } else if (cluster == "temperature-control-server") {
222 sources += [
223 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
224 "${_app_root}/clusters/${cluster}/supported-temperature-levels-manager.h",
225 ]
William4eaace42023-07-21 13:15:35 +0100226 } else if (cluster == "mode-base-server") {
227 sources += [
228 "${_app_root}/clusters/mode-base-server/mode-base-cluster-objects.cpp",
229 "${_app_root}/clusters/mode-base-server/mode-base-cluster-objects.h",
230 "${_app_root}/clusters/mode-base-server/mode-base-server.cpp",
231 "${_app_root}/clusters/mode-base-server/mode-base-server.h",
232 ]
chrisdecenzo2b0679a2021-12-02 17:47:43 -0800233 } else if (cluster == "application-launcher-server") {
234 sources += [
chrisdecenzo0c94a802022-01-27 09:05:43 -0800235 "${_app_root}/app-platform/ContentApp.cpp",
236 "${_app_root}/app-platform/ContentAppPlatform.cpp",
chrisdecenzo2b0679a2021-12-02 17:47:43 -0800237 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
chrisdecenzo2b0679a2021-12-02 17:47:43 -0800238 ]
Timothy Maes628e86a2022-01-12 18:38:44 +0100239 } else if (cluster == "ota-requestor") {
240 sources += [
241 # TODO - align name of folder ?
242 "${_app_root}/clusters/${cluster}/${cluster}-server.cpp",
243 "${_app_root}/clusters/${cluster}/BDXDownloader.cpp",
244 "${_app_root}/clusters/${cluster}/BDXDownloader.h",
Carol Yang5b62cea2022-04-04 17:48:08 -0700245 "${_app_root}/clusters/${cluster}/DefaultOTARequestor.cpp",
Carol Yang04f1acd2022-04-05 01:44:44 -0700246 "${_app_root}/clusters/${cluster}/DefaultOTARequestorDriver.cpp",
Damian Królikaa17b2f2022-03-09 14:13:29 +0100247 "${_app_root}/clusters/${cluster}/DefaultOTARequestorStorage.cpp",
248 "${_app_root}/clusters/${cluster}/DefaultOTARequestorStorage.h",
Shubham Patil47cf0692022-03-31 08:49:01 +0530249 "${_app_root}/clusters/${cluster}/DefaultOTARequestorUserConsent.h",
Carol Yang535c6c82022-03-08 09:44:03 -0800250 "${_app_root}/clusters/${cluster}/ExtendedOTARequestorDriver.cpp",
Damian Królikaa17b2f2022-03-09 14:13:29 +0100251 "${_app_root}/clusters/${cluster}/OTARequestorStorage.h",
Damian Królik3030a192022-06-22 04:49:37 +0200252 "${_app_root}/clusters/${cluster}/OTATestEventTriggerDelegate.cpp",
253 "${_app_root}/clusters/${cluster}/OTATestEventTriggerDelegate.h",
Timothy Maes628e86a2022-01-12 18:38:44 +0100254 ]
Jiacheng Guo59a61a32022-01-20 21:08:10 +0800255 } else if (cluster == "bindings") {
256 sources += [
257 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
258 "${_app_root}/clusters/${cluster}/BindingManager.cpp",
259 "${_app_root}/clusters/${cluster}/BindingManager.h",
Jiacheng Guo6f9fa8e2022-02-08 04:43:11 +0800260 "${_app_root}/clusters/${cluster}/PendingNotificationMap.cpp",
261 "${_app_root}/clusters/${cluster}/PendingNotificationMap.h",
Jiacheng Guo59a61a32022-01-20 21:08:10 +0800262 ]
fesseha-evefa07cc92023-07-05 10:04:51 +0200263 } else if (cluster == "time-synchronization-server") {
264 sources += [
265 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
266 "${_app_root}/clusters/${cluster}/DefaultTimeSyncDelegate.cpp",
267 "${_app_root}/clusters/${cluster}/TimeSyncDataProvider.cpp",
268 ]
C Freeman9853ecf2023-09-26 15:02:44 -0400269 defines +=
270 [ "TIME_SYNC_ENABLE_TSC_FEATURE=${time_sync_enable_tsc_feature}" ]
lpbeliveau-silabs5dea83e2023-05-30 19:23:04 -0400271 } else if (cluster == "scenes-server") {
272 sources += [
273 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
274 "${_app_root}/clusters/scenes-server/ExtensionFieldSetsImpl.cpp",
275 "${_app_root}/clusters/scenes-server/SceneTableImpl.cpp",
276 ]
mideayanghuida3e6f02023-07-13 15:31:13 +0800277 } else if (cluster == "operational-state-server") {
278 sources += [
279 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
280 "${_app_root}/clusters/${cluster}/${cluster}.h",
William81c4c9a2023-08-08 19:33:11 +0100281 "${_app_root}/clusters/${cluster}/operational-state-cluster-objects.h",
mideayanghuida3e6f02023-07-13 15:31:13 +0800282 ]
fengdx4d328c302023-07-24 23:18:02 +0800283 } else if (cluster == "dishwasher-alarm-server") {
284 sources += [
285 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
286 "${_app_root}/clusters/${cluster}/${cluster}.h",
287 "${_app_root}/clusters/${cluster}/dishwasher-alarm-delegate.h",
288 ]
Junior Martineze6f610b2023-07-17 21:04:30 -0400289 } else if (cluster == "icd-management-server") {
290 sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ]
291
Ricardo Casallas60faf712023-07-19 15:18:07 -0400292 deps += [ "${chip_root}/src/app/icd:cluster-srcs" ]
Tobiasgraf78c62b02023-07-20 04:16:15 +0200293 } else if (cluster == "resource-monitoring-server") {
294 sources += [
295 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
296 "${_app_root}/clusters/${cluster}/${cluster}.h",
Cliff Chungd2d47012023-07-20 12:02:01 -0700297 "${_app_root}/clusters/${cluster}/replacement-product-list-manager.h",
Tobiasgraf78c62b02023-07-20 04:16:15 +0200298 "${_app_root}/clusters/${cluster}/resource-monitoring-cluster-objects.cpp",
299 "${_app_root}/clusters/${cluster}/resource-monitoring-cluster-objects.h",
300 ]
Matt Hazley8e77e1a2023-08-23 19:16:57 +0100301 } else if (cluster == "concentration-measurement-server") {
302 sources += [
303 "${_app_root}/clusters/${cluster}/${cluster}.h",
304 "${_app_root}/clusters/${cluster}/concentration-measurement-cluster-objects.h",
305 ]
EricZijian_Sitera3c4b482023-08-10 11:58:46 +0800306 } else if (cluster == "smoke-co-alarm-server") {
307 sources += [
308 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
309 "${_app_root}/clusters/${cluster}/${cluster}.h",
310 "${_app_root}/clusters/${cluster}/SmokeCOTestEventTriggerDelegate.cpp",
311 "${_app_root}/clusters/${cluster}/SmokeCOTestEventTriggerDelegate.h",
312 ]
Williamcbc38652023-08-22 10:24:56 +0100313 } else if (cluster == "air-quality-server") {
314 sources += [
315 "${_app_root}/clusters/${cluster}/${cluster}.cpp",
316 "${_app_root}/clusters/${cluster}/${cluster}.h",
317 ]
Michael Spang9e282882021-04-26 15:54:03 -0400318 } else {
319 sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ]
Michael Spange772be02021-04-09 14:03:22 -0400320 }
321 }
322
Michael Spange772be02021-04-09 14:03:22 -0400323 if (!defined(public_deps)) {
324 public_deps = []
325 }
326
327 public_deps += [
Andrei Litvin559c7d52022-10-21 13:38:11 -0400328 ":${_data_model_name}_codegen",
Andrei Litvin89c6fb62023-01-17 21:29:11 -0500329 ":${_data_model_name}_zapgen",
Michael Spange772be02021-04-09 14:03:22 -0400330 "${chip_root}/src/app",
yunhanw-googled2403a02021-09-28 07:19:40 -0700331 "${chip_root}/src/app/common:cluster-objects",
Vivien Nicolasb86e9a42021-04-27 22:40:35 +0200332 "${chip_root}/src/controller",
Michael Spange772be02021-04-09 14:03:22 -0400333 "${chip_root}/src/lib/core",
334 "${chip_root}/src/lib/support",
Pankaj Garg362c5f22021-04-14 16:35:15 -0700335 "${chip_root}/src/protocols/secure_channel",
Michael Spange772be02021-04-09 14:03:22 -0400336 ]
337
Andrei Litvin89c6fb62023-01-17 21:29:11 -0500338 if (is_server) {
Vivien Nicolas92e36832021-05-01 00:38:25 +0200339 public_deps += [ "${chip_root}/src/app/server" ]
340 }
341
Boris Zbarsky2f1c2d12021-06-25 15:29:20 -0400342 cflags += [ "-Wconversion" ]
343
Boris Zbarsky3f0e0432023-03-31 15:00:36 -0400344 if (non_spec_compliant_ota_action_delay_floor >= 0) {
345 cflags += [ "-DNON_SPEC_COMPLIANT_OTA_ACTION_DELAY_FLOOR=${non_spec_compliant_ota_action_delay_floor}" ]
346 }
347
Michael Spange772be02021-04-09 14:03:22 -0400348 if (!defined(public_configs)) {
349 public_configs = []
350 }
351
352 public_configs += [ ":${_data_model_name}_config" ]
353 }
354}