From 2f8bcc1175657f74b13de72d957bbdba5399084a Mon Sep 17 00:00:00 2001
From: Geoff Viola <geoffrey.viola@asirobots.com>
Date: Sat, 26 Mar 2016 22:59:59 -0600
Subject: [PATCH] added common warning level macros

---
 Modules/Warnings.cmake | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Modules/Warnings.cmake

diff --git a/Modules/Warnings.cmake b/Modules/Warnings.cmake
new file mode 100644
index 0000000..854eb95
--- /dev/null
+++ b/Modules/Warnings.cmake
@@ -0,0 +1,76 @@
+macro(set_warning_level_high)
+  set_warning_level_high_folder()
+endmacro()
+
+macro(set_warning_level_high_folder)
+  if(MSVC)
+    set(flags_for_compilers
+      CMAKE_C_FLAGS
+      CMAKE_CXX_FLAGS
+    )
+    foreach(flags_for_compiler ${flags_for_compilers})
+      if(${${flags_for_compiler}} MATCHES "/W[0-4]")
+        STRING(REGEX REPLACE  "/W[0-4]" "/W4" ${flags_for_compiler} 
+            ${${flags_for_compiler}})
+      else()
+        set(${flags_for_compiler} "${${flags_for_compiler}} /W4")
+      endif()
+    endforeach()
+  elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
+    add_definitions("-Wall -pedantic")
+  elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+    add_definitions("-Weverything")
+  else()
+    message(WARNING "set_warning_level_high_folder: "
+        "compilers \"${CMAKE_C_COMPILER_ID}\" and/or "
+        "\"${CMAKE_CXX_COMPILER_ID}\" not supported")
+  endif()
+endmacro()
+
+macro(set_warnings_as_errors)
+  set_warnings_as_errors_folder()
+endmacro()
+
+macro(set_warnings_as_errors_folder)
+  if (MSVC)
+    add_definitions("/WX")
+  elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX OR
+      CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+    add_definitions("-Werror")
+  elseif(GHSMULTI)
+    add_definitions("--quit_after_warnings")
+  else()
+    message(WARNING "set_warnings_as_errors_folder: "
+        "compilers \"${CMAKE_C_COMPILER_ID}\" and/or "
+        "\"${CMAKE_CXX_COMPILER_ID}\" not supported")
+  endif()
+endmacro()
+
+macro(ignore_warnings)
+  ignore_warnings_folder()
+endmacro()
+
+macro(ignore_warnings_folder)
+  if(MSVC)
+    add_definitions("/W0")
+  elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
+  else()
+    message(WARNING "ignore_warnings_folder: "
+        "compilers \"${CMAKE_C_COMPILER_ID}\" and/or "
+        "\"${CMAKE_CXX_COMPILER_ID}\" not supported")
+  endif()
+endmacro()
+
+macro(ignore_warnings_target target)
+  if(MSVC)
+    # Doesn't do anything when the global call is made
+    set_target_properties(${target} PROPERTIES COMPILE_FLAGS "/W0")
+  elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
+    set_target_properties(${target} PROPERTIES COMPILE_FLAGS "-w")
+  else()
+    message(WARNING "ignore_warnings_target: "
+        "compilers \"${CMAKE_C_COMPILER_ID}\" and/or "
+        "\"${CMAKE_CXX_COMPILER_ID}\" not supported")
+  endif()
+endmacro()
-- 
1.8.1.msysgit.1

