一、Android平台
1. 进入网址https://repology.org/metapackage/libevhtp/versions,下载libevhtp压缩包。
2. 解压进入libevhtp-1.2.16目录,在当前目录下创建文件夹openssl,将openssl的头文件以及库分别拷贝openssl /include到和openssl/lib目录下,并将openssl的头文件拷贝到include目录下。
3. 在当前目录下创建文件夹libevent,将libevent的头文件以及库分别拷贝libevent/include到和libevent/lib目录下。
4. 修改CMakeLists.txt,注释掉196行的list (APPEND LIBEVHTP_EXTERNAL_LIBS pthread),因为Android平台的pthread库在c库里了,不需要额外链接。
5.进入build目录,新建ShellScript脚本。
#!/bin/bash
rm -rf CMakeCache.txt
rm -rf CMakeFiles
rm -rf cmake_install.cmake
rm -rf Makefile
rm -rf CTestTestfile.cmake
if [[ “$@“ =~ "-d" ]];then
echo "----------------------------cmake debug----------------------------"
cmake -DDEBUG=ON -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
-DANDROID_NDK=$ANDROID_NDK_HOME \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_PLATFORM=android-21 \
-DANDROID_STL=c++_shared \
-DEVHTP_BUILD_SHARED=ON \
-DLIBEVENT_INCLUDE_DIR=../libevent/include \
-DLIBEVENT_LIBRARY=../libevent/lib/libevent.a \
-DLIBEVENT_CORE=../libevent/lib/libevent_core.a \
-DLIBEVENT_EXTRA=../libevent/lib/libevent_extra.a \
-DLIBEVENT_THREAD=../libevent/lib/libevent_pthreads.a \
-DLIBEVENT_SSL=../libevent/lib/libevent_openssl.a \
-DOPENSSL_INCLUDE_DIR=../openssl/include \
-DOPENSSL_CRYPTO_LIBRARY=../openssl/lib/libcrypto.a \
-DOPENSSL_SSL_LIBRARY=../openssl/lib/libssl.a \
..
else
echo "----------------------------cmake release----------------------------"
cmake -DDEBUG=NO -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
-DANDROID_NDK=$ANDROID_NDK_HOME \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_PLATFORM=android-21 \
-DANDROID_STL=c++_shared \
-DEVHTP_BUILD_SHARED=ON \
-DLIBEVENT_INCLUDE_DIR=../libevent/include \
-DLIBEVENT_LIBRARY=../libevent/lib/libevent.a \
-DLIBEVENT_CORE=../libevent/lib/libevent_core.a \
-DLIBEVENT_EXTRA=../libevent/lib/libevent_extra.a \
-DLIBEVENT_THREAD=../libevent/lib/libevent_pthreads.a \
-DLIBEVENT_SSL=../libevent/lib/libevent_openssl.a \
-DOPENSSL_INCLUDE_DIR=../openssl/include \
-DOPENSSL_CRYPTO_LIBRARY=../openssl/lib/libcrypto.a \
-DOPENSSL_SSL_LIBRARY=../openssl/lib/libssl.a \
..
fi
make
rm -rf CMakeCache.txt
rm -rf CMakeFiles
rm -rf cmake_install.cmake
rm -rf Makefile
rm -rf CTestTestfile.cmake
5.使用chmod +x ShellScript给ShellScript脚本赋予执行权限。
6. ./ShellScript
一、iOS平台
1. 进入网址https://repology.org/metapackage/libevhtp/versions,下载libevhtp压缩包。
2. 解压进入libevhtp-1.2.16目录,在当前目录下创建文件夹openssl,将openssl的头文件以及库分别拷贝openssl /include到和openssl/lib目录下,并将openssl的头文件拷贝到include目录下。
3. 在当前目录下创建文件夹libevent,将libevent的头文件以及库分别拷贝libevent/include到和libevent/lib目录下。
4. 修改CMakeLists.txt,增加两行。
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-abi-version=2 -fobjc-arc -std=gnu++11 -stdlib=libc++ -isysroot ${CMAKE_OSX_SYSROOT}")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fobjc-abi-version=2 -fobjc-arc -isysroot ${CMAKE_OSX_SYSROOT}")
5.进入build目录,新建ShellScript脚本。
#!/bin/bash
rm -rf CMakeCache.txt
rm -rf CMakeFiles
rm -rf cmake_install.cmake
rm -rf Makefile
rm -rf CTestTestfile.cmake
if [ “$@“ =~ "-d" ];then
echo "----------------------------cmake debug----------------------------"
cmake -DDEBUG=ON -DCMAKE_TOOLCHAIN_FILE=./toolchain/iOS.cmake -DIOS_PLATFORM=OS -DBUILD_ARM64=1 \
-DEVHTP_BUILD_SHARED=OFF \
-DCMAKE_SIZEOF_VOID_P=8 \
-DLIBEVENT_INCLUDE_DIR=../libevent/include \
-DLIBEVENT_LIBRARY=../libevent/lib/libevent.a \
-DLIBEVENT_CORE=../libevent/lib/libevent_core.a \
-DLIBEVENT_EXTRA=../libevent/lib/libevent_extra.a \
-DLIBEVENT_THREAD=../libevent/lib/libevent_pthreads.a \
-DLIBEVENT_SSL=../libevent/lib/libevent_openssl.a \
-DOPENSSL_INCLUDE_DIR=../openssl/include \
-DOPENSSL_CRYPTO_LIBRARY=../openssl/lib/libcrypto.a \
-DOPENSSL_SSL_LIBRARY=../openssl/lib/libssl.a \
..
else
echo "----------------------------cmake release----------------------------"
cmake -DDEBUG=NO -DCMAKE_TOOLCHAIN_FILE=./toolchain/iOS.cmake -DIOS_PLATFORM=OS -DBUILD_ARM64=1 \
-DEVHTP_BUILD_SHARED=OFF \
-DCMAKE_SIZEOF_VOID_P=8 \
-DLIBEVENT_INCLUDE_DIR=../libevent/include \
-DLIBEVENT_LIBRARY=../libevent/lib/libevent.a \
-DLIBEVENT_CORE=../libevent/lib/libevent_core.a \
-DLIBEVENT_EXTRA=../libevent/lib/libevent_extra.a \
-DLIBEVENT_THREAD=../libevent/lib/libevent_pthreads.a \
-DLIBEVENT_SSL=../libevent/lib/libevent_openssl.a \
-DOPENSSL_INCLUDE_DIR=../openssl/include \
-DOPENSSL_CRYPTO_LIBRARY=../openssl/lib/libcrypto.a \
-DOPENSSL_SSL_LIBRARY=../openssl/lib/libssl.a \
..
fi
make
rm -rf CMakeCache.txt
rm -rf CMakeFiles
rm -rf cmake_install.cmake
rm -rf Makefile
rm -rf CTestTestfile.cmake
6.下载iOS cmake交叉编译链,下载链接:https://download.csdn.net/download/zhuyunier/10273702。解压压缩包到build目录下,进入build目录,执行ShellScript脚本。