[Meson] Add ndk-build to be part of ndk build
authorJihoon Lee <jhoon.it.lee@samsung.com>
Thu, 3 Dec 2020 06:38:29 +0000 (15:38 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 8 Dec 2020 03:10:50 +0000 (12:10 +0900)
**Changes proposed in this PR:**
- Add option to build library using ndk

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
.gitignore
jni/Android.mk
jni/prepare_iniparser.sh
jni/prepare_tflite.sh
meson.build
meson_options.txt

index 3a288c9..58d1a37 100644 (file)
@@ -5,7 +5,7 @@
 /build
 
 # jni build files
-/jni/iniparser
+iniparser/
 libs/
 obj/
 
index 22ed7a4..b97bcb8 100644 (file)
@@ -8,6 +8,10 @@ ifndef NNTRAINER_ROOT
 NNTRAINER_ROOT := $(LOCAL_PATH)/..
 endif
 
+ifndef NDK_LIBS_OUT
+NDK_LIBS_OUT := $(NDK_PROJECT_PATH)
+endif
+
 include $(CLEAR_VARS)
 
 ifndef INIPARSER_ROOT
@@ -15,12 +19,13 @@ ifneq ($(MAKECMDGOALS),clean)
 $(warning INIPARSER_ROOT is not defined!)
 $(warning INIPARSER SRC is going to be downloaded!)
 
-INIPARSER_ROOT :=./iniparser
+INIPARSER_ROOT :=$(NDK_LIBS_OUT)/iniparser
+
+$(info $(shell ($(LOCAL_PATH)/prepare_iniparser.sh $(NDK_LIBS_OUT))))
 
 endif
 endif
 
-$(info $(shell ($(LOCAL_PATH)/prepare_iniparser.sh )))
 
 include $(CLEAR_VARS)
 
@@ -36,9 +41,9 @@ ifneq ($(MAKECMDGOALS),clean)
 $(warning TENSORFLOW_ROOT is not defined!)
 $(warning TENSORFLOW SRC is going to be downloaded!)
 
-$(info $(shell ($(NNTRAINER_JNI_ROOT)/prepare_tflite.sh $(TENSORFLOW_VERSION) $(NNTRAINER_APPLICATION))))
+TENSORFLOW_ROOT := $(NDK_LIBS_OUT)/tensorflow-$(TENSORFLOW_VERSION)/tensorflow-lite
 
-TENSORFLOW_ROOT := $(NNTRAINER_JNI_ROOT)/tensorflow-$(TENSORFLOW_VERSION)/tensorflow-lite
+$(info $(shell ($(NNTRAINER_JNI_ROOT)/prepare_tflite.sh $(TENSORFLOW_VERSION) $(NDK_LIBS_OUT))))
 
 endif #TENSORFLOW_ROOT
 endif #MAKECMDGOALS
index 406166c..2e6bde2 100755 (executable)
@@ -1,7 +1,16 @@
 #!/usr/bin/env bash
+TARGET=$1
 
-# Get Iniparser
+if [ ! -d ${TARGET} ]; then
+  mkdir -p ${TARGET}
+fi
+
+pushd ${TARGET}
 
+# Get Iniparser
 if [ ! -d "iniparer" ]; then
-    git clone https://github.com/ndevilla/iniparser.git
+    echo "PREPARING ini parser at ${TARGET}"
+    git clone https://github.com/ndevilla/iniparser.git iniparser
 fi
+
+popd
index 2621b1c..80ae75c 100755 (executable)
@@ -4,6 +4,10 @@ TARGET=$2
 
 echo "PREPARING TENSORFLOW ${VERSION} at ${TARGET}"
 
+if [ ! -d ${TARGET} ]; then
+  mkdir -p ${TARGET}
+fi
+
 pushd ${TARGET}
 
 #Get tensorflow
index 48e6b42..dac0a0f 100644 (file)
@@ -167,3 +167,38 @@ if get_option('enable-nnstreamer-tensor-filter')
    nnstreamer_dep = dependency('nnstreamer', required: true)
    subdir('nnstreamer/tensor_filter')
 endif
+
+if get_option('enable-android')
+
+  ndk_build = find_program('ndk-build', required : true)
+  jni_root = meson.current_source_dir() / 'jni'
+  jni_build_root = meson.build_root() / 'jni'
+
+  ndk_args = {
+    'NDK_PROJECT_PATH': jni_root,
+    'APP_BUILD_SCRIPT': jni_root / 'Android.mk',
+    'NDK_APPLICATION_MK': jni_root / 'Application.mk',
+    'NDK_LIBS_OUT': jni_build_root / 'libs',
+    'NDK_OUT': jni_build_root / 'objs',
+  }
+
+  num_threads = run_command('grep', '-c', '^processor', '/proc/cpuinfo').stdout().strip()
+  message('num processor are: ' + num_threads)
+
+  thread_opt_flag = '-j' + num_threads
+
+  ndk_additional_flags = [thread_opt_flag]
+
+  ndk_build_command = [ndk_build]
+  foreach key, val : ndk_args
+    ndk_build_command += '@0@=@1@'.format(key, val)
+  endforeach
+  ndk_build_command += ndk_additional_flags
+
+  android_build_target = custom_target('android',
+    output: 'jni',
+    build_by_default: true,
+    command: ndk_build_command
+  )
+
+endif
index fc9cf1d..8f322d8 100644 (file)
@@ -12,3 +12,4 @@ option('enable-tizen-feature-check', type: 'boolean', value: true)
 option('enable-nnstreamer-tensor-filter', type: 'boolean', value: true)
 option('enable-nnstreamer-backbone', type: 'boolean', value: true)
 option('enable-tflite-backbone', type: 'boolean', value: true)
+option('enable-android', type: 'boolean', value: false)