Accesing internal build flags of a library to add a project wide include path

Hello,

I would like to reference a project header in the proj/include/ folder from a library. This way, it is possible to configure the library per-project basis. The structure is like this:

proj/lib/comm_manager/library.json
proj/lib/comm_manager/include/comm_manager.h
proj/include/comm_config.h

The comm_manager.h needs comm_config.h for being able to be modified.

As far as I see, it is not possible to access internal build flags of the library, also with extraScript. For tweaking it would be nice to have something like this:

library_env = LibraryEnvironment()
library_env.Append(CCFLAGS=["-I include"])

It should then add proj/include folder to the build flags of the library
(if the CCFLAGS is the right way to do it)

With regards,
Ivan

Yes it is. Just do

Import("env")
env.Append(
    CPPPATH=[env.subst("$PROJECT_INCLUDE_DIR")]
 )

in the library’s extra script to add the project’s include directory to the available header search path. See GitHub - maxgerhardt/pio-lib-access-project-includes.

That and similiar techniques are used by dozens of PlatformIO, e.g., think of FreeRTOS with its FreeRTOSConfig.h…

The alternative would be to add to the global include flags by using build_flags. build_flags = -Iinclude in the platformio.ini has the same effect.

Thanks for your effort! It works now!