Skip to content

Commit

Permalink
Refs #11808. Add WITH_UBSAN option to cmake script.
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsteve committed May 19, 2015
1 parent 49fab8b commit 5b006c9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Code/Mantid/Build/CMake/GNUSetup.cmake
Expand Up @@ -14,6 +14,11 @@ elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
message( STATUS "clang version ${CMAKE_CXX_COMPILER_VERSION}" )
endif()

#Use the old ABI until the dust has settled and all dependencies are built with the new ABI.
if ( CMAKE_COMPILER_IS_GNUCXX AND NOT (GCC_COMPILER_VERSION VERSION_LESS "5.1.0"))
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()

# Global warning flags.
set( GNUFLAGS "-Wall -Wextra -Wconversion -Winit-self -Wpointer-arith -Wcast-qual -Wcast-align -fno-common" )
# Disable some warnings about deprecated headers and type conversions that
Expand Down Expand Up @@ -46,6 +51,20 @@ if(WITH_ASAN)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address -lasan" )
endif()

option(WITH_UBSAN "Enable undefined behavior sanitizer" OFF)
if(WITH_UBSAN)
message(STATUS "enabling undefined behavior sanitizers")
set( UBSAN_NO_RECOVER "-fno-sanitize-recover")
if ( CMAKE_COMPILER_IS_GNUCXX AND GCC_COMPILER_VERSION VERSION_LESS "5.1.0")
set( UBSAN_NO_RECOVER "")
endif()
set(SAN_FLAGS "-fno-omit-frame-pointer -fno-common -fsanitize=undefined ${UBSAN_NO_RECOVER}")
add_compile_options(-fno-omit-frame-pointer -fno-common -fsanitize=undefined ${UBSAN_NO_RECOVER})
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SAN_FLAGS}" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SAN_FLAGS}" )
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SAN_FLAGS}" )
endif()

# Set the options for gcc and g++
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GNUFLAGS}" )
# -Wno-overloaded-virtual is down here because it's not applicable to the C_FLAGS
Expand Down

0 comments on commit 5b006c9

Please sign in to comment.