diff --git a/CMakeLists.txt b/CMakeLists.txt index 52c8b10fc..7e5601981 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/other/travis/toxcore-script b/other/travis/toxcore-script index 591e158e7..78c1a44c6 100755 --- a/other/travis/toxcore-script +++ b/other/travis/toxcore-script @@ -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