mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 21:13:34 +08:00
cmake add asan and ubsan
This commit is contained in:
+35
-1
@@ -20,6 +20,8 @@ option(SUPPORT_STDIOSTREAM "If enabled provides support for << operator (as used
|
|||||||
option(TESTING "Enable testing" OFF)
|
option(TESTING "Enable testing" OFF)
|
||||||
option(FORMAT "Enable formatting" OFF)
|
option(FORMAT "Enable formatting" OFF)
|
||||||
option(COV_HTML "Display html for coverage" OFF)
|
option(COV_HTML "Display html for coverage" OFF)
|
||||||
|
option(ASAN "Enable address sanitizer" OFF)
|
||||||
|
option(UBSAN "Enable undefined behaviour sanitizer" OFF)
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@ add_compile_options(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# clang tolerate unknown gcc options
|
# clang tolerate unknown gcc options
|
||||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||||
add_compile_options(
|
add_compile_options(
|
||||||
-Wno-error=unused-command-line-argument-hard-error-in-future
|
-Wno-error=unused-command-line-argument-hard-error-in-future
|
||||||
-Wno-unknown-warning-option
|
-Wno-unknown-warning-option
|
||||||
@@ -86,6 +88,38 @@ else()
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# santiziers (ASAN, UBSAN)
|
||||||
|
if(ASAN)
|
||||||
|
message(STATUS "address sanitizer enabled")
|
||||||
|
|
||||||
|
# environment variables
|
||||||
|
# ASAN_OPTIONS=detect_stack_use_after_return=1
|
||||||
|
# ASAN_OPTIONS=check_initialization_order=1
|
||||||
|
|
||||||
|
add_compile_options(
|
||||||
|
-fsanitize=address
|
||||||
|
-g3
|
||||||
|
-O1
|
||||||
|
-fno-omit-frame-pointer
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address)
|
||||||
|
|
||||||
|
elseif(UBSAN)
|
||||||
|
message(STATUS "undefined behaviour sanitizer enabled")
|
||||||
|
|
||||||
|
add_compile_options(
|
||||||
|
-fsanitize=undefined
|
||||||
|
-fsanitize=integer
|
||||||
|
-g3
|
||||||
|
-O1
|
||||||
|
-fno-omit-frame-pointer
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
|
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
|
||||||
|
|
||||||
if(TESTING)
|
if(TESTING)
|
||||||
|
|||||||
Reference in New Issue
Block a user