Skip to content

Commit e05f605

Browse files
committed
add iOS App
1 parent 86861ae commit e05f605

File tree

8 files changed

+261
-0
lines changed

8 files changed

+261
-0
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
lint:
11+
runs-on: macos-14
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Install dependencies
16+
run: brew install swift-format
17+
18+
- name: Lint
19+
run: |
20+
swift-format lint -rs src
21+
22+
build:
23+
needs: lint
24+
runs-on: ${{ matrix.os }}
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
os: [macos-14, macos-13]
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- name: Build
34+
run: |
35+
cmake -B build -G Xcode \
36+
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.cmake \
37+
-DIOS_PLATFORM=SIMULATOR
38+
cmake --build build --config Release
39+
40+
- name: Install
41+
run: |
42+
xcrun simctl boot "iPhone 15"
43+
xcrun simctl install booted build/src/Release-iphonesimulator/Fcitx5.app
44+
xcrun simctl launch booted org.fcitx.Fcitx5
45+
46+
- name: Setup tmate session
47+
if: ${{ failure() }}
48+
uses: mxschmitt/action-tmate@v3

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.27)
2+
3+
# Avoid MinSizeRel and RelWithDebInfo.
4+
set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING INTERNAL FORCE)
5+
6+
project(fcitx5-ios VERSION 0.1.0 LANGUAGES Swift)
7+
set(CMAKE_Swift_LANGUAGE_VERSION 5.9)
8+
9+
set(BUNDLE_IDENTIFIER "org.fcitx.Fcitx5")
10+
set(BUNDLE_NAME "Fcitx5")
11+
set(ICON_FILE "icon.icns")
12+
13+
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
14+
15+
add_subdirectory(src)

assets/icon.icns

554 KB
Binary file not shown.

cmake/MacOSXBundleInfo.plist.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleIdentifier</key>
6+
<string>@BUNDLE_IDENTIFIER@</string>
7+
<key>CFBundleName</key>
8+
<string>@BUNDLE_NAME@</string>
9+
<key>CFBundleDisplayName</key>
10+
<string>@BUNDLE_NAME@</string>
11+
<key>CFBundleVersion</key>
12+
<string>@PROJECT_VERSION@</string>
13+
<key>CFBundleShortVersionString</key>
14+
<string>@PROJECT_VERSION@</string>
15+
<key>CFBundleExecutable</key>
16+
<string>@BUNDLE_NAME@</string>
17+
<key>CFBundleIconFile</key>
18+
<string>@ICON_FILE@</string>
19+
<!-- A random string makes it fullscreen. -->
20+
<key>UILaunchScreen</key>
21+
<string>foo</string>
22+
</dict>
23+
</plist>

cmake/ios.cmake

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
set (CMAKE_SYSTEM_NAME Darwin)
2+
set (CMAKE_SYSTEM_VERSION 1)
3+
set (UNIX True)
4+
set (APPLE True)
5+
set (IOS True)
6+
7+
# Force the compilers to Clang for iOS
8+
include (CMakeForceCompiler)
9+
set (CMAKE_C_COMPILER /usr/bin/clang Clang)
10+
set (CMAKE_CXX_COMPILER /usr/bin/clang++ Clang)
11+
set (CMAKE_AR ar CACHE FILEPATH "" FORCE)
12+
13+
# Skip the platform compiler checks for cross compiling
14+
set (CMAKE_CXX_COMPILER_WORKS TRUE)
15+
set (CMAKE_C_COMPILER_WORKS TRUE)
16+
17+
# All iOS/Darwin specific settings - some may be redundant
18+
set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
19+
set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
20+
set (CMAKE_SHARED_MODULE_PREFIX "lib")
21+
set (CMAKE_SHARED_MODULE_SUFFIX ".so")
22+
set (CMAKE_MODULE_EXISTS 1)
23+
set (CMAKE_DL_LIBS "")
24+
25+
set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
26+
set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
27+
set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
28+
set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
29+
30+
set (CMAKE_C_FLAGS_INIT "")
31+
set (CMAKE_CXX_FLAGS_INIT "")
32+
33+
set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
34+
set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
35+
36+
set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
37+
set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
38+
set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
39+
set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
40+
set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
41+
set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
42+
43+
find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
44+
45+
# Setup iOS platform unless specified manually with IOS_PLATFORM
46+
if (NOT DEFINED IOS_PLATFORM)
47+
set (IOS_PLATFORM "OS")
48+
endif()
49+
set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
50+
51+
# Check the platform selection and setup for developer root
52+
if (IOS_PLATFORM STREQUAL "OS")
53+
set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
54+
55+
# This causes the installers to properly locate the output libraries
56+
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
57+
elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
58+
set (SIMULATOR true)
59+
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
60+
# This causes the installers to properly locate the output libraries
61+
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
62+
else ()
63+
message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
64+
endif ()
65+
66+
set (CMAKE_IOS_DEVELOPER_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
67+
68+
# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
69+
if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
70+
file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
71+
if (_CMAKE_IOS_SDKS)
72+
list (SORT _CMAKE_IOS_SDKS)
73+
list (REVERSE _CMAKE_IOS_SDKS)
74+
list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
75+
else (_CMAKE_IOS_SDKS)
76+
message (FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.")
77+
endif (_CMAKE_IOS_SDKS)
78+
message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
79+
endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
80+
set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
81+
82+
# Set the sysroot default to the most recent SDK
83+
set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
84+
85+
# set the architecture for iOS
86+
if (IOS_PLATFORM STREQUAL "OS")
87+
set (IOS_ARCH arm64)
88+
elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
89+
set (IOS_ARCH "${CMAKE_HOST_SYSTEM_PROCESSOR}")
90+
endif ()
91+
92+
set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS")
93+
94+
# Set the find root to the iOS developer roots and to user defined paths
95+
set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE STRING "iOS find search path root")
96+
97+
# default to searching for frameworks first
98+
set (CMAKE_FIND_FRAMEWORK FIRST)
99+
100+
# set up the default search directories for frameworks
101+
set (CMAKE_SYSTEM_FRAMEWORK_PATH
102+
${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
103+
${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
104+
${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
105+
)
106+
107+
# only search the iOS sdks, not the remainder of the host filesystem
108+
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
109+
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
110+
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
111+
112+
# This little macro lets you set any XCode specific property
113+
macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
114+
set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
115+
endmacro (set_xcode_property)
116+
117+
# This macro lets you find executable programs on the host system
118+
macro (find_host_package)
119+
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
120+
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
121+
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
122+
set (IOS FALSE)
123+
124+
find_package(${ARGN})
125+
126+
set (IOS TRUE)
127+
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
128+
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
129+
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
130+
endmacro (find_host_package)

src/App.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import SwiftUI
2+
3+
@main
4+
struct Fcitx5App: App {
5+
var body: some Scene {
6+
WindowGroup {
7+
ContentView()
8+
}
9+
}
10+
}

src/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
add_executable(
2+
${BUNDLE_NAME}
3+
MACOSX_BUNDLE
4+
ContentView.swift
5+
App.swift
6+
)
7+
8+
add_custom_command(
9+
TARGET ${BUNDLE_NAME}
10+
POST_BUILD COMMAND /bin/sh -c
11+
\"COMMAND_DONE=0 \;
12+
if ${CMAKE_COMMAND} -E copy
13+
${PROJECT_SOURCE_DIR}/assets/${ICON_FILE}
14+
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app
15+
\&\>/dev/null \; then
16+
COMMAND_DONE=1 \;
17+
fi \;
18+
if [ \\$$COMMAND_DONE -eq 0 ] \; then
19+
echo Failed to copy the icon into the app bundle \;
20+
exit 1 \;
21+
fi\"
22+
)

src/ContentView.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import SwiftUI
2+
3+
struct ContentView: View {
4+
var body: some View {
5+
VStack {
6+
Image(systemName: "globe")
7+
.imageScale(.large)
8+
.foregroundStyle(.tint)
9+
Text("Hello, world!")
10+
}
11+
.padding()
12+
}
13+
}

0 commit comments

Comments
 (0)