Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve iOS build #73

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ a.out
compile_commands.json
libsimple.*
build/
build-ios/
*.gch
bin/
output/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ make install

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

### 代码
Expand Down
15 changes: 15 additions & 0 deletions build-ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/zsh

current_dir=$(pwd)/$(dirname "$0")
build_dir="${current_dir}/build-ios"
lib_prefix="${current_dir}/output"

cmake "$current_dir" -G Xcode -DCMAKE_TOOLCHAIN_FILE=contrib/ios.toolchain.cmake \
-DPLATFORM=OS64COMBINED -DENABLE_BITCODE=1 \
-DCMAKE_INSTALL_PREFIX="" -B "$build_dir" \
-DDEPLOYMENT_TARGET=8.0

cd "$build_dir" || exit

cmake --build "$build_dir" --config Release
cmake --install "$build_dir" --config Release --prefix "${lib_prefix}"
11 changes: 11 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ set(SOURCE_FILES
entry.cc
)

if (IOS)
# iOS only support static library.
add_library(simple STATIC ${SOURCE_FILES})
else()
add_library(simple SHARED ${SOURCE_FILES})
endif()

if(SIMPLE_WITH_JIEBA)
add_dependencies(simple cppjieba)
Expand All @@ -44,3 +49,9 @@ endif()
target_link_libraries(simple PUBLIC coverage_config PRIVATE PINYIN_TEXT SQLite3)

install(TARGETS simple DESTINATION bin)

if (IOS)
# iOS build as static library. so we need install PINYIN_TEXT too.
install(TARGETS PINYIN_TEXT DESTINATION bin)
endif()