"build config" header generation?

45 views
Skip to first unread message

Charles Nicholson

unread,
Jan 18, 2022, 9:29:05 AM1/18/22
to gn-dev
Hello GN people-

Does anyone have any best-practices guidance on generating semi-global "configuration" header files? It's sometimes desirable to convert build args into macros so that the configuration can be accessible to the program being built.

Examples include things like version strings, debug/release information, configuration flags that might be clearer as #define directives instead of compile flags.

One obvious way is to do it early in the build itself via a custom action. This is straightforward; a custom action takes the various arguments and stamps out a file. This does need to be maintained as the arguments change over time, though, with new arguments plumbed through to the emission script.

Another way might be to use write_file, so that this happens at configuration-time, but then of course the challenge is getting the args into a C header format.

If you've solved this and feel like sharing any wisdom learned along the way, I'd love to hear it! I suspect the answer is simply "write the action, plumb the relevant args through it, emit a .h file, keep it up to date" but thought I'd ask in case there's a less manual trick.

Thanks,
Charles

Nico Weber

unread,
Jan 18, 2022, 9:47:24 AM1/18/22
to Charles Nicholson, gn-dev

Charles Nicholson

unread,
Jan 18, 2022, 9:50:20 AM1/18/22
to Nico Weber, gn-dev
Thanks for the quick response and reference, Nico. This is very helpful and along the lines of what I was thinking of!

Best
Charles
Reply all
Reply to author
Forward
0 new messages