ESP-IDF: How to disable specific warnings

Sometimes ESP-IDF programs emit lots of useless warnings that you want to suppress so you can see the error messages more clearly, for example:

/home/user/MyESPIDFProject/src/Network.cpp:382:1: warning: missing initializer for member 'httpd_uri::user_ctx' [-Wmissing-field-initializers]

The first step is to identify what warning you need to suppress. This is easy, just look for the flag at the end of the warning message. In this case, it’s -Wmissing-field-initializers. The flag to suppress this type of warning is obtained by appending no just after -W: -Wno-missing-field-initializers.

Now use the method outlined in ESP-IDF: How to add custom compiler-flags to add the suppression flag to your project: Add this to main/CMakeLists.txt (do not confuse with the CMakeLists.txt in the project root directory):

# Suppress specific warnings
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-missing-field-initializers)