From b3d77c8ea035e1fb42131eec5c274ca0adce5627 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Fri, 28 Apr 2017 22:37:19 +0300 Subject: [PATCH] Implemented checking for UBSAN compiler option for Debug (and RelWithDebInfo) build types. --- src/CMakeLists.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 310668a3..80d0b9af 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -135,8 +135,19 @@ message(STATUS "Build configuration: ${CMAKE_BUILD_TYPE}") set(DEBUG_FLAGS "-ggdb -fno-omit-frame-pointer") set(RELEASE_FLAGS "-DNDEBUG") -if(DEBUG_USE_UBSAN) - set(DEBUG_FLAGS "${DEBUG_FLAGS} -fsanitize=undefined") +if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + # "Debug build" is a build where ${DEBUG_FLAGS} are used. + set(DEBUG_BUILD TRUE) +endif() + +if(DEBUG_USE_UBSAN AND DEFINED DEBUG_BUILD) + include(CheckCCompilerFlag) + CHECK_C_COMPILER_FLAG("-fsanitize=undefined" COMPILER_SUPPORTS_UBSAN) + if(COMPILER_SUPPORTS_UBSAN) + set(DEBUG_FLAGS "${DEBUG_FLAGS} -fsanitize=undefined") + else() + message(STATUS " DEBUG_USE_UBSAN not supported by compiler, turned off.") + endif() endif() if(DEBUG_USE_ASAN)