Here are two simple CMake functions that take a list of compiler flags, and append those that do not result in an error when used to the supplied variable.
Depending on which version of CMake you need to support, you might want to
look into the COMPILE_FLAGS
property and target_compile_options()
.