CMake: Prefer C11 with a fallback to C99

There is no need to make a similar change in configure.ac.
With Autoconf 2.72, the deprecated macro AC_PROG_CC_C99
is an alias for AC_PROG_CC which prefers a C11 compiler.
This commit is contained in:
Lasse Collin 2024-06-12 14:26:44 +03:00
parent c97e9c12fe
commit 2178acf8a4
1 changed files with 11 additions and 6 deletions

View File

@ -162,12 +162,17 @@ if(OVERRIDE_O3_IN_C_FLAGS_RELEASE)
endif() endif()
# We need a compiler that supports enough C99 or newer (variable-length arrays # We need a compiler that supports enough C99 or newer (variable-length arrays
# aren't needed, those are optional in C17). Setting CMAKE_C_STANDARD here # aren't needed, those are optional in C11/C17). C11 is preferred since C11
# makes it the default for all targets. It doesn't affect the INTERFACE so # features may be optionally used if they are available.
# liblzma::liblzma won't end up with INTERFACE_COMPILE_FEATURES "c_std_99" #
# (the API headers are C89 and C++ compatible). # Setting CMAKE_C_STANDARD here makes it the default for all targets.
set(CMAKE_C_STANDARD 99) # It doesn't affect the INTERFACE so liblzma::liblzma won't end up with
set(CMAKE_C_STANDARD_REQUIRED ON) # INTERFACE_COMPILE_FEATURES "c_std_99" or such (the API headers are C89
# and C++ compatible).
#
# Avoid set(CMAKE_C_STANDARD_REQUIRED ON) because it's fine to decay
# to C99 if C11 isn't supported.
set(CMAKE_C_STANDARD 11)
# Support 32-bit x86 assembly files. # Support 32-bit x86 assembly files.
if(NOT MSVC) if(NOT MSVC)