Global cflags from library

Hi!

I’ve search here and didn’t found a working solution. My goal is to set a define from a library extra_script that will be visible from every compiled file.
Looking at the various answers here, I’ve managed to have the following build script in the library that almost work… almost because it work when building the project for the native platform, but fails on esp32 using esp-idf (I’m using pio 6.1.16 with latest espidf builder)

With the code below, I can see the flag in every library except the main app! But why does it work for native and not for espidf? I know that setting the cpp defines in projenv solved the issue with native.

I tried everything, but maybe it’s just not possible and should look for an other solution?

Thanks!
My extra script is here:

Import("projenv")
global_env = DefaultEnvironment()
    
# propagate too all possible envs... iterate to all libraries + global_env for some libraries + projenv for the app
envs = [ lb.env for lb in env.GetLibBuilders()] + [global_env, projenv]
    
for e in envs:
    e.Append(CPPDEFINES=[
        ("VERSION_MAJOR", pkg_json["sdk_major"]),
        ("VERSION_MINOR", pkg_json["sdk_minor"]),
        ("VERSION_REVISION", pkg_json["sdk_revision"]),
        ("GIT_REVISION", '\\"%s\\"' %(pkg_json["git_revision"])),
    ])

I see that the esp builder is using “compileGroups” but I failed to find which part is setting this config (nothing in platformio core, nor in the esp builder or in scons itself)

ok, compileGroups is from cmake, that’s why…

Now I’ve found something in the esp builder. Using the following make me go farther

for e in envs:
    e.Append(SRC_BUILD_FLAGS=[
            "-DVERSION_MAJOR=%s"%(pkg_json["sdk_major"]),
            "-DVERSION_MINOR=%s" %(pkg_json["sdk_minor"]),
            "-DVERSION_REVISION=%s" %(pkg_json["sdk_revision"]),
            '-DGIT_REVISION=\\"%s\\"' %(pkg_json["git_revision"]),
        ])

I’m not sure why SRC_BUILD_FLAGS is used instead of BUILD_FLAGS… but now the app gets the cflags I want… however the other libs are not getting the cflags

I finally got it to work using the following:

for e in envs:
        cflags = [
            "-DVERSION_MAJOR=%s"%(pkg_json["sdk_major"]),
            "-DVERSION_MINOR=%s" %(pkg_json["sdk_minor"]),
            "-DVERSION_REVISION=%s" %(pkg_json["sdk_revision"]),
            '-DGIT_REVISION=\\"%s\\"' %(pkg_json["git_revision"]),
        ]
        e.Append(CFLAGS=cflags)
        e.Append(SRC_BUILD_FLAGS=cflags)

I had to set both CFLAGS and SRC_BUILD_FLAGS