SDL_ttf: cmake updates for SDL3

From 5bb0a5691a80dabf1f4004c2e081b99c513c0e98 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 7 Jan 2023 13:49:57 +0100
Subject: [PATCH] cmake updates for SDL3

---
 .github/workflows/main.yml                    |  95 +++-------
 CMakeLists.txt                                | 168 ++++++------------
 SDL3_ttf.pc.in                                |  13 --
 SDL_ttf.c                                     |   7 +-
 ...on.cmake => sdl3_ttf-config-version.cmake} |   2 +-
 ...ttf-config.cmake => sdl3_ttf-config.cmake} |   4 +-
 ...on.cmake => sdl3_ttf-config-version.cmake} |   0
 ...ttf-config.cmake => sdl3_ttf-config.cmake} |   0
 cmake/PrivateSdlFunctions.cmake               |  94 ++++------
 .../SDL3_ttfConfig.cmake.in                   |   0
 cmake/sdl3-ttf.pc.in                          |  13 ++
 .../cmake/sdl2_ttf-config-version.cmake       |  19 --
 mingw/pkg-support/cmake/sdl2_ttf-config.cmake |  19 --
 .../cmake/sdl3_ttf-config-version.cmake       |  19 ++
 mingw/pkg-support/cmake/sdl3_ttf-config.cmake |  19 ++
 sdl3_ttf-config-version.cmake.in              |  12 --
 sdl3_ttf-config.cmake.in                      |  94 ----------
 17 files changed, 174 insertions(+), 404 deletions(-)
 delete mode 100644 SDL3_ttf.pc.in
 rename VisualC/pkg-support/cmake/{sdl2_ttf-config-version.cmake => sdl3_ttf-config-version.cmake} (99%)
 rename VisualC/pkg-support/cmake/{sdl2_ttf-config.cmake => sdl3_ttf-config.cmake} (93%)
 rename Xcode/pkg-support/resources/CMake/{sdl2_ttf-config-version.cmake => sdl3_ttf-config-version.cmake} (100%)
 rename Xcode/pkg-support/resources/CMake/{sdl2_ttf-config.cmake => sdl3_ttf-config.cmake} (100%)
 rename SDL3_ttfConfig.cmake.in => cmake/SDL3_ttfConfig.cmake.in (100%)
 create mode 100644 cmake/sdl3-ttf.pc.in
 delete mode 100644 mingw/pkg-support/cmake/sdl2_ttf-config-version.cmake
 delete mode 100644 mingw/pkg-support/cmake/sdl2_ttf-config.cmake
 create mode 100644 mingw/pkg-support/cmake/sdl3_ttf-config-version.cmake
 create mode 100644 mingw/pkg-support/cmake/sdl3_ttf-config.cmake
 delete mode 100644 sdl3_ttf-config-version.cmake.in
 delete mode 100644 sdl3_ttf-config.cmake.in

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 168fb35..ecb5f26 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -15,15 +15,12 @@ jobs:
       fail-fast: false
       matrix:
         platform:
-        - { name: Windows (MSVC+CMake),         os: windows-latest, shell: sh,   cmake: '-DSDL2TTF_VENDORED=ON -GNinja', msvc: 1, shared: 1, static: 0 }
-        - { name: Windows (mingw32+autotools),  os: windows-latest, shell: 'msys2 {0}', msystem: mingw32, msys-env: mingw-w64-i686, shared: 1, static: 1 }
+        - { name: Windows (MSVC+CMake),         os: windows-latest, shell: sh,   cmake: '-DSDL3TTF_VENDORED=ON -GNinja', msvc: 1, shared: 1, static: 0 }
         - { name: Windows (mingw64+CMake),      os: windows-latest, shell: 'msys2 {0}', msystem: mingw64, msys-env: mingw-w64-x86_64, shared: 1, static: 0,
-            cmake: '-DSDL2TTF_VENDORED=OFF -G "Ninja Multi-Config"' }
-        - { name: Linux (autotools),            os: ubuntu-20.04,   shell: sh,   shared: 1, static: 1 }
-        - { name: Linux (CMake),                os: ubuntu-20.04,   shell: sh,   cmake: '-DSDL2TTF_VENDORED=ON -GNinja', shared: 1, static: 0 }
-        - { name: 'Linux (CMake, static)',      os: ubuntu-20.04,   shell: sh,   cmake: '-GNinja -DBUILD_SHARED_LIBS=OFF', shared: 0, static: 1 }
-        - { name: Macos (autotools),            os: macos-latest,   shell: sh,   shared: 1, static: 1}
-        - { name: Macos (CMake),                os: macos-latest,   shell: sh,   cmake: '-DSDL2TTF_VENDORED=ON -GNinja', shared: 1, static: 0 }
+            cmake: '-DSDL3TTF_VENDORED=OFF -G "Ninja Multi-Config"' }
+        - { name: Linux,                        os: ubuntu-20.04,   shell: sh,   cmake: '-DSDL3TTF_VENDORED=ON -GNinja', shared: 1, static: 0 }
+        - { name: 'Linux (static)',             os: ubuntu-20.04,   shell: sh,   cmake: '-GNinja -DBUILD_SHARED_LIBS=OFF', shared: 0, static: 1 }
+        - { name: Macos,                        os: macos-latest,   shell: sh,   cmake: '-DSDL3TTF_VENDORED=ON -GNinja', shared: 1, static: 0 }
 
     steps:
     - name: Set up MSYS2
@@ -32,8 +29,7 @@ jobs:
       with:
         msystem: ${{ matrix.platform.msystem }}
         install: >-
-          ${{ matrix.platform.msys-env }}-SDL2
-          ${{ matrix.platform.msys-env }}-autotools
+          ${{ matrix.platform.msys-env }}-SDL3
           ${{ matrix.platform.msys-env }}-cmake
           ${{ matrix.platform.msys-env }}-gcc
           ${{ matrix.platform.msys-env }}-freetype
@@ -45,33 +41,27 @@ jobs:
       if: runner.os == 'macOS'
       run: |
           brew install \
-            autoconf \
-            automake \
             freetype \
             harfbuzz \
-            libtool \
             ninja \
             pkg-config \
-            sdl2 \
+            sdl3 \
             ${NULL+}
     - name: Setup Linux dependencies
       if: runner.os == 'Linux'
       run: |
         sudo apt-get update
         sudo apt-get -y install \
-          autoconf \
-          automake \
           cmake \
           file \
           fonts-dejavu-core \
           libfreetype-dev \
           libharfbuzz-dev \
-          libsdl2-dev \
-          libtool \
+          libsdl3-dev \
           ninja-build \
           pkg-config \
           ${NULL+}
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v3
       with:
         submodules: recursive
 
@@ -80,7 +70,7 @@ jobs:
       shell: pwsh
       run: |
         .github/fetch_sdl_vc.ps1
-        echo "SDL2_DIR=$Env:GITHUB_WORKSPACE/SDL2-devel-VC" >> $Env:GITHUB_ENV
+        echo "SDL3_DIR=$Env:GITHUB_WORKSPACE/SDL3-devel-VC" >> $Env:GITHUB_ENV
     - name: Setup Ninja for MSVC
       if: "matrix.platform.msvc"
       uses: ashutoshvarma/setup-ninja@master
@@ -92,85 +82,44 @@ jobs:
         arch: x64
 
     - name: Check that versioning is consistent
-      # We only need to run this once: arbitrarily use the Linux/CMake build
-      if: "runner.os == 'Linux' && matrix.platform.cmake"
+      # We only need to run this once: arbitrarily use the Linux build
+      if: "runner.os == 'Linux'"
       run: ./test-versioning.sh
 
-    - name: Configure (CMake)
-      if: "matrix.platform.cmake"
+    - name: Configure
       run: |
         cmake -B build-cmake \
           -DBUILD_SHARED_LIBS=ON \
-          -DSDL2TTF_HARFBUZZ=ON \
-          -DSDL2TTF_SAMPLES=ON \
+          -DSDL3TTF_HARFBUZZ=ON \
+          -DSDL3TTF_SAMPLES=ON \
+          -DSDL3TTF_WERROR=ON \
           -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
           -DCMAKE_BUILD_TYPE=Release \
           -DCMAKE_INSTALL_PREFIX=prefix_cmake \
           ${{ matrix.platform.cmake }}
-    - name: Build (CMake)
-      if: "matrix.platform.cmake"
+    - name: Build
       run: |
         cmake --build build-cmake --config Release --verbose
-    - name: Install (CMake)
-      if: "matrix.platform.cmake"
+    - name: Install
       run: |
         set -eu
         rm -rf prefix_cmake
         cmake --install build-cmake/ --config Release --verbose
-        echo "SDL2_ttf_DIR=$(pwd)/prefix_cmake" >> $GITHUB_ENV
+        echo "SDL3_ttf_DIR=$(pwd)/prefix_cmake" >> $GITHUB_ENV
         ( cd prefix_cmake; find . ) | LC_ALL=C sort -u
-    - name: Test using showfont (CMake)
-      if: "runner.os == 'Linux' && matrix.platform.cmake"
+    - name: Test using showfont
+      if: "runner.os == 'Linux'"
       run: |
           # Just check that it doesn't crash, we can't really test the results...
           env -C build-cmake/ SDL_VIDEODRIVER=dummy ./showfont -dump /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
           # ... but we can at least assert that it outputs a .bmp
           file build-cmake/glyph-100.bmp
 
-    - name: Configure (Autotools)
-      if: "! matrix.platform.cmake"
-      run: |
-        set -eu
-        rm -fr build-autotools
-        mkdir build-autotools
-        ./autogen.sh
-        set -- --prefix=$(pwd)/prefix_autotools
-        ( cd build-autotools && ../configure "$@" )
-    - name: Build (Autotools)
-      if: "! matrix.platform.cmake"
-      run: |
-        set -eu
-        parallel="$(getconf _NPROCESSORS_ONLN)"
-        make -j"${parallel}" -C build-autotools V=1
-    - name: Test (showfont)
-      if: "runner.os == 'Linux' && ! matrix.platform.cmake"
-      run: |
-        # Just check that it doesn't crash, we can't really test the results...
-        env -C build-autotools SDL_VIDEODRIVER=dummy ./showfont -dump /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
-        # ... but we can at least assert that it outputs a .bmp
-        file build-autotools/glyph-100.bmp
-    - name: Install (Autotools)
-      if: "! matrix.platform.cmake"
-      run: |
-        set -eu
-        curdir="$(pwd)"
-        parallel="$(getconf _NPROCESSORS_ONLN)"
-        rm -rf prefix_autotools
-        make -j"${parallel}" -C build-autotools install V=1
-        echo "SDL2_ttf_DIR=$(pwd)/prefix_autotools" >> $GITHUB_ENV
-        ( cd prefix_autotools; find . ) | LC_ALL=C sort -u
-    - name: Distcheck (Autotools)
-      if: "runner.os == 'Linux' && ! matrix.platform.cmake"
-      run: |
-        set -eu
-        parallel="$(getconf _NPROCESSORS_ONLN)"
-        make -j"${parallel}" -C build-autotools distcheck V=1
-
     - name: Verify CMake configuration files
       run: |
           cmake -S cmake/test -B cmake_config_build \
             -DCMAKE_BUILD_TYPE=Release \
-            -DCMAKE_PREFIX_PATH="${{ env.SDL2_ttf_DIR }};${{ env.SDL2_DIR }}" \
+            -DCMAKE_PREFIX_PATH="${{ env.SDL3_ttf_DIR }};${{ env.SDL3_DIR }}" \
             -DTEST_SHARED=${{ matrix.platform.shared }} \
             -DTEST_STATIC=${{ matrix.platform.static }}
           cmake --build cmake_config_build --verbose --config Release
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21f7e86..d03cca6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,18 +8,18 @@ set(MINOR_VERSION 0)
 set(MICRO_VERSION 0)
 set(SDL_REQUIRED_VERSION 3.0.0)
 
-include(PrivateSdlFunctions)
-sdl_calculate_derived_version_variables()
-
 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
     message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the SDL_ttf source code and call cmake from there")
 endif()
 
 project(SDL3_ttf
     LANGUAGES C
-    VERSION "${FULL_VERSION}"
+    VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}"
 )
 
+include(PrivateSdlFunctions)
+sdl_calculate_derived_version_variables(${MAJOR_VERSION} ${MINOR_VERSION} ${MICRO_VERSION})
+
 message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}")
 
 if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
@@ -28,11 +28,6 @@ else()
     set(SDL3TTF_ROOTPROJECT OFF)
 endif()
 
-# Set defaults preventing destination file conflicts
-set(SDL3TTF_DEBUG_POSTFIX "d"
-    CACHE STRING "Name suffix for debug builds")
-mark_as_advanced(SDL3TTF_DEBUG_POSTFIX)
-
 # Assume MSVC projects don't have a package manager and need vendored dependencies (by default).
 # Most other platforms have some kind of package manager.
 # FIXME: consider a package manager such as conan/vcpkg instead of vendoring
@@ -50,9 +45,12 @@ include(CheckSymbolExists)
 option(CMAKE_POSITION_INDEPENDENT_CODE "Build static libraries with -fPIC" ON)
 option(BUILD_SHARED_LIBS "Build the library as a shared library" ON)
 
-option(SDL3TTF_SAMPLES "Build the SDL3_ttf sample program(s)" ${SDL3TTF_ROOTPROJECT})
 option(SDL3TTF_INSTALL "Enable SDL3_ttf install target" ${SDL3TTF_ROOTPROJECT})
 option(SDL3TTF_VENDORED "Use vendored third-party libraries" ${vendored_default})
+option(SDL3TTF_WERROR "Treat warnings as errors" OFF)
+
+option(SDL3TTF_SAMPLES "Build the SDL3_ttf sample program(s)" ${SDL3TTF_ROOTPROJECT})
+cmake_dependent_option(SDL3TTF_SAMPLES_INSTALL "Install the SDL3_ttf sample program(s)" OFF "SDL3TTF_SAMPLES;SDL3TTF_INSTALL" OFF)
 
 # For style consistency, create a SDL3TTF_FREETYPE CMake variable. This variable is NOT configurable.
 set(SDL3TTF_FREETYPE ON)
@@ -74,7 +72,23 @@ else()
     set(sdl3_target_name SDL3::SDL3-static)
 endif()
 
-sdl_find_sdl3(${sdl3_target_name} ${SDL_REQUIRED_VERSION})
+if(NOT TARGET ${sdl3_target_name})
+    find_package(SDL3 ${SDL_REQUIRED_VERSION} REQUIRED)
+endif()
+
+add_library(sdl3ttf_build_options INTERFACE)
+if(MSVC)
+    target_compile_options(sdl3ttf_build_options INTERFACE /W2)
+else()
+    target_compile_options(sdl3ttf_build_options INTERFACE -Wall -Wextra)
+endif()
+if(SDL3TTF_WERROR)
+    if(MSVC)
+        target_compile_options(sdl3ttf_build_options INTERFACE /WX)
+    else()
+        target_compile_options(sdl3ttf_build_options INTERFACE -Werror)
+    endif()
+endif()
 
 # Enable large file support on 32-bit glibc, so that the vendored libraries
 # can access files with large inode numbers
@@ -100,6 +114,7 @@ target_compile_definitions(SDL3_ttf PRIVATE
     SDL_BUILD_MICRO_VERSION=${MICRO_VERSION}
 )
 target_link_libraries(SDL3_ttf PRIVATE $<BUILD_INTERFACE:${sdl3_target_name}>)
+target_link_libraries(SDL3_ttf PRIVATE $<BUILD_INTERFACE:sdl3ttf_build_options>)
 if(WIN32 AND SDL3TTF_BUILD_SHARED_LIBS)
     target_sources(SDL3_ttf PRIVATE
         version.rc
@@ -111,44 +126,30 @@ set_target_properties(SDL3_ttf PROPERTIES
     C_VISIBILITY_PRESET "hidden"
 )
 if(NOT ANDROID)
-    set_target_properties(SDL3_ttf PROPERTIES
-        DEBUG_POSTFIX "${SDL3TTF_DEBUG_POSTFIX}"
-    )
     if(APPLE)
         # the SOVERSION property corresponds to the compatibility version and VERSION corresponds to the current version
         # https://cmake.org/cmake/help/latest/prop_tgt/SOVERSION.html#mach-o-versions
         set_target_properties(SDL3_ttf PROPERTIES
-            SOVERSION "${DYLIB_COMPATIBILITY_VERSION}"
+            SOVERSION "${DYLIB_COMPAT_VERSION}"
             VERSION "${DYLIB_CURRENT_VERSION}"
         )
     else()
         set_target_properties(SDL3_ttf PROPERTIES
-            SOVERSION "${LT_MAJOR}"
-            VERSION "${LT_VERSION}"
+            SOVERSION "${SO_VERSION_MAJOR}"
+            VERSION "${SO_VERSION}"
         )
     endif()
 endif()
-if(SDL3TTF_BUILD_SHARED_LIBS AND (APPLE OR (UNIX AND NOT ANDROID)))
-    add_custom_command(TARGET SDL3_ttf POST_BUILD
-        COMMAND "${CMAKE_COMMAND}" -E create_symlink "$<TARGET_SONAME_FILE_NAME:SDL3_ttf>" "libSDL3_ttf$<$<CONFIG:Debug>:${SDL3TTF_DEBUG_POSTFIX}>$<TARGET_FILE_SUFFIX:SDL3_ttf>"
-        # BYPRODUCTS "libSDL3_ttf$<$<CONFIG:Debug>:${SDL3TTF_DEBUG_POSTFIX}>$<TARGET_FILE_SUFFIX:SDL3_ttf>" # Needs CMake 3.20
-        WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
-    )
-endif()
 if(SDL3TTF_BUILD_SHARED_LIBS)
-    if(WIN32 OR OS2)
+    if(WIN32)
         set_target_properties(SDL3_ttf PROPERTIES
             PREFIX ""
         )
     endif()
-    if(OS2)
-        # OS/2 doesn't support a DLL name longer than 8 characters.
-        set_target_properties(SDL3_ttf PROPERTIES
-            OUTPUT_NAME "SDL3ttf"
-        )
-    elseif(UNIX AND NOT ANDROID)
+else()
+    if(MSVC)
         set_target_properties(SDL3_ttf PROPERTIES
-            OUTPUT_NAME "SDL3_ttf-${LT_RELEASE}"
+            OUTPUT_NAME "SDL3_ttf-static"
         )
     endif()
 endif()
@@ -241,35 +242,6 @@ endif()
 # Restore BUILD_SHARED_LIBS variable
 set(BUILD_SHARED_LIBS ${SDL3TTF_BUILD_SHARED_LIBS})
 
-if (APPLE)
-    # TODO: Use DYLIB_COMPATIBILITY_VERSION, DYLIB_CURRENT_VERSION here
-elseif (UNIX AND NOT APPLE AND NOT ANDROID)
-    set_target_properties(SDL3_ttf PROPERTIES
-        SOVERSION "${LT_MAJOR}"
-        VERSION "${LT_VERSION}"
-    )
-endif()
-if (BUILD_SHARED_LIBS)
-    if (WIN32 OR OS2)
-        set_target_properties(SDL3_ttf PROPERTIES
-            PREFIX ""
-        )
-    endif()
-    if (OS2)
-        # OS/2 doesn't support a DLL name longer than 8 characters.
-        set_target_properties(SDL3_ttf PROPERTIES
-           OUTPUT_NAME "SDL3ttf"
-        )
-    elseif (UNIX AND NOT APPLE AND NOT ANDROID)
-        set_target_properties(SDL3_ttf PROPERTIES
-            OUTPUT_NAME "SDL3_ttf-${LT_RELEASE}"
-        )
-    endif()
-endif()
-
-# Restore BUILD_SHARED_LIBS variable
-set(BUILD_SHARED_LIBS "${SDL3TTF_BUILD_SHARED_LIBS}")
-
 if(SDL3TTF_INSTALL)
     install(
         TARGETS SDL3_ttf
@@ -294,69 +266,53 @@ if(SDL3TTF_INSTALL)
     endif()
 
     if(WIN32 AND NOT MINGW)
-        set(SDLTTF_INSTALL_CMAKEDIR_DEFAULT "cmake")
+        set(SDL3TTF_INSTALL_CMAKEDIR_DEFAULT "cmake")
+    else()
+        set(SDL3TTF_INSTALL_CMAKEDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake/SDL3_ttf")
+    endif()
+    set(SDL3TTF_INSTALL_CMAKEDIR_ROOT "${SDL3TTF_INSTALL_CMAKEDIR_DEFAULT}" CACHE STRING "Location where to install SDL3_ttfConfig.cmake")
+
+    if(WIN32 AND NOT MINGW)
+        set(SDL3TTF_INSTALL_CMAKEDIR "${SDL3TTF_INSTALL_CMAKEDIR_ROOT}")
+        set(LICENSES_PREFIX "licenses/SDL3_ttf")
     else()
-        set(SDLTTF_INSTALL_CMAKEDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake/SDL3_ttf")
+        set(SDL3TTF_INSTALL_CMAKEDIR "${SDL3TTF_INSTALL_CMAKEDIR_ROOT}/SDL3_ttf")
+        set(LICENSES_PREFIX "${CMAKE_INSTALL_DATAROOTDIR}/licenses/SDL3_ttf")
     endif()
-    set(SDLTTF_INSTALL_CMAKEDIR "${SDLTTF_INSTALL_CMAKEDIR_DEFAULT}" CACHE STRING "Location where to install SDL3_ttfConfig.cmake")
 
-    configure_package_config_file(SDL3_ttfConfig.cmake.in SDL3_ttfConfig.cmake
-        INSTALL_DESTINATION "${SDLTTF_INSTALL_CMAKEDIR}"
+    configure_package_config_file(cmake/SDL3_ttfConfig.cmake.in SDL3_ttfConfig.cmake
+        INSTALL_DESTINATION "${SDL3TTF_INSTALL_CMAKEDIR}"
     )
     write_basic_package_version_file("${PROJECT_BINARY_DIR}/SDL3_ttfConfigVersion.cmake"
-        VERSION ${FULL_VERSION}
         COMPATIBILITY AnyNewerVersion
     )
     install(
         FILES
             "${CMAKE_CURRENT_BINARY_DIR}/SDL3_ttfConfig.cmake"
             "${CMAKE_CURRENT_BINARY_DIR}/SDL3_ttfConfigVersion.cmake"
-        DESTINATION ${SDLTTF_INSTALL_CMAKEDIR}
+        DESTINATION ${SDL3TTF_INSTALL_CMAKEDIR}
         COMPONENT devel
     )
     install(EXPORT SDL3_ttfTargets
         FILE SDL3_ttf-${sdl3_ttf_install_name_infix}-targets.cmake
         NAMESPACE SDL3_ttf::
-        DESTINATION "${SDLTTF_INSTALL_CMAKEDIR}"
+        DESTINATION "${SDL3TTF_INSTALL_CMAKEDIR}"
         COMPONENT devel
     )
 
-    set(prefix "${CMAKE_INSTALL_PREFIX}")
-    set(exec_prefix "\${prefix}")
-    set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
-    set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
-    set(PACKAGE "${PROJECT_NAME}")
-    set(VERSION ${FULL_VERSION})
-    set(SDL_VERSION ${SDL_REQUIRED_VERSION})
     string(JOIN " " PC_REQUIRES ${PC_REQUIRES})
     string(JOIN " " PC_LIBS ${PC_LIBS})
-    configure_file("${PROJECT_SOURCE_DIR}/SDL3_ttf.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/SDL3_ttf.pc.intermediate" @ONLY)
-    file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/SDL3_ttf-$<CONFIG>.pc" INPUT "${CMAKE_CURRENT_BINARY_DIR}/SDL3_ttf.pc.intermediate")
+    configure_file(cmake/sdl3-ttf.pc.in sdl3-ttf.pc @ONLY)
 
-    set(PC_DESTDIR)
     if(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
         # FreeBSD uses ${PREFIX}/libdata/pkgconfig
         set(PC_DESTDIR "libdata/pkgconfig")
     else()
         set(PC_DESTDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
     endif()
-    # Always install SDL3_ttf.pc file: libraries might be different between config modes
-    install(CODE "
-        # FIXME: use file(COPY_FILE) if CMake 3.21+
-        execute_process(COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different
-            \"${CMAKE_CURRENT_BINARY_DIR}/SDL3_ttf-$<CONFIG>.pc\"
-            \"${CMAKE_CURRENT_BINARY_DIR}/SDL3_ttf.pc\")
-        file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${PC_DESTDIR}\"
-            TYPE FILE
-            FILES \"${CMAKE_CURRENT_BINARY_DIR}/SDL3_ttf.pc\")" COMPONENT devel)
-
-    if(SDL3TTF_BUILD_SHARED_LIBS AND (APPLE OR (UNIX AND NOT ANDROID)))
-        install(FILES
-            "${PROJECT_BINARY_DIR}/libSDL3_ttf$<$<CONFIG:Debug>:${SDL3TTF_DEBUG_POSTFIX}>$<TARGET_FILE_SUFFIX:SDL3_ttf>"
-            DESTINATION "${CMAKE_INSTALL_LIBDIR}"
-            COMPONENT devel
-        )
-    endif()
+    # Always install sdl3-ttf.pc file: libraries might be different between config modes
+    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sdl3-ttf.pc"
+        DESTINATION "${PC_DESTDIR}" COMPONENT devel)
 
     install(FILES "LICENSE.txt"
         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}"
@@ -379,21 +335,13 @@ if(SDL3TTF_SAMPLES)
     endif()
 
     foreach(prog glfont showfont)
-        if(MINGW)
-            target_link_libraries(${prog} PRIVATE mingw32)
-            target_link_options(${prog} PRIVATE -mwindows)
-        endif()
         target_link_libraries(${prog} PRIVATE SDL3_ttf::${sdl3_ttf_export_name})
         target_link_libraries(${prog} PRIVATE ${sdl3_target_name})
-    endforeach()
-endif()
 
-add_library(SDL3::ttf INTERFACE IMPORTED GLOBAL)
-set_target_properties(SDL3::ttf PROPERTIES
-    INTERFACE_LINK_LIBRARIES "SDL3_ttf"
-)
-if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17")
-    set_target_properties(SDL3::ttf PROPERTIES
-        DEPRECATION "Use SDL3_ttf::SDL3_ttf or SDL3_ttf::SDL3_ttf-static instead"
-    )
+        if(SDL3TTF_SAMPLES_INSTALL)
+            install(TARGETS ${prog}
+                RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+                )
+        endif()
+    endforeach()
 endif()
diff --git a/SDL3_ttf.pc.in b/SDL3_ttf.pc.in
deleted file mode 100644
index b60a26b..0000000
--- a/SDL3_ttf.pc.in
+++ /dev/null
@@ -1,13 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: SDL3_ttf
-Description: ttf library for Simple DirectMedia Layer with FreeType 2 support
-Version: @VERSION@
-Requires: sdl3 >= @SDL_VERSION@
-Libs: -L${libdir} -lSDL3_ttf
-Cflags: -I${includedir}/SDL3
-Requires.private: @PC_REQUIRES@
-Libs.private: @PC_LIBS@
diff --git a/SDL_ttf.c b/SDL_ttf.c
index e14600f..a6f758c 100644
--- a/SDL_ttf.c
+++ b/SDL_ttf.c
@@ -113,6 +113,7 @@ int TTF_SetScript(int script) /* hb_script_t */
 /* Round glyph to 16 bytes width and use SSE2 instructions */
 #if defined(__SSE2__)
 #  define HAVE_SSE2_INTRINSICS 1
+#include <emmintrin.h>
 #endif
 
 /* Round glyph width to 16 bytes use NEON instructions */
@@ -1012,6 +1013,8 @@ static void Draw_Line(TTF_Font *font, const SDL_Surface *textbuf, int column, in
     if (hb_direction == HB_DIRECTION_TTB || hb_direction == HB_DIRECTION_BTT) {
         return;
     }
+#else
+    (void) font;
 #endif
 
     /* Not needed because of "font->height = SDL_max(font->height, bottom_row);".
@@ -2499,7 +2502,7 @@ static FT_Error Load_Glyph(TTF_Font *font, c_glyph *cached, int want, int transl
                     if (ft_render_mode != FT_RENDER_MODE_SDF) {
                         SDL_memcpy(dstp, srcp, src->width);
                     } else {
-                        int x;
+                        unsigned int x;
                         for (x = 0; x < src->width; x++) {
                             Uint8 s = srcp[x];
                             Uint8 d;
@@ -3098,6 +3101,7 @@ int TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction)
     font->hb_direction = dir;
     return 0;
 #else
+    (void) font;
     (void) direction;
     return -1;
 #endif
@@ -3122,6 +3126,7 @@ int TTF_SetFontScriptName(TTF_Font *font, const char *script)
     font->hb_script = scr;
     return 0;
 #else
+    (void) font;
     (void) script;
     return -1;
 #endif
diff --git a/VisualC/pkg-support/cmake/sdl2_ttf-config-version.cmake b/VisualC/pkg-support/cmake/sdl3_ttf-config-version.cmake
similarity index 99%
rename from VisualC/pkg-support/cmake/sdl2_ttf-config-version.cmake
rename to VisualC/pkg-support/cmake/sdl3_ttf-config-version.cmake
index d95575d..076c78e 100644
--- a/VisualC/pkg-support/cmake/sdl2_ttf-config-version.cmake
+++ b/VisualC/pkg-support/cmake/sdl3_ttf-config-version.cmake
@@ -1,7 +1,7 @@
 # based on the files generated by CMake's write_basic_package_version_file
 
 # SDL3_ttf CMake version configuration file:
-# This file is meant to be placed in a cmake subfolder of SDL3_ttf-devel-2.x.y-VC
+# This file is meant to be placed in a cmake subfolder of SDL3_ttf-devel-3.x.y-VC
 
 if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/../include/SDL3/SDL_ttf.h")
     message(AUTHOR_WARNING "Could not find SDL_ttf.h. This script is meant to be placed in a CMake subfolder of SDL3_ttf-devel-3.x.y-VC")
diff --git a/VisualC/pkg-support/cmake/sdl2_ttf-config.cmake b/VisualC/pkg-support/cmake/sdl3_ttf-config.cmake
similarity index 93%
rename from VisualC/pkg-support/cmake/sdl2_ttf-config.cmake
rename to VisualC/pkg-support/cmake/sdl3_ttf-config.cmake
index 042523b..8ac3f06 100644
--- a/VisualC/pkg-support/cmake/sdl2_ttf-config.cmake
+++ b/VisualC/pkg-support/cmake/sdl3_ttf-config.cmake
@@ -1,5 +1,5 @@
 # SDL3_image CMake configuration file:
-# This file is meant to be placed in a cmake subfolder of SDL3_image-devel-2.x.y-VC
+# This file is meant to be placed in a cmake subfolder of SDL3_image-devel-3.x.y-VC
 
 include(FeatureSummary)
 set_package_properties(SDL3_ttf PROPERTIES
@@ -37,7 +37,7 @@ if(NOT TARGET SDL3_ttf::SDL3_ttf)
     add_library(SDL3_ttf::SDL3_ttf SHARED IMPORTED)
     set_target_properties(SDL3_ttf::SDL3_ttf
         PROPERTIES
-            INTERFACE_INCLUDE_DIRECTORIES "${_sdl3ttf_incdir}"
+            INTERFACE_INCLUDE_DIRECTORIES "${_sdl3ttf_incdir};${_sdl3ttf_incdir}/SDL3"
             IMPORTED_IMPLIB "${_sdl3ttf_library}"
             IMPORTED_LOCATION "${_sdl3ttf_dll}"
             COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
diff --git a/Xcode/pkg-support/resources/CMake/sdl2_ttf-config-version.cmake b/Xcode/pkg-support/resources/CMake/sdl3_ttf-config-version.cmake
similarity index 100%
rename from Xcode/pkg-support/resources/CMake/sdl2_ttf-config-version.cmake
rename to Xcode/pkg-support/resources/CMake/sdl3_ttf-config-version.cmake
diff --git a/Xcode/pkg-support/resources/CMake/sdl2_ttf-config.cmake b/Xcode/pkg-support/resources/CMake/sdl3_ttf-config.cmake
similarity index 100%
rename from Xcode/pkg-support/resources/CMake/sdl2_ttf-config.cmake
rename to Xcode/pkg-support/resources/CMake/sdl3_ttf-config.cmake
diff --git a/cmake/PrivateSdlFunctions.cmake b/cmake/PrivateSdlFunctions.cmake
index 80fa5fc..5612056 100644
--- a/cmake/PrivateSdlFunctions.cmake
+++ b/cmake/PrivateSdlFunctions.cmake
@@ -1,52 +1,27 @@
-# This file is shared amongst SDL_image/SDL_mixer/SDL_net/SDL_ttf
+# This file is shared amongst SDL_image/SDL_mixer/SDL_ttf
 
-macro(sdl_calculate_derived_version_variables)
-    if (NOT DEFINED MAJOR_VERSION OR NOT DEFINED MINOR_VERSION OR NOT DEFINED MICRO_VERSION)
-        message(FATAL_ERROR "MAJOR_VERSION, MINOR_VERSION and MICRO_VERSION need to be defined")
-    endif()
-
-    set(FULL_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}")
+macro(sdl_calculate_derived_version_variables MAJOR MINOR MICRO)
+    set(SO_VERSION_MAJOR "0")
+    set(SO_VERSION_MINOR "${MINOR_VERSION}")
+    set(SO_VERSION_MICRO "${MICRO_VERSION}")
+    set(SO_VERSION "${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}.${SO_VERSION_MICRO}")
 
-    # Calculate a libtool-like version number
-    math(EXPR BINARY_AGE "${MINOR_VERSION} * 100 + ${MICRO_VERSION}")
-    math(EXPR IS_DEVELOPMENT "${MINOR_VERSION} % 2")
-    if (IS_DEVELOPMENT)
-        # Development branch, 2.5.1 -> libSDL2_XXXXX-2.0.so.0.501.0
-        set(INTERFACE_AGE 0)
+    if(MINOR MATCHES "[02468]$")
+        math(EXPR DYLIB_COMPAT_VERSION_MAJOR "100 * ${MINOR} + 1")
+        set(DYLIB_COMPAT_VERSION_MINOR "0")
+        math(EXPR DYLIB_CURRENT_VERSION_MAJOR "${DYLIB_COMPAT_VERSION_MAJOR}")
+        set(DYLIB_CURRENT_VERSION_MINOR "${MICRO}")
     else()
-        # Stable branch, 2.6.1 -> libSDL2_XXXXX-2.0.so.0.600.1
-        set(INTERFACE_AGE ${MICRO_VERSION})
+        math(EXPR DYLIB_COMPAT_VERSION_MAJOR "100 * ${MINOR} + ${MICRO} + 1")
+        set(DYLIB_COMPAT_VERSION_MINOR "0")
+        math(EXPR DYLIB_CURRENT_VERSION_MAJOR "${DYLIB_COMPAT_VERSION_MAJOR}")
+        set(DYLIB_CURRENT_VERSION_MINOR "0")
     endif()
+    set(DYLIB_COMPAT_VERSION_MICRO "0")
+    set(DYLIB_CURRENT_VERSION_MICRO "0")
 
-    # Increment this if there is an incompatible change - but if that happens,
-    # we should rename the library from SDL2 to SDL3, at which point this would
-    # reset to 0 anyway.
-    set(LT_MAJOR "0")
-
-    math(EXPR LT_AGE "${BINARY_AGE} - ${INTERFACE_AGE}")
-    math(EXPR LT_CURRENT "${LT_MAJOR} + ${LT_AGE}")
-    set(LT_REVISION "${INTERFACE_AGE}")
-    # For historical reasons, the library name redundantly includes the major
-    # version twice: libSDL2_XXXXX-2.0.so.0.
-    # TODO: in SDL 3, set the OUTPUT_NAME to plain SDL3_XXXXX, which will simplify
-    # it to libSDL2_XXXXX.so.0
-    set(LT_RELEASE "2.0")
-    set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
-
-    # The following should match the versions in the Xcode project file.
-    # Each version is 1 higher than you might expect, for compatibility
-    # with libtool: macOS ABI versioning is 1-based, unlike other platforms
-    # which are normally 0-based.
-    math(EXPR DYLIB_CURRENT_VERSION_MAJOR "${LT_MAJOR} + ${LT_AGE} + 1")
-    math(EXPR DYLIB_CURRENT_VERSION_MINOR "${LT_REVISION}")
-    set(DYLIB_CURRENT_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.${DYLIB_CURRENT_VERSION_MINOR}.0")
-    set(DYLIB_COMPATIBILITY_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.0.0")
-endmacro()
-
-macro(sdl_find_sdl3 TARGET VERSION)
-    if(NOT TARGET ${TARGET})
-        find_package(SDL3 ${VERSION} REQUIRED QUIET)
-    endif()
+    set(DYLIB_CURRENT_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.${DYLIB_CURRENT_VERSION_MINOR}.${DYLIB_CURRENT_VERSION_MICRO}")
+    set(DYLIB_COMPAT_VERSION "${DYLIB_COMPAT_VERSION_MAJOR}.${DYLIB_COMPAT_VERSION_MINOR}.${DYLIB_COMPAT_VERSION_MICRO}")
 endmacro()
 
 function(read_absolute_symlink DEST PATH)
@@ -157,38 +132,37 @@ function(target_get_dynamic_library DEST TARGET)
         # 1. find the target library a file might be symbolic linking to
         # 2. find all other files in the same folder that symolic link to it
         # 3. sort all these files, and select the 2nd item
-        set(props_to_check IMPORTED_LOCATION)
+        set(location_properties IMPORTED_LOCATION)
         if (CMAKE_BUILD_TYPE)
-            list(APPEND props_to_check IMPORTED_LOCATION_${CMAKE_BUILD_TYPE})
+            list(APPEND location_properties IMPORTED_LOCATION_${CMAKE_BUILD_TYPE})
         endif()
         foreach (config_type ${CMAKE_CONFIGURATION_TYPES} RELEASE DEBUG RELWITHDEBINFO MINSIZEREL)
-            list(APPEND props_to_check IMPORTED_LOCATION_${config_type})
+            list(APPEND location_properties IMPORTED_LOCATION_${config_type})
         endforeach()
-        foreach(prop_to_check ${props_to_check})
+        foreach(location_property ${location_properties})
             if (NOT result)
-                get_target_property(propvalue "${TARGET}" ${prop_to_check})
-                if (EXISTS "${propvalue}")
-                    while (IS_SYMLINK "${propvalue}")
-                        read_absolute_symlink(propvalue "${propvalue}")
+                get_target_property(library_path "${TARGET}" ${location_property})
+                if (EXISTS "${library_path}")
+                    while (IS_SYMLINK "${library_path}")
+                        read_absolute_symlink(library_path "${library_path}")
                     endwhile()
-                    get_filename_component(libdir "${propvalue}" DIRECTORY)
+                    get_filename_component(libdir "${library_path}" DIRECTORY)
                

(Patch may be truncated, please check the link at the top of this post.)