Setup CMake to compile with Clang/GCC sanitizers.

See https://github.com/arsenm/sanitizers-cmake for more details.
This commit is contained in:
Dan Glastonbury 2017-05-19 17:06:38 +10:00 committed by Matthew Gregan
parent ac8496de67
commit 033b736e69
3 changed files with 31 additions and 59 deletions

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "googletest"]
path = googletest
url = https://github.com/google/googletest
[submodule "cmake/sanitizers-cmake"]
path = cmake/sanitizers-cmake
url = https://github.com/arsenm/sanitizers-cmake

View file

@ -23,6 +23,9 @@ if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/.git")
message(FATAL_ERROR "submodules not initialized: run\n\tgit submodule update --init --recursive\nin base git checkout")
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/sanitizers-cmake/cmake")
find_package(Sanitizers)
add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
set(gtest_force_shared_crt ON CACHE BOOL "")
add_subdirectory(googletest)
@ -51,6 +54,8 @@ target_compile_definitions(cubeb PRIVATE FLOATING_POINT)
target_compile_definitions(cubeb PRIVATE EXPORT=)
target_compile_definitions(cubeb PRIVATE RANDOM_PREFIX=speex)
add_sanitizers(cubeb)
include(GenerateExportHeader)
generate_export_header(cubeb EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/exports/cubeb_export.h)
target_include_directories(cubeb PUBLIC ${CMAKE_BINARY_DIR}/exports)
@ -157,30 +162,20 @@ endif()
enable_testing()
add_executable(test_sanity test/test_sanity.cpp)
target_include_directories(test_sanity PRIVATE ${gtest_SOURCE_DIR}/include)
target_link_libraries(test_sanity PRIVATE cubeb gtest_main)
add_test(sanity test_sanity)
macro(cubeb_add_test NAME)
add_executable(test_${NAME} test/test_${NAME}.cpp)
target_include_directories(test_${NAME} PRIVATE ${gtest_SOURCE_DIR}/include)
target_include_directories(test_${NAME} PRIVATE src)
target_link_libraries(test_${NAME} PRIVATE cubeb gtest_main)
add_test(${NAME} test_${NAME})
add_sanitizers(test_${NAME})
endmacro(cubeb_add_test)
add_executable(test_tone test/test_tone.cpp)
target_include_directories(test_tone PRIVATE ${gtest_SOURCE_DIR}/include)
target_link_libraries(test_tone PRIVATE cubeb gtest_main)
add_test(tone test_tone)
add_executable(test_audio test/test_audio.cpp)
target_include_directories(test_audio PRIVATE ${gtest_SOURCE_DIR}/include)
target_link_libraries(test_audio PRIVATE cubeb gtest_main)
add_test(audio test_audio)
add_executable(test_record test/test_record.cpp)
target_include_directories(test_record PRIVATE ${gtest_SOURCE_DIR}/include)
target_link_libraries(test_record PRIVATE cubeb gtest_main)
add_test(record test_record)
add_executable(test_devices test/test_devices.cpp)
target_include_directories(test_devices PRIVATE ${gtest_SOURCE_DIR}/include)
target_link_libraries(test_devices PRIVATE cubeb gtest_main)
add_test(devices test_devices)
cubeb_add_test(sanity)
cubeb_add_test(tone)
cubeb_add_test(audio)
cubeb_add_test(record)
cubeb_add_test(devices)
add_executable(test_resampler test/test_resampler.cpp src/cubeb_resampler.cpp $<TARGET_OBJECTS:speex>)
target_include_directories(test_resampler PRIVATE ${gtest_SOURCE_DIR}/include)
@ -191,47 +186,19 @@ target_compile_definitions(test_resampler PRIVATE EXPORT=)
target_compile_definitions(test_resampler PRIVATE RANDOM_PREFIX=speex)
target_link_libraries(test_resampler PRIVATE cubeb gtest_main)
add_test(resampler test_resampler)
add_sanitizers(test_resampler)
add_executable(test_duplex test/test_duplex.cpp)
target_include_directories(test_duplex PRIVATE ${gtest_SOURCE_DIR}/include)
target_link_libraries(test_duplex PRIVATE cubeb gtest_main)
add_test(duplex test_duplex)
cubeb_add_test(duplex)
if (USE_WASAPI)
add_executable(test_overload_callback test/test_overload_callback.cpp)
target_include_directories(test_overload_callback PRIVATE ${gtest_SOURCE_DIR}/include)
target_link_libraries(test_overload_callback PRIVATE cubeb gtest_main)
add_test(overload_callback test_overload_callback)
cubeb_add_test(overload_callback)
endif()
add_executable(test_latency test/test_latency.cpp)
target_include_directories(test_latency PRIVATE ${gtest_SOURCE_DIR}/include)
target_link_libraries(test_latency PRIVATE cubeb gtest_main)
add_test(latency test_latency)
add_executable(test_ring_array test/test_ring_array.cpp)
target_include_directories(test_ring_array PRIVATE ${gtest_SOURCE_DIR}/include)
target_include_directories(test_ring_array PRIVATE src)
target_link_libraries(test_ring_array PRIVATE cubeb gtest_main)
add_test(ring_array test_ring_array)
add_executable(test_mixer test/test_mixer.cpp src/cubeb_mixer.cpp)
target_include_directories(test_mixer PRIVATE ${gtest_SOURCE_DIR}/include)
target_include_directories(test_mixer PRIVATE src)
target_link_libraries(test_mixer PRIVATE cubeb gtest_main)
add_test(mixer test_mixer)
add_executable(test_utils test/test_utils.cpp)
target_include_directories(test_utils PRIVATE ${gtest_SOURCE_DIR}/include)
target_include_directories(test_utils PRIVATE src)
target_link_libraries(test_utils PRIVATE cubeb gtest_main)
add_test(utils test_utils)
add_executable(test_ring_buffer test/test_ring_buffer.cpp)
target_include_directories(test_ring_buffer PRIVATE ${gtest_SOURCE_DIR}/include)
target_include_directories(test_ring_buffer PRIVATE src)
target_link_libraries(test_ring_buffer PRIVATE cubeb gtest_main)
add_test(ring_buffer test_ring_buffer)
cubeb_add_test(latency test_latency)
cubeb_add_test(ring_array)
cubeb_add_test(mixer)
cubeb_add_test(utils)
cubeb_add_test(ring_buffer)
if(USE_AUDIOUNIT)
add_executable(test_deadlock test/test_deadlock.cpp)
@ -239,4 +206,5 @@ if(USE_AUDIOUNIT)
target_include_directories(test_deadlock PRIVATE src)
target_link_libraries(test_deadlock PRIVATE cubeb gtest_main)
add_test(deadlock test_deadlock)
add_sanitizers(test_deadlock)
endif()

@ -0,0 +1 @@
Subproject commit f09151bc87ba210f955d58dffc07b0ee1e755234