summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-08-25 17:32:54 +0200
committerPatrick Steinhardt <ps@pks.im>2017-08-25 17:32:54 +0200
commit4a46a8c14fb05e54825d117722c61143ede44bf3 (patch)
tree5d726c5d78653895accce68dc1c090dfe18b8197
parent0a93ded1b931c0cd3476300a0794dc2f3e946356 (diff)
downloadlibgit2-4a46a8c14fb05e54825d117722c61143ede44bf3.tar.gz
cmake: encapsulate enabling/disabling compiler warnings
There are multiple sites where we enable or disable compiler warning via "-W<warning>" or "-Wno-<warning>". As we want to extend this mechanism later on to conditionally switch these over to "-Werror=<warning>", we encapsulate the logic into its their own macros `ENABLE_WARNINGS` and `DISABLE_WARNINGS`. Note that we in fact have to use a macro here. Using a function would not modify the CFLAGS inside of the callers scope, but in the function's scope only.
-rw-r--r--CMakeLists.txt28
1 files changed, 18 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1a9436f09..0a43701c4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -223,8 +223,16 @@ IF (MSVC)
ELSE ()
SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
- ADD_C_FLAG_IF_SUPPORTED(-Wall)
- ADD_C_FLAG_IF_SUPPORTED(-Wextra)
+ MACRO(ENABLE_WARNINGS flag)
+ ADD_C_FLAG_IF_SUPPORTED(-W${flag})
+ ENDMACRO()
+
+ MACRO(DISABLE_WARNINGS flag)
+ ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag})
+ ENDMACRO()
+
+ ENABLE_WARNINGS(all)
+ ENABLE_WARNINGS(extra)
IF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
SET(CMAKE_C_FLAGS "-std=c99 -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
@@ -247,16 +255,16 @@ ELSE ()
ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1)
ENDIF ()
- ADD_C_FLAG_IF_SUPPORTED(-Wdocumentation)
- ADD_C_FLAG_IF_SUPPORTED(-Wno-missing-field-initializers)
- ADD_C_FLAG_IF_SUPPORTED(-Wstrict-aliasing=2)
- ADD_C_FLAG_IF_SUPPORTED(-Wstrict-prototypes)
- ADD_C_FLAG_IF_SUPPORTED(-Wdeclaration-after-statement)
- ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-const-variable)
- ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-function)
+ ENABLE_WARNINGS(documentation)
+ DISABLE_WARNINGS(missing-field-initializers)
+ ENABLE_WARNINGS(strict-aliasing=2)
+ ENABLE_WARNINGS(strict-prototypes)
+ ENABLE_WARNINGS(declaration-after-statement)
+ DISABLE_WARNINGS(unused-const-variable)
+ DISABLE_WARNINGS(unused-function)
IF (APPLE) # Apple deprecated OpenSSL
- ADD_C_FLAG_IF_SUPPORTED(-Wno-deprecated-declarations)
+ DISABLE_WARNINGS(deprecated-declarations)
ENDIF()
IF (PROFILE)