@echo off
rem Please add to environment ANDROID_QT5_DIR (path to Qt directory) and ANDROID_NDK_HOME (path to android ndk directory)
rem Execute with Android API version and arch e. g. : #cmake_android.bat 24 arm ../libs
rem Arches: arm, arm64, x86, x86_64
set _usage_=0
if [%~1]==[] set _usage_=1
if [%~2]==[] set _usage_=1
if [%~3]==[] set _usage_=1
if %_usage_%==1 (
	echo Usage: cmake_android.bat ^<API_LEVEL^> ^<ARCH^> ^<SRC^>
	echo ^ ^ ^<API_LEVEL^> - number of API ^(e.g. 19^)
	echo ^ ^ ^<ARCH^> - architecture ^(arm, arm64, x86, x86_64^)
	echo ^ ^ ^<SRC^> - path to sources
	echo.
	echo You also have to set next env variables^:
	echo ^ ^ ANDROID_QT5_DIR  - path to Qt dir, contains subdirs for arch
	echo ^ ^ ANDROID_NDK_HOME - path to android ndk directory
	exit /b
)
set QARCH=
set AARCH=
set _PLATFORM_=%~1
if %~2==arm (
	set QARCH=armv7
	set AARCH=armeabi-v7a
)
if %~2==arm64 (
	set QARCH=arm64_v8a
	set AARCH=arm64-v8a
	if /i %_PLATFORM_% LSS 21 set _PLATFORM_=21
)
if %~2==x86 (
	set QARCH=x86
	set AARCH=x86
)
if %~2==x86_64 (
	set QARCH=x86_64
	set AARCH=x86_64
	if /i %_PLATFORM_% LSS 21 set _PLATFORM_=21
)
rem set Qt5_ROOT=%ANDROID_QT5_DIR%\android_%QARCH%\lib\cmake
set Qt5_ROOT=%ANDROID_QT5_DIR%\lib\cmake
rem set Qt5_DIR=%Qt5_ROOT%\Qt5
if NOT [%QARCH%]==[] (
	@echo on
	cmake_mgw -Wno-dev -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_HOME%\build\cmake\android.toolchain.cmake -DANDROID_STL=c++_shared -DANDROID_PLATFORM=android-%_PLATFORM_% -DANDROID_ABI=%AARCH% -DICU=0 -DQt4=0 -DQt5=1 -DQGLVIEW=0 -DQGLENGINE=0 -DQt5_DIR=%Qt5_ROOT%\Qt5 -DQt5LinguistTools_DIR=%Qt5_ROOT%\Qt5LinguistTools -DQt5UiPlugin_DIR=%Qt5_ROOT%\Qt5UiPlugin -DQt5UiTools_DIR=%Qt5_ROOT%\Qt5UiTools -DQt5Widgets_DIR=%Qt5_ROOT%\Qt5Widgets -DQt5Core_DIR=%Qt5_ROOT%\Qt5Core -DQt5Gui_DIR=%Qt5_ROOT%\Qt5Gui -DQt5Sql_DIR=%Qt5_ROOT%\Qt5Sql -DQt5OpenGL_DIR=%Qt5_ROOT%\Qt5OpenGL -DQt5PrintSupport_DIR=%Qt5_ROOT%\Qt5PrintSupport -DQt5Script_DIR=%Qt5_ROOT%\Qt5Script -DQt5Positioning_DIR=%Qt5_ROOT%\Qt5Positioning -DQt5Network_DIR=%Qt5_ROOT%\Qt5Network -DQt5Qml_DIR=%Qt5_ROOT%\Qt5Qml -DQt5Quick_DIR=%Qt5_ROOT%\Qt5Quick -DQt5QuickWidgets_DIR=%Qt5_ROOT%\Qt5QuickWidgets -DQt5QmlModels_DIR=%Qt5_ROOT%\Qt5QmlModels -DQt5AndroidExtras_DIR=%Qt5_ROOT%\Qt5AndroidExtras %~3 %~4 %~5 %~6
) else (
	@echo on
	cmake_mgw -Wno-dev -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_HOME%\build\cmake\android.toolchain.cmake -DANDROID_STL=c++_shared -DANDROID_PLATFORM=android-%_PLATFORM_% -DANDROID_ABI=%AARCH% -DICU=0 -DQt4=0 -DQt5=0 -DQGLVIEW=0 %~3 %~4 %~5 %~6
)
