From 9e8f409778e3bdeb92d376daafec029f099dbcca Mon Sep 17 00:00:00 2001 From: MyungJoo Ham Date: Fri, 14 Jun 2019 13:06:38 +0900 Subject: [PATCH] [CAPI] Beautify CAPI Generality Support 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 --- api/capi/include/nnstreamer.h | 7 +++++-- api/capi/meson.build | 19 +++++++++++++++---- api/capi/modify_nnstreamer_h_for_nontizen.sh | 11 +++++++++++ meson.build | 4 ++++ meson_options.txt | 1 + packaging/nnstreamer.spec | 15 +-------------- 6 files changed, 37 insertions(+), 20 deletions(-) create mode 100755 api/capi/modify_nnstreamer_h_for_nontizen.sh diff --git a/api/capi/include/nnstreamer.h b/api/capi/include/nnstreamer.h index 55077b5..2428c52 100644 --- a/api/capi/include/nnstreamer.h +++ b/api/capi/include/nnstreamer.h @@ -25,7 +25,11 @@ #define __NNSTREAMER_CAPI_H__ #include -#include +/** + * Apply modify_nnstreamer_h_for_nontizen.sh if you want to use + * in non-Tizen Linux machines + */ +#include #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 /** * @brief Enumeration for the error codes of NNStreamer Pipelines. * @since_tizen 5.5 diff --git a/api/capi/meson.build b/api/capi/meson.build index 472eaf5..ff5a4ef 100644 --- a/api/capi/meson.build +++ b/api/capi/meson.build @@ -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 index 0000000..5962905 --- /dev/null +++ b/api/capi/modify_nnstreamer_h_for_nontizen.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +sed -i "s|#include |#include \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 diff --git a/meson.build b/meson.build index c5cf5dd..50764df 100644 --- a/meson.build +++ b/meson.build @@ -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') diff --git a/meson_options.txt b/meson_options.txt index 7c5adf5..4c9aeb0 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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) diff --git a/packaging/nnstreamer.spec b/packaging/nnstreamer.spec index 0fcfc40..ccccc3a 100644 --- a/packaging/nnstreamer.spec +++ b/packaging/nnstreamer.spec @@ -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 ||" 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} -- 2.7.4