# Information
# https://androidsdkmanager.azurewebsites.net/
# https://developer.android.com/studio/releases/cmdline-tools
# https://developer.android.com/studio?hl=fr#command-tools
# https://androidsdkoffline.blogspot.com/p/android-sdk-cmdline-tools-offline.html

# Downloads
# https://dl.google.com/android/repository/commandlinetools-win-7302050_latest.zip
# https://dl.google.com/android/repository/commandlinetools-mac-7302050_latest.zip
# https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip

### DEPENDS ###
DKDEPEND(jdk)

### VERSION ###
DKSET(ANDROIDTOOLS ${3RDPARTY}/android-cmdline-tools)
DKSET(SDKMANAGER_EXE ${ANDROIDTOOLS}/bin/sdkmanager.bat)
WIN_DKSET(ANDROIDTOOLS_DL https://dl.google.com/android/repository/commandlinetools-win-7302050_latest.zip)
MAC_DKSET(ANDROIDTOOLS_DL https://dl.google.com/android/repository/commandlinetools-mac-7302050_latest.zip)
LINUX_DKSET(ANDROIDTOOLS_DL https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip)


### INSTALL ###
DKINSTALL(${ANDROIDTOOLS_DL} android-cmdline-tools ${ANDROIDTOOLS})

if(CMAKE_HOST_WIN32)
	DKEXECUTE_PROCESS(COMMAND cmd /c sdkmanager --sdk_root=${ANDROIDSDK} WORKING_DIRECTORY ${ANDROIDTOOLS}/bin)
#	if(NOT EXISTS ${ANDROIDSDK}/build-tools/${ANDROIDBUILDTOOLS_VERSION})
#		message("Installing Android build-tools: ${ANDROIDBUILDTOOLS_VERSION} . . .")
#		set(ARGUMNTS "${SDKMANAGER_EXE} --install build-tools\\;${ANDROIDBUILDTOOLS_VERSION} --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		DKEXECUTE_PROCESS(COMMAND cmd /c ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDTOOLS}/bin)
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/build-tools/${ANDROIDBUILDTOOLS_VERSION})
#		message(FATAL_ERROR "Failed to install Android build-tools")
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/platforms/${ANDROIDPLATFORM_VERSION})
#		message("Installing Android platform: ${ANDROIDPLATFORM_VERSION} . . .")
#		set(ARGUMNTS "${SDKMANAGER_EXE} --install platforms\\;${ANDROIDPLATFORM_VERSION} --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND cmd /c ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/platforms/${ANDROIDPLATFORM_VERSION})
#		message(FATAL_ERROR "Failed to install Android platform")
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/Sources/${ANDROIDSOURCES_VERSION})
#		message("Installing Android API sources: ${ANDROIDSOURCES_VERSION}")
#		set(ARGUMNTS "${SDKMANAGER_EXE} --install sources\\;${ANDROIDSOURCES_VERSION} --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND cmd /c ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/Sources/${ANDROIDSOURCES_VERSION})
#		message(FATAL_ERROR "Failed to install Android sources")
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/system-images/${ANDROIDIMAGES_VERSION}/google_apis/armeabi-v7a)
#		message("Installing Android system image: ${ANDROIDIMAGES_VERSION} armeabi-v7a")
#		set(ARGUMNTS "${SDKMANAGER_EXE} --install system-images\\;${ANDROIDIMAGES_VERSION}\\;google_apis\\;armeabi-v7a --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND cmd /c ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/system-images/${ANDROIDIMAGES_VERSION}/google_apis/armeabi-v7a)
#		message(FATAL_ERROR "Failed to install Android Image armeabi-v7a")
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/system-images/${ANDROIDIMAGES_VERSION}/google_apis/arm64-v8a)
#		message("Installing Android API system image: ${ANDROIDIMAGES_VERSION} arm64-v8a")
#		set(ARGUMNTS "${SDKMANAGER_EXE} --install system-images\\;${ANDROIDIMAGES_VERSION}\\;google_apis\\;arm64-v8a --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND cmd /c ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/system-images/${ANDROIDIMAGES_VERSION}/google_apis/arm64-v8a)
#		message(FATAL_ERROR "Failed to install Android Image arm64-v8a")
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/system-images/${ANDROIDIMAGES_VERSION}/google_apis/x86)
#		message("Installing Android API system image: ${ANDROIDIMAGES_VERSION} x86")
#		set(ARGUMNTS "${SDKMANAGER_EXE} --install system-images\\;${ANDROIDIMAGES_VERSION}\\;google_apis\\;x86 --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND cmd /c ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/system-images/${ANDROIDIMAGES_VERSION}/google_apis/x86)
#		message(FATAL_ERROR "Failed to install Android Image x86")
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/system-images/${ANDROIDIMAGES_VERSION}/google_apis/x86_64)
#		message("Installing Android API system image: ${ANDROIDIMAGES_VERSION} x86_64")
#		set(ARGUMNTS "${SDKMANAGER_EXE} --install system-images\\;${ANDROIDIMAGES_VERSION}\\;google_apis\\;x86_64 --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND cmd /c ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/system-images/${ANDROIDIMAGES_VERSION}/google_apis/x86_64)
#		message(FATAL_ERROR "Failed to install Android Image x86_64")
#	endif()
endif()


#if(CMAKE_HOST_APPLE)
#	if(NOT EXISTS ${ANDROIDSDK}/build-tools/${ANDROIDBUILDTOOLS_VERSION})
#		message("Installing Android build-tools: ${ANDROIDBUILDTOOLS_VERSION} . . .")
#		set(ARGUMNTS "${ANDROIDSDK}/bin/sdkmanager --install build-tools\\;${ANDROIDBUILDTOOLS_VERSION} --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/platforms/${ANDROIDPLATFORM_VERSION})
#		message("Installing Android platform: ${ANDROIDPLATFORM_VERSION} . . .")
#		set(ARGUMNTS "${ANDROIDSDK}/bin/sdkmanager --install platforms\\;${ANDROIDPLATFORM_VERSION} --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#endif()



#if(CMAKE_HOST_LINUX)
#	if(NOT EXISTS ${ANDROIDSDK}/build-tools/${ANDROIDBUILDTOOLS_VERSION})
#		message("Installing Android build-tools: ${ANDROIDBUILDTOOLS_VERSION} . . .")
#		set(ARGUMNTS "${ANDROIDSDK}/bin/sdkmanager --install build-tools\\;${ANDROIDBUILDTOOLS_VERSION} --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#	if(NOT EXISTS ${ANDROIDSDK}/platforms/${ANDROIDPLATFORM_VERSION})
#		message("Installing Android platform: ${ANDROIDPLATFORM_VERSION} . . .")
#		set(ARGUMNTS "${ANDROIDSDK}/bin/sdkmanager --install platforms\\;${ANDROIDPLATFORM_VERSION} --sdk_root=${ANDROIDSDK}")
#		separate_arguments(ARGUMNTS)
#		execute_process(COMMAND ${ARGUMNTS} WORKING_DIRECTORY ${ANDROIDSDK}/bin)
#	endif()
#endif()
