From ecba70703e3e79e36e0f226685010f8df6a411b0 Mon Sep 17 00:00:00 2001 From: Joy1024 <412555203@qq.com> Date: Fri, 18 Oct 2024 20:46:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=92=88=E5=AF=B9android?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ libmetartc7/CMakeLists.txt | 4 +++ libmetartc7/cmake_android.sh | 65 +++++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 259148fa..361a156a 100755 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ *.exe *.out *.app + +build/ +.vscode \ No newline at end of file diff --git a/libmetartc7/CMakeLists.txt b/libmetartc7/CMakeLists.txt index cb787980..02c1c5e5 100755 --- a/libmetartc7/CMakeLists.txt +++ b/libmetartc7/CMakeLists.txt @@ -3,6 +3,10 @@ project(libmetartc7) add_definitions(-D__STDC_FORMAT_MACROS) +if(ANDROID) + add_definitions(-DYang_OS_ANDROID) +endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -std=gnu11 ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=gnu++11 ") set(HOME_BASE_REL "../") diff --git a/libmetartc7/cmake_android.sh b/libmetartc7/cmake_android.sh index cfbeefb5..419c6646 100755 --- a/libmetartc7/cmake_android.sh +++ b/libmetartc7/cmake_android.sh @@ -1,27 +1,44 @@ -NDK_ROOT=/home/yang/pro/ndk -API=29 -rm -rf build -mkdir build -cd build +#!/usr/bin/env bash + +NDK_ROOT=/media/gaojie/lvm2/Android/Sdk/ndk/28.0.12433566/ +API=34 + #arm64-v8a armeabi x86_64 -ARCH=arm64-v8a -cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_NDK=$NDK_ROOT -DCMAKE_SYSTEM_NAME=Android -DANDROID_PLATFORM=android-${API} -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=${ARCH} -DAndroid=ON -DANDROID_STL=c++_static -DCMAKE_CXX_STANDARD=11 -DANDROID_NATIVE_API_LEVEL=${API} .. -make -if [ ! -d "../../bin/lib_android/arm64-v8a" ] ; then -mkdir -p ../../bin/lib_android/arm64-v8a -fi -cp ./libmetartc7.a ../../bin/lib_android/arm64-v8a/ - -cd .. -rm -rf build -mkdir build -cd build -ARCH=x86_64 -cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_NDK=$NDK_ROOT -DCMAKE_SYSTEM_NAME=Android -DANDROID_PLATFORM=android-${API} -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=${ARCH} -DAndroid=ON -DANDROID_STL=c++_static -DCMAKE_CXX_STANDARD=11 -DANDROID_NATIVE_API_LEVEL=${API} .. -make -if [ ! -d "../../bin/lib_android/x86_64" ] ; then -mkdir -p ../../bin/lib_android/x86_64 -fi -cp ./libmetartc7.a ../../bin/lib_android/x86_64/ +ARCHS="arm64-v8a armeabi-v7a x86_64" + +build() { + ARCH=$1 + + echo "Build for $ARCH" + BUILD_DIR=build/$ARCH + echo "Build dir is: $BUILD_DIR" + + #clean build dir + # rm -rf $BUILD_DIR + + # configuration + cmake -B $BUILD_DIR \ + -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake \ + -DCMAKE_SYSTEM_NAME=Android \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_CXX_STANDARD=11 \ + -DANDROID_NDK=$NDK_ROOT \ + -DANDROID_PLATFORM=android-${API} \ + -DANDROID_ABI=${ARCH} -DAndroid=ON \ + -DANDROID_STL=c++_static \ + -DANDROID_NATIVE_API_LEVEL=${API} \ + -DYang_OS_ANDROID=ON + + # build + cmake --build $BUILD_DIR + +} + + +for arch in $ARCHS +do + build $arch +done +