### Configure OpenGL for glfont Example Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Configures OpenGL support for the 'glfont' example, linking against the appropriate OpenGL target based on availability. ```cmake set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL) if(TARGET OpenGL::OpenGL) target_compile_definitions(glfont PRIVATE HAVE_OPENGL) target_link_libraries(glfont PRIVATE OpenGL::OpenGL) elseif(TARGET OpenGL::GL) target_compile_definitions(glfont PRIVATE HAVE_OPENGL) target_link_libraries(glfont PRIVATE OpenGL::GL) endif() ``` -------------------------------- ### Add SDL_ttf Sample Applications Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Adds several example applications for SDL_ttf using the previously defined function. These examples demonstrate various functionalities of the library. ```cmake 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(showfps examples/showfps.c) add_sdl_ttf_example_executable(testapp examples/testapp.c) add_sdl_ttf_example_executable(testgputext examples/testgputext.c) ``` -------------------------------- ### CMake Minimum Version and Project Setup Source: https://github.com/libsdl-org/sdl_ttf/blob/main/cmake/test/CMakeLists.txt Sets the minimum required CMake version and defines the project name and languages. This is standard practice for CMake projects. ```cmake cmake_minimum_required(VERSION 3.12...3.28) project(sdl_test LANGUAGES C) ``` -------------------------------- ### Define SDL_ttf Example Executable Function Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Defines a CMake function to add an example executable, handling differences between Android and other platforms. It links necessary libraries and sets compile features. ```cmake 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}) sdl_target_link_options_no_undefined(${TARGET}) 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() ``` -------------------------------- ### Find System FreeType Library Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Finds and links to an installed system FreeType library using find_package. It also adds 'freetype2' to the list of required packages. ```cmake find_package(Freetype "${FREETYPE_REQUIRED_VERSION}" REQUIRED) list(APPEND PC_REQUIRES freetype2) target_link_libraries(${sdl3_ttf_target_name} PRIVATE Freetype::Freetype) ``` -------------------------------- ### Find System plutosvg Library Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Finds an installed system plutosvg library using find_package and links it to the SDL_ttf target. It also adds 'plutosvg' to the list of required packages. ```cmake find_package(plutosvg ${find_package_strict_arg}) if(plutosvg_FOUND) message(STATUS "${PROJECT_NAME}: Using system plutosvg library") set(plutosvg_link_libraries plutosvg::plutosvg) list(APPEND PC_REQUIRES plutosvg) set(SDLTTF_PLUTOSVG_ENABLED TRUE) else() message(${fatal_error} "plutosvg NOT found") endif() ``` -------------------------------- ### Configure Vendored plutosvg Build Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Sets CMake cache variables for a vendored plutosvg build, disabling examples and image writing, and enabling FreeType support. It then adds plutosvg and plutovg as subdirectories. ```cmake set(BUILD_SHARED_LIBS OFF) set(PLUTOSVG_ENABLE_FREETYPE ON CACHE BOOL "plutosvg enable freetype" FORCE) set(PLUTOSVG_BUILD_EXAMPLES OFF CACHE BOOL "plutosvg build examples" FORCE) set(PLUTOVG_ENABLE_IMAGE_WRITE OFF CACHE BOOL "plutovg enable image write" FORCE) set(PLUTOVG_BUILD_EXAMPLES OFF CACHE BOOL "plutovg build examples" FORCE) sdl_check_project_in_subfolder(external/plutovg plutovg SDLTTF_VENDORED) add_subdirectory(external/plutovg external/plutovg-build EXCLUDE_FROM_ALL) sdl_check_project_in_subfolder(external/plutosvg plutosvg SDLTTF_VENDORED) add_subdirectory(external/plutosvg external/plutosvg-guild EXCLUDE_FROM_ALL) ``` -------------------------------- ### Download External Dependencies Source: https://github.com/libsdl-org/sdl_ttf/blob/main/docs/INTRO-xcode.md Run this script to download necessary external dependencies for SDL_ttf. Ensure you are in the 'external' directory before execution. ```bash download.sh ``` -------------------------------- ### Run SDL_ttf Executable on Windows Source: https://github.com/libsdl-org/sdl_ttf/blob/main/docs/INTRO-cmake.md Navigate to the Debug directory within your build folder and execute the application. This is specific to Windows builds. ```sh cd build/Debug ./hello ``` -------------------------------- ### Static Library Build Configuration Source: https://github.com/libsdl-org/sdl_ttf/blob/main/cmake/test/CMakeLists.txt Configures the build for a static SDL3_ttf library. It enables C++ support, finds the necessary packages, and links the `main_static` executable against the static libraries. ```cmake if(TEST_STATIC) find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3) # some static vendored libraries use c++ (enable CXX after `find_package` might show a warning) enable_language(CXX) find_package(SDL3_ttf REQUIRED CONFIG) add_executable(main_static main.c) target_link_libraries(main_static PRIVATE SDL3_ttf::SDL3_ttf-static SDL3::SDL3) endif() ``` -------------------------------- ### Run SDL_ttf Executable on Other Platforms Source: https://github.com/libsdl-org/sdl_ttf/blob/main/docs/INTRO-cmake.md Navigate to the main build directory and execute the application. This command is for non-Windows platforms. ```sh cd build ./hello ``` -------------------------------- ### Build SDL_ttf Project with CMake Source: https://github.com/libsdl-org/sdl_ttf/blob/main/docs/INTRO-cmake.md Commands to configure and build your project using CMake. This process generates build files and compiles your application. ```sh cmake -S . -B build cmake --build build ``` -------------------------------- ### Report Enabled and Disabled SDL_ttf Backends Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Iterates through a list of potential SDL_ttf backends, checks their enabled status, and reports the enabled and disabled backends to the user. ```cmake set(available_deps) set(unavailable_deps) foreach(dep IN LISTS SDLTTF_BACKENDS) set(var SDLTTF_${dep}_ENABLED) if(NOT DEFINED ${var}) message(AUTHOR_WARNING "${var} not defined") endif() if(${var}) list(APPEND available_deps ${dep}) else() list(APPEND unavailable_deps ${dep}) endif() endforeach() string(JOIN " " avail_str ${available_deps}) string(TOLOWER "${avail_str}" avail_str) string(JOIN " " unavail_str ${unavailable_deps}) string(TOLOWER "${unavail_str}" unavail_str) message(STATUS "SDL3_ttf backends:") message(STATUS "- enabled: ${avail_str}") message(STATUS "- disabled: ${unavail_str}") ``` -------------------------------- ### CMakeLists.txt for SDL_ttf Emscripten Project Source: https://github.com/libsdl-org/sdl_ttf/blob/main/docs/INTRO-emscripten.md This CMakeLists.txt file configures a project to use SDL and SDL_ttf with Emscripten. It sets output directories, includes SDL and SDL_ttf as subdirectories, and generates an HTML file for web targets. ```cmake cmake_minimum_required(VERSION 3.16) project(hello) # set the output directory for built objects. # This makes sure that the dynamic library goes into the build directory automatically. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$") # This assumes the SDL source is available in vendored/SDL add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL) # This assumes the SDL_ttf source is available in vendored/SDL_ttf add_subdirectory(vendored/SDL_ttf EXCLUDE_FROM_ALL) # on Web targets, we need CMake to generate a HTML webpage. if(EMSCRIPTEN) set(CMAKE_EXECUTABLE_SUFFIX ".html" CACHE INTERNAL "") endif() # Create your game executable target as usual add_executable(hello WIN32 hello.c) # Link to the actual SDL3 library. target_link_libraries(hello PRIVATE SDL3_ttf::SDL3_ttf SDL3::SDL3) ``` -------------------------------- ### Build SDL_ttf Emscripten Project Source: https://github.com/libsdl-org/sdl_ttf/blob/main/docs/INTRO-emscripten.md Commands to build an SDL_ttf Emscripten project using Emscripten's CMake and Make wrappers. Ensure you are in the project's build directory before running these commands. ```sh emcmake cmake -S . -B build cd build emmake make ``` -------------------------------- ### Shared Library Build Configuration Source: https://github.com/libsdl-org/sdl_ttf/blob/main/cmake/test/CMakeLists.txt Configures the build for a shared SDL3_ttf library. It finds the necessary SDL3 and SDL3_ttf packages and links the `main_shared` executable against them. ```cmake if(TEST_SHARED) find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3) find_package(SDL3_ttf REQUIRED CONFIG) add_executable(main_shared main.c) target_link_libraries(main_shared PRIVATE SDL3_ttf::SDL3_ttf-shared SDL3::SDL3) endif() ``` -------------------------------- ### Build Option for Static Library Testing Source: https://github.com/libsdl-org/sdl_ttf/blob/main/cmake/test/CMakeLists.txt Defines a CMake option to enable testing of the static SDL3_ttf library. This option defaults to ON. ```cmake option(TEST_STATIC "Test linking to static SDL3_ttf libary" ON) add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library") ``` -------------------------------- ### Feature Summary Display Source: https://github.com/libsdl-org/sdl_ttf/blob/main/cmake/test/CMakeLists.txt Generates and displays a summary of all configured features for the project. This is typically used at the end of a CMake script. ```cmake feature_summary(WHAT ALL) ``` -------------------------------- ### Feature Summary Inclusion Source: https://github.com/libsdl-org/sdl_ttf/blob/main/cmake/test/CMakeLists.txt Includes the `FeatureSummary` module, which is used later to display a summary of configured features. ```cmake include(FeatureSummary) ``` -------------------------------- ### Link Vendored plutosvg Libraries Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Configures include directories, compile definitions, and sources for vendored plutosvg and plutovg libraries when building static libraries. For shared libraries, it directly links the plutosvg::plutosvg target. ```cmake if(SDLTTF_BUILD_SHARED_LIBS) set(plutosvg_link_libraries plutosvg::plutosvg) else() set(plutosvg_compile_definitions $ $) set(plutosvg_include_directories $ $) set(plutosvg_sources $ $) endif() ``` -------------------------------- ### CMake Policy and Path Configuration Source: https://github.com/libsdl-org/sdl_ttf/blob/main/cmake/test/CMakeLists.txt Applies a specific CMake policy and configures the search path for packages. This ensures that SDL3_ttf can be found correctly, even outside the system root. ```cmake cmake_policy(SET CMP0074 NEW) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) ``` -------------------------------- ### Build Option for Shared Library Testing Source: https://github.com/libsdl-org/sdl_ttf/blob/main/cmake/test/CMakeLists.txt Defines a CMake option to enable testing of the shared SDL3_ttf library. This option defaults to ON. ```cmake option(TEST_SHARED "Test linking to shared SDL3_ttf library" ON) add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library") ``` -------------------------------- ### CMakeLists.txt for SDL_ttf Subproject Source: https://github.com/libsdl-org/sdl_ttf/blob/main/docs/INTRO-cmake.md Configure your CMake project to include SDL and SDL_ttf as vendored subprojects. Ensure SDL source is in 'vendored/SDL' and SDL_ttf source is in 'vendored/SDL_ttf'. ```cmake cmake_minimum_required(VERSION 3.16) project(hello) # set the output directory for built objects. # This makes sure that the dynamic library goes into the build directory automatically. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$") # Use vendored libs set(SDLTTF_VENDORED ON) # This assumes the SDL source is available in vendored/SDL add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL) # This assumes the SDL_ttf source is available in vendored/SDL_ttf add_subdirectory(vendored/SDL_ttf EXCLUDE_FROM_ALL) # Create your game executable target as usual add_executable(hello WIN32 hello.c) # Link to the actual SDL3 library. target_link_libraries(hello PRIVATE SDL3_ttf::SDL3_ttf SDL3::SDL3) ``` -------------------------------- ### Configure Vendored Harfbuzz Build Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Sets CMake variables to configure a vendored harfbuzz build. This includes disabling certain harfbuzz features and enabling platform-specific backends like CoreText on Apple and Uniscribe/GDI on Windows. ```cmake set(BUILD_SHARED_LIBS OFF) list(APPEND SDLTTF_BACKENDS HARFBUZZ) set(SDLTTF_HARFBUZZ_ENABLED FALSE) if(SDLTTF_HARFBUZZ) set(harfbuzz_sources) set(harfbuzz_link_libraries) set(harfbuzz_include_directories) if(SDLTTF_HARFBUZZ_VENDORED) message(STATUS "${PROJECT_NAME}: Using vendored harfbuzz library") # HB_BUILD_SUBSET variable is used by harfbuzz set(HB_BUILD_SUBSET OFF CACHE BOOL "build harfbuzz-subset" FORCE) # HB_BUILD_UTILS variable is used by harfbuzz set(HB_BUILD_UTILS OFF CACHE BOOL "harfbuzz build utils" FORCE) # SKIP_INSTALL_LIBRARIES variable is used by harfbuzz set(SKIP_INSTALL_LIBRARIES ON CACHE BOOL "harfbuzz install option" FORCE) # HB_HAVE_FREETYPE variable is used by harfbuzz set(HB_HAVE_FREETYPE ${SDLTTF_FREETYPE} CACHE BOOL "harfbuzz freetype helpers" FORCE) # target-specific harfbuzz backends : if(APPLE) # Minimum version for $ cmake_minimum_required(VERSION 3.24) # HB_HAVE_CORETEXT variable is used by harfbuzz set(HB_HAVE_CORETEXT ON CACHE BOOL "harfbuzz coretext backend" FORCE) endif() if(WIN32) # HB_HAVE_UNISCRIBE variable is used by harfbuzz set(HB_HAVE_UNISCRIBE ON CACHE BOOL "harfbuzz uniscribe backend" FORCE) # HB_HAVE_GDI variable is used by harfbuzz set(HB_HAVE_GDI ON CACHE BOOL "harfbuzz windows backend" FORCE) endif() ## HACK: HACK: These fail detection, we rely on our own vendored FreeType having them ## set(HAVE_FT_GET_VAR_BLEND_COORDINATES 1 CACHE BOOL "FT_Get_Var_Blend_Coordinates" FORCE) set(HAVE_FT_SET_VAR_BLEND_COORDINATES 1 CACHE BOOL "FT_Set_Var_Blend_Coordinates" FORCE) set(HAVE_FT_DONE_MM_VAR 1 CACHE BOOL "FT_Done_MM_Var" FORCE) set(HAVE_FT_GET_TRANSFORM 1 CACHE BOOL "FT_Get_Transform" FORCE) sdl_check_project_in_subfolder(external/harfbuzz harfbuzz SDLTTF_VENDORED) add_subdirectory(external/harfbuzz external/harfbuzz-build EXCLUDE_FROM_ALL) # harfbuzz is a c++ project, enable c++ here to ensure linking to the c++ standard library. enable_language(CXX) if(NOT TARGET harfbuzz::harfbuzz) add_library(harfbuzz::harfbuzz ALIAS harfbuzz) endif() set(SDLTTF_HARFBUZZ_ENABLED TRUE) if(SDLTTF_BUILD_SHARED_LIBS) set(harfbuzz_link_libraries harfbuzz::harfbuzz) else() set(harfbuzz_sources $) set(harfbuzz_include_directories $) if(WIN32) # for uniscribe and gdi backends : list(APPEND harfbuzz_link_libraries usp10 gdi32 rpcrt4) list(APPEND PC_LIBS -lusp10 -lgdi32 -lrpcrt4) elseif(APPLE) # for coretext backend : list(APPEND harfbuzz_link_libraries "$") list(APPEND harfbuzz_link_libraries "$") list(APPEND harfbuzz_link_libraries "$") list(APPEND PC_LIBS "-Wl,-framework,CoreText") list(APPEND PC_LIBS "-Wl,-framework,CoreGraphics") list(APPEND PC_LIBS "-Wl,-framework,CoreFoundation") else() find_package(Threads) set(harfbuzz_link_libraries Threads::Threads) endif() endif() else() find_package(harfbuzz "${HARFBUZZ_REQUIRED_VERSION}" ${find_package_strict_arg}) if(harfbuzz_FOUND) message(STATUS "${PROJECT_NAME}: Using system harfbuzz library") list(APPEND PC_REQUIRES harfbuzz) set(SDLTTF_HARFBUZZ_ENABLED TRUE) set(harfbuzz_link_libraries harfbuzz::harfbuzz) else() message(${fatal_error} "harfbuzz NOT found") endif() endif() if(SDLTTF_HARFBUZZ_ENABLED) target_compile_definitions(${sdl3_ttf_target_name} PRIVATE TTF_USE_HARFBUZZ=1) target_sources(${sdl3_ttf_target_name} PRIVATE ${harfbuzz_sources}) target_include_directories(${sdl3_ttf_target_name} PRIVATE ${harfbuzz_include_directories}) target_link_libraries(${sdl3_ttf_target_name} PRIVATE ${harfbuzz_link_libraries}) endif() endif() ``` -------------------------------- ### Integrate plutosvg into SDL_ttf Target Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Applies plutosvg specific compile definitions, include directories, sources, and link libraries to the main SDL_ttf target when plutosvg is enabled. ```cmake target_compile_definitions(${sdl3_ttf_target_name} PRIVATE TTF_USE_PLUTOSVG=1) target_sources(${sdl3_ttf_target_name} PRIVATE ${plutosvg_sources}) target_compile_definitions(${sdl3_ttf_target_name} PRIVATE ${plutosvg_compile_definitions}) target_include_directories(${sdl3_ttf_target_name} PRIVATE ${plutosvg_include_directories}) target_link_libraries(${sdl3_ttf_target_name} PRIVATE ${plutosvg_link_libraries}) ``` -------------------------------- ### Add FreeType Subdirectory for Vendored Build Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Adds the FreeType library as a subdirectory for a vendored build. It checks for the existence of FreeType sources and creates an alias target if it doesn't already exist. ```cmake if(NOT EXISTS "${PROJECT_SOURCE_DIR}/external/freetype/CMakeLists.txt") message(FATAL_ERROR "No freetype sources found. Install a freetype development package or run the download script in the external folder.") endif() add_subdirectory(external/freetype external/freetype-build EXCLUDE_FROM_ALL) if(NOT TARGET Freetype::Freetype) add_library(Freetype::Freetype ALIAS freetype) endif() ``` -------------------------------- ### Configure FreeType Build Options Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Sets CMake cache variables to control FreeType's build configuration, such as disabling PNG and Brotli support, and conditionally enabling or requiring HarfBuzz based on SDLTTF_HARFBUZZ. ```cmake set(FT_DISABLE_PNG ON CACHE BOOL "freetype png option") set(FT_DISABLE_BROTLI ON CACHE BOOL "freetype option") if(SDLTTF_HARFBUZZ) set(FT_DISABLE_HARFBUZZ OFF CACHE BOOL "freetype harfbuzz option" FORCE) set(FT_REQUIRE_HARFBUZZ ON CACHE BOOL "freetype harfbuzz option" FORCE) else() set(FT_DISABLE_HARFBUZZ ON CACHE BOOL "freetype harfbuzz option" FORCE) set(FT_REQUIRE_HARFBUZZ OFF CACHE BOOL "freetype harfbuzz option" FORCE) endif() ``` -------------------------------- ### Configure Vendored FreeType Build Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Sets CMake variables to configure a vendored freetype build. This includes disabling zlib and bzip2 support within freetype. ```cmake list(APPEND SDLTTF_BACKENDS FREETYPE) set(SDLTTF_FREETYPE_ENABLED FALSE) if(SDLTTF_FREETYPE) if(SDLTTF_FREETYPE_VENDORED) message(STATUS "${PROJECT_NAME}: Using vendored freetype library") # FT_DISABLE_ZLIB variable is used by freetype set(FT_DISABLE_ZLIB ON CACHE BOOL "freetype zlib option") # FT_DISABLE_BZIP2 variable is used by freetype set(FT_DISABLE_BZIP2 ON CACHE BOOL "freetype bzip2 option") ``` -------------------------------- ### Android Executable Macro Override Source: https://github.com/libsdl-org/sdl_ttf/blob/main/cmake/test/CMakeLists.txt Overrides the `add_executable` macro for Android builds to create a shared library instead of an executable. This is a platform-specific adjustment. ```cmake if(ANDROID) macro(add_executable NAME) set(args ${ARGN}) list(REMOVE_ITEM args WIN32) add_library(${NAME} SHARED ${args}) unset(args) endmacro() endif() ``` -------------------------------- ### Link FreeType Library for SDL_ttf Source: https://github.com/libsdl-org/sdl_ttf/blob/main/CMakeLists.txt Links the FreeType library to the SDL_ttf target. It uses target_link_libraries for shared libraries and $ for static libraries. ```cmake if(SDLTTF_BUILD_SHARED_LIBS) target_link_libraries(${sdl3_ttf_target_name} PRIVATE Freetype::Freetype) else() target_sources(${sdl3_ttf_target_name} PRIVATE $) target_include_directories(${sdl3_ttf_target_name} PRIVATE $) endif() ``` -------------------------------- ### Migrate Error Code Checks Source: https://github.com/libsdl-org/sdl_ttf/blob/main/docs/README-migration.md Update conditional checks for functions that now return a boolean instead of an error code. Previously, checks for negative error codes or specific values like -1 were common. Now, a simple truthiness check is sufficient. ```c if (TTF_Function() < 0 || TTF_Function() == -1) { /* Failure... */ } ``` ```c if (TTF_Function() == 0) { /* Success... */ } ``` ```c if (!TTF_Function()) { /* Success... */ } ``` ```c if (TTF_Function()) { /* Success... */ } else { /* Failure... */ } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.