1 project('nntrainer', 'c', 'cpp',
3 license: ['apache-2.0'],
4 meson_version: '>=0.50.0',
13 add_project_arguments('-DMIN_CPP_VERSION=201402', language:['c','cpp'])
15 cc = meson.get_compiler('c')
16 cxx = meson.get_compiler('cpp')
19 if get_option('enable-tizen')
20 # Pass __TIZEN__ to the compiler
21 build_platform = 'tizen'
22 add_project_arguments('-D__TIZEN__=1', 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',
46 '-Wmissing-declarations',
47 '-Wmissing-include-dirs',
48 '-Wmissing-prototypes',
51 '-Wold-style-definition',
52 '-Wdeclaration-after-statement',
56 foreach extra_arg : warning_flags
57 if cc.has_argument (extra_arg)
58 add_project_arguments([extra_arg], language: 'c')
60 if cxx.has_argument (extra_arg)
61 add_project_arguments([extra_arg], language: 'cpp')
65 foreach extra_arg : warning_c_flags
66 if cc.has_argument (extra_arg)
67 add_project_arguments([extra_arg], language: 'c')
72 nntrainer_prefix = get_option('prefix')
73 nntrainer_libdir = nntrainer_prefix / get_option('libdir')
74 nntrainer_bindir = nntrainer_prefix / get_option('bindir')
75 nntrainer_includedir = nntrainer_prefix / get_option('includedir')
76 nntrainer_confdir = get_option('sysconfdir')
77 application_install_dir = nntrainer_bindir / 'applications'
80 nntrainer_resdir = meson.build_root() / 'res'
81 run_command('mkdir', '-p', nntrainer_resdir)
83 if get_option('install-app')
84 # add a script to install resources from installs to application_install_dir
85 meson.add_install_script(
86 'sh', '-c', 'cp -r @0@ ${DESTDIR}@1@'.format(nntrainer_resdir, application_install_dir)
90 # Set default configuration
91 nntrainer_conf = configuration_data()
92 nntrainer_conf.set('VERSION', meson.project_version())
93 nntrainer_conf.set('PREFIX', nntrainer_prefix)
94 nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
95 nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
96 nntrainer_conf.set('PLUGIN_INSTALL_PREFIX', nntrainer_libdir / 'nntrainer')
97 nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir)
99 dummy_dep = dependency('', required: false)
103 if get_option('enable-cublas')
104 add_project_arguments('-DUSE_CUBLAS=1', language:['c','cpp'])
107 if get_option('enable-blas')
108 add_project_arguments('-DUSE_BLAS=1', language:['c','cpp'])
109 if build_platform == 'tizen'
110 blas_dep = dependency('openblas')
112 blas_dep = dependency('blas-openblas', required:false)
114 if not blas_dep.found()
115 blas_dep = dependency('openblas')
120 if get_option('enable-profile')
121 add_project_arguments('-DPROFILE=1', language:['c', 'cpp'])
124 if get_option('use_gym')
125 add_project_arguments('-DUSE_GYM=1', language:['c','cpp'])
128 if get_option('enable-logging')
129 add_project_arguments('-D__LOGGING__=1', language:['c','cpp'])
132 if get_option('enable-test')
133 add_project_arguments('-DENABLE_TEST=1', language:['c','cpp'])
136 libm_dep = cxx.find_library('m') # cmath library
137 libdl_dep = cxx.find_library('dl') # DL library
138 thread_dep = dependency('threads') # pthread for tensorflow-lite
139 iniparser_dep = dependency('iniparser', required : false, version : '>=4.1') # iniparser
140 if not iniparser_dep.found()
141 message('falling back to find libiniparser library and header files')
142 libiniparser_dep = cxx.find_library('iniparser')
143 if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
144 args : '-I/usr/include/iniparser')
145 iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
146 compile_args : '-I/usr/include/iniparser')
150 nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required:false)
151 if nnstreamer_capi_dep.found()
152 add_project_arguments('-DNNSTREAMER_AVAILABLE=1', language:['c','cpp'])
153 # accessing this variable when dep_.not_found() remains hard error on purpose
154 supported_nnstreamer_capi = nnstreamer_capi_dep.version().version_compare('>=1.7.0')
155 if not supported_nnstreamer_capi
156 add_project_arguments('-DUNSUPPORTED_NNSTREAMER=1', language:['c','cpp'])
157 warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
161 ml_api_common_dep = dependency(get_option('capi-ml-common-actual'), required:true)
163 if get_option('enable-nnstreamer-backbone')
164 add_project_arguments('-DENABLE_NNSTREAMER_BACKBONE=1', language:['c','cpp'])
167 tflite_dep = dependency('tensorflow-lite', required: false)
168 if get_option('enable-tflite-backbone')
169 add_project_arguments('-DENABLE_TFLITE_BACKBONE=1', language:['c','cpp'])
172 gtest_dep = dependency('gtest', static: true, main: false, required: false)
173 gtest_main_dep = dependency('gtest', static: true, main: true, required: false)
175 opencv_dep = dependency('opencv', required: false)
176 if not opencv_dep.found()
177 opencv_dep = dependency('opencv4', required: false)
178 if not opencv_dep.found()
179 opencv_dep = dependency('opencv3', required: false)
182 if opencv_dep.found()
183 add_project_arguments('-DENABLE_DATA_AUGMENTATION_OPENCV=1', language:['c','cpp'])
187 configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
188 install_dir: nntrainer_libdir / 'pkgconfig',
189 configuration: nntrainer_conf
194 input: 'nntrainer.ini.in',
195 output: 'nntrainer.ini',
196 install_dir: nntrainer_confdir,
197 configuration: nntrainer_conf
199 nntrainer_conf_abs_path = get_option('prefix') / nntrainer_confdir / 'nntrainer.ini'
200 message('NNTRAINER_CONF_PATH=@0@'.format(nntrainer_conf_abs_path))
202 add_project_arguments(
203 '-DNNTRAINER_CONF_PATH="@0@"'.format(nntrainer_conf_abs_path),
204 language: ['c', 'cpp']
213 if get_option('enable-test')
217 error('test enabled but gtest not found')
221 if get_option('enable-app')
222 jsoncpp_dep = dependency('jsoncpp') # jsoncpp
223 libcurl_dep = dependency('libcurl')
224 if not tflite_dep.found()
225 error('Tensorflow-Lite dependency not found')
227 subdir('Applications')
230 if get_option('enable-nnstreamer-tensor-filter')
231 nnstreamer_dep = dependency('nnstreamer', required: true)
232 subdir('nnstreamer/tensor_filter')
235 if get_option('enable-android')
237 ndk_build = find_program('ndk-build', required : true)
238 jni_root = meson.current_source_dir() / 'jni'
239 jni_build_root = meson.current_build_dir() / 'jni'
242 'NDK_PROJECT_PATH': jni_root,
243 'APP_BUILD_SCRIPT': jni_root / 'Android.mk',
244 'NDK_APPLICATION_MK': jni_root / 'Application.mk',
245 'NDK_LIBS_OUT': jni_build_root / 'libs',
246 'NDK_OUT': jni_build_root / 'objs',
247 'ENABLE_PROFILE': get_option('enable-profile') ? 1 : 0,
248 'ENABLE_BLAS': get_option('enable-blas') ? 1 : 0,
251 num_threads = run_command('grep', '-c', '^processor', '/proc/cpuinfo').stdout().strip()
252 message('num processor are: ' + num_threads)
254 thread_opt_flag = '-j' + num_threads
256 ndk_additional_flags = [thread_opt_flag]
258 ndk_build_command = [ndk_build]
259 foreach key, val : ndk_args
260 ndk_build_command += '@0@=@1@'.format(key, val)
262 ndk_build_command += ndk_additional_flags
264 android_build_target = custom_target('android',
266 build_by_default: true,
267 command: ndk_build_command