Skip to content

Commit 73157b5

Browse files
committed
meson: add
Significantly faster than autotools thanks to Ninja and shorter code. Signed-off-by: Rosen Penev <rosenp@gmail.com>
1 parent f25144b commit 73157b5

File tree

8 files changed

+556
-0
lines changed

8 files changed

+556
-0
lines changed

meson.build

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
project(
2+
'libtorrent',
3+
'cpp',
4+
version: '0.16.3',
5+
meson_version: '>=1.3.0',
6+
default_options: ['cpp_std=c++17', 'warning_level=1'],
7+
)
8+
9+
if get_option('b_ndebug') not in ['true', 'if-release']
10+
add_project_arguments('-DDEBUG', language: 'cpp')
11+
endif
12+
13+
cdata = configuration_data()
14+
15+
cdata.set('HAVE_CONFIG_H', 1)
16+
cdata.set_quoted('VERSION', meson.project_version())
17+
cdata.set_quoted('PEER_NAME', '-lt1002-')
18+
cdata.set_quoted('PEER_VERSION', 'lt\\x10\\x02')
19+
20+
cc = meson.get_compiler('cpp')
21+
if cc.has_function_attribute('visibility:default')
22+
cdata.set('SUPPORT_ATTRIBUTE_VISIBILITY', 1)
23+
endif
24+
25+
cdata.set('IS_@0@_ENDIAN'.format(host_machine.endian().to_upper()), 1)
26+
27+
cdata.set('LT_INSTRUMENTATION', 1)
28+
29+
if cc.has_header_symbol('new', 'std::hardware_constructive_interference_size')
30+
cdata.set('LT_SMP_CACHE_BYTES', 'std::hardware_constructive_interference_size')
31+
else
32+
cdata.set('LT_SMP_CACHE_BYTES', '128')
33+
endif
34+
35+
cdata.set('lt_cacheline_aligned', 'alignas(LT_SMP_CACHE_BYTES)')
36+
if cc.sizeof('void*') == 8
37+
cdata.set('DEFAULT_ADDRESS_SPACE_SIZE', 4096)
38+
else
39+
cdata.set('DEFAULT_ADDRESS_SPACE_SIZE', 1024)
40+
endif
41+
42+
foreach h : ['epoll', 'inotify']
43+
if cc.has_header('sys/@0@.h'.format(h), required: get_option(h))
44+
cdata.set('USE_@0@'.format(h.to_upper()), 1)
45+
endif
46+
endforeach
47+
48+
foreach f : ['madvise', 'mincore']
49+
if cc.has_header_symbol('sys/mman.h', f, required: get_option(f))
50+
cdata.set('USE_@0@'.format(f.to_upper()), 1)
51+
endif
52+
endforeach
53+
54+
if cc.has_function('__builtin_popcount')
55+
cdata.set('USE_BUILTIN_POPCOUNT', 1)
56+
endif
57+
58+
if cc.has_function('posix_fadvise')
59+
cdata.set('USE_POSIX_FADVISE', 1)
60+
endif
61+
62+
if cc.has_function('fallocate')
63+
cdata.set('USE_FALLOCATE', 1)
64+
elif host_machine.system() == 'darwin'
65+
cdata.set('SYS_DARWIN', 1)
66+
elif cc.has_function('posix_fallocate')
67+
cdata.set('USE_POSIX_FALLOCATE', 1)
68+
endif
69+
70+
if cdata.has('USE_MINCORE')
71+
if cc.compiles('#include <sys/mman.h>\nint main(){mincore(0,0,(unsigned char*)0);}', werror: true)
72+
cdata.set('USE_MINCORE_UNSIGNED', 1)
73+
else
74+
cdata.set('USE_MINCORE_UNSIGNED', 0)
75+
endif
76+
endif
77+
78+
if cc.compiles('#include <pthread.h>\nint main(){pthread_setname_np("foo");}')
79+
cdata.set('HAS_PTHREAD_SETNAME_NP_DARWIN', 1)
80+
elif cc.compiles('#include <pthread.h>\nint main(){pthread_t t;pthread_setname_np(t,"foo");}')
81+
cdata.set('HAS_PTHREAD_SETNAME_NP_GENERIC', 1)
82+
endif
83+
84+
if cc.has_header('sys/statvfs.h', required: get_option('statvfs'))
85+
cdata.set('HAVE_SYS_STATVFS_H', 1)
86+
cdata.set('FS_STAT_FD', 'fstatvfs(fd, &m_stat) == 0')
87+
cdata.set('FS_STAT_FN', 'statvfs(fn, &m_stat) == 0')
88+
cdata.set('FS_STAT_STRUCT', 'struct statvfs')
89+
cdata.set('FS_STAT_SIZE_TYPE', 'unsigned long')
90+
cdata.set('FS_STAT_COUNT_TYPE', 'fsblkcnt_t')
91+
cdata.set('FS_STAT_BLOCK_SIZE', '(m_stat.f_frsize)')
92+
elif cc.has_header('sys/statfs.h', required: get_option('statfs'))
93+
cdata.set('HAVE_SYS_STATFS_H', 1)
94+
cdata.set('HAVE_SYS_VFS_H', 1)
95+
cdata.set('FS_STAT_FD', 'fstatfs(fd, &m_stat) == 0')
96+
cdata.set('FS_STAT_FN', 'statfs(fn, &m_stat) == 0')
97+
cdata.set('FS_STAT_STRUCT', 'struct statfs')
98+
cdata.set('FS_STAT_SIZE_TYPE', 'long')
99+
cdata.set('FS_STAT_COUNT_TYPE', 'long')
100+
cdata.set('FS_STAT_BLOCK_SIZE', '(m_stat.f_bsize)')
101+
else
102+
cdata.set('FS_STAT_FD', '(errno = ENOSYS) == 0')
103+
cdata.set('FS_STAT_FN', '(errno = ENOSYS) == 0')
104+
cdata.set('FS_STAT_STRUCT', 'struct {blocksize_type f_bsize;blockcount_type f_bavail;}')
105+
cdata.set('FS_STAT_SIZE_TYPE', 'int')
106+
cdata.set('FS_STAT_COUNT_TYPE', 'int')
107+
cdata.set('FS_STAT_BLOCK_SIZE', '(4096)')
108+
endif
109+
110+
if get_option('execinfo').enabled()
111+
if cc.has_function('backtrace')
112+
execinfo_dep = dependency('', required: false)
113+
else
114+
execinfo_dep = cc.find_library('execinfo')
115+
endif
116+
cdata.set('HAVE_BACKTRACE', 1)
117+
else
118+
execinfo_dep = cc.find_library('execinfo', required: get_option('execinfo'))
119+
if cc.has_function('backtrace', required: get_option('execinfo')) or execinfo_dep.found()
120+
cdata.set('HAVE_BACKTRACE', 1)
121+
endif
122+
endif
123+
124+
if cdata.has('USE_EPOLL')
125+
if get_option('kqueue').enabled()
126+
error('epoll and kqueue are mutually exclusive. Please enable only one')
127+
endif
128+
elif get_option('kqueue').disabled()
129+
error('One of epoll or kqueue must be enabled')
130+
endif
131+
132+
kqueue_opt = get_option('kqueue').disable_auto_if(cdata.has('USE_EPOLL'))
133+
if kqueue_opt.allowed()
134+
if cc.has_header('sys/event.h', required: false)
135+
kqueue_dep = dependency('', required: false)
136+
else
137+
kqueue_dep = dependency('libkqueue')
138+
endif
139+
cdata.set('USE_KQUEUE', 1)
140+
else
141+
kqueue_dep = dependency('', required: false)
142+
endif
143+
144+
if host_machine.system() != 'sunos'
145+
socket_dep = dependency('', required: false)
146+
else
147+
socket_dep = cc.find_library('socket')
148+
endif
149+
150+
if cc.links('#include <atomic>\nint main(){std::atomic<long long> b;return b.fetch_add(5);}')
151+
atomic_dep = dependency('', required: false)
152+
else
153+
atomic_dep = cc.find_library('atomic')
154+
endif
155+
156+
curl_dep = dependency('libcurl')
157+
ssl_dep = dependency('libcrypto')
158+
thread_dep = dependency('threads')
159+
zlib_dep = dependency('zlib')
160+
161+
cfile = configure_file(
162+
configuration: cdata,
163+
output: 'config.h',
164+
)
165+
166+
subdir('src')
167+
subdir('test')

meson_options.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
option('epoll', type: 'feature')
2+
option('execinfo', type: 'feature')
3+
option('inotify', type: 'feature')
4+
option('kqueue', type: 'feature')
5+
option('madvise', type: 'feature')
6+
option('mincore', type: 'feature')
7+
option('statvfs', type: 'feature')
8+
option('statfs', type: 'feature')
9+
option('tests', type: 'feature')

src/meson.build

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
incdirs = include_directories('..', '.')
2+
3+
libtorrent_files = files(
4+
'data/chunk.cc',
5+
'data/chunk_list.cc',
6+
'data/chunk_part.cc',
7+
'data/hash_check_queue.cc',
8+
'data/hash_chunk.cc',
9+
'data/hash_queue.cc',
10+
'data/hash_queue_node.cc',
11+
'data/hash_torrent.cc',
12+
'data/memory_chunk.cc',
13+
'data/socket_file.cc',
14+
'data/thread_disk.cc',
15+
'dht/dht_bucket.cc',
16+
'dht/dht_node.cc',
17+
'dht/dht_router.cc',
18+
'dht/dht_server.cc',
19+
'dht/dht_tracker.cc',
20+
'dht/dht_transaction.cc',
21+
'download/available_list.cc',
22+
'download/chunk_selector.cc',
23+
'download/chunk_statistics.cc',
24+
'download/delegator.cc',
25+
'download/download_constructor.cc',
26+
'download/download_main.cc',
27+
'download/download_wrapper.cc',
28+
'net/address_list.cc',
29+
'net/curl_get.cc',
30+
'net/curl_socket.cc',
31+
'net/curl_stack.cc',
32+
'net/listen.cc',
33+
'net/socket_base.cc',
34+
'net/socket_datagram.cc',
35+
'net/socket_fd.cc',
36+
'net/socket_set.cc',
37+
'net/socket_stream.cc',
38+
'net/thread_net.cc',
39+
'net/throttle_internal.cc',
40+
'net/throttle_list.cc',
41+
'net/udns_library.cc',
42+
'net/udns_resolver.cc',
43+
'protocol/extensions.cc',
44+
'protocol/handshake.cc',
45+
'protocol/handshake_encryption.cc',
46+
'protocol/handshake_manager.cc',
47+
'protocol/initial_seed.cc',
48+
'protocol/peer_connection_base.cc',
49+
'protocol/peer_connection_leech.cc',
50+
'protocol/peer_connection_metadata.cc',
51+
'protocol/peer_factory.cc',
52+
'protocol/request_list.cc',
53+
'tracker/thread_tracker.cc',
54+
'tracker/tracker_controller.cc',
55+
'tracker/tracker_dht.cc',
56+
'tracker/tracker_http.cc',
57+
'tracker/tracker_list.cc',
58+
'tracker/tracker_udp.cc',
59+
'tracker/tracker_worker.cc',
60+
'utils/diffie_hellman.cc',
61+
'utils/instrumentation.cc',
62+
'utils/signal_interrupt.cc',
63+
)
64+
65+
subdir('torrent')
66+
67+
libtorrent_other = static_library(
68+
'torrent_other',
69+
libtorrent_files,
70+
gnu_symbol_visibility: 'hidden',
71+
dependencies: [curl_dep, ssl_dep],
72+
include_directories: '..',
73+
)
74+
75+
depinc = include_directories('.')
76+
libtorrent_other_dep = declare_dependency(
77+
include_directories: depinc,
78+
link_with: [libtorrent_torrent, libtorrent_other],
79+
)
80+
81+
libtorrent = library(
82+
'libtorrent',
83+
'manager.cc',
84+
'thread_main.cc',
85+
gnu_symbol_visibility: 'hidden',
86+
name_prefix: '',
87+
link_whole: libtorrent_torrent,
88+
dependencies: [atomic_dep, libtorrent_other_dep, ssl_dep],
89+
version: '31.0.0',
90+
include_directories: '..',
91+
install: true,
92+
)
93+
94+
libtorrent_dep = declare_dependency(
95+
include_directories: depinc,
96+
link_with: libtorrent,
97+
)
98+
99+
pconf = import('pkgconfig')
100+
pconf.generate(
101+
libtorrent,
102+
description: 'A BitTorrent client',
103+
)

0 commit comments

Comments
 (0)