Skip to content

Commit 11c28ad

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 208da76 commit 11c28ad

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

CMakeLists.txt

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,23 +289,30 @@ if(SDLNET_INSTALL)
289289
endif()
290290

291291
if(SDLNET_SAMPLES)
292-
add_executable(voipchat examples/voipchat.c)
293-
add_executable(simple-http-get examples/simple-http-get.c)
294-
add_executable(resolve-hostnames examples/resolve-hostnames.c)
295-
add_executable(get-local-addrs examples/get-local-addrs.c)
296-
297-
set(examples voipchat simple-http-get resolve-hostnames get-local-addrs)
298-
foreach(example IN LISTS examples)
299-
target_link_libraries(${example} PRIVATE SDL3_net::SDL3_net SDL3::SDL3)
300-
set_property(TARGET ${example} PROPERTY C_STANDARD 99)
301-
set_property(TARGET ${example} PROPERTY C_EXTENSIONS FALSE)
302-
sdl_add_warning_options(${example} WARNING_AS_ERROR ${SDLNET_WERROR})
292+
function(add_sdl_net_example_executable TARGET)
293+
if(ANDROID)
294+
add_library(${TARGET} SHARED ${ARGN})
295+
else()
296+
add_executable(${TARGET} ${ARGN})
297+
endif()
298+
sdl_add_warning_options(${TARGET} WARNING_AS_ERROR ${SDLTTF_WERROR})
299+
sdl_target_link_options_no_undefined(${TARGET})
300+
target_link_libraries(${TARGET} PRIVATE SDL3_net::${sdl3_net_target_name})
301+
target_link_libraries(${TARGET} PRIVATE ${sdl3_target_name})
302+
set_property(TARGET ${TARGET} PROPERTY C_STANDARD 99)
303+
set_property(TARGET ${TARGET} PROPERTY C_EXTENSIONS FALSE)
304+
303305
if(SDLNET_SAMPLES_INSTALL)
304-
install(TARGETS ${example}
305-
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
306+
install(TARGETS ${TARGET}
307+
RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3_net"
306308
)
307309
endif()
308-
endforeach()
310+
endfunction()
311+
add_sdl_net_example_executable(voipchat examples/voipchat.c)
312+
add_sdl_net_example_executable(simple-http-get examples/simple-http-get.c)
313+
add_sdl_net_example_executable(resolve-hostnames examples/resolve-hostnames.c)
314+
add_sdl_net_example_executable(get-local-addrs examples/get-local-addrs.c)
315+
309316
# Build at least one example in C90
310317
set_property(TARGET get-local-addrs PROPERTY C_STANDARD 90)
311318
endif()

0 commit comments

Comments
 (0)