mirror of
https://github.com/TokTok/c-toxcore
synced 2026-09-17 03:44:45 +00:00
Add address sanitizer option to cmake file.
This commit is contained in:
@@ -26,6 +26,18 @@ if(ASSOC_DHT)
|
||||
add_definitions(-DENABLE_ASSOC_DHT=1)
|
||||
endif()
|
||||
|
||||
option(ASAN "Enable address-sanitizer to detect invalid memory accesses" OFF)
|
||||
if(ASAN)
|
||||
include(CheckCCompilerFlag)
|
||||
set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
|
||||
set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address")
|
||||
check_c_compiler_flag("-fsanitize=address" HAVE_ASAN)
|
||||
if(HAVE_ASAN)
|
||||
set(CMAKE_C_FLAGS "-fsanitize=address")
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}")
|
||||
endif()
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@ git diff --exit-code
|
||||
|
||||
# Build toxcore and run tests.
|
||||
export CFLAGS="-O3 -fprofile-arcs -ftest-coverage -DTRAVIS_ENV=1"
|
||||
RUN $CMAKE -B$BUILD_DIR -H. -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX -DDEBUG=ON -DASSOC_DHT=ON
|
||||
# TODO(iphydf): Enable ASAN. It currently has some bad interactions with gcov,
|
||||
# so it's disabled on Travis.
|
||||
RUN $CMAKE -B$BUILD_DIR -H. -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX -DDEBUG=ON -DASSOC_DHT=ON #-DASAN=ON
|
||||
|
||||
export CTEST_OUTPUT_ON_FAILURE=1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user