Skip to content

Commit

Permalink
Made the asan build only address sanitize the Zimtohrli code, not all…
Browse files Browse the repository at this point in the history
… the dependencies as well, to avoid exploding on unsanitary deps.
  • Loading branch information
Martin Bruse authored and zond committed Apr 25, 2024
1 parent 389db42 commit 4be4e54
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ include(cmake/deps.cmake)
enable_testing()
include(GoogleTest)

option(ZIMTOHRLI_ASAN "Build Zimtohrli with address sanitizer." OFF)
macro(asan_target TARGET)
if (ZIMTOHRLI_ASAN)
target_compile_options(${TARGET} PRIVATE -fsanitize=address)
target_link_options(${TARGET} PRIVATE -fsanitize=address)
endif()
endmacro()

add_library(zimtohrli_base STATIC
cpp/zimt/audio.cc
cpp/zimt/audio.h
Expand All @@ -29,6 +37,7 @@ add_library(zimtohrli_base STATIC
cpp/zimt/zimtohrli.cc
cpp/zimt/zimtohrli.h
)
asan_target(zimtohrli_base)
target_include_directories(zimtohrli_base PUBLIC cpp)
target_link_libraries(zimtohrli_base PRIVATE absl::check)
target_link_libraries(zimtohrli_base PUBLIC hwy portaudio absl::statusor absl::span sndfile)
Expand All @@ -38,6 +47,7 @@ add_library(zimtohrli_visqol_adapter STATIC
cpp/zimt/visqol.cc
cpp/zimt/resample.h
)
asan_target(zimtohrli_visqol_adapter)
target_include_directories(zimtohrli_visqol_adapter PUBLIC cpp)
target_link_libraries(zimtohrli_visqol_adapter PRIVATE visqol samplerate hwy)
target_link_libraries(zimtohrli_visqol_adapter PUBLIC absl::span)
Expand All @@ -57,6 +67,7 @@ add_library(zimtohrli_goohrli_glue STATIC
cpp/zimt/goohrli.cc
go/goohrli/goohrli.h
)
asan_target(zimtohrli_goohrli_glue)
target_include_directories(zimtohrli_goohrli_glue PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/go/goohrli ${CMAKE_CURRENT_SOURCE_DIR}/go/gosqol)
target_link_libraries(zimtohrli_goohrli_glue zimtohrli_base zimtohrli_visqol_adapter)

Expand Down Expand Up @@ -87,13 +98,15 @@ add_library(zimtohrli_ux STATIC
cpp/zimt/ux.cc
cpp/zimt/ux.h
)
asan_target(zimtohrli_ux)
target_include_directories(zimtohrli_ux PRIVATE ${imgui_SOURCE_DIR}/backends ${gles_INCLUDE_DIRS})
target_include_directories(zimtohrli_ux PUBLIC ${imgui_SOURCE_DIR})
target_link_libraries(zimtohrli_ux zimtohrli_base glfw OpenGL::GL imgui)

add_executable(zimtohrli_compare
cpp/zimt/compare.cc
)
asan_target(zimtohrli_compare)
target_link_libraries(zimtohrli_compare zimtohrli_ux zimtohrli_base absl::flags_parse)
set_target_properties(zimtohrli_compare PROPERTIES
PREFIX ""
Expand Down
2 changes: 2 additions & 0 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_executable(zimtohrli_test
cpp/zimt/zimtohrli_test.cc
cpp/zimt/test_file_paths.cc
)
asan_target(zimtohrli_test)
target_link_libraries(zimtohrli_test zimtohrli_base gtest gmock_main benchmark)
target_compile_definitions(zimtohrli_test PRIVATE CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR})
gtest_discover_tests(zimtohrli_test)
Expand Down Expand Up @@ -57,4 +58,5 @@ add_executable(zimtohrli_benchmark
cpp/zimt/masking_test.cc
cpp/zimt/zimtohrli_test.cc
)
asan_target(zimtohrli_benchmark)
target_link_libraries(zimtohrli_benchmark zimtohrli_base gtest gmock benchmark_main)
2 changes: 1 addition & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ "${1}" == "debug" ]; then
(cd debug_build && cmake -G Ninja -DCMAKE_C_FLAGS='-fPIC' -DCMAKE_CXX_FLAGS='-fPIC' -DCMAKE_BUILD_TYPE=RelWithDebInfo ..)
elif [ "${1}" == "asan" ]; then
mkdir -p asan_build
(cd asan_build && cmake -G Ninja -DCMAKE_C_FLAGS='-fPIC -fsanitize=address' -DCMAKE_CXX_FLAGS='-fPIC -fsanitize=address' -DCMAKE_BUILD_TYPE=RelWithDebInfo ..)
(cd asan_build && cmake -G Ninja -DCMAKE_C_FLAGS='-fPIC' -DZIMTOHRLI_ASAN=1 -DCMAKE_CXX_FLAGS='-fPIC' -DCMAKE_BUILD_TYPE=RelWithDebInfo ..)
else
mkdir -p build
(cd build && cmake -G Ninja -DCMAKE_C_FLAGS='-fPIC' -DCMAKE_CXX_FLAGS='-fPIC' -DCMAKE_BUILD_TYPE=Release ..)
Expand Down

0 comments on commit 4be4e54

Please sign in to comment.