From 2108b1d1953505854d1c6fbd8a5e282576ec154e Mon Sep 17 00:00:00 2001 From: Derek Dai Date: Fri, 3 Mar 2017 08:52:40 +0800 Subject: [PATCH] add compiler flag to do sanity check of undefined behaviours. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9f81e6..690038f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,10 @@ check_c_compiler_flag(-fstack-protector-strong HAS_STACK_PROTCTOR_STRONG) if(HAS_STACK_PROTCTOR_STRONG) set(CMAKE_C_FLAGS "-fstack-protector-strong ${CMAKE_C_FLAGS}") endif() +check_c_compiler_flag(-fsanitize=undefined HAS_SANITIZE_UNDEFINED) +if(HAS_SANITIZE_UNDEFINED) + set(CMAKE_C_FLAGS "-fsanitize=undefined ${CMAKE_C_FLAGS}") +endif() set(CMAKE_C_FLAGS "-std=gnu11 -Wall ${CMAKE_C_FLAGS}") add_definitions(-D_GNU_SOURCE)