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',
40 '-Wdefaulted-function-deleted',
42 '-Wno-maybe-uninitialized',
43 '-Wno-unused-variable'
47 '-Wmissing-declarations',
48 '-Wmissing-include-dirs',
49 '-Wmissing-prototypes',
52 '-Wold-style-definition',
53 '-Wdeclaration-after-statement',
59 # '-mfp16-format=alternative',
61 # '-mfloat-abi=softfp'
64 # if get_option('enable-fp16')
65 # foreach extra_arg : arm_fp16_flags
66 # if cc.has_argument (extra_arg)
67 # add_project_arguments([extra_arg], language: 'c')
69 # if cxx.has_argument (extra_arg)
70 # add_project_arguments([extra_arg], language: 'cpp')
75 foreach extra_arg : warning_flags
76 if cc.has_argument (extra_arg)
77 add_project_arguments([extra_arg], language: 'c')
79 if cxx.has_argument (extra_arg)
80 add_project_arguments([extra_arg], language: 'cpp')
84 foreach extra_arg : warning_c_flags
85 if cc.has_argument (extra_arg)
86 add_project_arguments([extra_arg], language: 'c')
91 nntrainer_prefix = get_option('prefix')
92 if get_option('platform') != 'android'
93 nntrainer_libdir = nntrainer_prefix / get_option('libdir')
94 nntrainer_bindir = nntrainer_prefix / get_option('bindir')
95 nntrainer_includedir = nntrainer_prefix / get_option('includedir') / 'nntrainer'
96 nntrainer_confdir = get_option('sysconfdir')
97 application_install_dir = nntrainer_bindir / 'applications'
98 nntrainer_swapdir = '/tmp'
100 nntrainer_prefix = meson.build_root() / 'android_build_result'
101 # @todo arch has to be option
102 nntrainer_libdir = nntrainer_prefix / 'lib'
103 nntrainer_includedir = nntrainer_prefix / 'include' / 'nntrainer'
104 nntrainer_bindir = nntrainer_prefix / 'bin'
105 nntrainer_confdir = nntrainer_prefix / 'conf'
106 application_install_dir = nntrainer_prefix / 'examples'
107 nntrainer_swapdir = '/data/local/tmp'
110 # handle swap options
111 if get_option('enable-memory-swap')
112 nntrainer_enable_swap = 'true'
114 nntrainer_enable_swap = 'false'
117 if get_option('memory-swap-path') != ''
118 nntrainer_swapdir = get_option('memory-swap-path')
122 nntrainer_resdir = meson.build_root() / 'res'
123 run_command('mkdir', '-p', nntrainer_resdir)
125 if get_option('install-app')
126 # add a script to install resources from installs to application_install_dir
127 meson.add_install_script(
128 'sh', '-c', 'cp -r @0@ ${DESTDIR}@1@'.format(nntrainer_resdir, application_install_dir)
132 # Set default configuration
133 nntrainer_conf = configuration_data()
134 nntrainer_conf.set('VERSION', meson.project_version())
135 nntrainer_conf.set('PREFIX', nntrainer_prefix)
136 nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
137 nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
138 nntrainer_conf.set('PLUGIN_INSTALL_PREFIX', nntrainer_libdir / 'nntrainer')
139 nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir / '..')
140 nntrainer_conf.set('MEMORY_SWAP', nntrainer_enable_swap)
141 nntrainer_conf.set('MEMORY_SWAP_PATH', nntrainer_swapdir)
143 dummy_dep = dependency('', required: false)
144 found_dummy_dep = declare_dependency() # dummy dep to use if found
146 # if ml-api-support is disabled, enable dummy common api interfaces and disable related dependencies.
147 ml_api_common_dep = dependency(get_option('capi-ml-common-actual'), required : get_option('ml-api-support').enabled())
148 nnstreamer_capi_dep = dummy_dep
149 if (ml_api_common_dep.found())
150 nntrainer_conf.set('CAPI_ML_COMMON_DEP', get_option('capi-ml-common-actual'))
151 extra_defines += '-DML_API_COMMON=1'
153 nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required : true)
154 extra_defines += '-DNNSTREAMER_AVAILABLE=1'
155 # accessing this variable when dep_.not_found() remains hard error on purpose
156 supported_nnstreamer_capi = nnstreamer_capi_dep.version().version_compare('>=1.7.0')
157 if not supported_nnstreamer_capi
158 extra_defines += '-DUNSUPPORTED_NNSTREAMER=1'
159 warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
162 nntrainer_conf.set('CAPI_ML_COMMON_DEP', '')
163 extra_defines += '-DML_API_COMMON=0'
167 if get_option('enable-cublas')
168 extra_defines += '-DUSE_CUBLAS=1'
171 if get_option('enable-blas')
172 extra_defines += '-DUSE_BLAS=1'
174 if get_option('platform') == 'android'
175 message('preparing blas')
176 run_command(meson.source_root() / 'jni' / 'prepare_openblas.sh', meson.build_root(), check: true)
177 blas_dep = found_dummy_dep
178 blas_root = meson.build_root() / 'openblas'
180 blas_dep = dependency('openblas')
184 if get_option('openblas-num-threads') > 0
185 extra_defines += '-DBLAS_NUM_THREADS=@0@'.format(get_option('openblas-num-threads'))
186 message('set openblas num threads=@0@'.format(get_option('openblas-num-threads')))
191 extra_defines += '-DNNTR_NUM_THREADS=@0@'.format(get_option('nntr-num-threads'))
192 message('set nntrainer num threads=@0@'.format(get_option('nntr-num-threads')))
194 openmp_dep = dummy_dep
195 if get_option('enable-openmp')
196 openmp_dep = dependency('openmp')
199 if get_option('enable-profile')
200 extra_defines += '-DPROFILE=1'
203 if get_option('enable-trace')
204 extra_defines += '-DTRACE=1'
207 if get_option('enable-debug')
208 extra_defines += '-DDEBUG=1'
211 if get_option('use_gym')
212 extra_defines += '-DUSE_GYM=1'
215 if get_option('enable-logging')
216 extra_defines += '-D__LOGGING__=1'
219 gmock_dep = dependency('gmock', static: true, main: false, required: false)
220 gtest_dep = dependency('gtest', static: true, main: false, required: false)
221 gtest_main_dep = dependency('gtest', static: true, main: true, required: false)
224 if get_option('enable-test') # and get_option('platform') != 'android'
225 extra_defines += '-DENABLE_TEST=1'
226 if gtest_dep.version().version_compare('<1.10.0')
227 extra_defines += '-DGTEST_BACKPORT=1'
229 test_timeout = get_option('test-timeout')
232 if get_option('reduce-tolerance')
233 extra_defines += '-DREDUCE_TOLERANCE=1'
236 libm_dep = cxx.find_library('m') # cmath library
237 libdl_dep = cxx.find_library('dl') # DL library
238 thread_dep = dependency('threads') # pthread for tensorflow-lite
240 iniparser_dep = dependency('iniparser', required : false, version : '>=4.1') # iniparser
241 if get_option('platform') == 'android'
242 message('preparing iniparser')
243 run_command(meson.source_root() / 'jni' / 'prepare_iniparser.sh', meson.build_root(), check: true)
244 iniparser_root = meson.build_root() / 'iniparser'
245 iniparser_dep = found_dummy_dep
248 if not iniparser_dep.found()
249 message('falling back to find libiniparser library and header files')
250 libiniparser_dep = cxx.find_library('iniparser')
251 sysroot = run_command(
252 cxx.cmd_array() + ['-print-sysroot']
253 ).stdout().split('\n')[0]
255 if sysroot.startswith('/')
256 sysroot_inc_cflags_template = '-I@0@/usr/include@1@'
257 sysroot_inc = sysroot_inc_cflags_template.format(sysroot, '')
258 add_project_arguments(sysroot_inc, language: ['c', 'cpp'])
259 sysroot_inc_cflags_iniparser = sysroot_inc_cflags_template.format(sysroot,
262 sysroot_inc_cflags_iniparser = '-I/usr/include/iniparser'
265 if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
266 args : sysroot_inc_cflags_iniparser)
267 iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
268 compile_args : sysroot_inc_cflags_iniparser)
270 error('Failed to resolve dependency on iniparser')
274 if get_option('platform') == 'android'
275 message('preparing ml api')
276 run_command(meson.source_root() / 'jni' / 'prepare_ml-api.sh', meson.build_root() / 'ml-api-inference', check: true)
277 ml_api_common_root = meson.build_root() / 'ml-api-inference'
278 ml_api_inc = ml_api_common_root / 'include'
279 meson.add_install_script(
280 'sh', '-c', 'cp @0@ ${DESTDIR}@1@'.format(ml_api_inc / 'ml-api-common.h', nntrainer_includedir)
282 meson.add_install_script(
283 'sh', '-c', 'cp @0@ ${DESTDIR}@1@'.format(ml_api_inc / 'tizen_error.h', nntrainer_includedir)
285 ml_api_common_dep = found_dummy_dep
288 if get_option('enable-nnstreamer-backbone') and get_option('platform') != 'android'
289 extra_defines += '-DENABLE_NNSTREAMER_BACKBONE=1'
292 tflite_dep = dummy_dep
294 if get_option('platform') != 'android'
295 tflite_dep = dependency('tensorflow2-lite', required: false)
297 if get_option('enable-tflite-backbone') or get_option('enable-tflite-interpreter')
298 message('preparing tflite, because either tflite backbone or interpreter is enabled')
299 run_command(meson.source_root() / 'jni' / 'prepare_tflite.sh', '2.3.0', meson.build_root(), check: true)
300 tflite_root = meson.build_root() / 'tensorflow-2.3.0' / 'tensorflow-lite'
301 tflite_dep = found_dummy_dep
305 if get_option('enable-tflite-backbone')
306 extra_defines += '-DENABLE_TFLITE_BACKBONE=1'
309 if get_option('enable-tflite-interpreter')
310 extra_defines += '-DENABLE_TFLITE_INTERPRETER=1'
313 opencv_dep = dummy_dep
315 if get_option('platform') != 'android'
316 opencv_dep = dependency('opencv', required: false)
317 if not opencv_dep.found()
318 opencv_dep = dependency('opencv4', required: false)
319 if not opencv_dep.found()
320 opencv_dep = dependency('opencv3', required: false)
323 if opencv_dep.found()
324 extra_defines += '-DENABLE_DATA_AUGMENTATION_OPENCV=1'
327 flatc_prog = find_program('flatc', required: false)
330 configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
331 install_dir: nntrainer_libdir / 'pkgconfig',
332 configuration: nntrainer_conf
337 input: 'nntrainer.ini.in',
338 output: 'nntrainer.ini',
339 install_dir: nntrainer_confdir,
340 configuration: nntrainer_conf
342 nntrainer_conf_abs_path = get_option('prefix') / nntrainer_confdir / 'nntrainer.ini'
343 message('NNTRAINER_CONF_PATH=@0@'.format(nntrainer_conf_abs_path))
345 if get_option('platform') != 'android'
346 extra_defines += '-DNNTRAINER_CONF_PATH="@0@"'.format(nntrainer_conf_abs_path)
349 # if get_option('enable-fp16')
350 # extra_defines += '-march=armv8.2-a+fp16 -mfpu=neon-fp16 -mfloat-abi=softfp'
353 message('extra defines are:' + ' '.join(extra_defines))
354 foreach defs: extra_defines
355 add_project_arguments(defs, language: ['c', 'cpp'])
366 if get_option('enable-test')
367 if get_option('platform') == 'android'
368 warning('test is not supported in android build, test skipped')
373 error('test enabled but gtest not found')
378 if get_option('enable-app')
379 if get_option('platform') == 'android'
380 warning('android app is not supported for now, building app skipped')
382 # this is needed for reinforcement application. We can move this to reinforecement app dependency
383 # jsoncpp_dep = dependency('jsoncpp') # jsoncpp
384 # libcurl_dep = dependency('libcurl')
385 # if not tflite_dep.found()
386 # error('Tensorflow-Lite dependency not found')
388 subdir('Applications')
392 # if get_option('platform') != 'android'
393 # nnstreamer_dep = dependency('nnstreamer')
394 # message('building nnstreamer')
395 # subdir('nnstreamer')
397 # warning('android nnstreamer-filter and nnstreamer-trainer are not yet supported, building them is skipped')
400 if get_option('platform') == 'android'
404 if get_option('platform') != 'none'
405 message('building for ' + get_option('platform'))