Skip to content

Commit

Permalink
Merge pull request #743 from axmo/ios
Browse files Browse the repository at this point in the history
Add iOS build support
  • Loading branch information
bvschaik authored Jan 9, 2025
2 parents 3110846 + 873b632 commit 33c7770
Show file tree
Hide file tree
Showing 19 changed files with 493 additions and 27 deletions.
17 changes: 17 additions & 0 deletions .ci_scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ function install_sdl_android {
tar -zxf $FILENAME -C ext/SDL2
}

function install_sdl_ios {
local MODULE=$1
local VERSION=$2
local DIRNAME=deps/$MODULE-$VERSION
local FILENAME=$DIRNAME.tar.gz
if [ ! -f "$FILENAME" ]
then
get_sdl_lib_url $MODULE $VERSION "tar.gz"
curl -o "$FILENAME" "$SDL_LIB_URL"
fi
tar -zxf $FILENAME -C ext/SDL2
}

mkdir -p deps
if [ "$BUILD_TARGET" == "appimage" ] || [ "$BUILD_TARGET" == "codeql-cpp" ]
then
Expand All @@ -105,6 +118,10 @@ then
then
install_sdl_android "SDL2" $SDL_VERSION
install_sdl_android "SDL2_mixer" $SDL_MIXER_VERSION
elif [ "$BUILD_TARGET" == "ios" ]
then
install_sdl_ios "SDL2" $SDL_VERSION
install_sdl_ios "SDL2_mixer" $SDL_MIXER_VERSION
else
if [ "$BUILD_TARGET" == "emscripten" ]
then
Expand Down
4 changes: 4 additions & 0 deletions .ci_scripts/run_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ case "$BUILD_TARGET" in
echo "Creating disk image"
hdiutil create -volname Julius -srcfolder julius.app -ov -format UDZO julius.dmg
;;
"ios")
cd build
xcodebuild clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -scheme julius
;;
"flatpak")
flatpak-builder repo com.github.bvschaik.julius.json --install-deps-from=flathub --keep-build-dirs
cp .flatpak-builder/build/julius/res/version.txt res/version.txt
Expand Down
3 changes: 3 additions & 0 deletions .ci_scripts/run_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ case "$BUILD_TARGET" in
"mac")
mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DSYSTEM_LIBS=OFF -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" ..
;;
"ios")
mkdir build && cd build && cmake .. -DTARGET_PLATFORM=ios -G Xcode
;;
"flatpak")
;;
"appimage")
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ jobs:
SDL_MIXER_VERSION: 2.8.0
BUILD_TARGET: mac
DEPLOY: mac
- name: iOS
os: macos-latest
cache-key: ios
SDL_VERSION: 2.30.9
SDL_MIXER_VERSION: 2.8.0
BUILD_TARGET: ios
DEPLOY: ios
- name: Nintendo Switch
os: ubuntu-20.04
BUILD_TARGET: switch
Expand Down
148 changes: 123 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.1)
include(CMakeDependentOption)

set(TARGET_PLATFORM "default" CACHE STRING "Platform to cross-compile for. Options: vita switch android emscripten. Leave blank for no cross compilation")
set_property(CACHE TARGET_PLATFORM PROPERTY STRINGS default vita switch android emscripten)
set(TARGET_PLATFORM "default" CACHE STRING "Platform to cross-compile for. Options: vita switch android ios emscripten. Leave blank for no cross compilation")
set_property(CACHE TARGET_PLATFORM PROPERTY STRINGS default vita switch android ios emscripten)

string(TOLOWER ${TARGET_PLATFORM} TARGET_PLATFORM)

Expand All @@ -29,6 +29,34 @@ if(${TARGET_PLATFORM} STREQUAL "emscripten" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE
message(FATAL_ERROR "Please define EMSDK to point to your Emscripten SDK path!")
endif()
endif()

if(${TARGET_PLATFORM} STREQUAL "ios")

set(CMAKE_SYSTEM_NAME "iOS")

set(SYSTEM_LIBS OFF)

# Build SDL2 as static library
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
set(SDL_SHARED OFF)
set(SDL_STATIC ON)

# Build SDL2_mixer as static library
set(BUILD_SHARED_LIBS OFF)

# Disable stuff that breaks the build and we don't need.
set(SDL2MIXER_WAVPACK OFF)
set(SDL2MIXER_OPUS OFF)
set(SDL2MIXER_MIDI OFF)
set(SDL2MIXER_MOD OFF)

# Explicitly set SDKROOT (called Base SDK in Xcode), otherwise it is set incorrectly.
set(CMAKE_XCODE_ATTRIBUTE_SDKROOT iphoneos)

# Support iPhone (1) and iPad (2) Destinations
set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
endif()


set(SHORT_NAME julius)
set(USER_FRIENDLY_NAME Julius)
Expand Down Expand Up @@ -206,6 +234,12 @@ elseif (${TARGET_PLATFORM} STREQUAL "android")
${PLATFORM_FILES}
${PROJECT_SOURCE_DIR}/src/platform/android/android.c
)
elseif (${TARGET_PLATFORM} STREQUAL "ios")
set(PLATFORM_FILES
${PLATFORM_FILES}
${PROJECT_SOURCE_DIR}/src/platform/ios/ios.m
${PROJECT_SOURCE_DIR}/src/platform/ios/GameDataPickerController.m
)
endif()

set(CORE_FILES
Expand Down Expand Up @@ -581,10 +615,20 @@ set(TRANSLATION_FILES
)

set(MACOSX_FILES "")
if(APPLE)
if(APPLE AND NOT ${TARGET_PLATFORM} STREQUAL "ios")
set(MACOSX_FILES ${PROJECT_SOURCE_DIR}/res/julius.icns)
endif()


set(IOS_FILES "")
if(${TARGET_PLATFORM} STREQUAL "ios")
set(IOS_FILES
${PROJECT_SOURCE_DIR}/res/ios/Assets.xcassets
)

endif()


set(EMSCRIPTEN_FILES "")
if(${TARGET_PLATFORM} STREQUAL "emscripten")
set(EMSCRIPTEN_FILES ${PROJECT_SOURCE_DIR}/res/shell.html)
Expand All @@ -611,41 +655,59 @@ set(SOURCE_FILES
${TINYFD_FILES}
${PROJECT_SOURCE_DIR}/res/julius.rc
${MACOSX_FILES}
${IOS_FILES}
${EMSCRIPTEN_FILES}
)

function(GET_SDL_EXT_DIR result module)
if(NOT module STREQUAL "")
set(module "_${module}")
endif()
set(SDL_LOCATION ${PROJECT_SOURCE_DIR}/ext/SDL2)
file(GLOB children
RELATIVE ${SDL_LOCATION}
CONFIGURE_DEPENDS
${SDL_LOCATION}/SDL${module}
${SDL_LOCATION}/SDL2${module}
${SDL_LOCATION}/SDL${module}-*
${SDL_LOCATION}/SDL2${module}-*
)
foreach(child ${children})
if(IS_DIRECTORY "${SDL_LOCATION}/${child}")
set(${result} "${SDL_LOCATION}/${child}" PARENT_SCOPE)
break()
endif()
endforeach()
endfunction()

if(${TARGET_PLATFORM} STREQUAL "emscripten")
set(USE_FLAGS "-s USE_SDL=2 -s USE_SDL_MIXER=2 -s SDL2_MIXER_FORMATS=[\"mp3\"] -s USE_MPG123=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${USE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS}")
else()
function(GET_SDL_EXT_DIR result module)
if(NOT module STREQUAL "")
set(module "_${module}")
endif()
set(SDL_LOCATION ${PROJECT_SOURCE_DIR}/ext/SDL2)
file(GLOB children
RELATIVE ${SDL_LOCATION}
CONFIGURE_DEPENDS
${SDL_LOCATION}/SDL${module}
${SDL_LOCATION}/SDL2${module}
${SDL_LOCATION}/SDL${module}-*
${SDL_LOCATION}/SDL2${module}-*
)
foreach(child ${children})
if(IS_DIRECTORY "${SDL_LOCATION}/${child}")
set(${result} "${SDL_LOCATION}/${child}" PARENT_SCOPE)
break()
endif()
endforeach()
endfunction()

elseif(${TARGET_PLATFORM} STREQUAL "ios")
GET_SDL_EXT_DIR(SDL_EXT_DIR "")
add_subdirectory(${SDL_EXT_DIR})
find_library(SDL2 NAMES SDL2-static SDL2main)
list(APPEND SDL2_LIBRARY
# We don't need to add SDL2-static here because SDL2_mixer will include it
SDL2main
)
GET_SDL_EXT_DIR(SDL_MIXER_EXT_DIR "mixer")
add_subdirectory(${SDL_MIXER_EXT_DIR})
find_library(SDL2_mixer NAMES SDL2_mixer-static)
list(APPEND SDL2_MIXER_LIBRARY
SDL2_mixer
)
else()
find_package(SDL2 REQUIRED)
find_package(SDL2_mixer REQUIRED)
endif()

if(${TARGET_PLATFORM} STREQUAL "android")
add_library(${SHORT_NAME} SHARED ${SDL2_ANDROID_HOOK} ${SOURCE_FILES})
elseif(${TARGET_PLATFORM} STREQUAL "ios")
add_executable(${SHORT_NAME} MACOSX_BUNDLE ${SOURCE_FILES})
else()
add_executable(${SHORT_NAME} WIN32 ${SOURCE_FILES})
endif()
Expand All @@ -660,7 +722,7 @@ if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
endif()

if(APPLE)
if(APPLE AND NOT ${TARGET_PLATFORM} STREQUAL "ios")
# generating a macOS icns file (see https://stackoverflow.com/a/20703594)
add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/res/julius.icns
COMMAND mkdir -p julius.iconset
Expand Down Expand Up @@ -727,6 +789,26 @@ if(APPLE)
")
endif()

if(${TARGET_PLATFORM} STREQUAL "ios")
# setting variables that will populate Info.plist
set_target_properties(${SHORT_NAME} PROPERTIES

MACOSX_BUNDLE_BUNDLE_NAME ${USER_FRIENDLY_NAME}
MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${VERSION_REVISION}"
MACOSX_BUNDLE_GUI_IDENTIFIER "com.github.bvschaik.julius"
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/res/ios/Info.plist"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
MACOSX_BUNDLE_UI_LAUNCH_STORYBOARD_NAME "LaunchScreen"
OUTPUT_NAME "${PROJECT_NAME}"
XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon"
XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY 1,2
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.github.bvschaik.julius"
)
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.0" CACHE STRING "Minimum OS X deployment version" FORCE)
set_source_files_properties(${PROJECT_SOURCE_DIR}/res/ios/Assets.xcassets PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
endif()

if(SDL2_INCLUDE_DIR)
include_directories(SYSTEM ${SDL2_INCLUDE_DIR})
endif()
Expand Down Expand Up @@ -831,6 +913,22 @@ else()
find_library(LOG_LIB log)
target_link_libraries(${SHORT_NAME} ${LOG_LIB})
endif()

if(${TARGET_PLATFORM} STREQUAL "ios")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -DUSE_SDL_MAIN")
# Add SDL2 and SDL_Mixer headers, or they won't be found
target_include_directories(${SHORT_NAME} PRIVATE "${SDL_EXT_DIR}/include")
target_include_directories(${SHORT_NAME} PRIVATE "${SDL_MIXER_EXT_DIR}/include")

# Add UniformTypeIdentifiers to the list of linked frameworks
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-framework,UniformTypeIdentifiers")

set_target_properties(${SHORT_NAME} PROPERTIES
XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)"
XCODE_ATTRIBUTE_SKIP_INSTALL "No"
)
endif()

target_link_libraries(${SHORT_NAME} ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARY})
if(NOT APPLE AND NOT ${TARGET_PLATFORM} STREQUAL "android")
install(TARGETS ${SHORT_NAME} RUNTIME DESTINATION bin)
Expand Down
23 changes: 23 additions & 0 deletions doc/iOS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# iOS instructions

Download SDL2 and SDL2_mixer source releases and put them in `ext/SDL2/SDL2` and `ext/SDL2/SDL2_mixer` respectively.

run the following commands:

```
$ mkdir build && cd build
$ cmake .. -DTARGET_PLATFORM=ios -G Xcode
```

Open the resulting Xcode Project file `julius.xcodeproj`

## Build for Simulator
Choose `julius` in the Build Schemes dropdown, choose a Simulator from the Run Destinations dropdown, and click Run.

## Build for Device
With the Julius project and target selected, set a Bundle Id, and choose a Development Team, then choose `julius` in the Build Schemes dropdown, choose a device from the Run Destinations dropdown, and click Run.

## Running
AirDrop or otherwise download a C3 install folder to your iOS device (or simulator).

Launch Julius. Immediately after the first launch, Julius will display a file-picker dialog. Navigate to your C3 folder, and choose 'Open'. The C3 files will be *copied* to Julius's application documents directory, and the game will use those files from then on. Use the default location for saved games.
11 changes: 11 additions & 0 deletions res/ios/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
14 changes: 14 additions & 0 deletions res/ios/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "julius_1024.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions res/ios/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
22 changes: 22 additions & 0 deletions res/ios/Assets.xcassets/Julius.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "julius_256.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "julius_512.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 33c7770

Please sign in to comment.