Skip to content

Improve documentation and add an ios build script #549

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 27 additions & 1 deletion docs/build.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
## Build

### Building static libraries

A static library can be build using:
```
mkdir build #make a build dir so that you can build out of tree
cd build
cmake -DUSE_TLS=1 ..
make -j
```
There are also two build scripts in the `tools` folder for creating static libraries for android and iOS/macOS respectively.<br>
Arguments can be changed in the script files.

Android:
```
mkdir build
cd build
./../tools/build_android.sh
make -j
```
macOS & iOS:
```
mkdir build
cd build
./../tools/build_ios.sh
```

### CMake

CMakefiles for the library and the examples are available. This library has few dependencies, so it is possible to just add the source files into your project. Otherwise the usual way will suffice.

```
mkdir build # make a build dir so that you can build out of tree.
mkdir build
cd build
cmake -DUSE_TLS=1 ..
make -j
Expand Down
10 changes: 8 additions & 2 deletions tools/build_android.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
# -DANDROID_NATIVE_API_LEVEL=23
# -DANDROID_TOOLCHAIN=clang
# jvmArgs :
#
#
# To use a specific version of openSSL, add the arguments:
# -DOPENSSL_VERSION="[version]"
# -DOPENSSL_FOUND=1
# -DOPENSSL_INCLUDE_DIR=[include path]
# -DOPENSSL_LIBRARIES="[lib path]/libssl.a;[lib path]/libcrypto.a"
#

CMAKE_TOOLCHAIN_FILE=/tools/android/android-ndk-r20-darwin/build/cmake/android.toolchain.cmake
ANDROID_HOME=/tools/android/android-sdk-darwin
Expand All @@ -33,4 +39,4 @@ ${CMAKE} \
-G'Unix Makefiles' \
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} \
-DCMAKE_MAKE_PROGRAM=make \
-DUSE_WS=1
-DUSE_TLS=1
35 changes: 35 additions & 0 deletions tools/build_ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

#
# This script creates static libraries for macOS and iOS devices
#
# To use a specific OpenSSL version add the arguments:
# -DOPENSSL_VERSION="[version]" \
# -DOPENSSL_FOUND=1 \
# -DOPENSSL_INCLUDE_DIR=[include path] \
# -DOPENSSL_LIBRARIES="[lib path]/libssl.a;[lib path]/libcrypto.a" \
#

DEPLOYMENT_TARGET_IOS='12.0'
DEPLOYMENT_TARGET_MAC='14.0'
CMAKE_DIR=/Applications/CMake.app/Contents/bin
CMAKE=${CMAKE_DIR}/cmake

${CMAKE} \
.. \
-GXcode \
-DUSE_TLS=1

mkdir -p ios sim mac

xcodebuild -project 'ixwebsocket.xcodeproj' -target "ixwebsocket" -sdk iphoneos ARCHS='arm64' TARGET_BUILD_DIR='$(PWD)/ios' BUILT_PRODUCTS_DIR='$(PWD)/ios' TARGET_NAME='ixwebsocket' IPHONEOS_DEPLOYMENT_TARGET=${DEPLOYMENT_TARGET_IOS}
xcodebuild -project 'ixwebsocket.xcodeproj' -target "ixwebsocket" -sdk iphonesimulator ARCHS='x86_64' TARGET_BUILD_DIR='$(PWD)/sim' BUILT_PRODUCTS_DIR='$(PWD)/sim' TARGET_NAME='ixwebsocket' IPHONEOS_DEPLOYMENT_TARGET=${DEPLOYMENT_TARGET_IOS}
xcodebuild -project 'ixwebsocket.xcodeproj' -target "ixwebsocket" -destination 'platform=OS X' ARCHS='x86_64 arm64' TARGET_BUILD_DIR='$(PWD)/mac' BUILT_PRODUCTS_DIR='$(PWD)/mac' TARGET_NAME='ixwebsocket' MACOSX_DEPLOYMENT_TARGET=${DEPLOYMENT_TARGET_MAC}

rm -rf ./out/*.a
rm -rf ./out/ios/*.a
rm -rf ./out/mac/*.a
mkdir -p out
mkdir -p ./out/ios ./out/mac
lipo -create "./ios/libixwebsocket.a" "./sim/libixwebsocket.a" -output ./out/ios/libixwebsocket.a
cp "./mac/libixwebsocket.a" ./out/mac/libixwebsocket.a