CMake compiler feature detect

For nearly all CMake projects we choose to detect compiler features rather than make brittle, difficult to maintain nested if/elseif based on compiler vendor and version. There are still cases where if statements to work around known compiler bugs are necessary, but where we can, we use compiler feature checks instead.

An example of this is in our project C23 examples. Suppose a project requires C11 variable length arrays. The CMakeLists.txt would look like:


set(CMAKE_C_STANDARD 11)  # so that check_source_compiles works

check_source_compiles(C "int main(void){for (int i = 1; i < 5; i++){int a[i];} return 0;}" c11vla)

if(NOT c11vla)
 # fatal error or disable feature using C11 VLA

add_executable(c11demo demo.c)
target_compile_features(c11demo PRIVATE c_std_11)  # best practice to set per target