From b8d95805ffcf7b483f66d13f899734033a7309aa Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Wed, 30 Oct 2024 14:25:27 -0300 Subject: [PATCH] Updated Android CMake --- build/Android/CMakeLists.txt | 46 ++++++++++-------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/build/Android/CMakeLists.txt b/build/Android/CMakeLists.txt index 2c44db8d..6ecb4f8e 100644 --- a/build/Android/CMakeLists.txt +++ b/build/Android/CMakeLists.txt @@ -1,47 +1,27 @@ cmake_minimum_required(VERSION 3.15) -# Set cross compiling settings -set(CMAKE_SYSTEM_NAME Android) -set(CMAKE_SYSTEM_VERSION 28) # API level -set(ANDROID_NATIVE_API_LEVEL 28) +set(ANDROID_PLATFORM_LEVEL 28) +set(ANDROID_NATIVE_API_LEVEL ${ANDROID_PLATFORM_LEVEL}) +set(ANDROID_PLATFORM ${ANDROID_PLATFORM_LEVEL}) -# Check Android NDK version -if(NOT CMAKE_ANDROID_NDK) - message(FATAL_ERROR "Cannot find Android NDK, make sure you pass -DCMAKE_ANDROID_NDK=[path_to_NDK]") -endif() - -file(READ "${CMAKE_ANDROID_NDK}/source.properties" SOURCE_PROPERTIES_CONTENT) -string(REGEX MATCH "Pkg\\.Revision = ([0-9]+)\\.([0-9]+)\\." NDK_VERSION_MATCH "${SOURCE_PROPERTIES_CONTENT}") -set(CMAKE_ANDROID_NDK_VERSION ${CMAKE_MATCH_1}) -set(CMAKE_ANDROID_NDK_VERSION_MINOR ${CMAKE_MATCH_2}) - -message("--Android NDK version: ${CMAKE_ANDROID_NDK_VERSION}.${CMAKE_ANDROID_NDK_VERSION_MINOR}") - -if(NOT CMAKE_ANDROID_NDK_VERSION EQUAL 25) - message(FATAL_ERROR "Android NDK LTS Version (r25b) stable long term support version required") -endif() - -# Check required input args if(NOT ANDROID_ABI) - message(FATAL_ERROR "Cannot find ANDROID_ABI, make sure you pass -DANDROID_ABI=[armeabi-v7a | arm64-v8a | x86 | x86_64]") + message(WARNING "ANDROID_ABI not provided. Setting to `arm64-v8a`.") + set(ANDROID_ABI arm64-v8a) endif() -set(CMAKE_ANDROID_ARCH_ABI ${ANDROID_ABI}) - -if(NOT ANDROID_TOOLCHAIN) - message(FATAL_ERROR "Cannot find ANDROID_TOOLCHAIN, make sure you pass -DANDROID_TOOLCHAIN=[e.g clang]") +if(NOT CMAKE_ANDROID_NDK) + if(DEFINED ENV{ANDROID_NDK_HOME}) + message(WARNING "Cannot find Android NDK, setting to $ENV{ANDROID_NDK_HOME}") + set(CMAKE_ANDROID_NDK $ENV{ANDROID_NDK_HOME}) + else() + message(FATAL_ERROR "Cannot find Android NDK, make sure you pass -DCMAKE_ANDROID_NDK=[path_to_NDK].") + endif() endif() -# Config param for android -set(CMAKE_ANDROID_STL_TYPE c++_static) +set(ANDROID_USE_LEGACY_TOOLCHAIN_FILE OFF CACHE BOOL "Disabling legacy toolchain behavior") -# Set toolchain file set(CMAKE_TOOLCHAIN_FILE "${CMAKE_ANDROID_NDK}/build/cmake/android.toolchain.cmake") -if(NOT EXISTS ${CMAKE_TOOLCHAIN_FILE}) - message(FATAL_ERROR "Android NDK toolchain file ${CMAKE_TOOLCHAIN_FILE} not found") -endif() - set(Boost_COMPILER "clang") # Project