diff options
author | João Valverde <j@v6e.pt> | 2021-12-12 21:41:42 +0000 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-12-14 11:23:05 +0000 |
commit | 0781007df4fdb4911fa43632285d63bbf8e33d86 (patch) | |
tree | acb4249cc225dfd1b5d11cf4b1b1befc63e624d5 /CMakeLists.txt | |
parent | b76a2b7a231ab42e868a6538a07b232bbfddb9b1 (diff) |
CMake: Change our configuration to enable C17
For now it only includes MSVC, GCC and clang.
Related to #17768.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 83 |
1 files changed, 21 insertions, 62 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4250801b99..76a3472026 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -567,6 +567,18 @@ 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 @@ -597,44 +609,20 @@ else() # ! MSVC endif() # - # Do whatever is necessary to enable as much C99 support as + # Do whatever is necessary to enable as much C17 support as # possible in the C compiler. Newer versions of compilers - # might default to supporting C99, but older versions may + # might default to supporting C17, but older versions may # require a special flag. # - # We do not want strict C99 support, as we may also want to + # We do not want strict C17 support, as we may also want to # use compiler extensions. # - # 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. + # We cannot use CMAKE_C_STANDARD to request C17 because + # it requires CMake 3.21. # # 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 C99 features + # test whether it's necessary in order to get the C17 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. @@ -642,39 +630,10 @@ else() # ! MSVC if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") # - # 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=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. + # We use -std=gnu17 rather than -std=c17 because extension + # use is evaluated on a case-by-case basis. # - set(CMAKE_C_FLAGS "-xc99 -v ${CMAKE_C_FLAGS}") - elseif(CMAKE_C_COMPILER_ID MATCHES "Intel") - set(CMAKE_C_FLAGS "-c99 ${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS "-std=gnu17 ${CMAKE_C_FLAGS}") endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang") |