[CAPI] Beautify CAPI Generality Support
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 14 Jun 2019 04:06:38 +0000 (13:06 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Fri, 14 Jun 2019 04:38:54 +0000 (13:38 +0900)
While the default CAPI header is focussed on Tizen,
if "-Denable-tizen=false", the CAPI header becomes
non-Tizen, which does not require any Tizen packages.

1. Beautify by not using .spec for sed (support non-RPM packages)
2. Beautify by not using unnecessary header in nnstreamer.h
3. Beautify by adding enable-tizen meson option.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
api/capi/include/nnstreamer.h
api/capi/meson.build
api/capi/modify_nnstreamer_h_for_nontizen.sh [new file with mode: 0755]
meson.build
meson_options.txt
packaging/nnstreamer.spec

index 55077b5..2428c52 100644 (file)
 #define __NNSTREAMER_CAPI_H__
 
 #include <stddef.h>
-#include <errno.h>
+/**
+ *  Apply modify_nnstreamer_h_for_nontizen.sh if you want to use
+ * in non-Tizen Linux machines
+ */
+#include <tizen_error.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -125,7 +129,6 @@ typedef enum _ml_tensor_type_e
   ML_TENSOR_TYPE_UNKNOWN          /**< Unknown type */
 } ml_tensor_type_e;
 
-#include <tizen_error.h>
 /**
  * @brief Enumeration for the error codes of NNStreamer Pipelines.
  * @since_tizen 5.5
index 472eaf5..ff5a4ef 100644 (file)
@@ -30,10 +30,21 @@ capi_devel_main += join_paths(meson.current_source_dir(), 'include', 'nnstreamer
 inc = include_directories('include')
 nninc = include_directories('../../gst')
 
-tizen_deps = [
-  dependency('capi-base-common'),
-  dependency('dlog')
-]
+tizen_deps = []
+
+if (get_option('enable-tizen'))
+  message('CAPI is in Tizen mode')
+  tizen_deps = [
+    dependency('capi-base-common'),
+    dependency('dlog')
+  ]
+else
+  r = run_command('./modify_nnstreamer_h_for_nontizen.sh')
+  if (r.returncode() != 0)
+    message('Non-Tizen mode support failed')
+  endif
+  message('CAPI is in non-Tizen mode')
+endif
 
 capi_deps = [
   nnstreamer_dep, glib_dep, gst_dep, gst_app_dep, tizen_deps
diff --git a/api/capi/modify_nnstreamer_h_for_nontizen.sh b/api/capi/modify_nnstreamer_h_for_nontizen.sh
new file mode 100755 (executable)
index 0000000..5962905
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+sed -i "s|#include <tizen_error.h>|#include <errno.h>\n\
+#define TIZEN_ERROR_NONE (0)\n\
+#define TIZEN_ERROR_INVALID_PARAMETER (-EINVAL)\n\
+#define TIZEN_ERROR_STREAMS_PIPE (-ESTRPIPE)\n\
+#define TIZEN_ERROR_TRY_AGAIN (-EAGAIN)\n\
+#define TIZEN_ERROR_UNKNOWN (-1073741824LL)\n\
+#define TIZEN_ERROR_TIMED_OUT (TIZEN_ERROR_UNKNOWN + 1)\n\
+#define TIZEN_ERROR_NOT_SUPPORTED (TIZEN_ERROR_UNKNOWN + 2)\
+|" include/nnstreamer.h
index c5cf5dd..50764df 100644 (file)
@@ -188,6 +188,10 @@ if get_option('enable-python')
   endif
 endif
 
+if get_option('enable-tizen')
+  add_project_arguments('-D__TIZEN__=1', language: ['c', 'cpp'])
+endif
+
 # Build nnstreamer (common, plugins)
 subdir('gst')
 
index 7c5adf5..4c9aeb0 100644 (file)
@@ -13,3 +13,4 @@ option('enable-env-var', type: 'boolean', value: true)
 option('enable-symbolic-link', type: 'boolean', value: true)
 option('enable-capi', type: 'boolean', value: false)
 option('enable-python', type: 'boolean', value: true)
+option('enable-tizen', type: 'boolean', value: false)
index 0fcfc40..ccccc3a 100644 (file)
@@ -165,19 +165,6 @@ cp %{SOURCE1001} .
 cp %{SOURCE1002} .
 %endif
 
-%if ! %{with tizen}
-##
-# If CAPI is built for Non Tizen platform, then below command will be executed.
-sed -i "s|#include <tizen_error.h>||" api/capi/include/nnstreamer.h
-sed -i "s|TIZEN_ERROR_NONE|0|" api/capi/include/nnstreamer.h
-sed -i "s|TIZEN_ERROR_INVALID_PARAMETER|-EINVAL|" api/capi/include/nnstreamer.h
-sed -i "s|TIZEN_ERROR_STREAMS_PIPE|-ESTRPIPE|" api/capi/include/nnstreamer.h
-sed -i "s|TIZEN_ERROR_TRY_AGAIN|-EAGAIN|" api/capi/include/nnstreamer.h
-sed -i "s|TIZEN_ERROR_UNKNOWN|(-1073741824LL)|" api/capi/include/nnstreamer.h
-sed -i "s|= TIZEN_ERROR_TIMED_OUT||" api/capi/include/nnstreamer.h
-sed -i "s|= TIZEN_ERROR_NOT_SUPPORTED||" api/capi/include/nnstreamer.h
-%endif
-
 %build
 %if 0%{?testcoverage}
 CXXFLAGS="${CXXFLAGS} -fprofile-arcs -ftest-coverage"
@@ -192,7 +179,7 @@ mkdir -p build
 %define enable_tf false
 %endif
 
-meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --libdir=%{_libdir} --bindir=%{nnstexampledir} --includedir=%{_includedir} -Dinstall-example=true -Denable-tensorflow=%{enable_tf} -Denable-pytorch=false %{api} -Denable-env-var=false -Denable-symbolic-link=false -Dc_args='-D__TIZEN__' build
+meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --libdir=%{_libdir} --bindir=%{nnstexampledir} --includedir=%{_includedir} -Dinstall-example=true -Denable-tensorflow=%{enable_tf} -Denable-pytorch=false %{api} -Denable-env-var=false -Denable-symbolic-link=false -Denable-tizen=true build
 
 ninja -C build %{?_smp_mflags}