# SDL\_ttf: cmake: build examples as shared library on Android

**URL:** <https://discourse.libsdl.org/t/sdl-ttf-cmake-build-examples-as-shared-library-on-android/59199>\
**Category:** SDL Commits\
**Created:** [April 12, 2025, 4:16pm UTC](https://discourse.libsdl.org/t/sdl-ttf-cmake-build-examples-as-shared-library-on-android/59199 "2025-04-12T16:16:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [April 12, 2025, 4:16pm UTC](https://discourse.libsdl.org/t/sdl-ttf-cmake-build-examples-as-shared-library-on-android/59199/1 "2025-04-12T16:16:05Z")

</div>

> <https://github.com/libsdl-org/SDL_ttf/commit/85375592ccacab9a225c265c0cb3252740677f20>
>
> These examples won't be useful without accompanying Java classes
> or Android mani…fest, but they will at least successfully link.

```diff
From 85375592ccacab9a225c265c0cb3252740677f20 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 12 Apr 2025 18:08:18 +0200
Subject: [PATCH] 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.
---
 CMakeLists.txt | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fbe12209..ae27a011 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -545,10 +545,29 @@ if(SDLTTF_INSTALL)
 endif()
 
 if(SDLTTF_SAMPLES)
- add_executable(glfont examples/glfont.c)
- add_executable(showfont examples/showfont.c examples/editbox.c)
- add_executable(testapp examples/testapp.c)
- add_executable(testgputext examples/testgputext.c)
+ function(add_sdl_ttf_example_executable TARGET)
+ if(ANDROID)
+ add_library(${TARGET} SHARED ${ARGN})
+ else()
+ add_executable(${TARGET} ${ARGN})
+ endif()
+ sdl_add_warning_options(${TARGET} WARNING_AS_ERROR ${SDLTTF_WERROR})
+ target_link_libraries(${TARGET} PRIVATE SDL3_ttf::${sdl3_ttf_target_name})
+ target_link_libraries(${TARGET} PRIVATE ${sdl3_target_name})
+ if("c_std_99" IN_LIST CMAKE_C_COMPILE_FEATURES)
+ target_compile_features(${TARGET} PRIVATE c_std_99)
+ endif()
+
+ if(SDLTTF_SAMPLES_INSTALL)
+ install(TARGETS ${TARGET}
+ RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3_ttf"
+ )
+ endif()
+ endfunction()
+ add_sdl_ttf_example_executable(glfont examples/glfont.c)
+ add_sdl_ttf_example_executable(showfont examples/showfont.c examples/editbox.c)
+ add_sdl_ttf_example_executable(testapp examples/testapp.c)
+ add_sdl_ttf_example_executable(testgputext examples/testgputext.c)
 
     set(OpenGL_GL_PREFERENCE GLVND)
     find_package(OpenGL)
@@ -559,21 +578,6 @@ if(SDLTTF_SAMPLES)
         target_compile_definitions(glfont PRIVATE HAVE_OPENGL)
         target_link_libraries(glfont PRIVATE OpenGL::GL)
     endif()
-
- foreach(prog glfont showfont testapp testgputext)
- sdl_add_warning_options(${prog} WARNING_AS_ERROR ${SDLTTF_WERROR})
- target_link_libraries(${prog} PRIVATE SDL3_ttf::${sdl3_ttf_target_name})
- target_link_libraries(${prog} PRIVATE ${sdl3_target_name})
- if("c_std_99" IN_LIST CMAKE_C_COMPILE_FEATURES)
- target_compile_features(${prog} PRIVATE c_std_99)
- endif()
-
- if(SDLTTF_SAMPLES_INSTALL)
- install(TARGETS ${prog}
- RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3_ttf"
- )
- endif()
- endforeach()
 endif()
 
 set(available_deps)

```
