Skip to content

Commit e3bb184

Browse files
committed
Add build script for iOS
1 parent f0c6979 commit e3bb184

File tree

3 files changed

+93
-7
lines changed

3 files changed

+93
-7
lines changed

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ if ( CMAKE_SYSTEM MATCHES "Linux" )
110110
option ( enable-systemd "compile systemd support (if it is available)" on )
111111
endif ( CMAKE_SYSTEM MATCHES "Linux" )
112112

113-
if ( CMAKE_SYSTEM MATCHES "Darwin" )
113+
if ( CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS" )
114114
option ( enable-coreaudio "compile CoreAudio support (if it is available)" on )
115115
option ( enable-coremidi "compile CoreMIDI support (if it is available)" on )
116116
option ( enable-framework "create a Mac OSX style FluidSynth.framework" on )
117-
endif ( CMAKE_SYSTEM MATCHES "Darwin" )
117+
endif ( CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS" )
118118

119119
if ( CMAKE_SYSTEM MATCHES "OS2" )
120120
option ( enable-dart "compile DART support (if it is available)" on )
@@ -201,7 +201,7 @@ unset ( ENABLE_UBSAN CACHE )
201201

202202
if ( CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "Intel" )
203203
# If we ever bump to CMake 3.29+, replace this with CMAKE_LANG_COMPILER_LINKER_ID
204-
if (NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|OS2|Emscripten|SunOS") )
204+
if (NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS|OS2|Emscripten|SunOS") )
205205
set ( CMAKE_EXE_LINKER_FLAGS
206206
"${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed" )
207207
set ( CMAKE_SHARED_LINKER_FLAGS
@@ -407,14 +407,14 @@ if ( CMAKE_SYSTEM MATCHES "SunOS" )
407407
set ( LIBFLUID_LIBS "${LIBFLUID_LIBS};nsl;socket" )
408408
endif ( CMAKE_SYSTEM MATCHES "SunOS" )
409409

410-
# Apple Mac OSX
410+
# Apple Mac OSX / iOS
411411
unset ( COREAUDIO_SUPPORT CACHE )
412412
unset ( COREAUDIO_LIBS CACHE )
413413
unset ( COREMIDI_SUPPORT CACHE )
414414
unset ( COREMIDI_LIBS CACHE )
415415
unset ( DARWIN CACHE )
416416
unset ( MACOSX_FRAMEWORK CACHE )
417-
if ( CMAKE_SYSTEM MATCHES "Darwin" )
417+
if ( CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS" )
418418
set ( DARWIN 1 )
419419
set ( CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR} )
420420
if ( enable-coreaudio )
@@ -428,13 +428,13 @@ if ( CMAKE_SYSTEM MATCHES "Darwin" )
428428
check_include_file ( CoreMIDI/MIDIServices.h COREMIDI_FOUND )
429429
if ( COREMIDI_FOUND )
430430
set ( COREMIDI_SUPPORT 1 )
431-
set ( COREMIDI_LIBS "-Wl,-framework,CoreMIDI,-framework,CoreServices" )
431+
set ( COREMIDI_LIBS "-Wl,-framework,CoreFoundation,-framework,CoreMIDI,-framework,CoreServices" )
432432
endif ( COREMIDI_FOUND )
433433
endif ( enable-coremidi )
434434
if ( enable-framework )
435435
set ( MACOSX_FRAMEWORK 1 )
436436
endif ( enable-framework )
437-
endif ( CMAKE_SYSTEM MATCHES "Darwin" )
437+
endif ( CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS" )
438438

439439
# Android
440440
if ( ANDROID_ABI )

ios/build.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
3+
# Framework build script for iOS
4+
# SDL3 is used instead of CoreAudio as CoreAudio/AudioHardware.h is not available in iOS.
5+
# Assumes the built SDL3 framework for both iOS and iOS simulator is located in /path/to/fluidsynth/SDL/build/SDL3.xcframework
6+
# Also assumes the build script is run on a Mac with XCode installed
7+
set -e
8+
9+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
SDL3_XCFRAMEWORK_DIR="${SCRIPT_DIR}/../SDL/build/SDL3.xcframework"
11+
SDL3_CMAKE_DIR_IOS="${SDL3_XCFRAMEWORK_DIR}/ios-arm64/SDL3.framework/CMake"
12+
SDL3_CMAKE_DIR_IOS_SIMULATOR="${SDL3_XCFRAMEWORK_DIR}/ios-arm64_x86_64-simulator/SDL3.framework/CMake"
13+
14+
# Clean up previous builds
15+
rm -rf build
16+
mkdir -p build
17+
cd build
18+
rm -rf build-ios build-ios-simulator
19+
mkdir -p build-ios build-ios-simulator
20+
21+
# Common CMake flags across builds
22+
CMAKE_COMMON_FLAGS=(
23+
-G Xcode
24+
-Dosal=cpp11
25+
-Denable-framework=ON
26+
-Denable-libinstpatch=0
27+
-Denable-aufile=OFF
28+
-Denable-dbus=OFF
29+
-Denable-ladspa=OFF
30+
-Denable-midishare=OFF
31+
-Denable-opensles=OFF
32+
-Denable-oboe=OFF
33+
-Denable-oss=OFF
34+
-Denable-pipewire=OFF
35+
-Denable-portaudio=OFF
36+
-Denable-pulseaudio=OFF
37+
-Denable-readline=OFF
38+
-Denable-coreaudio=OFF
39+
-Denable-sdl3=ON
40+
-Denable-systemd=OFF
41+
-Denable-threads=ON
42+
-Denable-waveout=OFF
43+
-Denable-network=OFF
44+
-Denable-ipv6=OFF
45+
-Denable-libsndfile=OFF
46+
-DCMAKE_MACOSX_BUNDLE=NO
47+
-DBUILD_SHARED_LIBS=ON
48+
)
49+
50+
# Download iOS toolchain
51+
curl -o ios.toolchain.cmake https://raw.githubusercontent.com/leetal/ios-cmake/master/ios.toolchain.cmake
52+
53+
# Build for iOS device (arm64)
54+
echo "Building for iOS device (arm64)..."
55+
cd build-ios
56+
cmake ../.. \
57+
-DCMAKE_TOOLCHAIN_FILE=../ios.toolchain.cmake \
58+
-DPLATFORM=OS64 \
59+
-DSDL3_DIR="${SDL3_CMAKE_DIR_IOS}" \
60+
"${CMAKE_COMMON_FLAGS[@]}"
61+
62+
xcodebuild -project FluidSynth.xcodeproj -target libfluidsynth -configuration Release -sdk iphoneos build 2>&1
63+
cd ..
64+
65+
# Build for iOS simulator
66+
echo "Building for iOS simulator..."
67+
cd build-ios-simulator
68+
cmake ../../ \
69+
-DCMAKE_TOOLCHAIN_FILE=../ios.toolchain.cmake \
70+
-DPLATFORM=SIMULATOR64COMBINED \
71+
-DSDL3_DIR="${SDL3_CMAKE_DIR_IOS_SIMULATOR}" \
72+
"${CMAKE_COMMON_FLAGS[@]}"
73+
74+
xcodebuild -project FluidSynth.xcodeproj -target libfluidsynth -configuration Release -sdk iphonesimulator build 2>&1
75+
cd ..
76+
77+
# Create XCFramework from the built dynamic frameworks
78+
echo "Creating XCFramework..."
79+
rm -rf FluidSynth.xcframework
80+
xcodebuild -create-xcframework \
81+
-framework build-ios/src/Release-iphoneos/FluidSynth.framework \
82+
-framework build-ios-simulator/src/Release-iphonesimulator/FluidSynth.framework \
83+
-output FluidSynth.xcframework
84+
85+
echo "FluidSynth.xcframework (dynamic framework) built successfully at build/FluidSynth.xcframework"

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ if ( MACOSX_FRAMEWORK )
332332
FRAMEWORK TRUE
333333
PUBLIC_HEADER "${public_main_HEADER}"
334334
FRAMEWORK_VERSION "${LIB_VERSION_CURRENT}"
335+
MACOSX_FRAMEWORK_IDENTIFIER "org.fluidsynth.FluidSynth"
335336
INSTALL_NAME_DIR ""
336337
VERSION ${LIB_VERSION_INFO}
337338
SOVERSION ${LIB_VERSION_CURRENT}

0 commit comments

Comments
 (0)