Skip to content

Commit d2ddf28

Browse files
committed
cmake: build examples as shared library on Android
These examples won't be useful without accompanying Java classes or Android manifest, but they will at least successfully link.
1 parent a83eb9c commit d2ddf28

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

CMakeLists.txt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,27 +1212,33 @@ if(SDLMIXER_SAMPLES)
12121212
check_include_file("signal.h" HAVE_SIGNAL_H)
12131213
check_symbol_exists("setbuf" "stdio.h" HAVE_SETBUF)
12141214

1215-
add_executable(playmus examples/playmus.c)
1216-
add_executable(playwave examples/playwave.c)
1217-
1218-
foreach(prog playmus playwave)
1219-
sdl_add_warning_options(${prog} WARNING_AS_ERROR ${SDLMIXER_WERROR})
1220-
target_link_libraries(${prog} PRIVATE SDL3::SDL3_test)
1221-
target_link_libraries(${prog} PRIVATE SDL3_mixer::${sdl3_mixer_target_name})
1222-
target_link_libraries(${prog} PRIVATE ${sdl3_target_name})
1215+
function(add_sdl_mixer_example_executable TARGET)
1216+
if(ANDROID)
1217+
add_library(${TARGET} SHARED ${ARGN})
1218+
else()
1219+
add_executable(${TARGET} ${ARGN})
1220+
endif()
1221+
sdl_add_warning_options(${TARGET} WARNING_AS_ERROR ${SDLMIXER_WERROR})
1222+
sdl_target_link_options_no_undefined(${TARGET})
1223+
target_link_libraries(${TARGET} PRIVATE SDL3::SDL3_test)
1224+
target_link_libraries(${TARGET} PRIVATE SDL3_mixer::${sdl3_mixer_target_name})
1225+
target_link_libraries(${TARGET} PRIVATE ${sdl3_target_name})
12231226
if(HAVE_SIGNAL_H)
1224-
target_compile_definitions(${prog} PRIVATE HAVE_SIGNAL_H)
1227+
target_compile_definitions(${TARGET} PRIVATE HAVE_SIGNAL_H)
12251228
endif()
12261229
if(HAVE_SETBUF)
1227-
target_compile_definitions(${prog} PRIVATE HAVE_SETBUF)
1230+
target_compile_definitions(${TARGET} PRIVATE HAVE_SETBUF)
12281231
endif()
12291232

12301233
if(SDLMIXER_SAMPLES_INSTALL)
1231-
install(TARGETS ${prog}
1234+
install(TARGETS ${TARGET}
12321235
RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3_mixer"
12331236
)
12341237
endif()
1235-
endforeach()
1238+
endfunction()
1239+
1240+
add_sdl_mixer_example_executable(playmus examples/playmus.c)
1241+
add_sdl_mixer_example_executable(playwave examples/playwave.c)
12361242
endif()
12371243

12381244
set(available_deps)

0 commit comments

Comments
 (0)