BLAKE3-team / BLAKE3

the official Rust and C implementations of the BLAKE3 cryptographic hash function
Apache License 2.0
4.71k stars 315 forks source link

build(CMake): Require C99 mode #365

Closed BurningEnlightenment closed 7 months ago

BurningEnlightenment commented 7 months ago

Specify language requirement as a compile-feature and force compiler extensions off ensuring portability problems are detected early on. Note that we do not use the C_STANDARD property, because it doesn't propagate to dependent targets and would prohibit users from compiling their code base with consistent flags / language configuations if they were to target a newer C standard. Similarly we do not configure C_STANDARD_REQUIRED as compile-features do not interact with it--they are enforced regardless.

Closes #348

oconnor663 commented 7 months ago

Thank you! Out of curiosity, if I had to figure out the right way to do something like this myself, where would I have found it? This all seems...very non-obvious...

BurningEnlightenment commented 7 months ago

Well, the main problem with CMake is the amount of cruft accumulated until CMake 3 refocused on targets and their properties. So if you google something and the solution involves set()ing CMAKE_ variables it is probably outdated. The reference documentation is fairly comprehensive, but it requires a bit of digging to grok the way it's structured.

A good starting point is the Tutorial section of the reference manual. In this case it would've already covered 90% of the topic. The unintuitive parts about compiler extensions are things I've learned the hard way--through user complaints about things blowing up in their face 🙃