Page 1 of 1

Disabling -Wno-error=unused-variable for main component

Posted: Fri Feb 16, 2024 3:24 pm
by aldami
I have enabled -Werror for my main component, but during build something enables -Wno-error=unused-variable (seen on compile_commands.json) which causes unused var warnings to not be considered as errors.

As far as I can see, that is set in esp-idf\make\project.mk:390 (v4.4):

Code: project.mk Select all

# Warnings-related flags relevant both for C and C++
COMMON_WARNING_FLAGS = -Wall -Werror=all \
-Wno-error=unused-function \
-Wno-error=unused-but-set-variable \
-Wno-error=unused-variable \
-Wno-error=deprecated-declarations \
-Wextra \
-Wno-unused-parameter -Wno-sign-compare

How can I override these without modifying esp-idf?

I have tried:
in project\main\CMakeLists.txt:

Code: CMakeLists.txt Select all

target_compile_options(${COMPONENT_LIB} PRIVATE -Wall -Wextra -Werror -Wunused-variable)

Code: CMakeLists.txt Select all

add_compile_options(-Wunused-variable)

Code: CMakeLists.txt Select all

set_source_files_properties(main.c
PROPERTIES COMPILE_FLAGS
-Wunused-variable
)

Both individually, and in combinations.

Thank you

Re: Disabling -Wno-error=unused-variable for main component

Posted: Sat Feb 17, 2024 10:06 pm
by MicroController
You can try idf_build_set_property(COMPILE_OPTIONS ...), or, if all else fails, use gcc's diagnostic pragmas in your code.