- Adapted bat file to new NDK and toolchain

- Able to build x86, x86_64, armv8, armv7 for android
- Automatically detects latest ndk on your system
pull/4454/head
Carlos Martinez Perez 2022-03-18 17:00:57 +01:00
parent 19f2a624a9
commit 90a24440db
2 changed files with 66 additions and 17 deletions

View File

@ -0,0 +1 @@
output

View File

@ -1,28 +1,76 @@
@echo off @echo off
set ASSIMP_PATH=D:\projects\asset-importer-lib\assimp set ANDROID_PLATFORM=21
set CMAKE_PATH="C:\Program Files\CMake\bin\cmake.exe" set /p ANDROID_PLATFORM="Enter Android platform - Enter to use %ANDROID_PLATFORM%: "
set ANDROID_NDK_PATH=C:\Users\kimkulling\AppData\Local\Android\Sdk\ndk-bundle
set ANDROID_CMAKE_PATH=contrib\android-cmake
pushd %ASSIMP_PATH% set ANDROID_ABI=armeabi-v7a
set /p ANDROID_ABI="Enter Android ABI ( armeabi-v7a, arm64-v8a , x86 , x86_64 ) - Enter to use %ANDROID_ABI% : "
rmdir /s /q build set COMMON_CXX_FLAGS=-DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -frtti -stdlib=libc++
mkdir build set COMMON_C_FLAGS=-DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions
cd build
%CMAKE_PATH% .. ^ if %ANDROID_ABI% == armeabi-v7a (
-G"MinGW Makefiles" ^ set CXX_FLAGS="%COMMON_CXX_FLAGS% -march=armv7-a -mthumb --target=armv7-none-linux-androideabi%ANDROID_PLATFORM%"
set C_FLAGS="%COMMON_C_FLAGS% -march=armv7-a -mthumb --target=armv7-none-linux-androideabi%ANDROID_PLATFORM%"
)
if %ANDROID_ABI% == arm64-v8a (
set CXX_FLAGS="%COMMON_CXX_FLAGS% -march=armv8-a --target=aarch64-none-linux-android%ANDROID_PLATFORM%"
set C_FLAGS="%COMMON_C_FLAGS% -march=armv8-a --target=aarch64-none-linux-android%ANDROID_PLATFORM%"
)
if %ANDROID_ABI% == x86 (
set CXX_FLAGS="%COMMON_CXX_FLAGS% --target=i686-none-linux-android%ANDROID_PLATFORM%"
set C_FLAGS="%COMMON_C_FLAGS% --target=i686-none-linux-android%ANDROID_PLATFORM%"
)
if %ANDROID_ABI% == x86_64 (
set CXX_FLAGS="%COMMON_CXX_FLAGS%"
set C_FLAGS="%COMMON_C_FLAGS%"
)
set CMAKE_PATH="%ProgramFiles%\CMake\bin\cmake.exe"
if exist %CMAKE_PATH% (
echo Found cmake at %CMAKE_PATH%
) else (
set /p CMAKE_PATH="Enter cmake.exe path: "
)
set ANDROID_NDK_PATH=""
FOR /F "tokens=* USEBACKQ" %%F IN (`dir "%LocalAppData%\Android\Sdk\ndk" /b /o:n /a:d`) DO (
SET ANDROID_NDK_PATH="%LocalAppData%\Android\Sdk\ndk\%%F"
)
if exist %ANDROID_NDK_PATH% (
echo Found NDK at %ANDROID_NDK_PATH%
) else (
set /p ANDROID_NDK_PATH="Enter ndk path: "
)
set BUILD_FOLDER=build
rmdir /s /q %BUILD_FOLDER%
mkdir %BUILD_FOLDER%
%CMAKE_PATH% ^
-G"Unix Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^ -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_TOOLCHAIN_FILE=%ANDROID_CMAKE_PATH%\android.toolchain.cmake ^ -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_PATH%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%ANDROID_NDK_PATH%\prebuilt\windows-x86_64\bin\make.exe ^ -DCMAKE_MAKE_PROGRAM=%ANDROID_NDK_PATH%\prebuilt\windows-x86_64\bin\make.exe ^
-DANDROID_NDK=%ANDROID_NDK_PATH% ^ -DANDROID_NDK=%ANDROID_NDK_PATH% ^
-DANDROID_NATIVE_API_LEVEL=android-9 ^ -DOPERATING_SYSTEM="Android" ^
-DANDROID_PLATFORM=%ANDROID_PLATFORM% ^
-DANDROID_ABI=%ANDROID_ABI% ^
-DASSIMP_ANDROID_JNIIOSYSTEM=ON ^ -DASSIMP_ANDROID_JNIIOSYSTEM=ON ^
-DANDROID_ABI=arm64-v8a ^ -DASSIMP_BUILD_TESTS=OFF ^
-DASSIMP_BUILD_ZLIB=ON ^ -DCMAKE_CXX_FLAGS=%CXX_FLAGS% ^
-DASSIMP_BUILD_TESTS=OFF -DMAKE_C_FLAGS=%C_FLAGS% ^
-S "..\.." ^
-B ".\%BUILD_FOLDER%\"
%CMAKE_PATH% --build . %CMAKE_PATH% --build ".\%BUILD_FOLDER%\"" -- -j 4"
popd set OUTPUT_FOLDER=.\output\
mkdir %OUTPUT_FOLDER%
mkdir "%OUTPUT_FOLDER%\lib\%ANDROID_ABI%"
copy "%BUILD_FOLDER%\bin\libassimp.so" "%OUTPUT_FOLDER%\lib\%ANDROID_ABI%\"
xcopy %BUILD_FOLDER%\include\assimp\ %OUTPUT_FOLDER%\include\assimp\ /y /s /e
xcopy ..\..\include\assimp\ %OUTPUT_FOLDER%\include\assimp\ /y /s /e
rmdir /s /q %BUILD_FOLDER%