SIGN IN SIGN UP

[cmake] Simplify C++ standard enforcement using target_compile_features (#8915)

Require C++20 directly on the `binaryen` target by adding
`cxx_std_20` to `target_compile_features`. This enables CMake to
automatically enforce that the compiler supports C++20 and propagates
the requirement to all consumers linking against `binaryen`.

Remove the manual `elseif(CMAKE_CXX_STANDARD LESS ...)` check and error
message from `CMakeLists.txt` since CMake now natively handles standard
validation and error reporting.

Also remove the `if(NOT CMAKE_CXX_STANDARD)` condition around
`set(CMAKE_CXX_STANDARD 20)` and its explanatory comment. The old
comment suggested the conditional allowed embedding in parent projects
with a higher default standard. However, variable assignments like
`set(CMAKE_CXX_STANDARD 20)` in a subdirectory (via `add_subdirectory`)
are strictly directory-scoped and do not leak into the parent project.
Furthermore, with `target_compile_features` enforcing `cxx_std_20` on
`binaryen`, any parent target linking against `binaryen` at a higher C++
standard (e.g., C++23) cleanly satisfies the feature requirement.
Therefore, unconditionally setting `CMAKE_CXX_STANDARD 20` for internal
Binaryen targets is completely safe and avoids inheriting incompatible
standards (< 20) from parent projects.
S
Sam Clegg committed
ebd74547228cffaf20e5609e600e40cdcce7ed61
Parent: 64e066e
Committed by GitHub <noreply@github.com> on 7/17/2026, 7:11:40 PM