Skip to content

Commit 50fdd7f

Browse files
Damian-Nordickkasperczyk-no
authored andcommitted
[nrf noup] Bypassed code generation at build time
Make chip_data_model.cmake correctly determine CHIP_ROOT constant if that is not defined in the application CMake. Also, use Python3 selected by CMake. Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no> [nrf noup] Bypassed code generation at build time Allow to bypass codegen at build time. Re-add removed callback-stub.cpp and plugin callback templates Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no> Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no> [nrf noup] Fix the external cluster injection mechanism The necessary change was reverted during the last upmerge. Without this fix, the external cluster injection does not work. Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
1 parent ffcd1d8 commit 50fdd7f

File tree

6 files changed

+97
-31
lines changed

6 files changed

+97
-31
lines changed

build/chip/chip_codegen.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ function(chip_codegen TARGET_NAME)
5252

5353
# Python is expected to be in the path
5454
#
55-
# find_package(Python3 REQUIRED)
55+
find_package(Python3 REQUIRED)
5656
add_custom_command(
5757
OUTPUT ${OUT_NAMES}
58-
COMMAND "${CHIP_ROOT}/scripts/codegen.py"
58+
COMMAND ${Python3_EXECUTABLE} "${CHIP_ROOT}/scripts/codegen.py"
5959
ARGS "--generator" "${ARG_GENERATOR}"
6060
"--output-dir" "${GEN_FOLDER}"
6161
"--expected-outputs" "${GEN_FOLDER}/expected.outputs"

src/app/chip_data_model.cmake

+39-27
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
set(CHIP_APP_BASE_DIR ${CMAKE_CURRENT_LIST_DIR})
1818

19+
if (NOT CHIP_ROOT)
20+
get_filename_component(CHIP_ROOT ${CHIP_APP_BASE_DIR}/../.. REALPATH)
21+
endif()
22+
1923
include("${CHIP_ROOT}/build/chip/chip_codegen.cmake")
2024

2125
# Configure ${APP_TARGET} with source files associated with ${CLUSTER} cluster
@@ -57,20 +61,22 @@ endfunction()
5761
#
5862
# Configure ${APP_TARGET} based on the selected data model configuration.
5963
# Available options are:
60-
# SCOPE CMake scope keyword that defines the scope of included sources.
61-
# The default is PRIVATE scope.
62-
# INCLUDE_SERVER Include source files from src/app/server directory.
63-
# ZAP_FILE Path to the ZAP file, used to determine the list of clusters
64-
# supported by the application.
65-
# IDL .matter IDL file to use for codegen. Inferred from ZAP_FILE
66-
# if not provided
67-
# EXTERNAL_CLUSTERS Clusters with external implementations. The default implementations
68-
# will not be used nor required for these clusters.
69-
# Format: MY_CUSTOM_CLUSTER'.
64+
# SCOPE Cmake scope keyword that defines the scope of included sources
65+
# The default is PRIVATE scope.
66+
# INCLUDE_SERVER Include source files from src/app/server directory
67+
# BYPASS_IDL Bypass code generation from .matter IDL file.
68+
# ZAP_FILE Path to the ZAP file, used to determine the list of clusters
69+
# supported by the application.
70+
# IDL .matter IDL file to use for codegen. Inferred from ZAP_FILE
71+
# if not provided
72+
# EXTERNAL_CLUSTERS Clusters with external implementations. The default implementations
73+
# will not be used nor required for these clusters.
74+
# Format: MY_CUSTOM_CLUSTER'.
7075
#
76+
7177
function(chip_configure_data_model APP_TARGET)
7278
set(SCOPE PRIVATE)
73-
cmake_parse_arguments(ARG "INCLUDE_SERVER" "SCOPE;ZAP_FILE;IDL" "EXTERNAL_CLUSTERS" ${ARGN})
79+
cmake_parse_arguments(ARG "INCLUDE_SERVER;BYPASS_IDL" "SCOPE;ZAP_FILE;GEN_DIR;IDL" "EXTERNAL_CLUSTERS" ${ARGN})
7480

7581
if(ARG_SCOPE)
7682
set(SCOPE ${ARG_SCOPE})
@@ -100,7 +106,7 @@ function(chip_configure_data_model APP_TARGET)
100106
endif()
101107
endif()
102108

103-
if(ARG_IDL)
109+
if (ARG_IDL AND NOT ARG_BYPASS_IDL)
104110
chip_codegen(${APP_TARGET}-codegen
105111
INPUT "${ARG_IDL}"
106112
GENERATOR "cpp-app"
@@ -114,24 +120,30 @@ function(chip_configure_data_model APP_TARGET)
114120

115121
target_include_directories(${APP_TARGET} ${SCOPE} "${APP_GEN_DIR}")
116122
add_dependencies(${APP_TARGET} ${APP_TARGET}-codegen)
123+
124+
chip_zapgen(${APP_TARGET}-zapgen
125+
INPUT "${ARG_ZAP_FILE}"
126+
GENERATOR "app-templates"
127+
OUTPUTS
128+
"zap-generated/access.h"
129+
"zap-generated/CHIPClientCallbacks.h"
130+
"zap-generated/endpoint_config.h"
131+
"zap-generated/gen_config.h"
132+
"zap-generated/IMClusterCommandHandler.cpp"
133+
OUTPUT_PATH APP_TEMPLATES_GEN_DIR
134+
OUTPUT_FILES APP_TEMPLATES_GEN_FILES
135+
)
136+
target_include_directories(${APP_TARGET} ${SCOPE} "${APP_TEMPLATES_GEN_DIR}")
137+
add_dependencies(${APP_TARGET} ${APP_TARGET}-zapgen)
117138
else()
118-
set(APP_GEN_FILES)
139+
target_compile_definitions(${APP_TARGET} PRIVATE CHIP_BYPASS_IDL)
140+
target_include_directories(${APP_TARGET} ${SCOPE} ${ARG_GEN_DIR})
141+
set(APP_GEN_FILES
142+
${ARG_GEN_DIR}/callback-stub.cpp
143+
${ARG_GEN_DIR}/IMClusterCommandHandler.cpp
144+
)
119145
endif()
120146

121-
chip_zapgen(${APP_TARGET}-zapgen
122-
INPUT "${ARG_ZAP_FILE}"
123-
GENERATOR "app-templates"
124-
OUTPUTS
125-
"zap-generated/access.h"
126-
"zap-generated/endpoint_config.h"
127-
"zap-generated/gen_config.h"
128-
"zap-generated/IMClusterCommandHandler.cpp"
129-
OUTPUT_PATH APP_TEMPLATES_GEN_DIR
130-
OUTPUT_FILES APP_TEMPLATES_GEN_FILES
131-
)
132-
target_include_directories(${APP_TARGET} ${SCOPE} "${APP_TEMPLATES_GEN_DIR}")
133-
add_dependencies(${APP_TARGET} ${APP_TARGET}-zapgen)
134-
135147
target_sources(${APP_TARGET} ${SCOPE}
136148
${CHIP_APP_BASE_DIR}/../../zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
137149
${CHIP_APP_BASE_DIR}/../../zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp

src/app/util/util.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
#include <lib/core/CHIPEncoding.h>
3030
#include <protocols/interaction_model/StatusCode.h>
3131

32-
// TODO: figure out a clear path for compile-time codegen
32+
#ifdef CHIP_BYPASS_IDL
33+
#include <zap-generated/PluginApplicationCallbacks.h>
34+
#else
3335
#include <app/PluginApplicationCallbacks.h>
36+
#endif
3437

3538
using namespace chip;
3639

src/app/zap-templates/app-templates.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
}
2121
],
2222
"templates": [
23+
{
24+
"path": "templates/app/callbacks/PluginApplicationCallbacks.zapt",
25+
"name": "Matter Application Callbacks header",
26+
"output": "PluginApplicationCallbacks.h"
27+
},
28+
{
29+
"path": "templates/app/callback-stub-src.zapt",
30+
"name": "ZCL callback-stub source",
31+
"output": "callback-stub.cpp"
32+
},
2333
{
2434
"path": "templates/app/endpoint_config.zapt",
2535
"name": "ZCL endpoint configuration",
@@ -41,4 +51,4 @@
4151
"output": "access.h"
4252
}
4353
]
44-
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{> header}}
2+
3+
#include <app-common/zap-generated/callback.h>
4+
#include <app-common/zap-generated/ids/Clusters.h>
5+
#include <lib/support/Span.h>
6+
#include <protocols/interaction_model/Constants.h>
7+
8+
using namespace chip;
9+
10+
// Cluster Init Functions
11+
void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId)
12+
{
13+
switch (clusterId)
14+
{
15+
{{#all_user_clusters_names}}
16+
case app::Clusters::{{asUpperCamelCase name}}::Id:
17+
emberAf{{asUpperCamelCase name}}ClusterInitCallback(endpoint);
18+
break;
19+
{{/all_user_clusters_names}}
20+
default:
21+
// Unrecognized cluster ID
22+
break;
23+
}
24+
}
25+
26+
{{#all_user_clusters_names}}
27+
void __attribute__((weak)) emberAf{{asUpperCamelCase name}}ClusterInitCallback(EndpointId endpoint)
28+
{
29+
// To prevent warning
30+
(void) endpoint;
31+
}
32+
{{/all_user_clusters_names}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{> header}}
2+
3+
#pragma once
4+
5+
{{#chip_server_clusters}}
6+
void Matter{{asUpperCamelCase name}}Plugin{{asUpperCamelCase side}}InitCallback();
7+
{{/chip_server_clusters}}
8+
9+
#define MATTER_PLUGINS_INIT {{#chip_server_clusters}}Matter{{asUpperCamelCase name}}Plugin{{asUpperCamelCase side}}InitCallback(); {{/chip_server_clusters}}

0 commit comments

Comments
 (0)