1# 2# CMake Toolchain file for crosscompiling Android / aarch64 3# 4# This can be used when running cmake in the following way: 5# cd build/ 6# cmake .. -DCMAKE_TOOLCHAIN_FILE=contrib/cross-aarch64-android.cmake 7# 8 9 10set(ANDROID_API_VER 24) 11set(ABARCH1 arm64) 12set(CMAKE_SYSTEM_PROCESSOR aarch64) 13set(NDK /opt/android/ndk/21.1.6352462/) 14set(CROSS_SYSROOT "${NDK}/platforms/android-${ANDROID_API_VER}/arch-${ABARCH1}") 15set(BUILD_ARCH linux-x86_64) 16 17# 18# Rest should be computed from the above 19# 20set(TC_PATH ${NDK}/toolchains/llvm/prebuilt/${BUILD_ARCH}) 21set(TC_BASE ${TC_PATH}/bin/${CMAKE_SYSTEM_PROCESSOR}-linux-android) 22set(PLATFORM android) 23set(CMAKE_SYSTEM_NAME Linux) 24set(CMAKE_C_COMPILER "${TC_BASE}${ANDROID_API_VER}-clang") 25set(CMAKE_CXX_COMPILER "${TC_BASE}${ANDROID_API_VER}-clang++") 26set(CMAKE_STAGING_PREFIX "${CROSS_SYSROOT}") 27 28# 29# Different build system distros set release optimization level to different 30# things according to their local policy, eg, Fedora is -O2 and Ubuntu is -O3 31# here. Actually the build system's local policy is completely unrelated to 32# our desire for cross-build release optimization policy for code built to run 33# on a completely different target than the build system itself. 34# 35# Since this goes last on the compiler commandline we have to override it to a 36# sane value for cross-build here. Notice some gcc versions enable broken 37# optimizations with -O3. 38# 39if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) 40 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") 41 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") 42endif() 43 44#-nostdlib 45SET(CMAKE_C_FLAGS "-DGCC_VER=\"\\\"$(GCC_VER)\\\"\" -DARM64=1 -D__LP64__=1 -Os -g3 -fpie -mstrict-align -fPIC -ffunction-sections -fdata-sections -D__ANDROID_API__=${ANDROID_API_VER} -Wno-pointer-sign" CACHE STRING "" FORCE) 46 47 48set(CMAKE_FIND_ROOT_PATH "${CROSS_SYSROOT}") 49 50# Adjust the default behavior of the FIND_XXX() commands: 51# search programs in the host environment only. 52set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 53 54# Search headers and libraries in the target environment only. 55set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 56set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 57 58 59