Skip to content

Commit

Permalink
cmake: add switch to build with -Werror
Browse files Browse the repository at this point in the history
Add a simple switch to enable building with "-Werror=<warning>" instead
of "-W<warning". Due to the encapsulated `ENABLE_WARNINGS` macro, this
is as simple as adding a new variable "ENABLE_WERROR`, which can be
passed on the command line via `-DENABLE_WERROR=ON`. The variable
defaults to NO to not bother developers in their day to day work.
  • Loading branch information
pks-t committed Jun 23, 2017
1 parent cbba7b7 commit 951bcfe
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,18 @@ ELSE(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR})
ENDIF(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR})

MACRO(ENABLE_WARNINGS flag)
ADD_C_FLAG_IF_SUPPORTED(-W${flag})
IF(ENABLE_WERROR)
ADD_C_FLAG_IF_SUPPORTED(-Werror=${flag})
ELSE()
ADD_C_FLAG_IF_SUPPORTED(-W${flag})
ENDIF()
ENDMACRO()

MACRO(DISABLE_WARNINGS flag)
ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag})
IF(ENABLE_WERROR)
ADD_C_FLAG_IF_SUPPORTED(-Wno-error=${flag})
ENDIF()
ENDMACRO()

FUNCTION(TARGET_OS_LIBRARIES target)
Expand Down

0 comments on commit 951bcfe

Please sign in to comment.