SDL: ci: build tvOs/iOs CMake project

From b9ad5fc5899203f04485a3cb0cab2f435d1884b7 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 12 Aug 2024 05:52:26 +0200
Subject: [PATCH] ci: build tvOs/iOs CMake project

---
 .github/workflows/create-test-plan.py | 19 +++++++++++++++++--
 .github/workflows/release.yml         |  6 +++---
 cmake/test/CMakeLists.txt             |  4 +++-
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/create-test-plan.py b/.github/workflows/create-test-plan.py
index a1850134f2a09..99b3a7db96ef1 100755
--- a/.github/workflows/create-test-plan.py
+++ b/.github/workflows/create-test-plan.py
@@ -124,8 +124,8 @@ class JobSpec:
     "android-cmake-lean": JobSpec(name="Android (CMake, lean)",             os=JobOs.UbuntuLatest,  platform=SdlPlatform.Android,     artifact="SDL-lean-android-arm64", android_abi="arm64-v8a", android_arch="aarch64", android_platform=23, lean=True, ),
     "android-mk": JobSpec(name="Android (Android.mk)",                      os=JobOs.UbuntuLatest,  platform=SdlPlatform.Android,     artifact=None,                     no_cmake=True, android_mk=True, ),
     "android-gradle": JobSpec(name="Android (Gradle)",                      os=JobOs.UbuntuLatest,  platform=SdlPlatform.Android,     artifact=None,                     no_cmake=True, android_gradle=True, ),
-    "ios-xcode": JobSpec(name="iOS (xcode)",                                os=JobOs.MacosLatest,   platform=SdlPlatform.Ios,         artifact=None,                     no_cmake=True, ),
-    "tvos-xcode": JobSpec(name="tvOS (xcode)",                              os=JobOs.MacosLatest,   platform=SdlPlatform.Tvos,        artifact=None,                     no_cmake=True, ),
+    "ios": JobSpec(name="iOS (CMake & xcode)",                              os=JobOs.MacosLatest,   platform=SdlPlatform.Ios,         artifact="SDL-ios-arm64"           ),
+    "tvos": JobSpec(name="tvOS (CMake & xcode)",                            os=JobOs.MacosLatest,   platform=SdlPlatform.Tvos,        artifact="SDL-tvos-arm64",         ),
     "emscripten": JobSpec(name="Emscripten",                                os=JobOs.UbuntuLatest,  platform=SdlPlatform.Emscripten,  artifact="SDL-emscripten", ),
     "haiku": JobSpec(name="Haiku",                                          os=JobOs.UbuntuLatest,  platform=SdlPlatform.Haiku,       artifact="SDL-haiku-x64",          container="haiku/cross-compiler:x86_64-r1beta4", ),
     "loongarch64": JobSpec(name="LoongArch64",                              os=JobOs.UbuntuLatest,  platform=SdlPlatform.LoongArch64, artifact="SDL-loongarch64", ),
@@ -417,11 +417,26 @@ def spec_to_job(spec: JobSpec) -> JobDetails:
             if ubuntu_year >= 22:
                 job.apt_packages.extend(("libpipewire-0.3-dev", "libdecor-0-dev"))
         case SdlPlatform.Ios | SdlPlatform.Tvos:
+            job.brew_packages.extend([
+                "ninja",
+                "pkg-config",
+            ])
+            job.clang_tidy = False
+            job.run_tests = False
+            job.test_pkg_config = False
             match spec.platform:
                 case SdlPlatform.Ios:
                     job.xcode_sdk = 'iphoneos'
+                    job.cmake_arguments.extend([
+                        "-DCMAKE_SYSTEM_NAME=iOS",
+                        "-DCMAKE_OSX_ARCHITECTURES=\"arm64\"",
+                    ])
                 case SdlPlatform.Tvos:
                     job.xcode_sdk = 'appletvos'
+                    job.cmake_arguments.extend([
+                        "-DCMAKE_SYSTEM_NAME=tvOS",
+                        "-DCMAKE_OSX_ARCHITECTURES=\"arm64\"",
+                    ])
         case SdlPlatform.MacOS:
             if spec.apple_framework:
                 job.static = False
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 7cf940ce91836..388f3806b7c45 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -621,7 +621,7 @@ jobs:
         run: |
           android_abis="x86 x86_64 armeabi-v7a arm64-v8a"
           for android_abi in ${android_abis}; do
-            echo "Configure ${android_abi}"
+            echo "Configuring ${android_abi}..."
             cmake -S "${{ steps.src.outputs.path }}/cmake/test"                               \
               -DTEST_FULL=TRUE                                                                \
               -DTEST_STATIC=FALSE                                                             \
@@ -632,6 +632,6 @@ jobs:
               -Werror=dev                                                                     \
               -DCMAKE_BUILD_TYPE=Release                                                      \
               -B "${android_abi}"
+            echo "Building ${android_abi}..."
+            cmake --build "${android_abi}" --config Release --verbose
           done
-          echo "Build ${android_abi}"
-          cmake --build "${android_abi}" --config Release --verbose
diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt
index 11754a828ef4e..e38159382b151 100644
--- a/cmake/test/CMakeLists.txt
+++ b/cmake/test/CMakeLists.txt
@@ -5,7 +5,9 @@ project(sdl_test LANGUAGES C)
 
 include(CheckLanguage)
 
-if(APPLE)
+# FIXME: how to target ios/tvos with Swift?
+# https://gitlab.kitware.com/cmake/cmake/-/issues/20104
+if(APPLE AND CMAKE_SYSTEM_NAME MATCHES ".*(Darwin|MacOS).*")
     # multiple values for CMAKE_OSX_ARCHITECTURES not supported with Swift
     list(LENGTH CMAKE_OSX_ARCHITECTURES count_osx_archs)
     if(count_osx_archs LESS_EQUAL 1)