Skip to content

Commit cf1e255

Browse files
committed
improve ios build
1 parent 85d61de commit cf1e255

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ a.out
44
compile_commands.json
55
libsimple.*
66
build/
7+
build-ios/
78
*.gch
89
bin/
910
output/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ make install
7171

7272
支持 iOS 编译:
7373
```
74-
cmake ../.. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../contrib/ios.toolchain.cmake -DPLATFORM=OS64COMBINED -DENABLE_BITCODE=0
74+
./build-ios.sh
7575
```
7676

7777
### 代码

build-ios.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/zsh
2+
3+
current_dir=$(pwd)/$(dirname "$0")
4+
build_dir="${current_dir}/build-ios"
5+
lib_prefix="${current_dir}/output"
6+
7+
cmake "$current_dir" -G Xcode -DCMAKE_TOOLCHAIN_FILE=contrib/ios.toolchain.cmake \
8+
-DPLATFORM=OS64COMBINED -DENABLE_BITCODE=1 \
9+
-DCMAKE_INSTALL_PREFIX="" -B "$build_dir" \
10+
-DDEPLOYMENT_TARGET=8.0
11+
12+
cd "$build_dir" || exit
13+
14+
cmake --build "$build_dir" --config Release
15+
cmake --install "$build_dir" --config Release --prefix "${lib_prefix}"

src/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ set(SOURCE_FILES
2525
entry.cc
2626
)
2727

28+
if (IOS)
29+
# iOS only support static library.
30+
add_library(simple STATIC ${SOURCE_FILES})
31+
else()
2832
add_library(simple SHARED ${SOURCE_FILES})
33+
endif()
2934

3035
if(SIMPLE_WITH_JIEBA)
3136
add_dependencies(simple cppjieba)
@@ -44,3 +49,9 @@ endif()
4449
target_link_libraries(simple PUBLIC coverage_config PRIVATE PINYIN_TEXT SQLite3)
4550

4651
install(TARGETS simple DESTINATION bin)
52+
53+
if (IOS)
54+
# iOS build as static library. so we need install PINYIN_TEXT too.
55+
install(TARGETS PINYIN_TEXT DESTINATION bin)
56+
endif()
57+

0 commit comments

Comments
 (0)