1 project('nntrainer', 'c', 'cpp',
3 license: ['apache-2.0'],
4 meson_version: '>=0.50.0',
13 extra_defines = ['-DMIN_CPP_VERSION=201703L']
15 cc = meson.get_compiler('c')
16 cxx = meson.get_compiler('cpp')
18 if get_option('platform') == 'tizen'
19 # Pass __TIZEN__ to the compiler
20 add_project_arguments('-D__TIZEN__=1', language:['c','cpp'])
21 add_project_arguments('-DTIZENVERSION=@0@'.format(get_option('tizen-version-major')), language: ['c', 'cpp'])
22 add_project_arguments('-DTIZENVERSIONMINOR=@0@'.format(get_option('tizen-version-minor')), language: ['c', 'cpp'])
24 if get_option('enable-tizen-feature-check')
25 add_project_arguments('-D__FEATURE_CHECK_SUPPORT__', language: ['c', 'cpp'])
33 '-Wformat-nonliteral',
41 '-Wdefaulted-function-deleted',
43 '-Wno-unused-variable'
47 '-Wmissing-declarations',
48 '-Wmissing-include-dirs',
49 '-Wmissing-prototypes',
52 '-Wold-style-definition',
53 '-Wdeclaration-after-statement',
58 foreach extra_arg : warning_flags
59 if cc.has_argument (extra_arg)
60 add_project_arguments([extra_arg], language: 'c')
62 if cxx.has_argument (extra_arg)
63 add_project_arguments([extra_arg], language: 'cpp')
67 foreach extra_arg : warning_c_flags
68 if cc.has_argument (extra_arg)
69 add_project_arguments([extra_arg], language: 'c')
74 nntrainer_prefix = get_option('prefix')
75 if get_option('platform') != 'android'
76 nntrainer_libdir = nntrainer_prefix / get_option('libdir')
77 nntrainer_bindir = nntrainer_prefix / get_option('bindir')
78 nntrainer_includedir = nntrainer_prefix / get_option('includedir') / 'nntrainer'
79 nntrainer_confdir = get_option('sysconfdir')
80 application_install_dir = nntrainer_bindir / 'applications'
82 nntrainer_prefix = meson.build_root() / 'android_build_result'
83 # @todo arch has to be option
84 nntrainer_libdir = nntrainer_prefix / 'lib' / 'arm64-v8a'
85 nntrainer_includedir = nntrainer_prefix / 'include' / 'nntrainer'
86 nntrainer_bindir = nntrainer_prefix / 'bin'
87 nntrainer_confdir = nntrainer_prefix / 'conf'
88 application_install_dir = nntrainer_prefix / 'examples'
92 nntrainer_resdir = meson.build_root() / 'res'
93 run_command('mkdir', '-p', nntrainer_resdir)
95 if get_option('install-app')
96 # add a script to install resources from installs to application_install_dir
97 meson.add_install_script(
98 'sh', '-c', 'cp -r @0@ ${DESTDIR}@1@'.format(nntrainer_resdir, application_install_dir)
102 # Set default configuration
103 nntrainer_conf = configuration_data()
104 nntrainer_conf.set('VERSION', meson.project_version())
105 nntrainer_conf.set('PREFIX', nntrainer_prefix)
106 nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
107 nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
108 nntrainer_conf.set('PLUGIN_INSTALL_PREFIX', nntrainer_libdir / 'nntrainer')
109 nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir / '..')
111 dummy_dep = dependency('', required: false)
112 found_dummy_dep = declare_dependency() # dummy dep to use if found
114 # if ml-api-support is disabled, enable dummy common api interfaces and disable related dependencies.
115 ml_api_common_dep = dependency(get_option('capi-ml-common-actual'), required : get_option('ml-api-support').enabled())
116 nnstreamer_capi_dep = dummy_dep
117 if (ml_api_common_dep.found())
118 nntrainer_conf.set('CAPI_ML_COMMON_DEP', get_option('capi-ml-common-actual'))
119 extra_defines += '-DML_API_COMMON=1'
121 nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required : true)
122 extra_defines += '-DNNSTREAMER_AVAILABLE=1'
123 # accessing this variable when dep_.not_found() remains hard error on purpose
124 supported_nnstreamer_capi = nnstreamer_capi_dep.version().version_compare('>=1.7.0')
125 if not supported_nnstreamer_capi
126 extra_defines += '-DUNSUPPORTED_NNSTREAMER=1'
127 warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
130 nntrainer_conf.set('CAPI_ML_COMMON_DEP', '')
131 extra_defines += '-DML_API_COMMON=0'
135 if get_option('enable-cublas')
136 extra_defines += '-DUSE_CUBLAS=1'
139 if get_option('enable-blas')
140 extra_defines += '-DUSE_BLAS=1'
142 if get_option('platform') == 'android'
143 message('preparing blas')
144 run_command(meson.source_root() / 'jni' / 'prepare_openblas.sh', meson.build_root(), check: true)
145 blas_dep = found_dummy_dep
146 blas_root = meson.build_root() / 'openblas'
148 blas_dep = dependency('openblas')
152 if get_option('openblas-num-threads') > 0
153 extra_defines += '-DBLAS_NUM_THREADS=@0@'.format(get_option('openblas-num-threads'))
154 message('set openblas num threads=@0@'.format(get_option('openblas-num-threads')))
159 openmp_dep = dummy_dep
160 if get_option('enable-openmp')
161 openmp_dep = dependency('openmp')
164 if get_option('enable-profile')
165 extra_defines += '-DPROFILE=1'
168 if get_option('enable-debug')
169 extra_defines += '-DDEBUG=1'
172 if get_option('use_gym')
173 extra_defines += '-DUSE_GYM=1'
176 if get_option('enable-logging')
177 extra_defines += '-D__LOGGING__=1'
180 if get_option('enable-test') # and get_option('platform') != 'android'
181 extra_defines += '-DENABLE_TEST=1'
184 if get_option('reduce-tolerance')
185 extra_defines += '-DREDUCE_TOLERANCE=1'
188 libm_dep = cxx.find_library('m') # cmath library
189 libdl_dep = cxx.find_library('dl') # DL library
190 thread_dep = dependency('threads') # pthread for tensorflow-lite
192 iniparser_dep = dependency('iniparser', required : false, version : '>=4.1') # iniparser
193 if get_option('platform') == 'android'
194 message('preparing iniparser')
195 run_command(meson.source_root() / 'jni' / 'prepare_iniparser.sh', meson.build_root(), check: true)
196 iniparser_root = meson.build_root() / 'iniparser'
197 iniparser_dep = found_dummy_dep
200 if not iniparser_dep.found()
201 message('falling back to find libiniparser library and header files')
202 libiniparser_dep = cxx.find_library('iniparser')
203 sysroot = run_command(
204 cxx.cmd_array() + ['-print-sysroot']
205 ).stdout().split('\n')[0]
207 if sysroot.startswith('/')
208 sysroot_inc_cflags_template = '-I@0@/usr/include@1@'
209 sysroot_inc = sysroot_inc_cflags_template.format(sysroot, '')
210 add_project_arguments(sysroot_inc, language: ['c', 'cpp'])
211 sysroot_inc_cflags_iniparser = sysroot_inc_cflags_template.format(sysroot,
214 sysroot_inc_cflags_iniparser = '-I/usr/include/iniparser'
217 if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
218 args : sysroot_inc_cflags_iniparser)
219 iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
220 compile_args : sysroot_inc_cflags_iniparser)
222 error('Failed to resolve dependency on iniparser')
226 if get_option('platform') == 'android'
227 message('preparing ml api')
228 run_command(meson.source_root() / 'jni' / 'prepare_ml-api.sh', meson.build_root() / 'ml-api-inference', check: true)
229 ml_api_common_root = meson.build_root() / 'ml-api-inference'
230 ml_api_inc = ml_api_common_root / 'include'
231 meson.add_install_script(
232 'sh', '-c', 'cp @0@ ${DESTDIR}@1@'.format(ml_api_inc / 'ml-api-common.h', nntrainer_includedir)
234 meson.add_install_script(
235 'sh', '-c', 'cp @0@ ${DESTDIR}@1@'.format(ml_api_inc / 'tizen_error.h', nntrainer_includedir)
237 ml_api_common_dep = found_dummy_dep
240 if get_option('enable-nnstreamer-backbone') and get_option('platform') != 'android'
241 extra_defines += '-DENABLE_NNSTREAMER_BACKBONE=1'
244 tflite_dep = dummy_dep
246 if get_option('platform') != 'android'
247 tflite_dep = dependency('tensorflow2-lite', required: false)
249 if get_option('enable-tflite-backbone') or get_option('enable-tflite-interpreter')
250 message('preparing tflite, because either tflite backbone or interpreter is enabled')
251 run_command(meson.source_root() / 'jni' / 'prepare_tflite.sh', '2.3.0', meson.build_root(), check: true)
252 tflite_root = meson.build_root() / 'tensorflow-2.3.0' / 'tensorflow-lite'
253 tflite_dep = found_dummy_dep
257 if get_option('enable-tflite-backbone')
258 extra_defines += '-DENABLE_TFLITE_BACKBONE=1'
261 if get_option('enable-tflite-interpreter')
262 extra_defines += '-DENABLE_TFLITE_INTERPRETER=1'
265 gtest_dep = dependency('gtest', static: true, main: false, required: false)
266 gtest_main_dep = dependency('gtest', static: true, main: true, required: false)
268 opencv_dep = dummy_dep
270 if get_option('platform') != 'android'
271 opencv_dep = dependency('opencv', required: false)
272 if not opencv_dep.found()
273 opencv_dep = dependency('opencv4', required: false)
274 if not opencv_dep.found()
275 opencv_dep = dependency('opencv3', required: false)
278 if opencv_dep.found()
279 extra_defines += '-DENABLE_DATA_AUGMENTATION_OPENCV=1'
282 flatc_prog = find_program('flatc', required: false)
285 configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
286 install_dir: nntrainer_libdir / 'pkgconfig',
287 configuration: nntrainer_conf
292 input: 'nntrainer.ini.in',
293 output: 'nntrainer.ini',
294 install_dir: nntrainer_confdir,
295 configuration: nntrainer_conf
297 nntrainer_conf_abs_path = get_option('prefix') / nntrainer_confdir / 'nntrainer.ini'
298 message('NNTRAINER_CONF_PATH=@0@'.format(nntrainer_conf_abs_path))
300 if get_option('platform') != 'android'
301 extra_defines += '-DNNTRAINER_CONF_PATH="@0@"'.format(nntrainer_conf_abs_path)
304 message('extra defines are:' + ' '.join(extra_defines))
305 foreach defs: extra_defines
306 add_project_arguments(defs, language: ['c', 'cpp'])
317 if get_option('enable-test')
318 if get_option('platform') == 'android'
319 warning('test is not supported in android build, test skipped')
324 error('test enabled but gtest not found')
329 if get_option('enable-app')
330 if get_option('platform') == 'android'
331 warning('android app is not supported for now, building app skipped')
333 # this is needed for reinforcement application. We can move this to reinforecement app dependency
334 jsoncpp_dep = dependency('jsoncpp') # jsoncpp
335 libcurl_dep = dependency('libcurl')
336 if not tflite_dep.found()
337 error('Tensorflow-Lite dependency not found')
339 subdir('Applications')
343 if get_option('enable-nnstreamer-tensor-filter')
344 if get_option('platform') == 'android'
345 warning('android nnstreamer-filter is not yet supported, building nnstreamer-filter skipped')
347 nnstreamer_dep = dependency('nnstreamer', required: true)
348 subdir('nnstreamer/tensor_filter')
352 if get_option('platform') == 'android'
356 if get_option('platform') != 'none'
357 message('building for ' + get_option('platform'))