Skip to content

Commit f8fe491

Browse files
authored
[cmake][common] Adding optional support for --zcl argument in chip_zapgen() cmake function (#40537)
* [cmake] Add optional support for --zcl argument in chip_zapgen CMake function Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com> * [NXP][cmake][common] Set "CHIP_ENABLE_ZCL_ARG" to ON for all NXP examples to allow default ZCL path to be passed as --zcl argument with chip_zapgen Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com> * [cmake] Simplify logic for handling ZCL_PATH Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com> * [cmake] Updating documentation to explain the usage of ZCL_PATH in chip_zapgen() and chip_configure_data_model() Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com> * [NXP][cmake] Updating all-clusters-app example to use custom ZCL_PATH argument with chip_configure_data_model Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com> * [cmake][common] Updating documentation of chip_zapgen and chip_configure_data_model to explain the purpose of using ZCL_PATH argument Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com> --------- Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
1 parent f5389c2 commit f8fe491

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

build/chip/chip_codegen.cmake

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ endfunction()
123123
# "zap-generated/IMClusterCommandHandler.cpp"
124124
# OUTPUT_PATH DIR_NAME_VAR
125125
# OUTPUT_FILES FILE_NAMES_VAR
126+
# ZCL_PATH "path/to/custom/zcl.json" # Optional: override default ZCL path
126127
# )
127128
#
128129
# Arguments:
@@ -135,11 +136,20 @@ endfunction()
135136
#
136137
# OUTPUT_FILES - [OUT] output variable will contain the path of generated files.
137138
# suitable to be added within a build target
139+
# ZCL_PATH - [OPTIONAL] Path to a custom ZCL JSON file.
140+
# This maps to the '--zcl' argument in the "scripts/tools/zap/generate.py" script.
141+
# By default, generate.py attempts to autodetect the ZCL path from the .zap
142+
# file which is often a relative path. When the .zap file is relocated or symlinked,
143+
# these relative paths become invalid, causing the build to fail.
144+
# Passing ZCL_PATH explicitly via CMake ensures the build remains robust and portable.
145+
# If ZCL_PATH is not provided, the default behavior is preserved unless CHIP_ENABLE_ZCL_ARG
146+
# is enabled, in which case the default path "src/app/zap-templates/zcl/zcl.json" is
147+
# automatically injected to simplify usage.
138148
#
139149
function(chip_zapgen TARGET_NAME)
140150
cmake_parse_arguments(ARG
141151
""
142-
"INPUT;GENERATOR;OUTPUT_PATH;OUTPUT_FILES"
152+
"INPUT;GENERATOR;OUTPUT_PATH;OUTPUT_FILES;ZCL_PATH"
143153
"OUTPUTS"
144154
${ARGN}
145155
)
@@ -180,6 +190,25 @@ function(chip_zapgen TARGET_NAME)
180190
message(SEND_ERROR "Unsupported zap generator: ${ARG_GENERATOR}")
181191
endif()
182192

193+
set(ZAPGEN_ARGS
194+
"--no-prettify-output"
195+
"--templates" "${TEMPLATE_PATH}"
196+
"--output-dir" "${GEN_FOLDER}/${OUTPUT_SUBDIR}"
197+
"--lock-file" "${CMAKE_BINARY_DIR}/zap_gen.lock"
198+
"--parallel"
199+
"${ARG_INPUT}"
200+
)
201+
202+
# Optional ZCL path for zapgen:
203+
# - If ZCL_PATH is passed, use it.
204+
# - If CHIP_ENABLE_ZCL_ARG is ON, use default path.
205+
# - Otherwise, skip --zcl to preserve default behavior.
206+
if(ARG_ZCL_PATH)
207+
list(APPEND ZAPGEN_ARGS "--zcl" "${ARG_ZCL_PATH}")
208+
elseif(CHIP_ENABLE_ZCL_ARG)
209+
list(APPEND ZAPGEN_ARGS "--zcl" "${CHIP_ROOT}/src/app/zap-templates/zcl/zcl.json")
210+
endif()
211+
183212
# Python is expected to be in the path
184213
# Forcing a call to find find_package here as ${Python3_EXECUTABLE} would be used
185214
find_package(Python3 REQUIRED)
@@ -191,13 +220,7 @@ function(chip_zapgen TARGET_NAME)
191220
add_custom_command(
192221
OUTPUT ${OUT_NAMES}
193222
COMMAND "${Python3_EXECUTABLE}" "${CHIP_ROOT}/scripts/tools/zap/generate.py"
194-
ARGS
195-
"--no-prettify-output"
196-
"--templates" "${TEMPLATE_PATH}"
197-
"--output-dir" "${GEN_FOLDER}/${OUTPUT_SUBDIR}"
198-
"--lock-file" "${CMAKE_BINARY_DIR}/zap_gen.lock"
199-
"--parallel"
200-
"${ARG_INPUT}"
223+
ARGS ${ZAPGEN_ARGS}
201224
DEPENDS
202225
"${ARG_INPUT}"
203226
${EXTRA_DEPENDENCIES}

examples/all-clusters-app/nxp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,6 @@ else()
105105
chip_configure_data_model(app
106106
INCLUDE_SERVER
107107
ZAP_FILE ${NXP_EXAMPLE_ZAP_DIR}/all-clusters-app.zap
108+
ZCL_PATH ${CHIP_ROOT}/src/app/zap-templates/zcl/zcl-with-test-extensions.json
108109
)
109110
endif()

examples/platform/nxp/common/app_common.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ if(NOT DEFINED EXAMPLE_NXP_PLATFORM_DIR)
2626
get_filename_component(EXAMPLE_NXP_PLATFORM_DIR ${CHIP_ROOT}/examples/platform/nxp/${CONFIG_CHIP_NXP_PLATFORM_FOLDER_NAME} REALPATH)
2727
endif()
2828

29+
# Enable default ZCL path to be passed to the zapgen command for all examples.
30+
# This is only used if the ZCL_PATH argument is not provided in the chip_configure_data_model().
31+
set(CHIP_ENABLE_ZCL_ARG ON)
32+
2933
if (CONFIG_CHIP_APP_COMMON)
3034
target_sources(app PRIVATE
3135
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/source/AppTaskBase.cpp

src/app/chip_data_model.cmake

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,26 @@ endfunction()
7171
# EXTERNAL_CLUSTERS Clusters with external implementations. The default implementations
7272
# will not be used nor required for these clusters.
7373
# Format: MY_CUSTOM_CLUSTER'.
74+
# ZCL_PATH [OPTIONAL] Path to a custom ZCL JSON file.
75+
# This maps to the '--zcl' argument in the "scripts/tools/zap/generate.py" script.
76+
# By default, generate.py attempts to autodetect the ZCL path from the .zap
77+
# file which is often a relative path. When the .zap file is relocated or symlinked,
78+
# these relative paths become invalid, causing the build to fail.
79+
# Passing ZCL_PATH explicitly via CMake ensures the build remains robust and portable.
80+
# If ZCL_PATH is not provided, the default behavior is preserved unless CHIP_ENABLE_ZCL_ARG
81+
# is enabled, in which case the default path "src/app/zap-templates/zcl/zcl.json" is
82+
# automatically injected to simplify usage.
83+
#
84+
# Example usage:
85+
# chip_configure_data_model(
86+
# APP_TARGET app
87+
# ZAP_FILE "some_file.zap"
88+
# ZCL_PATH "path/to/custom/zcl.json" # Optional: override default ZCL path
89+
# )
7490
#
7591
function(chip_configure_data_model APP_TARGET)
7692
set(SCOPE PRIVATE)
77-
cmake_parse_arguments(ARG "" "SCOPE;ZAP_FILE;IDL" "EXTERNAL_CLUSTERS" ${ARGN})
93+
cmake_parse_arguments(ARG "" "SCOPE;ZAP_FILE;IDL;ZCL_PATH" "EXTERNAL_CLUSTERS" ${ARGN})
7894

7995
if(ARG_SCOPE)
8096
set(SCOPE ${ARG_SCOPE})
@@ -134,6 +150,7 @@ function(chip_configure_data_model APP_TARGET)
134150
"zap-generated/IMClusterCommandHandler.cpp"
135151
OUTPUT_PATH APP_TEMPLATES_GEN_DIR
136152
OUTPUT_FILES APP_TEMPLATES_GEN_FILES
153+
ZCL_PATH ${ARG_ZCL_PATH}
137154
)
138155
target_include_directories(${APP_TARGET} ${SCOPE} "${APP_TEMPLATES_GEN_DIR}")
139156
target_include_directories(${APP_TARGET} ${SCOPE} "${CHIP_APP_BASE_DIR}/zzz_generated")

0 commit comments

Comments
 (0)