Make android platform's cmake flags configurable (#3239)
Don't hardcode the cmake configurations in the Android platform's CMakeLists.txt. Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3238
This commit is contained in:
@ -312,7 +312,7 @@ WAMR provides some features which can be easily configured by passing options to
|
||||
|
||||
## Android
|
||||
|
||||
able to generate a shared library support Android platform.
|
||||
Able to generate a shared library support Android platform.
|
||||
- need an [android SDK](https://developer.android.com/studio). Go and get the "Command line tools only"
|
||||
- look for a command named *sdkmanager* and download below components. version numbers might need to check and pick others
|
||||
- "build-tools;29.0.3"
|
||||
@ -326,7 +326,7 @@ able to generate a shared library support Android platform.
|
||||
- export ANDROID_NDK_LATEST_HOME=/the/path/of/downloaded/sdk/ndk/2x.xxx/
|
||||
- ready to go
|
||||
|
||||
Use such commands, you are able to compile with default configurations. Any compiling requirement should be satisfied by modifying product-mini/platforms/android/CMakeList.txt. For example, chaning ${WAMR_BUILD_TARGET} in CMakeList could get different libraries support different ABIs.
|
||||
Use such commands, you are able to compile with default configurations.
|
||||
|
||||
``` shell
|
||||
$ cd product-mini/platforms/android/
|
||||
@ -339,6 +339,15 @@ $ # include/ includes all necesary head files
|
||||
$ # lib includes libiwasm.so
|
||||
```
|
||||
|
||||
To change the target architecture and ABI, you can define `WAMR_BUILD_TARGET` or `ANDROID_ABI` respectively. To build for [supported Android ABIs](https://developer.android.com/ndk/guides/abis#sa):
|
||||
|
||||
```shell
|
||||
$ cmake .. -DWAMR_BUILD_TARGET=X86_32 -DANDROID_ABI=x86 # 32-bit Intel CPU
|
||||
$ cmake .. -DWAMR_BUILD_TARGET=X86_64 -DANDROID_ABI=x86_64 # 64-bit Intel CPU
|
||||
$ cmake .. -DWAMR_BUILD_TARGET=ARMV7A -DANDROID_ABI=armeabi-v7a # 32-bit ARM CPU
|
||||
$ cmake .. -DWAMR_BUILD_TARGET=AARCH64 -DANDROID_ABI=arm64-v8a # 64-bit ARM CPU
|
||||
```
|
||||
|
||||
## NuttX
|
||||
|
||||
WAMR is intergrated with NuttX, just enable the WAMR in Kconfig option (Application Configuration/Interpreters).
|
||||
|
||||
@ -1,53 +1,59 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
cmake_minimum_required (VERSION 3.4.1)
|
||||
|
||||
set (CMAKE_VERBOSE_MAKEFILE on)
|
||||
set (CMAKE_BUILD_TYPE Release)
|
||||
|
||||
# https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md#environment-variables-3
|
||||
set (CMAKE_TOOLCHAIN_FILE "$ENV{ANDROID_NDK_LATEST_HOME}/build/cmake/android.toolchain.cmake")
|
||||
set (ANDROID_SDK $ENV{ANDROID_HOME})
|
||||
set (ANDROID_NDK $ENV{ANDROID_NDK_LATEST_HOME})
|
||||
|
||||
set (ANDROID_ABI "x86")
|
||||
set (ANDROID_LD lld)
|
||||
if (NOT DEFINED ANDROID_PLATFORM)
|
||||
set (ANDROID_PLATFORM 24)
|
||||
endif ()
|
||||
|
||||
project (iwasm)
|
||||
|
||||
set (WAMR_BUILD_PLATFORM "android")
|
||||
set (WAMR_BUILD_TARGET "X86_32")
|
||||
set (WAMR_BUILD_TYPE Release)
|
||||
set (WAMR_BUILD_INTERP 1)
|
||||
set (WAMR_BUILD_AOT 1)
|
||||
set (WAMR_BUILD_JIT 0)
|
||||
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
||||
set (WAMR_BUILD_LIBC_WASI 1)
|
||||
cmake_minimum_required (VERSION 3.14)
|
||||
|
||||
# Reset default linker flags
|
||||
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
||||
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
|
||||
|
||||
# Set WAMR_BUILD_TARGET, currently values supported:
|
||||
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
|
||||
if (NOT DEFINED WAMR_BUILD_TARGET)
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
# Build as X86_64 by default in 64-bit platform
|
||||
set (WAMR_BUILD_TARGET "X86_64")
|
||||
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
# Build as X86_32 by default in 32-bit platform
|
||||
set (WAMR_BUILD_TARGET "X86_32")
|
||||
message (FATAL_ERROR "WAMR_BUILD_TARGET isn't set")
|
||||
endif ()
|
||||
|
||||
if (NOT (WAMR_BUILD_TARGET STREQUAL "X86_64"
|
||||
OR WAMR_BUILD_TARGET STREQUAL "X86_32"
|
||||
OR WAMR_BUILD_TARGET MATCHES "AARCH64.*"
|
||||
OR WAMR_BUILD_TARGET MATCHES "ARM.*"
|
||||
OR WAMR_BUILD_TARGET MATCHES "RISCV64.*"))
|
||||
message (FATAL_ERROR "Unsupported build target platform ${WAMR_BUILD_TARGET}!")
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED ANDROID_ABI)
|
||||
if (WAMR_BUILD_TARGET STREQUAL "X86_64")
|
||||
set (ANDROID_ABI "x86_64")
|
||||
elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
|
||||
set (ANDROID_ABI "x86")
|
||||
elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*")
|
||||
set (ANDROID_ABI "arm64-v8a")
|
||||
elseif (WAMR_BUILD_TARGET MATCHES "ARM.*")
|
||||
set (ANDROID_ABI "armeabi-v7a")
|
||||
else ()
|
||||
message(SEND_ERROR "Unsupported build target platform!")
|
||||
set (ANDROID_ABI "riscv64")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED ANDROID_LD)
|
||||
set (ANDROID_LD lld)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED ANDROID_PLATFORM)
|
||||
set (ANDROID_PLATFORM 24)
|
||||
endif ()
|
||||
|
||||
# https://android.googlesource.com/platform/ndk/+/master/build/cmake/android.toolchain.cmake
|
||||
set (CMAKE_TOOLCHAIN_FILE "$ENV{ANDROID_NDK_LATEST_HOME}/build/cmake/android.toolchain.cmake")
|
||||
set (ANDROID_SDK $ENV{ANDROID_HOME})
|
||||
set (ANDROID_NDK $ENV{ANDROID_NDK_LATEST_HOME})
|
||||
|
||||
project (iwasm)
|
||||
|
||||
set (WAMR_BUILD_PLATFORM "android")
|
||||
|
||||
set (CMAKE_VERBOSE_MAKEFILE ON)
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
set (CMAKE_BUILD_TYPE Release)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_INTERP)
|
||||
@ -55,6 +61,11 @@ if (NOT DEFINED WAMR_BUILD_INTERP)
|
||||
set (WAMR_BUILD_INTERP 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
||||
# Enable fast interpreter
|
||||
set (WAMR_BUILD_FAST_INTERP 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_AOT)
|
||||
# Enable AOT by default.
|
||||
set (WAMR_BUILD_AOT 1)
|
||||
@ -75,6 +86,21 @@ if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
|
||||
set (WAMR_BUILD_LIBC_WASI 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
|
||||
# Disable multiple modules by default
|
||||
set (WAMR_BUILD_MULTI_MODULE 0)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
|
||||
# Disable pthread library by default
|
||||
set (WAMR_BUILD_LIB_PTHREAD 0)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_LIB_WASI_THREADS)
|
||||
# Disable wasi threads library by default
|
||||
set (WAMR_BUILD_LIB_WASI_THREADS 0)
|
||||
endif()
|
||||
|
||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
||||
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
|
||||
Reference in New Issue
Block a user