From 3c9be9d9916504510ca16e102aa7494e982cff62 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Mon, 4 Aug 2025 16:25:25 +0200 Subject: [PATCH] feat(cmakev2/build): add __init_build() stub Most of the global settings are configured in idf.cmake, but certain elements can only be initialized after the project() function is called and the toolchain is set up. For example, this includes the compilation options, which may depend on identified compiler or the project name and version set in the project() call. The __init_build function is called at the beginning of the idf_build_library() function, meaning it should be executed after the project() call. It ensures that initialization occurs only once by setting the __BUILD_INITIALIZED build property. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/build.cmake | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index f8a8e7307a0..6475a961914 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -89,6 +89,24 @@ function(__dump_build_properties) endforeach() endfunction() +#[[ + __init_build() + + Initialize settings that need to be configured after the project() function + is called. This primarily involves setting compilation options, define + settings, and configuring linker options. +#]] +function(__init_build) + idf_build_get_property(build_initialized __BUILD_INITIALIZED) + if(build_initialized) + # Ensure this function is executed only once throughout the entire + # project. + return() + endif() + + idf_build_set_property(__BUILD_INITIALIZED YES) +endfunction() + #[[ __get_library_interface_or_die(LIBRARY OUTPUT ) @@ -243,6 +261,10 @@ function(idf_build_library) set(ARG_COMPONENTS "${component_names}") endif() + # Initialize settings that must be configured after the project() function + # is called. + __init_build() + add_library("${ARG_INTERFACE}" INTERFACE) idf_build_set_property(LIBRARY_INTERFACES "${ARG_INTERFACE}" APPEND) idf_library_set_property("${ARG_INTERFACE}" LIBRARY_COMPONENTS "${ARG_COMPONENTS}")