1 project('nntrainer', 'c', 'cpp',
3 license: ['apache-2.0'],
4 meson_version: '>=0.50.0',
13 add_project_arguments('-DMIN_CPP_VERSION=201703L', language:['c','cpp'])
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 nntrainer_libdir = nntrainer_prefix / get_option('libdir')
72 nntrainer_bindir = nntrainer_prefix / get_option('bindir')
73 nntrainer_includedir = nntrainer_prefix / get_option('includedir')
74 nntrainer_confdir = get_option('sysconfdir')
75 application_install_dir = nntrainer_bindir / 'applications'
78 nntrainer_resdir = meson.build_root() / 'res'
79 run_command('mkdir', '-p', nntrainer_resdir)
81 if get_option('install-app')
82 # add a script to install resources from installs to application_install_dir
83 meson.add_install_script(
84 'sh', '-c', 'cp -r @0@ ${DESTDIR}@1@'.format(nntrainer_resdir, application_install_dir)
88 # Set default configuration
89 nntrainer_conf = configuration_data()
90 nntrainer_conf.set('VERSION', meson.project_version())
91 nntrainer_conf.set('PREFIX', nntrainer_prefix)
92 nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
93 nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
94 nntrainer_conf.set('PLUGIN_INSTALL_PREFIX', nntrainer_libdir / 'nntrainer')
95 nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir)
96 nntrainer_conf.set('CAPI_ML_COMMON_DEP', get_option('capi-ml-common-actual'))
98 dummy_dep = dependency('', required: false)
102 if get_option('enable-cublas')
103 add_project_arguments('-DUSE_CUBLAS=1', language:['c','cpp'])
106 if get_option('enable-blas')
107 add_project_arguments('-DUSE_BLAS=1', language:['c','cpp'])
108 if get_option('platform') == 'tizen' or get_option('platform') == 'yocto'
109 blas_dep = dependency('openblas')
111 blas_dep = dependency('blas-openblas', required:false)
113 if not blas_dep.found()
114 blas_dep = dependency('openblas')
119 if get_option('enable-profile')
120 add_project_arguments('-DPROFILE=1', language:['c', 'cpp'])
123 if get_option('enable-debug')
124 add_project_arguments('-DDEBUG=1', language:['c', 'cpp'])
127 if get_option('use_gym')
128 add_project_arguments('-DUSE_GYM=1', language:['c','cpp'])
131 if get_option('enable-logging')
132 add_project_arguments('-D__LOGGING__=1', language:['c','cpp'])
135 if get_option('enable-test')
136 add_project_arguments('-DENABLE_TEST=1', language:['c','cpp'])
139 if get_option('reduce-tolerance')
140 add_project_arguments('-DREDUCE_TOLERANCE=1', language:['c', 'cpp'])
143 libm_dep = cxx.find_library('m') # cmath library
144 libdl_dep = cxx.find_library('dl') # DL library
145 thread_dep = dependency('threads') # pthread for tensorflow-lite
147 iniparser_dep = dependency('iniparser', required : false, version : '>=4.1') # iniparser
148 if not iniparser_dep.found()
149 message('falling back to find libiniparser library and header files')
150 libiniparser_dep = cxx.find_library('iniparser')
151 sysroot = run_command(
152 cxx.cmd_array() + ['-print-sysroot']
153 ).stdout().split('\n')[0]
155 if sysroot.startswith('/')
156 sysroot_inc_cflags_template = '-I@0@/usr/include@1@'
157 sysroot_inc = sysroot_inc_cflags_template.format(sysroot, '')
158 add_project_arguments(sysroot_inc, language: ['c', 'cpp'])
159 sysroot_inc_cflags_iniparser = sysroot_inc_cflags_template.format(sysroot,
162 sysroot_inc_cflags_iniparser = '-I/usr/include/iniparser'
165 if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
166 args : sysroot_inc_cflags_iniparser)
167 iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
168 compile_args : sysroot_inc_cflags_iniparser)
170 error('Failed to resolve dependency on iniparser')
174 nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required:false)
175 if nnstreamer_capi_dep.found()
176 add_project_arguments('-DNNSTREAMER_AVAILABLE=1', language:['c','cpp'])
177 # accessing this variable when dep_.not_found() remains hard error on purpose
178 supported_nnstreamer_capi = nnstreamer_capi_dep.version().version_compare('>=1.7.0')
179 if not supported_nnstreamer_capi
180 add_project_arguments('-DUNSUPPORTED_NNSTREAMER=1', language:['c','cpp'])
181 warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
185 ml_api_common_dep = dependency(get_option('capi-ml-common-actual'), required: true)
187 if get_option('enable-nnstreamer-backbone')
188 add_project_arguments('-DENABLE_NNSTREAMER_BACKBONE=1', language:['c','cpp'])
191 tflite_dep = dependency('tensorflow2-lite', required: false)
192 if get_option('enable-tflite-backbone')
193 add_project_arguments('-DENABLE_TFLITE_BACKBONE=1', language:['c','cpp'])
196 gtest_dep = dependency('gtest', static: true, main: false, required: false)
197 gtest_main_dep = dependency('gtest', static: true, main: true, required: false)
199 opencv_dep = dependency('opencv', required: false)
200 if not opencv_dep.found()
201 opencv_dep = dependency('opencv4', required: false)
202 if not opencv_dep.found()
203 opencv_dep = dependency('opencv3', required: false)
206 if opencv_dep.found()
207 add_project_arguments('-DENABLE_DATA_AUGMENTATION_OPENCV=1', language:['c','cpp'])
209 flatc_prog = find_program('flatc', required: false)
212 configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
213 install_dir: nntrainer_libdir / 'pkgconfig',
214 configuration: nntrainer_conf
219 input: 'nntrainer.ini.in',
220 output: 'nntrainer.ini',
221 install_dir: nntrainer_confdir,
222 configuration: nntrainer_conf
224 nntrainer_conf_abs_path = get_option('prefix') / nntrainer_confdir / 'nntrainer.ini'
225 message('NNTRAINER_CONF_PATH=@0@'.format(nntrainer_conf_abs_path))
227 add_project_arguments(
228 '-DNNTRAINER_CONF_PATH="@0@"'.format(nntrainer_conf_abs_path),
229 language: ['c', 'cpp']
238 if get_option('enable-test')
242 error('test enabled but gtest not found')
246 if get_option('enable-app')
247 jsoncpp_dep = dependency('jsoncpp') # jsoncpp
248 libcurl_dep = dependency('libcurl')
249 if not tflite_dep.found()
250 error('Tensorflow-Lite dependency not found')
252 subdir('Applications')
255 if get_option('enable-nnstreamer-tensor-filter')
256 nnstreamer_dep = dependency('nnstreamer', required: true)
257 subdir('nnstreamer/tensor_filter')
260 if get_option('enable-android')
262 ndk_build = find_program('ndk-build', required : true)
263 jni_root = meson.current_source_dir() / 'jni'
264 jni_build_root = meson.current_build_dir() / 'jni'
267 'NDK_PROJECT_PATH': jni_root,
268 'APP_BUILD_SCRIPT': jni_root / 'Android.mk',
269 'NDK_APPLICATION_MK': jni_root / 'Application.mk',
270 'NDK_LIBS_OUT': jni_build_root / 'libs',
271 'NDK_OUT': jni_build_root / 'objs',
272 'ENABLE_PROFILE': get_option('enable-profile') ? 1 : 0,
273 'ENABLE_BLAS': get_option('enable-blas') ? 1 : 0,
276 num_threads = run_command('grep', '-c', '^processor', '/proc/cpuinfo').stdout().strip()
277 message('num processor are: ' + num_threads)
279 thread_opt_flag = '-j' + num_threads
281 ndk_additional_flags = [thread_opt_flag]
283 ndk_build_command = [ndk_build]
284 foreach key, val : ndk_args
285 ndk_build_command += '@0@=@1@'.format(key, val)
287 ndk_build_command += ndk_additional_flags
289 android_build_target = custom_target('android',
291 build_by_default: true,
292 command: ndk_build_command