Compile only my source code / libraries, without linking to framework

Hi,
I would check if my code is fine w.r.t. -Wall -Wextra -Wpedantic. However, the underlying libraries and framework throw a huge amount of warnings, so that finding the output for my sources is almost impossible.
Is there a way to compile only my source code in PlatformIO? I think I don’t need to link to framework for these checks.

1 Like

Removing the framework = .. line in the platformio.ini removes the link to the framework (e.g. Arduino core) and only builds the sources in src/ and lib/. If there’s a reference to any framework file, it will fail of course.

On the other hand, per Advanced Scripting can be used to inject arbitrary compiler flags on a few selective sources. You could e.g. try a simple script like e.g. pendantic_checks.py

Import("projenv")
# projenv is used for only sources in the project folder

projenv.Append(CCFLAGS=["-Wall", "-Wextra", "-Wpedantic"])

and

extra_scripts = pedantic_checks.py

in the platformio.ini, and verify that with the project task “Advanced → Verbose Build”. Not tested.

1 Like

Will projenv.Append(CCFLAGS=["-Wall", "-Wextra", "-Wpedantic"]) be applied to lib and src folders of my project directory?

Per linked documentation about projenv, no, only src_dir.

In the case of modifying build flags for libs however one can take a very general approach as in Granular optimisation settings to modify the flags arbitrary for any file (that can then be further filtered by filename or path etc.)

So is projenv.Append(CCFLAGS=["-Wall", "-Wextra", "-Wpedantic"]) very similar to src_build_flags?

Good catch, I wasn’t aware of that. But per docs yes. So that makes above redudant.

But in other words, you can use src_build_flags for the src/ folder and for any libraries you control, you can inject extra build flags via the flags section of the library.json of the library.

many thanks! However there is another problem (already seen in this forum): system/framework headers contains many warnings.

I read this “old” topic, but it seems a solution (last post) is #pragma GCC diagnostic, which is not very appealing since I have to modify all the files in my library (I will do if it is THE solution):

Maybe new solutions are emerged in the meanwhile…