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)