Skip to content

Commit

Permalink
Merge pull request #47 from CESNET/cmake-sanitizers
Browse files Browse the repository at this point in the history
CMake: introduce optional build with ASAN and UBSAN sanitizers
  • Loading branch information
SiskaPavel authored Oct 9, 2024
2 parents ecbcb19 + 5b192ee commit 8e87067
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(NM_NG_ENABLE_DOC_DOXYGEN "Enable build of code documentation" OFF)
option(NM_NG_BUILD_WITH_ASAN "Build with Address Sanitizer (only for CMAKE_BUILD_TYPE=Debug)" OFF)
option(NM_NG_BUILD_WITH_UBSAN "Build with Undefined Behavior Sanitizer (only for CMAKE_BUILD_TYPE=Debug)" OFF)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Wunused -Wconversion -Wsign-conversion")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -ggdb3")

if (NM_NG_BUILD_WITH_ASAN)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize-recover=address")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize-recover=address")
endif()

if (NM_NG_BUILD_WITH_UBSAN)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=undefined")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=undefined")
endif()

include(cmake/dependencies.cmake)

add_subdirectory(modules)
Expand Down

0 comments on commit 8e87067

Please sign in to comment.