aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDan Glastonbury <[email protected]>2017-05-19 17:06:38 +1000
committerMatthew Gregan <[email protected]>2017-05-22 13:06:17 +1200
commit033b736e69bb2011594284a7e7b5638e25372b68 (patch)
tree3772a4572e6e1cf1f63e261a5579cb606871fae0
parentac8496de671eaa361e989fc2ce5036b64776b19b (diff)
downloadcubeb-033b736e69bb2011594284a7e7b5638e25372b68.tar.gz
cubeb-033b736e69bb2011594284a7e7b5638e25372b68.zip
Setup CMake to compile with Clang/GCC sanitizers.
See https://github.com/arsenm/sanitizers-cmake for more details.
-rw-r--r--.gitmodules3
-rw-r--r--CMakeLists.txt92
m---------cmake/sanitizers-cmake0
3 files changed, 33 insertions, 62 deletions
diff --git a/.gitmodules b/.gitmodules
index 7e38e13..a819201 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -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
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6397db4..1c97e23 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
-
-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)
+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)
+
+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)
-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(overload_callback)
+endif()
+
+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()
diff --git a/cmake/sanitizers-cmake b/cmake/sanitizers-cmake
new file mode 160000
+Subproject f09151bc87ba210f955d58dffc07b0ee1e75523