You can use check_c_compiler_flag
check_c_compiler_flag
https://cmake.org/cmake/help/latest/module/CheckCCompilerFlag.html