5

How to add a things like -O2 or a custom -DSOMETHING so they appear in cflags and defines of the *.ninja files?

Recompiling this:

https://webrtc.org/native-code/development/

It has changed the build system. Now the first build step is:

gn gen out/Default --args='is_debug=false'

Building on Ubuntu, targeting itself.

Where can it be added to the *.gn or *.gni files?

Velkan
  • 7,067
  • 6
  • 43
  • 87

1 Answers1

0

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).

Charles Nicholson
  • 888
  • 1
  • 8
  • 21