From 88e56c2e5aa5a89c646250c42412a96d181f7aa7 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 21 Jun 2021 15:46:37 +0100 Subject: 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. --- CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 44b433ac8f..6016cd654d 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 -- cgit v1.2.1