From 047ea3f9b01682607d0f7f86570fe226a6ef09ca Mon Sep 17 00:00:00 2001
From: Martin Stump <martin.stump@mercedes-benz.com>
Date: Fri, 20 Jan 2023 15:03:33 +0100
Subject: [PATCH] Add compiler warnings

* Based on cppbestpractices

Signed-off-by: Martin Stump <martin.stump@mercedes-benz.com>
---
 CMakeLists.txt | 60 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d368067..28a2fb4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,8 +24,10 @@ project(
   HOMEPAGE_URL https://gitlab.eclipse.org/eclipse/simopenpass/yase
   LANGUAGES CXX)
 
-option(Yase_BUILD_TESTS "Build the tests" ${Yase_IS_TOP_LEVEL})
 option(Yase_BUILD_DOCS "Build the documentation" ${Yase_IS_TOP_LEVEL})
+option(Yase_BUILD_TESTS "Build the tests" ${Yase_IS_TOP_LEVEL})
+option(Yase_ENABLE_WARNINGS "Enable compiler warnings" ${Yase_IS_TOP_LEVEL})
+option(Yase_ENABLE_WERROR "Fail on compiler warnings" ${Yase_IS_TOP_LEVEL})
 option(Yase_INSTALL "Enable installation" ${Yase_IS_TOP_LEVEL})
 
 include(CMakeDependentOption)
@@ -52,6 +54,62 @@ if(Yase_BUILD_TESTS)
   enable_testing()
 endif()
 
+if(MSVC)
+  if(Yase_ENABLE_WARNINGS)
+    add_compile_options(
+      /permissive-
+      /w14242
+      /w14254
+      /w14263
+      /w14265
+      /w14287
+      /w14296
+      /w14311
+      /w14545
+      /w14546
+      /w14547
+      /w14549
+      /w14555
+      /w14619
+      /w14640
+      /w14640
+      /w14826
+      /w14905
+      /w14906
+      /w14928
+      /W4
+      /we4289)
+  endif()
+  if(Yase_ENABLE_WERROR)
+    add_compile_options(/WX)
+  endif()
+else()
+  if(Yase_ENABLE_WARNINGS)
+    add_compile_options(
+      -pedantic
+      -Wall
+      -Wcast-align
+      -Wconversion
+      -Wdouble-promotion
+      -Wduplicated-branches
+      -Wduplicated-cond
+      -Wextra
+      -Wformat=2
+      -Wimplicit-fallthrough
+      -Wmisleading-indentation
+      -Wnon-virtual-dtor
+      -Wnull-dereference
+      -Wold-style-cast
+      -Woverloaded-virtual
+      -Wshadow
+      -Wsign-conversion
+      -Wunused)
+  endif()
+  if(Yase_ENABLE_WERROR)
+    add_compile_options(-Werror)
+  endif()
+endif()
+
 add_subdirectory(middle_end)
 
 export(
-- 
GitLab