[CMake] Simplify code for detecting/setting compiler flags