Skip to content

Commit

Permalink
cmake: encapsulate enabling/disabling compiler warnings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pks-t committed Jun 23, 2017
1 parent fa94875 commit cbba7b7
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ ELSE(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR})
SET (PKGCONFIG_INCLUDEDIR "\${prefix}/${INCLUDE_INSTALL_DIR}")
ENDIF(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR})

MACRO(ENABLE_WARNINGS flag)
ADD_C_FLAG_IF_SUPPORTED(-W${flag})
ENDMACRO()

MACRO(DISABLE_WARNINGS flag)
ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag})
ENDMACRO()

FUNCTION(TARGET_OS_LIBRARIES target)
IF(WIN32)
TARGET_LINK_LIBRARIES(${target} ws2_32)
Expand Down Expand Up @@ -471,8 +479,8 @@ 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)
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}")
Expand All @@ -495,16 +503,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)
ENABLE_WARNINGS(strict-aliasing=2)
ENABLE_WARNINGS(strict-prototypes)
ENABLE_WARNINGS(declaration-after-statement)
DISABLE_WARNINGS(missing-field-initializers)
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)
Expand Down

0 comments on commit cbba7b7

Please sign in to comment.