Silence warnings for dependencies / external libraries?

When I create a minimal project with

[env:nodemcuv2]
platform = espressif8266@4.2.0
board = nodemcuv2
framework = arduino
build_unflags = -std=gnu17
build_flags =  -std=gnu++20
build_src_flags = -Wall -Wextra -Wpedantic

and a src/main.cpp that just has

#include <Arduino.h>

void setup() {}
void loop() {}

in it, indeed it throws tons of errors.

In file included from C:\Users\Max\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/esp8266_peri.h:28,
                 from C:\Users\Max\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/Arduino.h:39,
                 from src\main.cpp:1:
C:\Users\Max\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/esp8266_undocumented.h:99:12: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
   99 |     struct {
      |            ^
C:\Users\Max\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/esp8266_undocumented.h:254:2: warning: extra ';' [-Wpedantic]
  254 | };
      |  ^
:...

now I add

extra_scripts =
    post:convert_sysincludes.py

with content

from pathlib import Path
Import("env" ,"projenv")

platform = env.PioPlatform()
FRAMEWORK_DIR = Path(platform.get_package_dir("framework-arduinoespressif8266"))
framework_includes = list()
filtered_cpppath = list()
# apply these changes to current working env, the project env and the global env
for e in (env, projenv, DefaultEnvironment()):
    for p in e["CPPPATH"]:
        # is the current include path inside the framework directory?
        if FRAMEWORK_DIR in Path(p).parents:
            framework_includes.append(p)
        else:
            filtered_cpppath.append(p)
    e.Replace(CPPPATH=filtered_cpppath)
    e.Append(CCFLAGS=[("-isystem", p) for p in framework_includes])

and the warnings are gone.

In the verbose build output, it can now be see that what was before

xtensa-lx106-elf-g++ -o .pio\build\nodemcuv2\src\main.cpp.o -c -std=gnu++20 -fno-rtti -std=gnu++17 -fno-exceptions -Os -mlongcalls -mtext-section-literals -falign-functions=4 -ffunction-sections -fdata-sections -Wall -Werror=return-type -free -fipa-pta -Wall -Wextra -Wpedantic -DPLATFORMIO=60107 -DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_NODEMCU_ESP12E -DF_CPU=80000000L -D__ets__ -DICACHE_FLASH -D_GNU_SOURCE -DARDUINO=10805 -DARDUINO_BOARD="PLATFORMIO_NODEMCUV2" -DARDUINO_BOARD_ID="nodemcuv2" -DFLASHMODE_DIO -DLWIP_OPEN_SRC -DNONOSDK22x_190703=1 -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DVTABLES_IN_FLASH -DMMU_IRAM_SIZE=0x8000 -DMMU_ICACHE_SIZE=0x8000 -U__STRICT_ANSI__ -Iinclude -Isrc -IC:\Users\Max.platformio\packages\framework-arduinoespressif8266\tools\sdk\include -IC:\Users\Max.platformio\packages\framework-arduinoespressif8266\cores\esp8266 -IC:\Users\Max.platformio\packages\toolchain-xtensa\include -IC:\Users\Max.platformio\packages\framework-arduinoespressif8266\tools\sdk\lwip2\include -IC:\Users\Max.platformio\packages\framework-arduinoespressif8266\variants\nodemcu src\main.cpp

Is now

xtensa-lx106-elf-g++ -o .pio\build\nodemcuv2\src\main.cpp.o -c -std=gnu++20 -fno-rtti -std=gnu++17 -fno-exceptions -Os -mlongcalls -mtext-section-literals -falign-functions=4 -ffunction-sections -fdata-sections -Wall -Werror=return-type -free -fipa-pta -Wall -Wextra -Wpedantic -isystem C:\Users\Max.platformio\packages\framework-arduinoespressif8266\tools\sdk\include -isystem C:\Users\Max.platformio\packages\framework-arduinoespressif8266\cores\esp8266 -isystem C:\Users\Max.platformio\packages\framework-arduinoespressif8266\tools\sdk\lwip2\include -isystem C:\Users\Max.platformio\packages\framework-arduinoespressif8266\variants\nodemcu-DPLATFORMIO=60107
-DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_NODEMCU_ESP12E -DF_CPU=80000000L -D__ets__ -DICACHE_FLASH -D_GNU_SOURCE -DARDUINO=10805 -DARDUINO_BOARD="PLATFORMIO_NODEMCUV2" -DARDUINO_BOARD_ID="nodemcuv2" -DFLASHMODE_DIO -DLWIP_OPEN_SRC -DNONOSDK22x_190703=1 -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DVTABLES_IN_FLASH -DMMU_IRAM_SIZE=0x8000 -DMMU_ICACHE_SIZE=0x8000 -U__STRICT_ANSI__ -IC:\Users\Max.platformio\packages\toolchain-xtensa\include -Iinclude -Isrc -IC:\Users\Max.platformio\packages\toolchain-xtensa\include src\main.cpp

So all framework includes were changed from -I to -isystem, supressing the errors coming from those files.

Other paths from user libraries and the toolchain are unaffected.

2 Likes