From 0c80fd62e70c97f1d3210e2cf80a1aeedef3bbf3 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 19 Aug 2025 13:00:21 +0200 Subject: [PATCH] feat(cmakev2/utilities): add file_generate function The file_generate function is used by some existing components, so it should be added to cmakev2 as well. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/utilities.cmake | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/cmakev2/utilities.cmake b/tools/cmakev2/utilities.cmake index 2d4688ae8f1..bab5ca6339d 100644 --- a/tools/cmakev2/utilities.cmake +++ b/tools/cmakev2/utilities.cmake @@ -563,3 +563,30 @@ function(fail_target target_name message_line0) ${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake VERBATIM) endfunction() + +#[[ + file_generate( + [INPUT ] + [CONTENT ]) + + :output[in]: Output file name. + :INPUT[in]: Input file name. + :CONTENT[in]: Input string. + + Utility to generate file and have the output automatically added to cleaned + files. +#]] +function(file_generate output) + cmake_parse_arguments(_ "" "INPUT;CONTENT" "" ${ARGN}) + + if(__INPUT) + file(GENERATE OUTPUT "${output}" INPUT "${__INPUT}") + elseif(__CONTENT) + file(GENERATE OUTPUT "${output}" CONTENT "${__CONTENT}") + else() + message(FATAL_ERROR "Content to generate not specified.") + endif() + + set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${output}") +endfunction()