mirror of
https://github.com/espressif/esp-idf.git
synced 2026-07-23 03:13:01 +03:00
Mirror the link-time optimization support into the cmakev2 build system so that both build systems behave identically. - project.cmake (__init_project_configuration): emit -flto=auto as a link option when CONFIG_COMPILER_LTO_LINKTIME is set, except for bootloader and ESP-TEE builds, otherwise keep -fno-lto. - build.cmake (idf_build_library): when CONFIG_COMPILER_LTO_COMPILETIME is set, compile each linked component with -flto=auto unless it has linker fragments, is placed by another component's fragment (see tools/cmake/lto.cmake), has opted out via NO_LTO, or is not a static library. - project.cmake: when CONFIG_APP_REPRODUCIBLE_BUILD is also enabled, apply the same three flags as the legacy build system to keep LTO output reproducible: pass the prefix-map options to the linker (so link-time code generation remaps DW_AT_comp_dir), add -save-temps (stable LTRANS object names instead of random $TMPDIR paths in the .map), and pin -frandom-seed (byte-identical LTO GIMPLE bytecode). See the commit message of "feat(build): add options to enable link-time optimization (LTO)" for the full analysis. The gcc-ar / gcc-ranlib selection and the NO_LTO component property are shared with the legacy build system through tools/cmake/toolchain.cmake and the common component registration code, so no cmakev2-specific changes are needed there. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>