Hello,
Why not add CMAKE_REQUIRED_FLAGS before CMAKE__FLAGS instead?
https://cmake.org/cmake/help/latest/module/CheckCSourceCompiles.html
CMAKE_REQUIRED_FLAGS
A space-separated string of additional flags to pass to the compiler. A semicolon-separated list will not work. The contents of CMAKE_FLAGS and its associated configuration-specific CMAKEFLAGS variables are automatically prepended to the compiler command before the contents of this variable.
It would avoid flags like -mno-avx2 provided by root project to be ignored by -mavx2 in subproject for example : causing runtime issues on release with incompatible CPU