Commit 175ab8e7653778c3ef7c805696c8a63d0023c727

Patrick Steinhardt 2017-08-25T17:36:24

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.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0a43701..4c03aa0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,6 +49,7 @@ OPTION( VALGRIND			"Configure build for valgrind"			OFF )
 OPTION( CURL			"Use curl for HTTP if available" ON)
 OPTION( USE_EXT_HTTP_PARSER		"Use system HTTP_Parser if available" ON)
 OPTION( DEBUG_POOL			"Enable debug pool allocator"			OFF )
+OPTION( ENABLE_WERROR			"Enable compilation with -Werror"		OFF )
 
 IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
 	SET( USE_ICONV ON )
@@ -224,11 +225,18 @@ ELSE ()
 	SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
 
 	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()
 
 	ENABLE_WARNINGS(all)