Skip to content

Commit 4a46a8c

Browse files
committed
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.
1 parent 0a93ded commit 4a46a8c

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

CMakeLists.txt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,16 @@ IF (MSVC)
223223
ELSE ()
224224
SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
225225

226-
ADD_C_FLAG_IF_SUPPORTED(-Wall)
227-
ADD_C_FLAG_IF_SUPPORTED(-Wextra)
226+
MACRO(ENABLE_WARNINGS flag)
227+
ADD_C_FLAG_IF_SUPPORTED(-W${flag})
228+
ENDMACRO()
229+
230+
MACRO(DISABLE_WARNINGS flag)
231+
ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag})
232+
ENDMACRO()
233+
234+
ENABLE_WARNINGS(all)
235+
ENABLE_WARNINGS(extra)
228236

229237
IF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
230238
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 ()
247255
ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1)
248256
ENDIF ()
249257

250-
ADD_C_FLAG_IF_SUPPORTED(-Wdocumentation)
251-
ADD_C_FLAG_IF_SUPPORTED(-Wno-missing-field-initializers)
252-
ADD_C_FLAG_IF_SUPPORTED(-Wstrict-aliasing=2)
253-
ADD_C_FLAG_IF_SUPPORTED(-Wstrict-prototypes)
254-
ADD_C_FLAG_IF_SUPPORTED(-Wdeclaration-after-statement)
255-
ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-const-variable)
256-
ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-function)
258+
ENABLE_WARNINGS(documentation)
259+
DISABLE_WARNINGS(missing-field-initializers)
260+
ENABLE_WARNINGS(strict-aliasing=2)
261+
ENABLE_WARNINGS(strict-prototypes)
262+
ENABLE_WARNINGS(declaration-after-statement)
263+
DISABLE_WARNINGS(unused-const-variable)
264+
DISABLE_WARNINGS(unused-function)
257265

258266
IF (APPLE) # Apple deprecated OpenSSL
259-
ADD_C_FLAG_IF_SUPPORTED(-Wno-deprecated-declarations)
267+
DISABLE_WARNINGS(deprecated-declarations)
260268
ENDIF()
261269

262270
IF (PROFILE)

0 commit comments

Comments
 (0)