1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

Enable compiler warnings when compiling CMake with Clang

I noticed that I wasn't getting any compiler warnings when testing my
merge requests locally. Turns out this happens because I am compiling
using Clang rather than GCC, so no warning flags are added to the build.
d06a9bdf3a enabled warnings by default
for GCC > 4.2, but Clang supports them too. This has been the case
since at least Clang 3.0 (I couldn't test any older versions on
godbolt.org). For AppleClang, we can also assume that the warning flags
are supported. According to Wikipedia Clang became the default
compiler starting with Xcode 4.2, and the table on
https://trac.macports.org/wiki/XcodeVersionInfo, states that XCode
4.2 Clang was based on upstream Clang 3.0, which supports all the
warning flags.

The warning flags are currently not added when compiling with clang-cl
since this exposes some pre-existing warnings that need to be fixed first.
This commit is contained in:
Alex Richardson
2021-06-21 15:46:37 +01:00
parent cadf2b632e
commit 88e56c2e5a

View File

@@ -812,8 +812,12 @@ CMAKE_SETUP_TESTING()
if(NOT CMake_TEST_EXTERNAL_CMAKE) if(NOT CMake_TEST_EXTERNAL_CMAKE)
if(NOT CMake_VERSION_IS_RELEASE) if(NOT CMake_VERSION_IS_RELEASE)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2) NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2) OR
(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 3.0 AND
NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") OR
CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
-Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
-Wmissing-format-attribute -fno-common -Wundef -Wmissing-format-attribute -fno-common -Wundef