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
|
project('libnaunet', 'c', version: '0.01',
meson_version: '>=0.63.0',
default_options: ['warning_level=2', 'c_std=c99'],
license: 'GPL-3.0-only')
compiler = meson.get_compiler('c')
is_debug = get_option('debug')
is_minsize = get_option('optimization') == 's'
is_windows = host_machine.system() == 'windows'
is_android = host_machine.system() == 'android'
is_static_shared_lib = is_android
cmake = import('cmake')
cmake_reltype = is_minsize ? 'MinSizeRel' : 'Release'
naunet_src = [
'src/common.c',
'src/util/error.c',
'src/util/buffer.c',
'src/util/packet.c',
'src/util/sort.c',
'src/util/file/util.c'
]
naunet_inc = [include_directories('include')]
naunet_deps = []
naunet_args = []
alabaster = subproject('libalabaster')
naunet_deps += [alabaster.get_variable('alabaster')]
math = compiler.find_library('m', required: false)
if math.found()
naunet_deps += [math]
endif
if get_option('event-loop').enabled()
naunet_src += [
'src/loop.c',
'src/poll.c',
'src/timer.c',
'src/signal.c',
'src/packet_pool.c',
'src/packet_cache.c',
'src/packet_stream.c',
'src/multiplex.c',
'src/rpc.c',
'src/line_processor.c'
]
# libev gets embedded in ev_embed_compat.c.
libev = subproject('libev').get_variable('ev')
naunet_src += ['src/ev_embed_compat.c']
naunet_deps += [libev]
naunet_has_curl = false
if get_option('curl').enabled()
libcurl_found = false
if 'curl' not in get_option('force_fallback_for') and get_option('wrap_mode') != 'forcefallback'
libcurl = dependency('libcurl', required: false, allow_fallback: false)
libcurl_found = libcurl.found()
endif
if not libcurl_found
bare_minimum_curl = is_android
curl_opts = cmake.subproject_options()
curl_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : cmake_reltype })
curl_opts.add_cmake_defines({ 'CMAKE_POSITION_INDEPENDENT_CODE': is_static_shared_lib })
curl_opts.add_cmake_defines({ 'BUILD_LIBCURL_DOCS': false })
curl_opts.add_cmake_defines({ 'BUILD_MISC_DOCS': false })
curl_opts.add_cmake_defines({ 'ENABLE_CURL_MANUAL': false })
curl_opts.add_cmake_defines({ 'BUILD_TESTING': false })
curl_opts.add_cmake_defines({ 'BUILD_CURL_EXE': false })
curl_opts.add_cmake_defines({ 'BUILD_SHARED_LIBS': false })
curl_opts.add_cmake_defines({ 'BUILD_STATIC_LIBS': true })
curl_opts.add_cmake_defines({ 'ENABLE_WEBSOCKETS': true })
if not bare_minimum_curl
curl_opts.add_cmake_defines({ 'CURL_USE_OPENSSL': true })
openssl = dependency('openssl')
naunet_deps += [openssl]
else
curl_opts.add_cmake_defines({ 'CURL_USE_OPENSSL': false })
endif
if not bare_minimum_curl
if is_windows
curl_opts.add_cmake_defines({ 'USE_WIN32_IDN': true })
naunet_deps += [
compiler.find_library('bcrypt'),
compiler.find_library('crypt32')
]
else
curl_opts.add_cmake_defines({ 'USE_LIBIDN2': true })
libidn2 = dependency('libidn2')
naunet_deps += [libidn2]
endif
endif
curl_opts.add_cmake_defines({ 'CURL_USE_LIBSSH2': false })
curl_opts.add_cmake_defines({ 'CURL_USE_LIBPSL': false })
curl_opts.add_cmake_defines({ 'CURL_DISABLE_LDAP': true })
libcurl = cmake.subproject('libcurl', options: curl_opts).dependency('libcurl_static')
zlib = dependency('zlib')
naunet_deps += [zlib]
endif
naunet_has_curl = libcurl.found()
if naunet_has_curl
naunet_src += [
'src/curl/curl.c',
'src/curl/http.c',
'src/curl/websocket.c'
]
naunet_deps += [libcurl]
naunet_args += ['-DNAUNET_HAS_CURL']
endif
endif
endif
if get_option('json').enabled()
#jsmn = subproject('jsmn').get_variable('jsmn')
#naunet_deps += [jsmn]
#naunet_args += ['-DNAUNET_HAS_JSON']
jansson_found = false
if 'jansson' not in get_option('force_fallback_for') and get_option('wrap_mode') != 'forcefallback'
jansson = dependency('jansson', required: false, allow_fallback: false)
jansson_found = jansson.found()
endif
if not jansson_found
jansson_opts = cmake.subproject_options()
jansson_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : cmake_reltype })
jansson_opts.add_cmake_defines({ 'CMAKE_POSITION_INDEPENDENT_CODE': is_static_shared_lib })
jansson_opts.add_cmake_defines({ 'JANSSON_EXAMPLES': false })
jansson_opts.add_cmake_defines({ 'JANSSON_WITHOUT_TESTS': true })
jansson_opts.add_cmake_defines({ 'JANSSON_BUILD_DOCS': false })
jansson_opts.add_cmake_defines({ 'JANSSON_INSTALL': false })
jansson = cmake.subproject('jansson', options: jansson_opts).dependency('jansson')
endif
naunet_deps += [jansson]
naunet_args += ['-DNAUNET_HAS_JSON']
endif
if is_windows
naunet_args += ['-DNAUNET_ON_WINDOWS']
if get_option('win32-compat')
# https://learn.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers
naunet_args += ['-DNAUNET_WIN32_COMPAT_MODE']
endif
naunet_src += [
'src/winwrap.c',
'src/util/timer/timer_windows.c',
'src/util/thread/thread_windows.c',
'src/util/file/file_stdio.c',
'src/socket/socket_windows.c',
'src/socket/bsd_common.c'
]
naunet_args += ['-DNAUNET_NEEDS_STDIO_ASSIST']
naunet_has_mmap = false
naunet_deps += [
compiler.find_library('kernel32'),
compiler.find_library('ws2_32')
]
else
if is_android
naunet_args += ['-DNAUNET_ON_ANDROID']
endif
naunet_src += [
'src/util/timer/timer_linux.c',
'src/util/thread/thread_linux.c',
'src/util/file/file_linux.c',
'src/socket/socket_linux.c',
'src/socket/bsd_common.c'
]
if get_option('event-loop').enabled()
naunet_src += ['src/fs_event/fs_event_inotify.c']
endif
naunet_args += ['-D_GNU_SOURCE']
naunet_has_mmap = true
pthreads = dependency('pthreads', required: false)
if pthreads.found()
naunet_deps += [pthreads]
endif
have_pthread_cancel = compiler.has_function('pthread_cancel', prefix: '#include <pthread.h>')
if have_pthread_cancel
naunet_args += ['-DNAUNET_HAS_THREAD_CANCEL']
endif
endif
naunet = declare_dependency(include_directories: naunet_inc,
dependencies: naunet_deps, sources: naunet_src,
compile_args: naunet_args)
if get_option('tests').allowed()
subdir('tests')
endif
|