Skip to content

Commit 175ab8e

Browse files
committed
cmake: add switch to build with -Werror
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.
1 parent 4a46a8c commit 175ab8e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ OPTION( VALGRIND "Configure build for valgrind" OFF )
4949
OPTION( CURL "Use curl for HTTP if available" ON)
5050
OPTION( USE_EXT_HTTP_PARSER "Use system HTTP_Parser if available" ON)
5151
OPTION( DEBUG_POOL "Enable debug pool allocator" OFF )
52+
OPTION( ENABLE_WERROR "Enable compilation with -Werror" OFF )
5253

5354
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
5455
SET( USE_ICONV ON )
@@ -224,11 +225,18 @@ ELSE ()
224225
SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
225226

226227
MACRO(ENABLE_WARNINGS flag)
227-
ADD_C_FLAG_IF_SUPPORTED(-W${flag})
228+
IF(ENABLE_WERROR)
229+
ADD_C_FLAG_IF_SUPPORTED(-Werror=${flag})
230+
ELSE()
231+
ADD_C_FLAG_IF_SUPPORTED(-W${flag})
232+
ENDIF()
228233
ENDMACRO()
229234

230235
MACRO(DISABLE_WARNINGS flag)
231236
ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag})
237+
IF(ENABLE_WERROR)
238+
ADD_C_FLAG_IF_SUPPORTED(-Wno-error=${flag})
239+
ENDIF()
232240
ENDMACRO()
233241

234242
ENABLE_WARNINGS(all)

0 commit comments

Comments
 (0)