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'])
22 if get_option('enable-tizen-feature-check')
23 add_project_arguments('-D__FEATURE_CHECK_SUPPORT__', language: ['c', 'cpp'])
31 '-Wformat-nonliteral',
39 '-Wdefaulted-function-deleted',
44 '-Wmissing-declarations',
45 '-Wmissing-include-dirs',
46 '-Wmissing-prototypes',
49 '-Wold-style-definition',
50 '-Wdeclaration-after-statement',
54 foreach extra_arg : warning_flags
55 if cc.has_argument (extra_arg)
56 add_project_arguments([extra_arg], language: 'c')
58 if cxx.has_argument (extra_arg)
59 add_project_arguments([extra_arg], language: 'cpp')
63 foreach extra_arg : warning_c_flags
64 if cc.has_argument (extra_arg)
65 add_project_arguments([extra_arg], language: 'c')
70 nntrainer_prefix = get_option('prefix')
71 if get_option('platform') != 'android'
72 nntrainer_libdir = nntrainer_prefix / get_option('libdir')
73 nntrainer_bindir = nntrainer_prefix / get_option('bindir')
74 nntrainer_includedir = nntrainer_prefix / get_option('includedir') / 'nntrainer'
75 nntrainer_confdir = get_option('sysconfdir')
76 application_install_dir = nntrainer_bindir / 'applications'
78 nntrainer_prefix = meson.build_root() / 'android_build_result'
79 # @todo arch has to be option
80 nntrainer_libdir = nntrainer_prefix / 'lib' / 'arm64-v8a'
81 nntrainer_includedir = nntrainer_prefix / 'include' / 'nntrainer'
82 nntrainer_bindir = nntrainer_prefix / 'bin'
83 nntrainer_confdir = nntrainer_prefix / 'conf'
84 application_install_dir = nntrainer_prefix / 'examples'
88 nntrainer_resdir = meson.build_root() / 'res'
89 run_command('mkdir', '-p', nntrainer_resdir)
91 if get_option('install-app')
92 # add a script to install resources from installs to application_install_dir
93 meson.add_install_script(
94 'sh', '-c', 'cp -r @0@ ${DESTDIR}@1@'.format(nntrainer_resdir, application_install_dir)
98 # Set default configuration
99 nntrainer_conf = configuration_data()
100 nntrainer_conf.set('VERSION', meson.project_version())
101 nntrainer_conf.set('PREFIX', nntrainer_prefix)
102 nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
103 nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
104 nntrainer_conf.set('PLUGIN_INSTALL_PREFIX', nntrainer_libdir / 'nntrainer')
105 nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir / '..')
106 nntrainer_conf.set('CAPI_ML_COMMON_DEP', get_option('capi-ml-common-actual'))
108 dummy_dep = dependency('', required: false)
109 found_dummy_dep = declare_dependency() # dummy dep to use if found
113 if get_option('enable-cublas')
114 extra_defines += '-DUSE_CUBLAS=1'
117 if get_option('enable-blas')
118 extra_defines += '-DUSE_BLAS=1'
119 if get_option('platform') == 'tizen' or get_option('platform') == 'yocto'
120 blas_dep = dependency('openblas')
121 elif get_option('platform') == 'android'
122 message('preparing blas')
123 run_command(meson.source_root() / 'jni' / 'prepare_openblas.sh', meson.build_root(), check: true)
124 blas_dep = found_dummy_dep
125 blas_root = meson.build_root() / 'openblas'
127 blas_dep = dependency('blas-openblas', required:false)
129 if not blas_dep.found()
130 blas_dep = dependency('openblas')
135 openmp_dep = dummy_dep
136 if get_option('enable-openmp')
137 openmp_dep = dependency('openmp')
140 if get_option('enable-profile')
141 extra_defines += '-DPROFILE=1'
144 if get_option('enable-debug')
145 extra_defines += '-DDEBUG=1'
148 if get_option('use_gym')
149 extra_defines += '-DUSE_GYM=1'
152 if get_option('enable-logging')
153 extra_defines += '-D__LOGGING__=1'
156 if get_option('enable-test') and get_option('platform') != 'android'
157 extra_defines += '-DENABLE_TEST=1'
160 if get_option('reduce-tolerance')
161 extra_defines += '-DREDUCE_TOLERANCE=1'
164 libm_dep = cxx.find_library('m') # cmath library
165 libdl_dep = cxx.find_library('dl') # DL library
166 thread_dep = dependency('threads') # pthread for tensorflow-lite
168 iniparser_dep = dependency('iniparser', required : false, version : '>=4.1') # iniparser
169 if get_option('platform') == 'android'
170 message('preparing iniparser')
171 run_command(meson.source_root() / 'jni' / 'prepare_iniparser.sh', meson.build_root(), check: true)
172 iniparser_root = meson.build_root() / 'iniparser'
173 iniparser_dep = found_dummy_dep
176 if not iniparser_dep.found()
177 message('falling back to find libiniparser library and header files')
178 libiniparser_dep = cxx.find_library('iniparser')
179 sysroot = run_command(
180 cxx.cmd_array() + ['-print-sysroot']
181 ).stdout().split('\n')[0]
183 if sysroot.startswith('/')
184 sysroot_inc_cflags_template = '-I@0@/usr/include@1@'
185 sysroot_inc = sysroot_inc_cflags_template.format(sysroot, '')
186 add_project_arguments(sysroot_inc, language: ['c', 'cpp'])
187 sysroot_inc_cflags_iniparser = sysroot_inc_cflags_template.format(sysroot,
190 sysroot_inc_cflags_iniparser = '-I/usr/include/iniparser'
193 if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
194 args : sysroot_inc_cflags_iniparser)
195 iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
196 compile_args : sysroot_inc_cflags_iniparser)
198 error('Failed to resolve dependency on iniparser')
202 nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required:false)
203 if nnstreamer_capi_dep.found()
204 extra_defines += '-DNNSTREAMER_AVAILABLE=1'
205 # accessing this variable when dep_.not_found() remains hard error on purpose
206 supported_nnstreamer_capi = nnstreamer_capi_dep.version().version_compare('>=1.7.0')
207 if not supported_nnstreamer_capi
208 extra_defines += '-DUNSUPPORTED_NNSTREAMER=1'
209 warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
213 ml_api_common_dep = dummy_dep
215 if get_option('platform') != 'android'
216 ml_api_common_dep = dependency(get_option('capi-ml-common-actual'), required: true)
218 message('preparing ml api')
219 run_command(meson.source_root() / 'jni' / 'prepare_ml-api.sh', meson.build_root() / 'ml-api-inference', check: true)
220 ml_api_common_root = meson.build_root() / 'ml-api-inference'
221 ml_api_common_dep = found_dummy_dep
224 if get_option('enable-nnstreamer-backbone') and get_option('platform') != 'android'
225 extra_defines += '-DENABLE_NNSTREAMER_BACKBONE=1'
228 tflite_dep = dummy_dep
230 if get_option('platform') != 'android'
231 tflite_dep = dependency('tensorflow2-lite', required: false)
233 message('preparing tflite')
234 run_command(meson.source_root() / 'jni' / 'prepare_tflite.sh', '2.3.0', meson.build_root(), check: true)
235 tflite_root = meson.build_root() / 'tensorflow-2.3.0' / 'tensorflow-lite'
236 tflite_dep = found_dummy_dep
239 if get_option('enable-tflite-backbone')
240 extra_defines += '-DENABLE_TFLITE_BACKBONE=1'
243 if get_option('enable-tflite-interpreter')
244 extra_defines += '-DENABLE_TFLITE_INTERPRETER=1'
247 gtest_dep = dependency('gtest', static: true, main: false, required: false)
248 gtest_main_dep = dependency('gtest', static: true, main: true, required: false)
250 opencv_dep = dummy_dep
252 if get_option('platform') != 'android'
253 opencv_dep = dependency('opencv', required: false)
254 if not opencv_dep.found()
255 opencv_dep = dependency('opencv4', required: false)
256 if not opencv_dep.found()
257 opencv_dep = dependency('opencv3', required: false)
260 if opencv_dep.found()
261 extra_defines += '-DENABLE_DATA_AUGMENTATION_OPENCV=1'
264 flatc_prog = find_program('flatc', required: false)
267 configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
268 install_dir: nntrainer_libdir / 'pkgconfig',
269 configuration: nntrainer_conf
274 input: 'nntrainer.ini.in',
275 output: 'nntrainer.ini',
276 install_dir: nntrainer_confdir,
277 configuration: nntrainer_conf
279 nntrainer_conf_abs_path = get_option('prefix') / nntrainer_confdir / 'nntrainer.ini'
280 message('NNTRAINER_CONF_PATH=@0@'.format(nntrainer_conf_abs_path))
282 if get_option('platform') != 'android'
283 extra_defines += '-DNNTRAINER_CONF_PATH="@0@"'.format(nntrainer_conf_abs_path)
286 message('extra defines are:' + ' '.join(extra_defines))
287 foreach defs: extra_defines
288 add_project_arguments(defs, language: ['c', 'cpp'])
297 if get_option('enable-test')
298 if get_option('platform') == 'android'
299 warning('test is not supported in android build, test skipped')
304 error('test enabled but gtest not found')
309 if get_option('enable-app')
310 if get_option('platform') == 'android'
311 warning('android app is not supported for now, building app skipped')
313 # this is needed for reinforcement application. We can move this to reinforecement app dependency
314 jsoncpp_dep = dependency('jsoncpp') # jsoncpp
315 libcurl_dep = dependency('libcurl')
316 if not tflite_dep.found()
317 error('Tensorflow-Lite dependency not found')
319 subdir('Applications')
323 if get_option('enable-nnstreamer-tensor-filter')
324 if get_option('platform') == 'android'
325 warning('android nnstreamer-filter is not yet supported, building nnstreamer-filter skipped')
327 nnstreamer_dep = dependency('nnstreamer', required: true)
328 subdir('nnstreamer/tensor_filter')
332 if get_option('platform') == 'android'
336 if get_option('platform') != 'none'
337 message('building for ' + get_option('platform'))