From c5c7835dbbc54bb5c616a9a174932df6a297d0c1 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 16 Nov 2021 20:18:09 +0100 Subject: [PATCH] Added an UndefinedBehaviorSanitizer option to the CMake configuration file. --- CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9ad2c5e2..c03021cb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ option(VLC_PLAYER "Set to ON to build the VLC-based video player" ${VLC_PLAYER}) option(CLANG_TIDY "Set to ON to build using the clang-tidy static analyzer" ${CLANG_TIDY}) option(ASAN "Set to ON to build with AddressSanitizer" ${ASAN}) option(TSAN "Set to ON to build with ThreadSanitizer" ${TSAN}) +option(UBSAN "Set to ON to build with UndefinedBehaviorSanitizer" ${UBSAN}) if(CLANG_TIDY) find_program(CLANG_TIDY_BINARY NAMES clang-tidy) @@ -213,6 +214,15 @@ if(TSAN) endif() endif() +if(UBSAN) + message("-- Building with UndefinedBehaviorSanitizer") + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + message(FATAL_ERROR "-- UndefinedBehaviorSanitizer not available for MSVC") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") + endif() +endif() + # The following removes half of the ranlib warnings on macOS regarding no symbols for files # that are #ifdef'ed away. There must be a way to remove the other half as well? if(APPLE)