Skip to content

Commit b7178ec

Browse files
committed
cmake: add SDLMIXER_TESTS option for tests
1 parent 75869dd commit b7178ec

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ jobs:
116116
-DSDLMIXER_VORBIS_VORBISFILE=ON \
117117
-DSDLMIXER_STRICT=ON \
118118
-DSDLMIXER_WERROR=ON \
119+
-DSDLMIXER_TESTS=ON \
120+
-DSDLMIXER_TESTS_INSTALL=ON \
119121
-DSDLMIXER_INSTALL_MAN=ON \
120122
-DCMAKE_INSTALL_PREFIX=prefix_cmake \
121123
${NULL+}

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ if(SDLMIXER_STRICT)
120120
set(fatal_error "FATAL_ERROR")
121121
endif()
122122

123+
option(SDLMIXER_TESTS "Build unit tests?" OFF)
124+
option(SDLMIXER_TESTS_INSTALL "Install unit tests?" OFF)
125+
123126
option(SDLMIXER_SAMPLES "Build the SDL3_mixer sample program(s)" ${SDLMIXER_SAMPLES_DEFAULT})
124127
cmake_dependent_option(SDLMIXER_SAMPLES_INSTALL "Install the SDL3_mixer sample program(s)" OFF "SDLMIXER_SAMPLES;SDLMIXER_INSTALL" OFF)
125128

@@ -1153,6 +1156,10 @@ if(SDLMIXER_SAMPLES)
11531156
add_sdl_mixer_example_executable(playwave examples/playwave.c)
11541157
endif()
11551158

1159+
if(SDLMIXER_TESTS)
1160+
add_subdirectory(test)
1161+
endif()
1162+
11561163
set(available_deps)
11571164
set(unavailable_deps)
11581165
foreach(dep IN LISTS SDLMIXER_BACKENDS)

test/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# CMake script for building SDL_mixer tests
2+
3+
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
4+
5+
set(RESOURCE_FILES
6+
)
7+
8+
function(add_sdl_mixer_test_executable TARGET)
9+
add_executable(${TARGET} ${ARGN})
10+
target_compile_definitions(${TARGET}
11+
PRIVATE
12+
$<TARGET_PROPERTY:${sdl3_mixer_target_name},COMPILE_DEFINITIONS>
13+
)
14+
sdl_add_warning_options(${TARGET} WARNING_AS_ERROR ${SDLMIXER_WERROR})
15+
target_link_libraries(${TARGET} PRIVATE SDL3_mixer::SDL3_mixer SDL3::SDL3)
16+
17+
if(SDLMIXER_TESTS_INSTALL)
18+
install(
19+
TARGETS ${TARGET}
20+
DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/${PROJECT_NAME}"
21+
)
22+
if(MSVC)
23+
SDL_install_pdb("${TARGET}" "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/${PROJECT_NAME}")
24+
endif()
25+
endif()
26+
endfunction()
27+
28+
add_sdl_mixer_test_executable(testaudiodecoder testaudiodecoder.c)
29+
add_sdl_mixer_test_executable(testmixer testmixer.c)
30+
add_sdl_mixer_test_executable(testspacialization testspatialization.c)
31+
32+
if(SDLMIXER_TESTS_INSTALL)
33+
install(
34+
FILES ${RESOURCE_FILES}
35+
DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/${PROJECT_NAME}"
36+
)
37+
endif()

0 commit comments

Comments
 (0)