Skip to content

Commit 8537559

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 81c273d commit 8537559

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

CMakeLists.txt

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,29 @@ if(SDLTTF_INSTALL)
545545
endif()
546546

547547
if(SDLTTF_SAMPLES)
548-
add_executable(glfont examples/glfont.c)
549-
add_executable(showfont examples/showfont.c examples/editbox.c)
550-
add_executable(testapp examples/testapp.c)
551-
add_executable(testgputext examples/testgputext.c)
548+
function(add_sdl_ttf_example_executable TARGET)
549+
if(ANDROID)
550+
add_library(${TARGET} SHARED ${ARGN})
551+
else()
552+
add_executable(${TARGET} ${ARGN})
553+
endif()
554+
sdl_add_warning_options(${TARGET} WARNING_AS_ERROR ${SDLTTF_WERROR})
555+
target_link_libraries(${TARGET} PRIVATE SDL3_ttf::${sdl3_ttf_target_name})
556+
target_link_libraries(${TARGET} PRIVATE ${sdl3_target_name})
557+
if("c_std_99" IN_LIST CMAKE_C_COMPILE_FEATURES)
558+
target_compile_features(${TARGET} PRIVATE c_std_99)
559+
endif()
560+
561+
if(SDLTTF_SAMPLES_INSTALL)
562+
install(TARGETS ${TARGET}
563+
RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3_ttf"
564+
)
565+
endif()
566+
endfunction()
567+
add_sdl_ttf_example_executable(glfont examples/glfont.c)
568+
add_sdl_ttf_example_executable(showfont examples/showfont.c examples/editbox.c)
569+
add_sdl_ttf_example_executable(testapp examples/testapp.c)
570+
add_sdl_ttf_example_executable(testgputext examples/testgputext.c)
552571

553572
set(OpenGL_GL_PREFERENCE GLVND)
554573
find_package(OpenGL)
@@ -559,21 +578,6 @@ if(SDLTTF_SAMPLES)
559578
target_compile_definitions(glfont PRIVATE HAVE_OPENGL)
560579
target_link_libraries(glfont PRIVATE OpenGL::GL)
561580
endif()
562-
563-
foreach(prog glfont showfont testapp testgputext)
564-
sdl_add_warning_options(${prog} WARNING_AS_ERROR ${SDLTTF_WERROR})
565-
target_link_libraries(${prog} PRIVATE SDL3_ttf::${sdl3_ttf_target_name})
566-
target_link_libraries(${prog} PRIVATE ${sdl3_target_name})
567-
if("c_std_99" IN_LIST CMAKE_C_COMPILE_FEATURES)
568-
target_compile_features(${prog} PRIVATE c_std_99)
569-
endif()
570-
571-
if(SDLTTF_SAMPLES_INSTALL)
572-
install(TARGETS ${prog}
573-
RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3_ttf"
574-
)
575-
endif()
576-
endforeach()
577581
endif()
578582

579583
set(available_deps)

0 commit comments

Comments
 (0)