CMake编译Android/iOS库
project(RayStreamNet)
cmake_minimum_required(VERSION 3.1)
add_compile_options(-fvisibility=hidden -std=c++14 -fPIC -O3)
add_definitions(-DASIO_STANDALONE -DRAYSTREAMNET_LIB -D_WEBSOCKETPP_CPP11_STL_)
add_definitions(-DLIB_TYPE=STATIC)
include_directories(
../Common
../depends/include
../depends/include/asio-1.18.0
)
aux_source_directory(./ RayStreamNetSrc)
aux_source_directory(../Common RayStreamNetSrc)
if (ANDROID)
link_libraries(log)
endif ()
add_library(${PROJECT_NAME} ${LIB_TYPE} ${RayStreamNetSrc})
#!/bin/bash
mkdir -p build
cd build
export build_abi="arm64-v8a armeabi-v7a x86 x86_64"
export NDK_HOME=/usr/local/android/android-ndk-r19c
export NAME="libRayStreamNet"
export LIB_TYPE="SHARED"
export EXT=".so"
mkdir -p $build_abi
build() {
for abi in $@
do
echo "build $abi"
cmake .. -DLIB_TYPE=$LIB_TYPE -DCMAKE_TOOLCHAIN_FILE=$NDK_HOME/build/cmake/android.toolchain.cmake -DANDROID_ABI=$abi -DANDROID_PLATFORM=android-22
cmake --build . --config Release -- -j8
mv $NAME$EXT $abi
done
}
build $build_abi
shopt -s extglob
rm -rf !(arm64-v8a|armeabi-v7a|x86|x86_64)
#!/bin/bash
rm -rf build
mkdir -p build
cd build
cmake .. -GXcode \
-DCMAKE_SYSTEM_NAME=iOS \
"-DCMAKE_OSX_ARCHITECTURES=armv7;armv7s;arm64" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=9.3 \
-DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \
-DCMAKE_IOS_INSTALL_COMBINED=YES
cmake --build . --config Release