forked from nnstreamer/nntrainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeson.build
210 lines (175 loc) · 5.78 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
project('nntrainer', 'c', 'cpp',
version: '0.0.1',
license: ['apache-2.0'],
meson_version: '>=0.50.0',
default_options: [
'werror=true',
'warning_level=1',
'c_std=gnu89',
'cpp_std=c++14'
]
)
add_project_arguments('-DMIN_CPP_VERSION=201402', language:['c','cpp'])
cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')
build_platform = ''
if get_option('enable-tizen')
# Pass __TIZEN__ to the compiler
build_platform = 'tizen'
add_project_arguments('-D__TIZEN__=1', language:['c','cpp'])
if get_option('enable-tizen-feature-check')
add_project_arguments('-D__FEATURE_CHECK_SUPPORT__', language: ['c', 'cpp'])
endif
endif
warning_flags = [
'-Wredundant-decls',
'-Wwrite-strings',
'-Wformat',
'-Wformat-nonliteral',
'-Wformat-security',
'-Winit-self',
'-Waddress',
'-Wno-multichar',
'-Wvla',
'-Wpointer-arith',
'-Wno-error=varargs',
'-O2',
'-ftree-vectorize'
]
warning_c_flags = [
'-Wmissing-declarations',
'-Wmissing-include-dirs',
'-Wmissing-prototypes',
'-Wnested-externs',
'-Waggregate-return',
'-Wold-style-definition',
'-Wdeclaration-after-statement',
'-Wno-error=varargs'
]
foreach extra_arg : warning_flags
if cc.has_argument (extra_arg)
add_project_arguments([extra_arg], language: 'c')
endif
if cxx.has_argument (extra_arg)
add_project_arguments([extra_arg], language: 'cpp')
endif
endforeach
foreach extra_arg : warning_c_flags
if cc.has_argument (extra_arg)
add_project_arguments([extra_arg], language: 'c')
endif
endforeach
# Set install path
nntrainer_prefix = get_option('prefix')
nntrainer_libdir = join_paths(nntrainer_prefix, get_option('libdir'))
nntrainer_bindir = join_paths(nntrainer_prefix, get_option('bindir'))
nntrainer_includedir = join_paths(nntrainer_prefix, get_option('includedir'))
nntrainer_inidir = get_option('sysconfdir')
application_install_dir = join_paths(nntrainer_bindir, 'applications')
# Set default configuration
nntrainer_conf = configuration_data()
nntrainer_conf.set('VERSION', meson.project_version())
nntrainer_conf.set('PREFIX', nntrainer_prefix)
nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir)
dummy_dep = dependency('', required: false)
blas_dep = dummy_dep
# Dependencies
if get_option('enable-cublas')
add_project_arguments('-DUSE_CUBLAS=1', language:['c','cpp'])
endif
if get_option('enable-blas')
add_project_arguments('-DUSE_BLAS=1', language:['c','cpp'])
if build_platform == 'tizen'
blas_dep = dependency('openblas')
else
blas_dep = dependency('blas-openblas')
endif
endif
if get_option('enable-profile')
add_project_arguments('-DPROFILE=1', language:['c', 'cpp'])
endif
if get_option('use_gym')
add_project_arguments('-DUSE_GYM=1', language:['c','cpp'])
endif
if get_option('enable-logging')
add_project_arguments('-D__LOGGING__=1', language:['c','cpp'])
endif
if get_option('enable-test')
add_project_arguments('-DENABLE_TEST=1', language:['c','cpp'])
endif
libm_dep = cxx.find_library('m') # cmath library
libdl_dep = cxx.find_library('dl') # DL library
thread_dep = dependency('threads') # pthread for tensorflow-lite
iniparser_dep = dependency('iniparser', required : false) # iniparser
if not iniparser_dep.found()
message('falling back to find libiniparser library and header files')
libiniparser_dep = cxx.find_library('iniparser')
if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
args : '-I/usr/include/iniparser')
iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
compile_args : '-I/usr/include/iniparser')
endif
endif
nnstreamer_capi_dep = dependency('capi-nnstreamer', required:false)
if get_option('enable-nnstreamer-backbone')
add_project_arguments('-DENABLE_NNSTREAMER_BACKBONE=1', language:['c','cpp'])
endif
tflite_dep = dependency('tensorflow-lite', required: false)
if get_option('enable-tflite-backbone')
add_project_arguments('-DENABLE_TFLITE_BACKBONE=1', language:['c','cpp'])
endif
jsoncpp_dep = dependency('jsoncpp') # jsoncpp
libcurl_dep = dependency('libcurl')
gtest_dep = dependency('gtest', required: false)
# Install .pc
configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
install_dir: join_paths(nntrainer_libdir, 'pkgconfig'),
configuration: nntrainer_conf
)
# Build nntrainer
subdir('nntrainer')
# Build api
subdir('api')
if get_option('enable-app')
if not tflite_dep.found()
error('Tensorflow-Lite dependency not found')
endif
subdir('Applications')
endif
if get_option('enable-test')
subdir('test')
endif
if get_option('enable-nnstreamer-tensor-filter')
nnstreamer_dep = dependency('nnstreamer', required: true)
subdir('nnstreamer/tensor_filter')
endif
if get_option('enable-android')
ndk_build = find_program('ndk-build', required : true)
jni_root = meson.current_source_dir() / 'jni'
jni_build_root = meson.current_build_dir() / 'jni'
ndk_args = {
'NDK_PROJECT_PATH': jni_root,
'APP_BUILD_SCRIPT': jni_root / 'Android.mk',
'NDK_APPLICATION_MK': jni_root / 'Application.mk',
'NDK_LIBS_OUT': jni_build_root / 'libs',
'NDK_OUT': jni_build_root / 'objs',
'ENABLE_PROFILE': get_option('enable-profile') ? 1 : 0,
'ENABLE_BLAS': get_option('enable-blas') ? 1 : 0,
}
num_threads = run_command('grep', '-c', '^processor', '/proc/cpuinfo').stdout().strip()
message('num processor are: ' + num_threads)
thread_opt_flag = '-j' + num_threads
ndk_additional_flags = [thread_opt_flag]
ndk_build_command = [ndk_build]
foreach key, val : ndk_args
ndk_build_command += '@0@=@1@'.format(key, val)
endforeach
ndk_build_command += ndk_additional_flags
android_build_target = custom_target('android',
output: 'jni',
build_by_default: true,
command: ndk_build_command
)
endif