From 27fe7a50db33aa5a6a004449d2645797bdb47248 Mon Sep 17 00:00:00 2001 From: talregev Date: Wed, 5 May 2021 23:32:47 +0300 Subject: [PATCH] Compile for android including armv6. (#16847) * compile for android including armv6. * Update arm-android.cmake * Update from comment in the PR support ANDROID_NATIVE_API_LEVEL from env variable. (to be able to compile also 16 and not just 21 as default) * Add ANDROID_ARM_NEON from env var * Short version of update ANDROID_ARM_NEON. * remove ANDROID_NATIVE_API_LEVEL now using vcpkg_CMAKE_SYSTEM_VERSION in triplet Add cache to ANDROID_ARM_NEON fix indents * Update neon triplet * Add arm-neon-android.cmake file. --- scripts/toolchains/android.cmake | 48 +++++++++++++---------- triplets/community/arm-android.cmake | 4 ++ triplets/community/arm-neon-android.cmake | 4 ++ triplets/community/arm64-android.cmake | 4 ++ triplets/community/armv6-android.cmake | 4 ++ triplets/community/x64-android.cmake | 4 ++ triplets/community/x86-android.cmake | 4 ++ 7 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 triplets/community/arm-android.cmake create mode 100644 triplets/community/arm-neon-android.cmake create mode 100644 triplets/community/arm64-android.cmake create mode 100644 triplets/community/armv6-android.cmake create mode 100644 triplets/community/x64-android.cmake create mode 100644 triplets/community/x86-android.cmake diff --git a/scripts/toolchains/android.cmake b/scripts/toolchains/android.cmake index c721c2c426..d0c989d18f 100644 --- a/scripts/toolchains/android.cmake +++ b/scripts/toolchains/android.cmake @@ -6,8 +6,14 @@ set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang CACHE STRING "") if (VCPKG_TARGET_TRIPLET MATCHES "^arm64-android") set(ANDROID_ABI arm64-v8a CACHE STRING "") +elseif(VCPKG_TARGET_TRIPLET MATCHES "^armv6-android") + set(ANDROID_ABI armeabi CACHE STRING "") +elseif(VCPKG_TARGET_TRIPLET MATCHES "^arm-neon-android") + set(ANDROID_ABI armeabi-v7a CACHE STRING "") + set(ANDROID_ARM_NEON ON CACHE BOOL "") elseif(VCPKG_TARGET_TRIPLET MATCHES "^arm-android") set(ANDROID_ABI armeabi-v7a CACHE STRING "") + set(ANDROID_ARM_NEON OFF CACHE BOOL "") elseif(VCPKG_TARGET_TRIPLET MATCHES "^x64-android") set(ANDROID_ABI x86_64 CACHE STRING "") elseif(VCPKG_TARGET_TRIPLET MATCHES "^x86-android") @@ -25,11 +31,11 @@ endif() if(DEFINED ENV{ANDROID_NDK_HOME}) set(ANDROID_NDK_HOME $ENV{ANDROID_NDK_HOME}) else() - set(ANDROID_NDK_HOME "$ENV{ProgramData}/Microsoft/AndroidNDK64/android-ndk-r13b/") - if(NOT EXISTS "${ANDROID_NDK_HOME}") - # Use Xamarin default installation folder - set(ANDROID_NDK_HOME "$ENV{ProgramFiles\(x86\)}/Android/android-sdk/ndk-bundle") - endif() + set(ANDROID_NDK_HOME "$ENV{ProgramData}/Microsoft/AndroidNDK64/android-ndk-r13b/") + if(NOT EXISTS "${ANDROID_NDK_HOME}") + # Use Xamarin default installation folder + set(ANDROID_NDK_HOME "$ENV{ProgramFiles\(x86\)}/Android/android-sdk/ndk-bundle") + endif() endif() if(NOT EXISTS "${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake") @@ -39,21 +45,21 @@ endif() include("${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake") if(NOT _VCPKG_ANDROID_TOOLCHAIN) -set(_VCPKG_ANDROID_TOOLCHAIN 1) -get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE ) -if(NOT _CMAKE_IN_TRY_COMPILE) - string(APPEND CMAKE_C_FLAGS " -fPIC ${VCPKG_C_FLAGS} ") - string(APPEND CMAKE_CXX_FLAGS " -fPIC ${VCPKG_CXX_FLAGS} ") - string(APPEND CMAKE_C_FLAGS_DEBUG " ${VCPKG_C_FLAGS_DEBUG} ") - string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${VCPKG_CXX_FLAGS_DEBUG} ") - string(APPEND CMAKE_C_FLAGS_RELEASE " ${VCPKG_C_FLAGS_RELEASE} ") - string(APPEND CMAKE_CXX_FLAGS_RELEASE " ${VCPKG_CXX_FLAGS_RELEASE} ") + set(_VCPKG_ANDROID_TOOLCHAIN 1) + get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE ) + if(NOT _CMAKE_IN_TRY_COMPILE) + string(APPEND CMAKE_C_FLAGS " -fPIC ${VCPKG_C_FLAGS} ") + string(APPEND CMAKE_CXX_FLAGS " -fPIC ${VCPKG_CXX_FLAGS} ") + string(APPEND CMAKE_C_FLAGS_DEBUG " ${VCPKG_C_FLAGS_DEBUG} ") + string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${VCPKG_CXX_FLAGS_DEBUG} ") + string(APPEND CMAKE_C_FLAGS_RELEASE " ${VCPKG_C_FLAGS_RELEASE} ") + string(APPEND CMAKE_CXX_FLAGS_RELEASE " ${VCPKG_CXX_FLAGS_RELEASE} ") - string(APPEND CMAKE_SHARED_LINKER_FLAGS " ${VCPKG_LINKER_FLAGS} ") - string(APPEND CMAKE_EXE_LINKER_FLAGS " ${VCPKG_LINKER_FLAGS} ") - string(APPEND CMAKE_SHARED_LINKER_FLAGS_DEBUG " ${VCPKG_LINKER_FLAGS_DEBUG} ") - string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG " ${VCPKG_LINKER_FLAGS_DEBUG} ") - string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE " ${VCPKG_LINKER_FLAGS_RELEASE} ") - string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE " ${VCPKG_LINKER_FLAGS_RELEASE} ") -endif() + string(APPEND CMAKE_SHARED_LINKER_FLAGS " ${VCPKG_LINKER_FLAGS} ") + string(APPEND CMAKE_EXE_LINKER_FLAGS " ${VCPKG_LINKER_FLAGS} ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_DEBUG " ${VCPKG_LINKER_FLAGS_DEBUG} ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG " ${VCPKG_LINKER_FLAGS_DEBUG} ") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE " ${VCPKG_LINKER_FLAGS_RELEASE} ") + string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE " ${VCPKG_LINKER_FLAGS_RELEASE} ") + endif() endif() diff --git a/triplets/community/arm-android.cmake b/triplets/community/arm-android.cmake new file mode 100644 index 0000000000..29ba5655ae --- /dev/null +++ b/triplets/community/arm-android.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE arm) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) diff --git a/triplets/community/arm-neon-android.cmake b/triplets/community/arm-neon-android.cmake new file mode 100644 index 0000000000..29ba5655ae --- /dev/null +++ b/triplets/community/arm-neon-android.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE arm) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) diff --git a/triplets/community/arm64-android.cmake b/triplets/community/arm64-android.cmake new file mode 100644 index 0000000000..20b255d392 --- /dev/null +++ b/triplets/community/arm64-android.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) diff --git a/triplets/community/armv6-android.cmake b/triplets/community/armv6-android.cmake new file mode 100644 index 0000000000..29ba5655ae --- /dev/null +++ b/triplets/community/armv6-android.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE arm) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) diff --git a/triplets/community/x64-android.cmake b/triplets/community/x64-android.cmake new file mode 100644 index 0000000000..6342ce5361 --- /dev/null +++ b/triplets/community/x64-android.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) diff --git a/triplets/community/x86-android.cmake b/triplets/community/x86-android.cmake new file mode 100644 index 0000000000..ca0fbaeffb --- /dev/null +++ b/triplets/community/x86-android.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE x86) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android)