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