Commit ac62bc74 authored by David Frank's avatar David Frank
Browse files

Add Sanitizers

Sanitizers where added to CMake. Build with ELSA_BUILT_WITH_SANITIZERS and choose Thread or Address sanitizer
parent 001bd049
Pipeline #163415 passed with stages
in 1 minute and 45 seconds
......@@ -7,7 +7,7 @@ project(elsa VERSION 0.5
# ------------ elsa options ------------
# ------------
# detect if elsa is being bundled, disable install and tests
# detect if elsa is being bundled, disable some options based on this
if (NOT DEFINED ELSA_MASTER_PROJECT)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(ELSA_MASTER_PROJECT ON)
......@@ -16,13 +16,14 @@ if (NOT DEFINED ELSA_MASTER_PROJECT)
endif()
endif ()
option(ELSA_TESTING "Enable the unit tests of elsa" ON)
option(ELSA_TESTING "Enable the unit tests of elsa" ${ELSA_MASTER_PROJECT})
option(ELSA_INSTALL "Generate the install target" ${ELSA_MASTER_PROJECT})
option(GIT_SUBMODULE "Check submodules during build" ${ELSA_MASTER_PROJECT})
option(ELSA_BUILD_EXAMPLES "Build examples" ${ELSA_MASTER_PROJECT})
option(ELSA_BUILD_CUDA_PROJECTORS "Attempts to build CUDA projectors if set" ON)
option(ELSA_BUILD_WITH_MORE_WARNINGS "Reduce noise of warnings, but make chaning fast and easy" OFF)
option(ELSA_BUILD_WITH_SANITIZERS "Build with Sanitizers. Pass ELSA_SANITIZE_THREAD or ELSA_SANITIZE_ADDRESS" ON)
# ------------ general setup -----------
# ------------
......@@ -74,6 +75,7 @@ if(ELSA_TESTING)
enable_testing()
add_subdirectory(thirdparty/Catch2)
# add the CMake modules for automatic test discovery
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/thirdparty/Catch2/contrib" ${CMAKE_MODULE_PATH})
else(ELSA_TESTING)
......
if(ELSA_SANITIZE_THREAD AND ELSA_SANITIZE_ADDRESS)
message(FATAL_ERROR "AddressSanitizer is not compatible with ThreadSanitizer.")
endif()
if(ELSA_SANITIZE_ADDRESS)
message(STATUS "AddressSanitizer enabled")
set(SANITIZER_FLAGS "-fsanitize=address,undefined")
add_compile_options("-fno-sanitize=signed-integer-overflow")
endif()
if(ELSA_SANITIZE_THREAD)
message(STATUS "ThreadSanitizer enabled")
set(SANITIZER_FLAGS "-fsanitize=thread")
endif()
if(ELSA_SANITIZE_THREAD OR ELSA_SANITIZE_ADDRESS)
add_compile_options(${SANITIZER_FLAGS})
add_compile_options("-fno-sanitize-recover=all")
add_compile_options("-fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS} -fuse-ld=gold")
endif()
......@@ -24,18 +24,24 @@ add_subdirectory(generators)
#---------------------------------------------------------------------------------------
# Turn on compiler warnings and sanitizers for all components on, if wanted
#---------------------------------------------------------------------------------------
if(${ELSA_MASTER_PROJECT} AND ${ELSA_BUILD_WITH_MORE_WARNINGS})
if(${ELSA_MASTER_PROJECT})
foreach (_component ${ELSA_REGISTERED_COMPONENTS})
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
target_compile_options( elsa_${_component} PUBLIC -Wall -Wextra -Wconversion -pedantic -Wfatal-errors)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options( elsa_${_component} PUBLIC /W3 /WX )
endif()
#include(cmake/sanitizers.cmake)
# add warnings if enabled
if(${ELSA_BUILD_WITH_MORE_WARNINGS})
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
target_compile_options( elsa_${_component} PUBLIC -Wall -Wextra -Wconversion -pedantic -Wfatal-errors)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options( elsa_${_component} PUBLIC /W3 /WX )
endif()
endif(${ELSA_BUILD_WITH_MORE_WARNINGS})
endforeach (_component ELSA_REGISTERED_COMPONENTS)
endif(${ELSA_MASTER_PROJECT} AND ${ELSA_BUILD_WITH_MORE_WARNINGS})
# add sanitizers if enabled
if(${ELSA_BUILD_WITH_SANITIZERS})
include(${PROJECT_SOURCE_DIR}/cmake/Sanitizers.cmake)
endif(${ELSA_BUILD_WITH_SANITIZERS})
endif(${ELSA_MASTER_PROJECT})
# propogate the variable to the parent scope
set(ELSA_REGISTERED_COMPONENTS "${ELSA_REGISTERED_COMPONENTS};" PARENT_SCOPE)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment