From 41a9cf5528032dcd598b3760442dab1559b31278 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Mon, 23 Apr 2018 17:32:22 +0200
Subject: [PATCH] Add block to define compilation flags

---
 CMakeLists.txt | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 471495fe..debc99e2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,6 +33,29 @@ if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
   enable_testing()
   include(CTest)
 
+  include (CheckCCompilerFlag)
+
+  # Set warnings for debug builds
+  check_c_compiler_flag( "-Wall" HAVE_WALL )
+  if( HAVE_WALL )
+    set( C_WFLAGS "${C_WFLAGS} -Wall" )
+  endif( HAVE_WALL )
+  check_c_compiler_flag( "-Wextra" HAVE_WEXTRA )
+  if( HAVE_WEXTRA )
+    set( C_WFLAGS "${C_WFLAGS} -Wextra" )
+  endif( HAVE_WEXTRA )
+
+  set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_WFLAGS}" )
+
+  # add gdb symbols in debug and relwithdebinfo
+  check_c_compiler_flag( "-g3" HAVE_G3 )
+  if( HAVE_G3 )
+    set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3" )
+    set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -g3" )
+  else()
+    set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0" )
+  endif( HAVE_G3 )
+
 else()
   set( BUILD_AS_SUBPROJECT ON )
 
-- 
GitLab