CMake compiler flag precedence

To ensure the user set compile flags take precedence by appearing later in the command line vs. CMake’s automatic flags, use add_compile_options to set language-specific or project-wide compiler options. target_compile_options is similar, but applies to only one target.

The generator expression $<$<COMPILE_LANGUAGE:C>:...> is used to only add the flag for the C language. This is important as many compiler options are language-specific, particularly for C / C++ and Fortran projects.

If one truly needs to wipe out all CMake automatic flags, try settingCMAKE_FLAGS variable to an empty string.