Revert "CMake: Change our configuration to enable C17"

This reverts commit 0781007df4.
This commit is contained in:
João Valverde 2021-12-14 23:45:25 +00:00
parent 85a8de25a4
commit 5623e60375
2 changed files with 62 additions and 22 deletions

View File

@ -567,18 +567,6 @@ if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
list(APPEND LOCAL_CFLAGS /analyze:WX-)
endif()
# The /std:c17 option enables ISO C17 conformance. It's available
# starting in Visual Studio 2019 version 16.8.
#
# XXX Do we need to split this into LOCAL_CFLAGS + LOCAL_CXXFLAGS?
#
list(APPEND LOCAL_CFLAGS /std:c17)
# MSVC 14.28 enables C5105, but the Windows SDK 10.0.18362.0 triggers it.
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19.28)
list(APPEND LOCAL_CFLAGS -wd5105)
endif()
# Additional compiler warnings to be treated as "Level 3"
# when compiling Wireshark sources. (Selected from "level 4" warnings).
## 4295: array is too small to include a terminating null character
@ -609,20 +597,44 @@ else() # ! MSVC
endif()
#
# Do whatever is necessary to enable as much C17 support as
# Do whatever is necessary to enable as much C99 support as
# possible in the C compiler. Newer versions of compilers
# might default to supporting C17, but older versions may
# might default to supporting C99, but older versions may
# require a special flag.
#
# We do not want strict C17 support, as we may also want to
# We do not want strict C99 support, as we may also want to
# use compiler extensions.
#
# We cannot use CMAKE_C_STANDARD to request C17 because
# it requires CMake 3.21.
# Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have
# any effect, so, unless and until we require CMake 3.1 or
# later, we have to do it ourselves on pre-3.1 CMake, so we
# just do it ourselves on all versions of CMake.
#
# Note: with CMake 3.1 through 3.5, the only compilers for
# which CMake handles CMAKE_C_STANDARD are GCC and Clang.
# 3.6 adds support only for Intel C; 3.9 adds support for
# PGI C, Sun C, and IBM XL C, and 3.10 adds support for
# Cray C and IAR C, but no version of CMake has support for
# HP C. Therefore, even if we use CMAKE_C_STANDARD with
# compilers for which CMake supports it, we may still have
# to do it ourselves on other compilers.
#
# In addition, CMake 3.5.2 seems to think that GCC versions
# less than 4.4 don't support -std=gnu99, which we need in
# order to get support for "for (int i = 0; i < n; i++) ;",
# which is another reason not to rely on CMake's CMAKE_C_STANDARD
# support.
#
# See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID
# variables for a list of compiler IDs.
#
# We don't worry about MSVC; it doesn't have such a flag -
# either it doesn't support the C99 features we need at all,
# or it supports them regardless of the compiler flag.
#
# XXX - we add the flag for a given compiler to CMAKE_C_FLAGS,
# so we test whether it works and add it if we do. We don't
# test whether it's necessary in order to get the C17 features
# test whether it's necessary in order to get the C99 features
# that we use; if we ever have a user who tries to compile with
# a compiler that can't be made to support those features, we
# can add a test to make sure we actually *have* C99 support.
@ -630,10 +642,39 @@ else() # ! MSVC
if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang")
#
# We use -std=gnu17 rather than -std=c17 because extension
# use is evaluated on a case-by-case basis.
# We use -std=gnu99 rather than -std=c99 because, for
# some older compilers such as GCC 4.4.7, -std=gnu99
# is required to avoid errors about C99 constructs
# such as "for (int i = 0; i < n; i++) ;".
#
set(CMAKE_C_FLAGS "-std=gnu17 ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
#
# We want support for extensions picked up for
# GNU C compatibility, so we use -qlanglvl=extc99.
#
set(CMAKE_C_FLAGS "-qlanglvl=extc99 ${CMAKE_C_FLAGS}")
elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
#
# We also need to add -Wp,-H200000 to handle some large
# #defines we have; that flag is not necessary for the
# C++ compiler unless the "legacy" C++ preprocessor is
# being used (+legacy_cpp). We don't want the legacy
# preprocessor if it's not the default, so we just add
# -Wp,-H200000 to the C flags. (If there are older
# versions of aC++ that only support the legacy
# preprocessor, and require that we boost the table
# size, we'd have to check whether -Wp,-H200000 is
# supported by the C++ compiler and add it only if it is.)
#
set(CMAKE_C_FLAGS "-AC99 -Wp,-H200000 $WS_CFLAGS ${CMAKE_C_FLAGS}")
elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
#
# We also crank up the warning level.
#
set(CMAKE_C_FLAGS "-xc99 -v ${CMAKE_C_FLAGS}")
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
set(CMAKE_C_FLAGS "-c99 ${CMAKE_C_FLAGS}")
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")

View File

@ -17,7 +17,6 @@ It is used for troubleshooting, analysis, development and education.
== Whats New
* The PCRE2 library (https://www.pcre.org/) is now a required dependency to build Wireshark.
* A compiler with C17 support is required.
Many improvements have been made.
See the “New and Updated Features” section below for more details.