Skip to content

Commit

Permalink
build cmake: added sanitize option
Browse files Browse the repository at this point in the history
Signed-off-by: John Sanpe <[email protected]>
  • Loading branch information
sanpeqf committed Feb 29, 2024
1 parent 8a792db commit 3d4285e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
21 changes: 1 addition & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.21)
project(adbd LANGUAGES C)


include(cmake/bfdev.cmake)
include(cmake/sanitize.cmake)

set(HEADERS
${PROJECT_SOURCE_DIR}/include/xdbd.h
Expand Down Expand Up @@ -33,25 +33,6 @@ set(
${PROJECT_SOURCE_DIR}/src/core/
)

set(BFDEV_ASAN true)

if(BFDEV_ASAN)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-fsanitize=address \
-fsanitize=undefined \
-fsanitize-recover=all \
-fno-omit-frame-pointer \
-fno-stack-protector"
)
if(NOT APPLE)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-fsanitize=leak"
)
endif()
endif()

include_directories(${XADB_INCLUDES})

add_executable(adbd ${SRCS})
Expand Down
47 changes: 47 additions & 0 deletions cmake/sanitize.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-License-Identifier: GPL-2.0-or-later */
#
# Copyright(c) 2024 John Sanpe <[email protected]>
#

option(XDBD_ASAN "Enable Address Sanitizer" OFF)
option(XDBD_UBSAN "Enable Undefined Behaviour Sanitizer" OFF)
option(XDBD_GCOV "Enable Code Coverage Test" OFF)

if(XDBD_ASAN)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-fsanitize=address \
-fsanitize=undefined \
-fsanitize-recover=all \
-fno-omit-frame-pointer \
-fno-stack-protector"
)
if(NOT APPLE)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-fsanitize=leak"
)
endif()
endif()

if(XDBD_UBSAN)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-fsanitize=alignment \
-fsanitize=bounds \
-fsanitize=shift \
-fsanitize=integer-divide-by-zero \
-fsanitize=unreachable \
-fsanitize=bool \
-fsanitize=enum \
-fsanitize-undefined-trap-on-error"
)
endif()

if(XDBD_GCOV)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-fprofile-arcs \
-ftest-coverage"
)
endif()

0 comments on commit 3d4285e

Please sign in to comment.