esp32/esp32_common.cmake: Add missing C flags to user C module sources.

On the esp32 port when adding a user C module, the source code for the user
C module was being compiled without certain C flags.  Notably the
optimisation flag was missing.

This commit fixes that by explicitly adding the missing C flags to the
compilation of user C modules.

The missing flags were the following, which are now included when building
user C modules (found by inspecting the generated CMake files when building
with ulab):

    -ffunction-sections
    -fdata-sections
    -Wall
    -Werror=all
    -Wno-error=unused-function
    -Wno-error=unused-variable
    -Wno-error=unused-but-set-variable
    -Wno-error=deprecated-declarations
    -Wextra
    -Wno-error=extra
    -Wno-unused-parameter
    -Wno-sign-compare
    -Wno-enum-conversion
    -gdwarf-4
    -ggdb
    -mdisable-hardware-atomics
    -O2
    -fmacro-prefix-map=micropython/ports/esp32=.
    -fmacro-prefix-map=espressif/esp-idf=/IDF
    -fstrict-volatile-bitfields
    -fno-jump-tables
    -fno-tree-switch-conversion

See related issue #18880.

Work done in collaboration with @andrewleech.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2026-03-03 15:19:49 +11:00
parent d41b8dc52e
commit e8a3ee0342

View File

@ -277,6 +277,11 @@ target_compile_options(${MICROPY_TARGET} PUBLIC
-Wno-missing-field-initializers
)
# User C modules don't pick up certain compile options set by the IDF, most
# importantly the optimisation level. So set them here.
idf_build_get_property(idf_compile_options COMPILE_OPTIONS)
target_compile_options(usermod INTERFACE ${idf_compile_options})
# Additional include directories needed for private NimBLE headers.
target_include_directories(${MICROPY_TARGET} PUBLIC
${IDF_PATH}/components/bt/host/nimble/nimble