summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2021-06-21 14:46:37 (GMT)
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2021-06-22 15:17:58 (GMT)
commit88e56c2e5aa5a89c646250c42412a96d181f7aa7 (patch)
tree62463462d20728a221230ff3a19240b13a3035e2 /CMakeLists.txt
parentcadf2b632e6a09945ef4907e96e66fb3aa922e0c (diff)
downloadCMake-88e56c2e5aa5a89c646250c42412a96d181f7aa7.zip
CMake-88e56c2e5aa5a89c646250c42412a96d181f7aa7.tar.gz
CMake-88e56c2e5aa5a89c646250c42412a96d181f7aa7.tar.bz2
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. d06a9bdf3ab47231cc91b78dac77bd50de390565 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.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt8
1 files changed, 6 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 44b433a..6016cd6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -812,8 +812,12 @@ CMAKE_SETUP_TESTING()
if(NOT CMake_TEST_EXTERNAL_CMAKE)
if(NOT CMake_VERSION_IS_RELEASE)
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
- NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
+ if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
+ 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
-Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
-Wmissing-format-attribute -fno-common -Wundef