Unfortunately, there's no immediate path from the "args" into your compiler invocation. Since GN supports multiple concurrent toolchains, it's unclear which one you'd want this to be applied to, whether it should apply to the C compiler, C++ compiler, linker, etc.
This requires at least some coordination between your GN "args" and whichever toolchain(s) you want to apply this to.
So, if in your BUILDCONFIG.gn you have:
declare_args() {
cl_cflags = ""
}
And then later in a toolchain you have:
toolchain("my_toolchain") {
tool("cc") {
...
command = "cc ... ${cl_cflags}"
}
}
Then the invocation ./gn gen out/Default --args='cl_cflags="-DFOO"'
will emit Ninja files that have -DFOO
added to every invocation of the C compiler.
Note that you do have to add this manually for every toolchain, and that there's no way to turn it off in a one-off scenario, because GN doesn't "know" about it (it's not a config
etc).