Skip to content

Commit

Permalink
Add options for building with address and undefined behavior sanitizers
Browse files Browse the repository at this point in the history
  • Loading branch information
pmatilai committed Mar 4, 2024
1 parent eccde48 commit 40ff6c9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set(POPT_SOVERSION 0)

# Configurable stuff
option(ENABLE_WERROR "Stop build on warnings" OFF)
option(ENABLE_ASAN "Enable address-sanitizer" OFF)
option(ENABLE_UBSAN "Enable undefined behavior-sanitizer" OFF)

# Set up GNU conventions and standard FHS paths
include(GNUInstallDirs)
Expand Down Expand Up @@ -86,6 +88,20 @@ if (ENABLE_WERROR)
add_compile_options(-Werror)
endif()

# Sanitizers
if (ENABLE_ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
if (ENABLE_UBSAN)
add_compile_options(-fsanitize=undefined)
add_link_options(-fsanitize=undefined)
endif()
if (ENABLE_ASAN OR ENABLE_UBSAN)
add_compile_options(-fno-omit-frame-pointer)
endif()


add_subdirectory(src)
add_subdirectory(doc)
if (EXISTS po/popt.pot)
Expand Down

0 comments on commit 40ff6c9

Please sign in to comment.