Skip to content

Commit

Permalink
improve ios build
Browse files Browse the repository at this point in the history
  • Loading branch information
boyan01 committed Dec 8, 2021
1 parent 85d61de commit cf1e255
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
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()

0 comments on commit cf1e255

Please sign in to comment.