[CAPI] Deprecate old dataset apis
[platform/core/ml/nntrainer.git] / meson.build
1 project('nntrainer', 'c', 'cpp',
2   version: '0.0.1',
3   license: ['apache-2.0'],
4   meson_version: '>=0.50.0',
5   default_options: [
6     'werror=true',
7     'warning_level=1',
8     'c_std=gnu89',
9     'cpp_std=c++17',
10     'buildtype=release'
11   ]
12 )
13 add_project_arguments('-DMIN_CPP_VERSION=201703L', language:['c','cpp'])
14
15 cc = meson.get_compiler('c')
16 cxx = meson.get_compiler('cpp')
17 build_platform = ''
18
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'])
23
24   if get_option('enable-tizen-feature-check')
25     add_project_arguments('-D__FEATURE_CHECK_SUPPORT__', language: ['c', 'cpp'])
26   endif
27 endif
28
29 warning_flags = [
30   '-Wredundant-decls',
31   '-Wwrite-strings',
32   '-Wformat',
33   '-Wformat-nonliteral',
34   '-Wformat-security',
35   '-Winit-self',
36   '-Waddress',
37   '-Wno-multichar',
38   '-Wvla',
39   '-Wpointer-arith',
40   '-Wno-error=varargs',
41   '-Wno-error=deprecated-declarations',
42   '-Wdefaulted-function-deleted',
43   '-ftree-vectorize'
44 ]
45
46 warning_c_flags = [
47   '-Wmissing-declarations',
48   '-Wmissing-include-dirs',
49   '-Wmissing-prototypes',
50   '-Wnested-externs',
51   '-Waggregate-return',
52   '-Wold-style-definition',
53   '-Wdeclaration-after-statement',
54   '-Wno-error=varargs'
55 ]
56
57 foreach extra_arg : warning_flags
58   if cc.has_argument (extra_arg)
59     add_project_arguments([extra_arg], language: 'c')
60   endif
61   if cxx.has_argument (extra_arg)
62     add_project_arguments([extra_arg], language: 'cpp')
63   endif
64 endforeach
65
66 foreach extra_arg : warning_c_flags
67   if cc.has_argument (extra_arg)
68     add_project_arguments([extra_arg], language: 'c')
69   endif
70 endforeach
71
72 # Set install path
73 nntrainer_prefix = get_option('prefix')
74 nntrainer_libdir = nntrainer_prefix / get_option('libdir')
75 nntrainer_bindir = nntrainer_prefix / get_option('bindir')
76 nntrainer_includedir = nntrainer_prefix / get_option('includedir')
77 nntrainer_confdir = get_option('sysconfdir')
78 application_install_dir = nntrainer_bindir / 'applications'
79
80 # handle resources
81 nntrainer_resdir = meson.build_root() / 'res'
82 run_command('mkdir', '-p', nntrainer_resdir)
83
84 if get_option('install-app')
85 # add a script to install resources from installs to application_install_dir
86 meson.add_install_script(
87   'sh', '-c', 'cp -r @0@ ${DESTDIR}@1@'.format(nntrainer_resdir, application_install_dir)
88 )
89 endif
90
91 # Set default configuration
92 nntrainer_conf = configuration_data()
93 nntrainer_conf.set('VERSION', meson.project_version())
94 nntrainer_conf.set('PREFIX', nntrainer_prefix)
95 nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
96 nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
97 nntrainer_conf.set('PLUGIN_INSTALL_PREFIX', nntrainer_libdir / 'nntrainer')
98 nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir)
99 nntrainer_conf.set('CAPI_ML_COMMON_DEP', get_option('capi-ml-common-actual'))
100
101 dummy_dep = dependency('', required: false)
102
103 blas_dep = dummy_dep
104 # Dependencies
105 if get_option('enable-cublas')
106    add_project_arguments('-DUSE_CUBLAS=1', language:['c','cpp'])
107 endif
108
109 if get_option('enable-blas')
110   add_project_arguments('-DUSE_BLAS=1', language:['c','cpp'])
111   if build_platform == 'tizen'
112     blas_dep = dependency('openblas')
113   else
114     blas_dep = dependency('blas-openblas', required:false)
115     # for Ubuntu 20.04
116     if not blas_dep.found()
117       blas_dep = dependency('openblas')
118     endif
119   endif
120 endif
121
122 if get_option('enable-profile')
123   add_project_arguments('-DPROFILE=1', language:['c', 'cpp'])
124 endif
125
126 if get_option('use_gym')
127    add_project_arguments('-DUSE_GYM=1', language:['c','cpp'])
128 endif
129
130 if get_option('enable-logging')
131    add_project_arguments('-D__LOGGING__=1', language:['c','cpp'])
132 endif
133
134 if get_option('enable-test')
135   add_project_arguments('-DENABLE_TEST=1', language:['c','cpp'])
136 endif
137
138 if get_option('reduce-tolerance')
139   add_project_arguments('-DREDUCE_TOLERANCE=1', language:['c', 'cpp'])
140 endif
141
142 libm_dep = cxx.find_library('m') # cmath library
143 libdl_dep = cxx.find_library('dl') # DL library
144 thread_dep = dependency('threads') # pthread for tensorflow-lite
145 iniparser_dep = dependency('iniparser', required : false, version : '>=4.1') # iniparser
146 if not iniparser_dep.found()
147   message('falling back to find libiniparser library and header files')
148   libiniparser_dep = cxx.find_library('iniparser')
149   if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
150         args : '-I/usr/include/iniparser')
151     iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
152       compile_args : '-I/usr/include/iniparser')
153   endif
154 endif
155
156 nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required:false)
157 if nnstreamer_capi_dep.found()
158   add_project_arguments('-DNNSTREAMER_AVAILABLE=1', language:['c','cpp'])
159   # accessing this variable when dep_.not_found() remains hard error on purpose
160   supported_nnstreamer_capi = nnstreamer_capi_dep.version().version_compare('>=1.7.0')
161   if not supported_nnstreamer_capi
162     add_project_arguments('-DUNSUPPORTED_NNSTREAMER=1', language:['c','cpp'])
163     warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
164   endif
165 endif
166
167 ml_api_common_dep = dependency(get_option('capi-ml-common-actual'), required: true)
168
169 if get_option('enable-nnstreamer-backbone')
170   add_project_arguments('-DENABLE_NNSTREAMER_BACKBONE=1', language:['c','cpp'])
171 endif
172
173 tflite_dep = dependency('tensorflow2-lite', required: false)
174 if get_option('enable-tflite-backbone')
175   add_project_arguments('-DENABLE_TFLITE_BACKBONE=1', language:['c','cpp'])
176 endif
177
178 gtest_dep = dependency('gtest', static: true, main: false, required: false)
179 gtest_main_dep = dependency('gtest', static: true, main: true, required: false)
180
181 opencv_dep = dependency('opencv', required: false)
182 if not opencv_dep.found()
183   opencv_dep = dependency('opencv4', required: false)
184   if not opencv_dep.found()
185     opencv_dep = dependency('opencv3', required: false)
186   endif
187 endif
188 if opencv_dep.found()
189   add_project_arguments('-DENABLE_DATA_AUGMENTATION_OPENCV=1', language:['c','cpp'])
190 endif
191 flatc_prog = find_program('flatc', required: false)
192
193 # Install .pc
194 configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
195   install_dir: nntrainer_libdir / 'pkgconfig',
196   configuration: nntrainer_conf
197 )
198
199 # Install conf
200 configure_file(
201   input: 'nntrainer.ini.in',
202   output: 'nntrainer.ini',
203   install_dir: nntrainer_confdir,
204   configuration: nntrainer_conf
205 )
206 nntrainer_conf_abs_path = get_option('prefix') / nntrainer_confdir / 'nntrainer.ini'
207 message('NNTRAINER_CONF_PATH=@0@'.format(nntrainer_conf_abs_path))
208
209 add_project_arguments(
210   '-DNNTRAINER_CONF_PATH="@0@"'.format(nntrainer_conf_abs_path),
211   language: ['c', 'cpp']
212 )
213
214 # Build nntrainer
215 subdir('nntrainer')
216
217 # Build api
218 subdir('api')
219
220 if get_option('enable-test')
221   if gtest_dep.found()
222     subdir('test')
223   else
224     error('test enabled but gtest not found')
225   endif
226 endif
227
228 if get_option('enable-app')
229   jsoncpp_dep = dependency('jsoncpp') # jsoncpp
230   libcurl_dep = dependency('libcurl')
231   if not tflite_dep.found()
232     error('Tensorflow-Lite dependency not found')
233   endif
234   subdir('Applications')
235 endif
236
237 if get_option('enable-nnstreamer-tensor-filter')
238   nnstreamer_dep = dependency('nnstreamer', required: true)
239   subdir('nnstreamer/tensor_filter')
240 endif
241
242 if get_option('enable-android')
243
244   ndk_build = find_program('ndk-build', required : true)
245   jni_root = meson.current_source_dir() / 'jni'
246   jni_build_root = meson.current_build_dir() / 'jni'
247
248   ndk_args = {
249     'NDK_PROJECT_PATH': jni_root,
250     'APP_BUILD_SCRIPT': jni_root / 'Android.mk',
251     'NDK_APPLICATION_MK': jni_root / 'Application.mk',
252     'NDK_LIBS_OUT': jni_build_root / 'libs',
253     'NDK_OUT': jni_build_root / 'objs',
254     'ENABLE_PROFILE': get_option('enable-profile') ? 1 : 0,
255     'ENABLE_BLAS': get_option('enable-blas') ? 1 : 0,
256   }
257
258   num_threads = run_command('grep', '-c', '^processor', '/proc/cpuinfo').stdout().strip()
259   message('num processor are: ' + num_threads)
260
261   thread_opt_flag = '-j' + num_threads
262
263   ndk_additional_flags = [thread_opt_flag]
264
265   ndk_build_command = [ndk_build]
266   foreach key, val : ndk_args
267     ndk_build_command += '@0@=@1@'.format(key, val)
268   endforeach
269   ndk_build_command += ndk_additional_flags
270
271   android_build_target = custom_target('android',
272     output: 'jni',
273     build_by_default: true,
274     command: ndk_build_command
275   )
276
277 endif