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

aldami
Posts: 4
Joined: Thu Feb 15, 2024 9:14 am

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

Postby aldami » Fri Feb 16, 2024 3:24 pm

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):

  1. # Warnings-related flags relevant both for C and C++
  2. COMMON_WARNING_FLAGS = -Wall -Werror=all \
  3.     -Wno-error=unused-function \
  4.     -Wno-error=unused-but-set-variable \
  5.     -Wno-error=unused-variable \
  6.     -Wno-error=deprecated-declarations \
  7.     -Wextra \
  8.     -Wno-unused-parameter -Wno-sign-compare

How can I override these without modifying esp-idf?

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

  1. target_compile_options(${COMPONENT_LIB} PRIVATE -Wall -Wextra -Werror -Wunused-variable)
  1. add_compile_options(-Wunused-variable)
  1. set_source_files_properties(main.c
  2.     PROPERTIES COMPILE_FLAGS
  3.     -Wunused-variable
  4. )

Both individually, and in combinations.

Thank you

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Sat Feb 17, 2024 10:06 pm

You can try idf_build_set_property(COMPILE_OPTIONS ...), or, if all else fails, use gcc's diagnostic pragmas in your code.

Who is online

Users browsing this forum: Bing [Bot] and 150 guests