cmake: Only add warning flags if the compiler supports them
I am compiling for FreeBSD where the compiler is Clang and doesn't accept all the GCC warning flags. This breaks the -Werror build:
error: unknown warning option '-Wduplicated-branches' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wduplicated-cond' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wjump-misses-init' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wlogical-op'; did you mean '-Wlong-long'? [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wrestrict' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wunused-but-set-variable'; did you mean '-Wunused-const-variable'? [-Werror,-Wunknown-warning-option]
With this change we use check_{c,cxx}_compiler_flag to check if the flag is supported before adding it. In the future this will allow adding clang-specific warning flags to the list of warnings as well since they will be ignored for GCC.
depends on !286 (merged)