From 634184850a85145f20147c84f5a02fcd6df185a2 Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Fri, 10 Nov 2017 00:04:27 +0100 Subject: Ensure C89 compliance and enable more warnings (#650) * Ensure C89 compliance and enable more warnings According to the contributing guidelines, the library is developed strictly in ANSI C 89. However, this is not enforced. Additionally, we enable more warnings: apart from -Wall and -Wextra we enable a warning that makes sure all enumeration values are covered in a switch statement. When compiling with Clang, we also turn on the warnings -Wc99-extensions and -Wc11-extensions. * Enable all warnings that are used on Travis This makes it easier to notice problems before pushing. --- CMakeLists.txt | 14 ++++++++++++++ src/PJ_aeqd.c | 2 +- src/PJ_airy.c | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6bbe8ea..f489f4ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,20 @@ cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR) project(PROJ4 C) set(PROJECT_INTERN_NAME PROJ) +# Set warnings +if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") + set(CMAKE_C_FLAGS "/WX ${CMAKE_C_FLAGS}") +elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_C_FLAGS "-std=c89 -Wall -Wextra -Wswitch -Werror \ + -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wformat \ + -Werror=format-security -Wshadow ${CMAKE_C_FLAGS}") +elseif("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") + set(CMAKE_C_FLAGS "-std=c89 -Wall -Wextra -Wswitch -Werror \ + -Wc99-extensions -Wc11-extensions -Wunused-parameter -Wmissing-prototypes \ + -Wmissing-declarations -Wformat -Werror=format-security -Wshadow \ + -Wfloat-conversion ${CMAKE_C_FLAGS}") +endif() + ################################################################################# # PROJ4 CMake modules ################################################################################# diff --git a/src/PJ_aeqd.c b/src/PJ_aeqd.c index aa1597e4..c089eed7 100644 --- a/src/PJ_aeqd.c +++ b/src/PJ_aeqd.c @@ -35,7 +35,7 @@ enum Mode { N_POLE = 0, S_POLE = 1, EQUIT = 2, - OBLIQ = 3, + OBLIQ = 3 }; struct pj_opaque { diff --git a/src/PJ_airy.c b/src/PJ_airy.c index 3b145475..f70e7f7a 100644 --- a/src/PJ_airy.c +++ b/src/PJ_airy.c @@ -38,7 +38,7 @@ enum Mode { N_POLE = 0, S_POLE = 1, EQUIT = 2, - OBLIQ = 3, + OBLIQ = 3 }; struct pj_opaque { -- cgit v1.2.3