From 79ff58720eb0e836a0ba18d9aa3dc01ae8b43fd4 Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Wed, 12 Dec 2018 15:24:58 +0900 Subject: [PATCH] [Meson] code clean 1. add flags for tensorflow and tensorflow-lite 2. set objs with the flags and dependency of libraries 3. build with each plugin files Signed-off-by: Jaeyun Jung --- gst/nnstreamer/meson.build | 18 ++-- gst/tensor_aggregator/meson.build | 11 +-- gst/tensor_converter/meson.build | 11 +-- gst/tensor_decoder/meson.build | 11 +-- gst/tensor_demux/meson.build | 11 +-- gst/tensor_filter/meson.build | 72 ++++++--------- gst/tensor_merge/meson.build | 11 +-- gst/tensor_mux/meson.build | 11 +-- gst/tensor_reposink/meson.build | 11 +-- gst/tensor_reposrc/meson.build | 11 +-- gst/tensor_saveload/meson.build | 11 +-- gst/tensor_sink/meson.build | 11 +-- gst/tensor_split/meson.build | 11 +-- gst/tensor_transform/meson.build | 29 +++--- meson.build | 104 +++++++++++++++------- tests/meson.build | 22 +++-- tests/nnstreamer_tensors/tensors_test/meson.build | 14 ++- 17 files changed, 169 insertions(+), 211 deletions(-) diff --git a/gst/nnstreamer/meson.build b/gst/nnstreamer/meson.build index 26b09a3..0357c41 100644 --- a/gst/nnstreamer/meson.build +++ b/gst/nnstreamer/meson.build @@ -1,13 +1,9 @@ -tensor_common_sources = [ - 'tensor_common.c', - 'tensor_repo.c' +nnst_common_sources = [ + 'nnstreamer.c', + 'tensor_repo.c', + 'tensor_common.c' ] -tensor_commonOBJ = static_library('tensor_common', - tensor_common_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_commonOBJ +foreach s : nnst_common_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_aggregator/meson.build b/gst/tensor_aggregator/meson.build index f43c4b6..3ec4b16 100644 --- a/gst/tensor_aggregator/meson.build +++ b/gst/tensor_aggregator/meson.build @@ -2,11 +2,6 @@ tensor_aggregator_sources = [ 'tensor_aggregator.c' ] -tensor_aggregatorOBJ = static_library('tensor_aggregator', - tensor_aggregator_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_aggregatorOBJ +foreach s : tensor_aggregator_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_converter/meson.build b/gst/tensor_converter/meson.build index 4a3430b..8fb217b 100644 --- a/gst/tensor_converter/meson.build +++ b/gst/tensor_converter/meson.build @@ -2,11 +2,6 @@ tensor_converter_sources = [ 'tensor_converter.c' ] -tensor_converterOBJ = static_library('tensor_converter', - tensor_converter_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_converterOBJ +foreach s : tensor_converter_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_decoder/meson.build b/gst/tensor_decoder/meson.build index 20c7b5a..04a751a 100644 --- a/gst/tensor_decoder/meson.build +++ b/gst/tensor_decoder/meson.build @@ -6,11 +6,6 @@ tensor_decoder_sources = [ 'tensordec-boundingbox.c' ] -tensor_decoderOBJ = static_library('tensor_decoder', - tensor_decoder_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_decoderOBJ +foreach s : tensor_decoder_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_demux/meson.build b/gst/tensor_demux/meson.build index 553da22..b10f370 100644 --- a/gst/tensor_demux/meson.build +++ b/gst/tensor_demux/meson.build @@ -2,11 +2,6 @@ tensor_demux_sources = [ 'gsttensordemux.c' ] -tensor_demuxOBJ = static_library('tensor_demux', - tensor_demux_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_demuxOBJ +foreach s : tensor_demux_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_filter/meson.build b/gst/tensor_filter/meson.build index 27461fd..eba228d 100644 --- a/gst/tensor_filter/meson.build +++ b/gst/tensor_filter/meson.build @@ -1,58 +1,36 @@ -tensor_filter_args = [nnstreamer_base_args] -tensor_filterOBJ = [] - -# For custom filter -tensor_filter_customOBJ = static_library('tensor_filter_custom', - 'tensor_filter_custom.c', - c_args: tensor_filter_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -tensor_filterOBJ += tensor_filter_customOBJ - -if get_option('ENABLE_TENSORFLOW_LITE') - tflite_dep = dependency('tensorflow-lite', required: true) +tensor_filter_sources = [ + 'tensor_filter.c', + 'tensor_filter_custom.c' +] - nnstreamer_deps += [tflite_dep] - tensor_filter_args += ['-DENABLE_TENSORFLOW_LITE'] +if have_tensorflow + tensor_filter_sources += ['tensor_filter_tensorflow.c'] - tensor_filter_tensorflow_liteOBJ = static_library('tensor_filter_tensorflow_lite', - ['tensor_filter_tensorflow_lite.c', 'tensor_filter_tensorflow_lite_core.cc'], - c_args: tensor_filter_args, - cpp_args: tensor_filter_args + ['-Wno-sign-compare'], - dependencies: [nnstreamer_deps], + tensor_filter_tfcore_lib = library('tensor_filter_tfcore', + ['tensor_filter_tensorflow_core.cc'], + cpp_args: nnstreamer_base_args + ['-Wno-sign-compare'], + dependencies: [tf_dep, protobuf_dep, glib_dep, gst_dep], include_directories: nnstreamer_inc - ).extract_all_objects() + ) - tensor_filterOBJ += tensor_filter_tensorflow_liteOBJ + tensor_filter_tfcore_dep = declare_dependency(link_with: tensor_filter_tfcore_lib) + nnstreamer_extra_deps += tensor_filter_tfcore_dep endif -if get_option('ENABLE_TENSORFLOW') - tf_dep = dependency('tensorflow', required: true) - protobuf_dep = dependency('protobuf', version: '>= 3.6.0', required: true) +if have_tensorflow_lite + tensor_filter_sources += ['tensor_filter_tensorflow_lite.c'] - nnstreamer_deps += [tf_dep, protobuf_dep] - tensor_filter_args += ['-DENABLE_TENSORFLOW'] - - tensor_filter_tensorflowOBJ = static_library('tensor_filter_tensorflow', - ['tensor_filter_tensorflow.c', 'tensor_filter_tensorflow_core.cc'], - c_args: tensor_filter_args, - cpp_args: tensor_filter_args + ['-Wno-sign-compare'], - dependencies: [nnstreamer_deps], + tensor_filter_tflitecore_lib = library('tensor_filter_tflitecore', + ['tensor_filter_tensorflow_lite_core.cc'], + cpp_args: nnstreamer_base_args + ['-Wno-sign-compare'], + dependencies: [tflite_dep, libpthread_dep, libdl_dep, glib_dep, gst_dep], include_directories: nnstreamer_inc - ).extract_all_objects() + ) - tensor_filterOBJ += tensor_filter_tensorflowOBJ + tensor_filter_tflitecore_dep = declare_dependency(link_with: tensor_filter_tflitecore_lib) + nnstreamer_extra_deps += tensor_filter_tflitecore_dep endif -tensor_filter_mainOBJ = static_library('tensor_filter_main', - 'tensor_filter.c', - c_args: tensor_filter_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -tensor_filterOBJ += tensor_filter_mainOBJ - -objects += tensor_filterOBJ +foreach s : tensor_filter_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_merge/meson.build b/gst/tensor_merge/meson.build index 7f6af3b..e93f8d7 100644 --- a/gst/tensor_merge/meson.build +++ b/gst/tensor_merge/meson.build @@ -2,11 +2,6 @@ tensor_merge_sources = [ 'gsttensormerge.c' ] -tensor_mergeOBJ = static_library('tensor_merge', - tensor_merge_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_mergeOBJ +foreach s : tensor_merge_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_mux/meson.build b/gst/tensor_mux/meson.build index b82167b..388e54e 100644 --- a/gst/tensor_mux/meson.build +++ b/gst/tensor_mux/meson.build @@ -2,11 +2,6 @@ tensor_mux_sources = [ 'gsttensormux.c' ] -tensor_muxOBJ = static_library('tensor_mux', - tensor_mux_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_muxOBJ +foreach s : tensor_mux_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_reposink/meson.build b/gst/tensor_reposink/meson.build index a950c18..5abc20d 100644 --- a/gst/tensor_reposink/meson.build +++ b/gst/tensor_reposink/meson.build @@ -2,11 +2,6 @@ tensor_reposink_sources = [ 'tensor_reposink.c' ] -tensor_reposinkOBJ = static_library('tensor_reposink', - tensor_reposink_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_reposinkOBJ +foreach s : tensor_reposink_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_reposrc/meson.build b/gst/tensor_reposrc/meson.build index 45880be..d2ceb85 100644 --- a/gst/tensor_reposrc/meson.build +++ b/gst/tensor_reposrc/meson.build @@ -2,11 +2,6 @@ tensor_reposrc_sources = [ 'tensor_reposrc.c' ] -tensor_reposrcOBJ = static_library('tensor_reposrc', - tensor_reposrc_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_reposrcOBJ +foreach s : tensor_reposrc_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_saveload/meson.build b/gst/tensor_saveload/meson.build index db6a050..ca8b276 100644 --- a/gst/tensor_saveload/meson.build +++ b/gst/tensor_saveload/meson.build @@ -2,11 +2,6 @@ tensor_saveload_sources = [ 'tensor_load.c' ] -tensor_saveloadOBJ = static_library('tensor_saveload', - tensor_saveload_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_saveloadOBJ +foreach s : tensor_saveload_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_sink/meson.build b/gst/tensor_sink/meson.build index 6d00391..1c85ae3 100644 --- a/gst/tensor_sink/meson.build +++ b/gst/tensor_sink/meson.build @@ -2,11 +2,6 @@ tensor_sink_sources = [ 'tensor_sink.c' ] -tensor_sinkOBJ = static_library('tensor_sink', - tensor_sink_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_sinkOBJ +foreach s : tensor_sink_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_split/meson.build b/gst/tensor_split/meson.build index 42104d5..a312432 100644 --- a/gst/tensor_split/meson.build +++ b/gst/tensor_split/meson.build @@ -2,11 +2,6 @@ tensor_split_sources = [ 'gsttensorsplit.c' ] -tensor_splitOBJ = static_library('tensor_split', - tensor_split_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() - -objects += tensor_splitOBJ +foreach s : tensor_split_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/gst/tensor_transform/meson.build b/gst/tensor_transform/meson.build index cc922eb..6f79203 100644 --- a/gst/tensor_transform/meson.build +++ b/gst/tensor_transform/meson.build @@ -2,25 +2,22 @@ tensor_transform_sources = [ 'tensor_transform.c' ] -orcsrc = 'transform-orc' if have_orcc # tensor_transform does not need to generate -dist files. + orcsrc = 'transform-orc' + orc_h = custom_target(orcsrc + '.h', - input : orcsrc + '.orc', - output : orcsrc + '.h', - command : orcc_args + ['--header', '-o', '@OUTPUT@', '@INPUT@']) + input: orcsrc + '.orc', + output: orcsrc + '.h', + command: orcc_args + ['--header', '-o', '@OUTPUT@', '@INPUT@']) orc_c = custom_target(orcsrc + '.c', - input : orcsrc + '.orc', - output : orcsrc + '.c', - command : orcc_args + ['--implementation', '-o', '@OUTPUT@', '@INPUT@']) - tensor_transform_sources += [orc_c, orc_h] -endif + input: orcsrc + '.orc', + output: orcsrc + '.c', + command: orcc_args + ['--implementation', '-o', '@OUTPUT@', '@INPUT@']) -tensor_transformOBJ = static_library('tensor_transform', - tensor_transform_sources, - c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc -).extract_all_objects() + nnstreamer_sources += [orc_c, orc_h] +endif -objects += tensor_transformOBJ +foreach s : tensor_transform_sources + nnstreamer_sources += join_paths(meson.current_source_dir(), s) +endforeach diff --git a/meson.build b/meson.build index 849215c..985f230 100644 --- a/meson.build +++ b/meson.build @@ -14,8 +14,16 @@ project('nnstreamer', 'c', 'cpp', add_project_arguments('-DVERSION="'+meson.project_version()+'"', language: 'c') +cc = meson.get_compiler('c') +cxx = meson.get_compiler('cpp') + gst_api_verision = '1.0' +nnstreamer_inc = include_directories('gst/nnstreamer') +nnstreamer_sources = [] +nnstreamer_base_args = [] + +# Dependencies glib_dep = dependency('glib-2.0') gst_dep = dependency('gstreamer-' + gst_api_verision) gst_base_dep = dependency('gstreamer-base-' + gst_api_verision) @@ -25,41 +33,70 @@ gst_audio_dep = dependency('gstreamer-audio-' + gst_api_verision) gst_app_dep = dependency('gstreamer-app-' + gst_api_verision) gst_check_dep = dependency('gstreamer-check-' + gst_api_verision) -cc = meson.get_compiler('c') -cxx = meson.get_compiler('cpp') +libm_dep = cc.find_library('m') # cmath library +libdl_dep = cc.find_library('dl') # DL library +libpthread_dep = cxx.find_library('pthread') # pthread for tensorflow-lite -nnstreamer_deps = [ +nnstreamer_base_deps = [ glib_dep, gst_dep, gst_base_dep, gst_controller_dep, gst_video_dep, gst_audio_dep, - # required 'false' mean is used only when needed. - cc.find_library('m', required: false), # cmath library - cc.find_library('dl', required: false), # DL library - cxx.find_library('pthread', required: false) # pthread for tensor_filter_tensorflow_lite + libm_dep, + libdl_dep, + libpthread_dep ] -nnstreamer_inc = include_directories('gst/nnstreamer') -nnstreamer_base_args = [] +# For extra dependencies (subplugins, filters) +nnstreamer_extra_deps = [] # Orc have_orcc = false -orcc_args = [] -orc_dep = dependency('orc-0.4', version: '>= 0.4.24', required: true) -orcc = find_program('orcc', required: true) +orc_dep = dependency('orc-0.4', version: '>= 0.4.17', required: false) +orcc = find_program('orcc', required: false) if orc_dep.found() and orcc.found() have_orcc = true orcc_args = [orcc, '--include', 'glib.h'] - nnstreamer_deps += [orc_dep] + nnstreamer_base_deps += [orc_dep] nnstreamer_base_args += ['-DHAVE_ORC=1'] else message('Cannot find orc library') nnstreamer_base_args += ['-DDISABLE_ORC=1'] endif +# Tensorflow +have_tensorflow = false + +if get_option('ENABLE_TENSORFLOW') + tf_dep = dependency('tensorflow', required: true) + protobuf_dep = dependency('protobuf', version: '>= 3.4.0', required: true) + + if tf_dep.found() and protobuf_dep.found() + have_tensorflow = true + nnstreamer_base_args += ['-DENABLE_TENSORFLOW=1'] + else + message('Cannot find tensorflow') + endif +endif + +# Tensorflow-lite +have_tensorflow_lite = false + +if get_option('ENABLE_TENSORFLOW_LITE') + tflite_dep = dependency('tensorflow-lite', required: true) + + if tflite_dep.found() + have_tensorflow_lite = true + nnstreamer_base_args += ['-DENABLE_TENSORFLOW_LITE=1'] + else + message('Cannot find tensorflow-lite') + endif +endif + +# Build nnstreamer (common, plugins) projects = [ 'nnstreamer', 'tensor_aggregator', @@ -77,33 +114,36 @@ projects = [ 'tensor_reposink' ] -objects = [] foreach p : projects subdir('gst/'+ p) endforeach -subdir('nnstreamer_example') - -if get_option('ENABLE_TEST') - subdir('tests') -endif - -nnstreamer_sources = [ - 'gst/nnstreamer/nnstreamer.c' -] - # "both_libraries" are supported from 0.46. -nnstreamer = shared_library('nnstreamer', +nnstreamer_shared = shared_library('nnstreamer', nnstreamer_sources, c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc, - objects: objects + dependencies: [nnstreamer_base_deps, nnstreamer_extra_deps], + include_directories: nnstreamer_inc ) -nnstreamer = static_library('nnstreamer', + +nnstreamer_static = static_library('nnstreamer', nnstreamer_sources, c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc, - objects: objects + dependencies: [nnstreamer_base_deps, nnstreamer_extra_deps], + include_directories: nnstreamer_inc ) + +nnstreamer_lib = nnstreamer_shared +if get_option('default_library') == 'static' + nnstreamer_lib = nnstreamer_static +endif + +nnstreamer_dep = declare_dependency(link_with: nnstreamer_lib) + +# Build nnstreamer examples +subdir('nnstreamer_example') + +# Build unittests +if get_option('ENABLE_TEST') + subdir('tests') +endif diff --git a/tests/meson.build b/tests/meson.build index d26030a..1fd9545 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -4,19 +4,25 @@ gtest_dep = dependency('gtest', main: false, required: true) if gtest_dep.found() # This custom filter is used in unittest_sink. - nnscustom_framecounter = shared_library('nnscustom_framecounter', + nnscustom_framecounter_lib = library('nnscustom_framecounter', 'nnstreamer_sink/nnscustom_framecounter.c', c_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps], - objects: [tensor_commonOBJ], + dependencies: [glib_dep], include_directories: nnstreamer_inc) + nnstreamer_unittest_deps = [ + nnstreamer_base_deps, + nnstreamer_dep, + gst_app_dep, + gst_check_dep, + gtest_dep + ] + # Run unittest_common unittest_common = executable('unittest_common', 'common/unittest_common.cpp', cpp_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps, gtest_dep], - objects: [tensor_commonOBJ], + dependencies: [nnstreamer_unittest_deps], include_directories: nnstreamer_inc) test('unittest_common', unittest_common) @@ -25,8 +31,7 @@ if gtest_dep.found() unittest_sink = executable('unittest_sink', 'nnstreamer_sink/unittest_sink.cpp', cpp_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps, gtest_dep, gst_app_dep], - objects: [tensor_commonOBJ], + dependencies: [nnstreamer_unittest_deps], include_directories: nnstreamer_inc) test('unittest_sink', unittest_sink, args: ['--gst-plugin-path=../']) @@ -35,8 +40,7 @@ if gtest_dep.found() unittest_plugins = executable('unittest_plugins', 'nnstreamer_plugins/unittest_plugins.cpp', cpp_args: nnstreamer_base_args, - dependencies: [nnstreamer_deps, gtest_dep, gst_check_dep], - objects: [tensor_commonOBJ, tensor_transformOBJ], + dependencies: [nnstreamer_unittest_deps], include_directories: nnstreamer_inc) test('unittest_plugins', unittest_plugins, args: ['--gst-plugin-path=../']) diff --git a/tests/nnstreamer_tensors/tensors_test/meson.build b/tests/nnstreamer_tensors/tensors_test/meson.build index 6473a5e..252794e 100644 --- a/tests/nnstreamer_tensors/tensors_test/meson.build +++ b/tests/nnstreamer_tensors/tensors_test/meson.build @@ -2,20 +2,18 @@ testtensors_sources = [ 'gsttesttensors.c' ] -testtensorsOBJ = shared_library('testtensors', +testtensors_lib = library('testtensors', testtensors_sources, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc, - objects: tensor_commonOBJ + dependencies: [gst_dep, nnstreamer_dep], + include_directories: nnstreamer_inc ) tensorscheck_sources = [ 'gsttensorscheck.c' ] -tensorscheckOBJ = shared_library('tensorscheck', +tensorscheck_lib = library('tensorscheck', tensorscheck_sources, - dependencies: [nnstreamer_deps], - include_directories: nnstreamer_inc, - objects: tensor_commonOBJ + dependencies: [gst_dep, nnstreamer_dep], + include_directories: nnstreamer_inc ) -- 2.7.4