mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[build] add CMake Android NDK support (#9010)
This commit is contained in:
@@ -400,3 +400,33 @@ jobs:
|
||||
export PATH=$(brew --prefix m4)/bin:$PATH
|
||||
script/check-posix-build
|
||||
script/check-simulation-build
|
||||
|
||||
android-ndk:
|
||||
name: android-ndk
|
||||
runs-on: ubuntu-22.04
|
||||
container:
|
||||
image: openthread/environment
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install unzip
|
||||
run: apt update && apt install -y unzip
|
||||
- name: Setup NDK
|
||||
id: setup-ndk
|
||||
uses: nttld/setup-ndk@v1
|
||||
with:
|
||||
ndk-version: r25c
|
||||
local-cache: true
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
run: |
|
||||
rm -rf build/ && OT_CMAKE_NINJA_TARGET="ot-daemon ot-ctl" script/cmake-build android-ndk
|
||||
rm -rf build/ && OT_CMAKE_NINJA_TARGET="ot-cli" script/cmake-build android-ndk
|
||||
|
||||
@@ -175,6 +175,7 @@ list(APPEND OT_PUBLIC_INCLUDES ${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
if(OT_PLATFORM STREQUAL "posix")
|
||||
target_include_directories(ot-config INTERFACE ${PROJECT_SOURCE_DIR}/src/posix/platform)
|
||||
target_compile_definitions(ot-config INTERFACE OPENTHREAD_PLATFORM_POSIX=1)
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/src/posix/platform")
|
||||
elseif(OT_PLATFORM STREQUAL "external")
|
||||
# skip in this case
|
||||
|
||||
@@ -79,6 +79,7 @@ macro(ot_option name ot_config description)
|
||||
endmacro()
|
||||
|
||||
ot_option(OT_15_4 OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE "802.15.4 radio link")
|
||||
ot_option(OT_ANDROID_NDK OPENTHREAD_CONFIG_ANDROID_NDK_ENABLE "enable android NDK")
|
||||
ot_option(OT_ANYCAST_LOCATOR OPENTHREAD_CONFIG_TMF_ANYCAST_LOCATOR_ENABLE "anycast locator")
|
||||
ot_option(OT_ASSERT OPENTHREAD_CONFIG_ASSERT_ENABLE "assert function OT_ASSERT()")
|
||||
ot_option(OT_BACKBONE_ROUTER OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE "backbone router functionality")
|
||||
|
||||
+57
-3
@@ -62,12 +62,12 @@
|
||||
|
||||
set -euxo pipefail
|
||||
|
||||
OT_CMAKE_NINJA_TARGET=${OT_CMAKE_NINJA_TARGET:-}
|
||||
OT_CMAKE_NINJA_TARGET=${OT_CMAKE_NINJA_TARGET-}
|
||||
|
||||
OT_SRCDIR="$(cd "$(dirname "$0")"/.. && pwd)"
|
||||
readonly OT_SRCDIR
|
||||
|
||||
OT_PLATFORMS=(simulation posix)
|
||||
OT_PLATFORMS=(simulation posix android-ndk)
|
||||
readonly OT_PLATFORMS
|
||||
|
||||
OT_POSIX_SIM_COMMON_OPTIONS=(
|
||||
@@ -152,11 +152,62 @@ main()
|
||||
shift
|
||||
local local_options=()
|
||||
local options=(
|
||||
"-DOT_PLATFORM=${platform}"
|
||||
"-DOT_SLAAC=ON"
|
||||
)
|
||||
|
||||
case "${platform}" in
|
||||
android-ndk)
|
||||
if [ -z "${NDK-}" ]; then
|
||||
echo "
|
||||
The 'NDK' environment variable needs to point to the Android NDK toolchain.
|
||||
Please ensure the NDK is downloaded and extracted then try to run this script again
|
||||
|
||||
For example:
|
||||
NDK=/opt/android-ndk-r25c ./script/cmake-build-android
|
||||
|
||||
You can download the NDK at https://developer.android.com/ndk/downloads
|
||||
|
||||
"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NDK_CMAKE_TOOLCHAIN_FILE="${NDK?}/build/cmake/android.toolchain.cmake"
|
||||
if [ ! -f "${NDK_CMAKE_TOOLCHAIN_FILE}" ]; then
|
||||
echo "
|
||||
Could not fild the Android NDK CMake toolchain file
|
||||
- NDK=${NDK}
|
||||
- NDK_CMAKE_TOOLCHAIN_FILE=${NDK_CMAKE_TOOLCHAIN_FILE}
|
||||
|
||||
"
|
||||
exit 2
|
||||
fi
|
||||
local_options+=(
|
||||
"-DOT_LOG_OUTPUT=PLATFORM_DEFINED"
|
||||
|
||||
# Add Android NDK flags
|
||||
"-DOT_ANDROID_NDK=1"
|
||||
"-DCMAKE_TOOLCHAIN_FILE=${NDK?}/build/cmake/android.toolchain.cmake"
|
||||
|
||||
# Android API needs to be >= android-24 for `getifsaddrs()`
|
||||
"-DANDROID_PLATFORM=android-24"
|
||||
|
||||
# Store thread settings in the CWD when executing ot-cli or ot-daemon
|
||||
'-DOT_POSIX_SETTINGS_PATH="./thread"'
|
||||
)
|
||||
|
||||
# Rewrite platform to posix
|
||||
platform="posix"
|
||||
|
||||
# Check if OT_DAEMON or OT_APP_CLI flags are needed
|
||||
if [[ ${OT_CMAKE_NINJA_TARGET[*]} =~ "ot-daemon" ]] || [[ ${OT_CMAKE_NINJA_TARGET[*]} =~ "ot-ctl" ]]; then
|
||||
local_options+=("-DOT_DAEMON=ON")
|
||||
elif [[ ${OT_CMAKE_NINJA_TARGET[*]} =~ "ot-cli" ]]; then
|
||||
local_options+=("-DOT_APP_CLI=ON")
|
||||
fi
|
||||
|
||||
options+=("${local_options[@]}")
|
||||
;;
|
||||
|
||||
posix)
|
||||
local_options+=(
|
||||
"-DOT_TCP=OFF"
|
||||
@@ -179,6 +230,9 @@ main()
|
||||
;;
|
||||
esac
|
||||
|
||||
options+=(
|
||||
"-DOT_PLATFORM=${platform}"
|
||||
)
|
||||
options+=("$@")
|
||||
build "${platform}" "${options[@]}"
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
#if !defined(OPENTHREAD_BUILD_DATETIME)
|
||||
#ifdef __ANDROID__
|
||||
#ifdef OPENTHREAD_ENABLE_ANDROID_NDK
|
||||
#ifdef OPENTHREAD_CONFIG_ANDROID_NDK_ENABLE
|
||||
#include <sys/system_properties.h>
|
||||
#else
|
||||
#include <cutils/properties.h>
|
||||
@@ -135,7 +135,7 @@ const char *otGetVersionString(void)
|
||||
|
||||
#if !defined(OPENTHREAD_BUILD_DATETIME) && defined(__ANDROID__)
|
||||
|
||||
#ifdef OPENTHREAD_ENABLE_ANDROID_NDK
|
||||
#ifdef OPENTHREAD_CONFIG_ANDROID_NDK_ENABLE
|
||||
static char sVersion[100 + PROP_VALUE_MAX];
|
||||
char dateTime[PROP_VALUE_MAX];
|
||||
|
||||
|
||||
@@ -65,6 +65,10 @@
|
||||
#error "OPENTHREAD_CONFIG_ENABLE_AUTO_START_SUPPORT was removed."
|
||||
#endif
|
||||
|
||||
#ifdef OPENTHREAD_ENABLE_ANDROID_NDK
|
||||
#error "OPENTHREAD_ENABLE_ANDROID_NDK was replaced by OPENTHREAD_CONFIG_ANDROID_NDK_ENABLE."
|
||||
#endif
|
||||
|
||||
#ifdef OPENTHREAD_ENABLE_CERT_LOG
|
||||
#error "OPENTHREAD_ENABLE_CERT_LOG was replaced by OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE."
|
||||
#endif
|
||||
|
||||
@@ -97,6 +97,10 @@ endif()
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-rdynamic ${CMAKE_EXE_LINKER_FLAGS}" PARENT_SCOPE)
|
||||
|
||||
if(OT_ANDROID_NDK)
|
||||
target_compile_options(ot-posix-config INTERFACE -Wno-sign-compare)
|
||||
endif()
|
||||
|
||||
add_library(openthread-posix
|
||||
alarm.cpp
|
||||
backbone.cpp
|
||||
@@ -141,7 +145,7 @@ target_link_libraries(openthread-posix
|
||||
ot-config-ftd
|
||||
ot-config
|
||||
ot-posix-config
|
||||
util
|
||||
$<$<NOT:$<BOOL:${OT_ANDROID_NDK}>>:util>
|
||||
$<$<STREQUAL:${CMAKE_SYSTEM_NAME},Linux>:rt>
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user