From cf09f23ba94d8faf17955020629ab669e429c67e Mon Sep 17 00:00:00 2001
From: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
Date: Mon, 2 Jan 2023 11:16:29 +0100
Subject: [PATCH] CMakeLists.txt: Add CMake flag 'ENABLE_WERROR' (defaulting to
 off).

Signed-off-by: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
---
 CMakeLists.txt | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b3fb26..3ef1ced 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,15 +20,21 @@ project(net-cpp VERSION 3.1.0)
 
 set(NET_CPP_SOVERSION 2 CACHE STRING "The version number from libnet-cpp's SONAME")
 
+option(ENABLE_WERROR "Treat all build warnings as errors" OFF)
+
 find_package(Threads)
 
 include(GNUInstallDirs)
 
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -pedantic -Wextra -fvisibility=hidden")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -Wextra")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -Wextra -fvisibility=hidden")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -Wextra")
 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
 add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
 
+if(ENABLE_WERROR)
+    add_compile_options("-Werror")
+endif()
+
 include(CTest)
 
 include_directories(
-- 
2.30.2

