Skip to content

Commit

Permalink
Updated Android CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
EduMenges committed Oct 30, 2024
1 parent fe6122e commit b8d9580
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions build/Android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b8d9580

Please sign in to comment.