[Build] Decouple gtest from nntrainer_test_util
[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   ]
11 )
12 add_project_arguments('-DMIN_CPP_VERSION=201402', language:['c','cpp'])
13
14 cc = meson.get_compiler('c')
15 cxx = meson.get_compiler('cpp')
16 build_platform = ''
17
18 if get_option('enable-tizen')
19   # Pass __TIZEN__ to the compiler
20   build_platform = 'tizen'
21   add_project_arguments('-D__TIZEN__=1', language:['c','cpp'])
22
23   if get_option('enable-tizen-feature-check')
24     add_project_arguments('-D__FEATURE_CHECK_SUPPORT__', language: ['c', 'cpp'])
25   endif
26 endif
27
28 warning_flags = [
29   '-Wredundant-decls',
30   '-Wwrite-strings',
31   '-Wformat',
32   '-Wformat-nonliteral',
33   '-Wformat-security',
34   '-Winit-self',
35   '-Waddress',
36   '-Wno-multichar',
37   '-Wvla',
38   '-Wpointer-arith',
39   '-Wno-error=varargs',
40   '-O2',
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_inidir = get_option('sysconfdir')
76 application_install_dir = nntrainer_bindir / 'applications'
77
78 # Set default configuration
79 nntrainer_conf = configuration_data()
80 nntrainer_conf.set('VERSION', meson.project_version())
81 nntrainer_conf.set('PREFIX', nntrainer_prefix)
82 nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
83 nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
84 nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir)
85
86 dummy_dep = dependency('', required: false)
87
88 blas_dep = dummy_dep
89 # Dependencies
90 if get_option('enable-cublas')
91    add_project_arguments('-DUSE_CUBLAS=1', language:['c','cpp'])
92 endif
93
94 if get_option('enable-blas')
95   add_project_arguments('-DUSE_BLAS=1', language:['c','cpp'])
96   if build_platform == 'tizen'
97     blas_dep = dependency('openblas')
98   else
99     blas_dep = dependency('blas-openblas', required:false)
100     # for Ubuntu 20.04
101     if not blas_dep.found()
102       blas_dep = dependency('openblas')
103     endif
104   endif
105 endif
106
107 if get_option('enable-profile')
108   add_project_arguments('-DPROFILE=1', language:['c', 'cpp'])
109 endif
110
111 if get_option('use_gym')
112    add_project_arguments('-DUSE_GYM=1', language:['c','cpp'])
113 endif
114
115 if get_option('enable-logging')
116    add_project_arguments('-D__LOGGING__=1', language:['c','cpp'])
117 endif
118
119 if get_option('enable-test')
120   add_project_arguments('-DENABLE_TEST=1', language:['c','cpp'])
121 endif
122
123 libm_dep = cxx.find_library('m') # cmath library
124 libdl_dep = cxx.find_library('dl') # DL library
125 thread_dep = dependency('threads') # pthread for tensorflow-lite
126 iniparser_dep = dependency('iniparser', required : false) # iniparser
127 if not iniparser_dep.found()
128   message('falling back to find libiniparser library and header files')
129   libiniparser_dep = cxx.find_library('iniparser')
130   if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
131         args : '-I/usr/include/iniparser')
132     iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
133       compile_args : '-I/usr/include/iniparser')
134   endif
135 endif
136
137 nnstreamer_capi_dep = dependency('capi-nnstreamer', required:false)
138 if nnstreamer_capi_dep.found()
139   add_project_arguments('-DNNSTREAMER_AVAILABLE=1', language:['c','cpp'])
140   # accessing this variable when dep_.not_found() remains hard error on purpose
141   supported_nnstreamer_capi = nnstreamer_capi_dep.version().version_compare('>=1.7.0')
142   if not supported_nnstreamer_capi
143     add_project_arguments('-DUNSUPPORTED_NNSTREAMER=1', language:['c','cpp'])
144     warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
145   endif
146 endif
147
148 # todo: change this to a capi-ml-common after #nnstreamer/3014
149 ml_api_common_dep = dependency('capi-nnstreamer', required:true)
150
151 if get_option('enable-nnstreamer-backbone')
152   add_project_arguments('-DENABLE_NNSTREAMER_BACKBONE=1', language:['c','cpp'])
153 endif
154
155 tflite_dep = dependency('tensorflow-lite', required: false)
156 if get_option('enable-tflite-backbone')
157   add_project_arguments('-DENABLE_TFLITE_BACKBONE=1', language:['c','cpp'])
158 endif
159
160 gtest_dep = dependency('gtest', static: true, main: false, required: false)
161 gtest_main_dep = dependency('gtest', static: true, main: true, required: false)
162
163 opencv_dep = dependency('opencv', required: false)
164 if not opencv_dep.found()
165   opencv_dep = dependency('opencv4', required: false)
166   if not opencv_dep.found()
167     opencv_dep = dependency('opencv3', required: false)
168   endif
169 endif
170 if opencv_dep.found()
171   add_project_arguments('-DENABLE_DATA_AUGMENTATION_OPENCV=1', language:['c','cpp'])
172 endif
173
174 # Install .pc
175 configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
176   install_dir: nntrainer_libdir / 'pkgconfig',
177   configuration: nntrainer_conf
178 )
179
180 # Build nntrainer
181 subdir('nntrainer')
182
183 # Build api
184 subdir('api')
185
186 if get_option('enable-app')
187   jsoncpp_dep = dependency('jsoncpp') # jsoncpp
188   libcurl_dep = dependency('libcurl')
189   if not tflite_dep.found()
190     error('Tensorflow-Lite dependency not found')
191   endif
192   subdir('Applications')
193 endif
194
195 if get_option('enable-test')
196   if gtest_dep.found()
197     subdir('test')
198   else
199     error('test enabled but gtest not found')
200   endif
201 endif
202
203 if get_option('enable-nnstreamer-tensor-filter')
204   nnstreamer_dep = dependency('nnstreamer', required: true)
205   subdir('nnstreamer/tensor_filter')
206 endif
207
208 if get_option('enable-android')
209
210   ndk_build = find_program('ndk-build', required : true)
211   jni_root = meson.current_source_dir() / 'jni'
212   jni_build_root = meson.current_build_dir() / 'jni'
213
214   ndk_args = {
215     'NDK_PROJECT_PATH': jni_root,
216     'APP_BUILD_SCRIPT': jni_root / 'Android.mk',
217     'NDK_APPLICATION_MK': jni_root / 'Application.mk',
218     'NDK_LIBS_OUT': jni_build_root / 'libs',
219     'NDK_OUT': jni_build_root / 'objs',
220     'ENABLE_PROFILE': get_option('enable-profile') ? 1 : 0,
221     'ENABLE_BLAS': get_option('enable-blas') ? 1 : 0,
222   }
223
224   num_threads = run_command('grep', '-c', '^processor', '/proc/cpuinfo').stdout().strip()
225   message('num processor are: ' + num_threads)
226
227   thread_opt_flag = '-j' + num_threads
228
229   ndk_additional_flags = [thread_opt_flag]
230
231   ndk_build_command = [ndk_build]
232   foreach key, val : ndk_args
233     ndk_build_command += '@0@=@1@'.format(key, val)
234   endforeach
235   ndk_build_command += ndk_additional_flags
236
237   android_build_target = custom_target('android',
238     output: 'jni',
239     build_by_default: true,
240     command: ndk_build_command
241   )
242
243 endif