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',
57 foreach extra_arg : warning_flags
58 if cc.has_argument (extra_arg)
59 add_project_arguments([extra_arg], language: 'c')
61 if cxx.has_argument (extra_arg)
62 add_project_arguments([extra_arg], language: 'cpp')
66 foreach extra_arg : warning_c_flags
67 if cc.has_argument (extra_arg)
68 add_project_arguments([extra_arg], language: 'c')
73 nntrainer_prefix = get_option('prefix')
74 if get_option('platform') != 'android'
75 nntrainer_libdir = nntrainer_prefix / get_option('libdir')
76 nntrainer_bindir = nntrainer_prefix / get_option('bindir')
77 nntrainer_includedir = nntrainer_prefix / get_option('includedir') / 'nntrainer'
78 nntrainer_confdir = get_option('sysconfdir')
79 application_install_dir = nntrainer_bindir / 'applications'
81 nntrainer_prefix = meson.build_root() / 'android_build_result'
82 # @todo arch has to be option
83 nntrainer_libdir = nntrainer_prefix / 'lib' / 'arm64-v8a'
84 nntrainer_includedir = nntrainer_prefix / 'include' / 'nntrainer'
85 nntrainer_bindir = nntrainer_prefix / 'bin'
86 nntrainer_confdir = nntrainer_prefix / 'conf'
87 application_install_dir = nntrainer_prefix / 'examples'
91 nntrainer_resdir = meson.build_root() / 'res'
92 run_command('mkdir', '-p', nntrainer_resdir)
94 if get_option('install-app')
95 # add a script to install resources from installs to application_install_dir
96 meson.add_install_script(
97 'sh', '-c', 'cp -r @0@ ${DESTDIR}@1@'.format(nntrainer_resdir, application_install_dir)
101 # Set default configuration
102 nntrainer_conf = configuration_data()
103 nntrainer_conf.set('VERSION', meson.project_version())
104 nntrainer_conf.set('PREFIX', nntrainer_prefix)
105 nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
106 nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
107 nntrainer_conf.set('PLUGIN_INSTALL_PREFIX', nntrainer_libdir / 'nntrainer')
108 nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir / '..')
109 nntrainer_conf.set('CAPI_ML_COMMON_DEP', get_option('capi-ml-common-actual'))
111 dummy_dep = dependency('', required: false)
112 found_dummy_dep = declare_dependency() # dummy dep to use if found
116 if get_option('enable-cublas')
117 extra_defines += '-DUSE_CUBLAS=1'
120 if get_option('enable-blas')
121 extra_defines += '-DUSE_BLAS=1'
122 if get_option('platform') == 'tizen' or get_option('platform') == 'yocto'
123 blas_dep = dependency('openblas')
124 elif get_option('platform') == 'android'
125 message('preparing blas')
126 run_command(meson.source_root() / 'jni' / 'prepare_openblas.sh', meson.build_root(), check: true)
127 blas_dep = found_dummy_dep
128 blas_root = meson.build_root() / 'openblas'
130 blas_dep = dependency('blas-openblas', required:false)
132 if not blas_dep.found()
133 blas_dep = dependency('openblas')
138 openmp_dep = dummy_dep
139 if get_option('enable-openmp')
140 openmp_dep = dependency('openmp')
143 if get_option('enable-profile')
144 extra_defines += '-DPROFILE=1'
147 if get_option('enable-debug')
148 extra_defines += '-DDEBUG=1'
151 if get_option('use_gym')
152 extra_defines += '-DUSE_GYM=1'
155 if get_option('enable-logging')
156 extra_defines += '-D__LOGGING__=1'
159 if get_option('enable-test') # and get_option('platform') != 'android'
160 extra_defines += '-DENABLE_TEST=1'
163 if get_option('reduce-tolerance')
164 extra_defines += '-DREDUCE_TOLERANCE=1'
167 libm_dep = cxx.find_library('m') # cmath library
168 libdl_dep = cxx.find_library('dl') # DL library
169 thread_dep = dependency('threads') # pthread for tensorflow-lite
171 iniparser_dep = dependency('iniparser', required : false, version : '>=4.1') # iniparser
172 if get_option('platform') == 'android'
173 message('preparing iniparser')
174 run_command(meson.source_root() / 'jni' / 'prepare_iniparser.sh', meson.build_root(), check: true)
175 iniparser_root = meson.build_root() / 'iniparser'
176 iniparser_dep = found_dummy_dep
179 if not iniparser_dep.found()
180 message('falling back to find libiniparser library and header files')
181 libiniparser_dep = cxx.find_library('iniparser')
182 sysroot = run_command(
183 cxx.cmd_array() + ['-print-sysroot']
184 ).stdout().split('\n')[0]
186 if sysroot.startswith('/')
187 sysroot_inc_cflags_template = '-I@0@/usr/include@1@'
188 sysroot_inc = sysroot_inc_cflags_template.format(sysroot, '')
189 add_project_arguments(sysroot_inc, language: ['c', 'cpp'])
190 sysroot_inc_cflags_iniparser = sysroot_inc_cflags_template.format(sysroot,
193 sysroot_inc_cflags_iniparser = '-I/usr/include/iniparser'
196 if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
197 args : sysroot_inc_cflags_iniparser)
198 iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
199 compile_args : sysroot_inc_cflags_iniparser)
201 error('Failed to resolve dependency on iniparser')
205 nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required:false)
206 if nnstreamer_capi_dep.found()
207 extra_defines += '-DNNSTREAMER_AVAILABLE=1'
208 # accessing this variable when dep_.not_found() remains hard error on purpose
209 supported_nnstreamer_capi = nnstreamer_capi_dep.version().version_compare('>=1.7.0')
210 if not supported_nnstreamer_capi
211 extra_defines += '-DUNSUPPORTED_NNSTREAMER=1'
212 warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
216 ml_api_common_dep = dummy_dep
218 if get_option('platform') != 'android'
219 ml_api_common_dep = dependency(get_option('capi-ml-common-actual'), required: true)
221 message('preparing ml api')
222 run_command(meson.source_root() / 'jni' / 'prepare_ml-api.sh', meson.build_root() / 'ml-api-inference', check: true)
223 ml_api_common_root = meson.build_root() / 'ml-api-inference'
224 ml_api_inc = ml_api_common_root / 'include'
225 meson.add_install_script(
226 'sh', '-c', 'cp @0@ ${DESTDIR}@1@'.format(ml_api_inc / 'ml-api-common.h', nntrainer_includedir)
228 meson.add_install_script(
229 'sh', '-c', 'cp @0@ ${DESTDIR}@1@'.format(ml_api_inc / 'tizen_error.h', nntrainer_includedir)
231 ml_api_common_dep = found_dummy_dep
234 if get_option('enable-nnstreamer-backbone') and get_option('platform') != 'android'
235 extra_defines += '-DENABLE_NNSTREAMER_BACKBONE=1'
238 tflite_dep = dummy_dep
240 if get_option('platform') != 'android'
241 tflite_dep = dependency('tensorflow2-lite', required: false)
243 if get_option('enable-tflite-backbone') or get_option('enable-tflite-interpreter')
244 message('preparing tflite, because either tflite backbone or interpreter is enabled')
245 run_command(meson.source_root() / 'jni' / 'prepare_tflite.sh', '2.3.0', meson.build_root(), check: true)
246 tflite_root = meson.build_root() / 'tensorflow-2.3.0' / 'tensorflow-lite'
247 tflite_dep = found_dummy_dep
251 if get_option('enable-tflite-backbone')
252 extra_defines += '-DENABLE_TFLITE_BACKBONE=1'
255 if get_option('enable-tflite-interpreter')
256 extra_defines += '-DENABLE_TFLITE_INTERPRETER=1'
259 gtest_dep = dependency('gtest', static: true, main: false, required: false)
260 gtest_main_dep = dependency('gtest', static: true, main: true, required: false)
262 opencv_dep = dummy_dep
264 if get_option('platform') != 'android'
265 opencv_dep = dependency('opencv', required: false)
266 if not opencv_dep.found()
267 opencv_dep = dependency('opencv4', required: false)
268 if not opencv_dep.found()
269 opencv_dep = dependency('opencv3', required: false)
272 if opencv_dep.found()
273 extra_defines += '-DENABLE_DATA_AUGMENTATION_OPENCV=1'
276 flatc_prog = find_program('flatc', required: false)
279 configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
280 install_dir: nntrainer_libdir / 'pkgconfig',
281 configuration: nntrainer_conf
286 input: 'nntrainer.ini.in',
287 output: 'nntrainer.ini',
288 install_dir: nntrainer_confdir,
289 configuration: nntrainer_conf
291 nntrainer_conf_abs_path = get_option('prefix') / nntrainer_confdir / 'nntrainer.ini'
292 message('NNTRAINER_CONF_PATH=@0@'.format(nntrainer_conf_abs_path))
294 if get_option('platform') != 'android'
295 extra_defines += '-DNNTRAINER_CONF_PATH="@0@"'.format(nntrainer_conf_abs_path)
298 message('extra defines are:' + ' '.join(extra_defines))
299 foreach defs: extra_defines
300 add_project_arguments(defs, language: ['c', 'cpp'])
309 if get_option('enable-test')
310 if get_option('platform') == 'android'
311 warning('test is not supported in android build, test skipped')
316 error('test enabled but gtest not found')
321 if get_option('enable-app')
322 if get_option('platform') == 'android'
323 warning('android app is not supported for now, building app skipped')
325 # this is needed for reinforcement application. We can move this to reinforecement app dependency
326 jsoncpp_dep = dependency('jsoncpp') # jsoncpp
327 libcurl_dep = dependency('libcurl')
328 if not tflite_dep.found()
329 error('Tensorflow-Lite dependency not found')
331 subdir('Applications')
335 if get_option('enable-nnstreamer-tensor-filter')
336 if get_option('platform') == 'android'
337 warning('android nnstreamer-filter is not yet supported, building nnstreamer-filter skipped')
339 nnstreamer_dep = dependency('nnstreamer', required: true)
340 subdir('nnstreamer/tensor_filter')
344 if get_option('platform') == 'android'
348 if get_option('platform') != 'none'
349 message('building for ' + get_option('platform'))