From efae51696f61bfffd705398873362115c18bc2fb Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 2 Sep 2025 09:46:57 +0200 Subject: [PATCH] feat(cmakev2/idf): enable ccache if requested Enable ccache if CCACHE_ENABLE is set. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/idf.cmake | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/cmakev2/idf.cmake b/tools/cmakev2/idf.cmake index eed60c7021d..25cf9f57b25 100644 --- a/tools/cmakev2/idf.cmake +++ b/tools/cmakev2/idf.cmake @@ -316,6 +316,25 @@ function(__init_toolchain) idf_build_set_property(IDF_TOOLCHAIN_FILE "${toolchain_file}") endfunction() +#[[ + __init_ccache() + + Enable ccache if requested through CCACHE_ENABLE. +#]] +function(__init_ccache) + if(NOT CCACHE_ENABLE) + return() + endif() + + find_program(CCACHE_FOUND ccache) + if(CCACHE_FOUND) + idf_msg("ccache will be used for faster recompilation") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + else() + idf_warn("enabled ccache in build but ccache program not found") + endif() +endfunction() + #[[ __init_components() @@ -565,6 +584,9 @@ __init_idf_target() # Set IDF_TOOLCHAIN, IDF_TOOLCHAIN_FILE and CMAKE_TOOLCHAIN_FILE. __init_toolchain() +# Enable ccache if requested. +__init_ccache() + # Discover and initialize components. __init_components()