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