]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
CMake: Prefer C11 with a fallback to C99
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 12 Jun 2024 11:26:44 +0000 (14:26 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 6 Sep 2024 15:56:17 +0000 (18:56 +0300)
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.

(cherry picked from commit 2178acf8a4d40a93e970cfcf9b807d5ef6c8da92)

CMakeLists.txt

index 675cba180f43bd434f492b0c611d2c1b5435fcef..2cf1a2abb64a50dfbf55d30db440945a6f506de9 100644 (file)
@@ -152,12 +152,17 @@ if(OVERRIDE_O3_IN_C_FLAGS_RELEASE)
 endif()
 
 # 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
-# makes it the default for all targets. It doesn't affect the INTERFACE so
-# liblzma::liblzma won't end up with INTERFACE_COMPILE_FEATURES "c_std_99"
-# (the API headers are C89 and C++ compatible).
-set(CMAKE_C_STANDARD 99)
-set(CMAKE_C_STANDARD_REQUIRED ON)
+# aren't needed, those are optional in C11/C17). C11 is preferred since C11
+# features may be optionally used if they are available.
+#
+# Setting CMAKE_C_STANDARD here makes it the default for all targets.
+# It doesn't affect the INTERFACE so liblzma::liblzma won't end up with
+# 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.
 if(NOT MSVC)