lbussy
June 27, 2022, 2:30pm
1
Conditional compile directives appear to be a popular subject here but I have not found this one documented (or I have not found the right search parameters.) This is similar to a previous item @maxgerhardt helped with.
I’d like to get build_type
into my CPP definitions. I can see it in the project config:
build_type = debug
… but using things like:
env.Append(CPPDEFINES=[
("BUILD_TYPE", env["build_type"])
])
don’t seem to be correct.
Looking at
which is implemented as
def GetBuildType(env):
modes = []
if (
set(["__debug", "sizedata"]) # sizedata = for memory inspection
& set(COMMAND_LINE_TARGETS)
or env.GetProjectOption("build_type") == "debug"
):
modes.append("debug")
if "__test" in COMMAND_LINE_TARGETS or env.GetProjectOption("build_type") == "test":
modes.append("test")
return "+".join(modes or ["release"])
and adding string escaping per Injection of version of the computed libraries - #2 by maxgerhardt , my first guess would be to use
env.Append(CPPDEFINES=[
("BUILD_TYPE", "\\\"%s\\\"" % env.GetBuildType())
])
with testing code
Serial.print("Build type: ");
Serial.println(BUILD_TYPE);
2 Likes
lbussy
June 27, 2022, 3:08pm
3
That’s it! Thanks so much!
Or using Stringification , requires PlatformIO Core 6.0.3 (pio upgrade --dev
) or above:
env.Append(CPPDEFINES=[
("BUILD_TYPE", env.StringifyMacro(env.GetBuildType()))
])
2 Likes