Skip to content

Commit 40e5710

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 0c05bce commit 40e5710

7 files changed

Lines changed: 514 additions & 0 deletions

File tree

meson.build

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

meson_options.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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('posix_fallocate', type: 'boolean', value: false)
8+
option('statvfs', type: 'feature')
9+
option('statfs', type: 'feature')
10+
option('tests', type: 'feature')

src/meson.build

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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/listen.cc',
30+
'net/socket_base.cc',
31+
'net/socket_datagram.cc',
32+
'net/socket_fd.cc',
33+
'net/socket_listen.cc',
34+
'net/socket_set.cc',
35+
'net/socket_stream.cc',
36+
'net/thread_net.cc',
37+
'net/throttle_internal.cc',
38+
'net/throttle_list.cc',
39+
'net/udns_resolver.cc',
40+
'net/udns/udns_dn.c',
41+
'net/udns/udns_init.c',
42+
'net/udns/udns_jran.c',
43+
'net/udns/udns_parse.c',
44+
'net/udns/udns_resolver.c',
45+
'net/udns/udns_rr_a.c',
46+
'net/udns/udns_XtoX.c',
47+
'protocol/extensions.cc',
48+
'protocol/handshake.cc',
49+
'protocol/handshake_encryption.cc',
50+
'protocol/handshake_manager.cc',
51+
'protocol/initial_seed.cc',
52+
'protocol/peer_connection_base.cc',
53+
'protocol/peer_connection_leech.cc',
54+
'protocol/peer_connection_metadata.cc',
55+
'protocol/peer_factory.cc',
56+
'protocol/request_list.cc',
57+
'tracker/thread_tracker.cc',
58+
'tracker/tracker_dht.cc',
59+
'tracker/tracker_http.cc',
60+
'tracker/tracker_udp.cc',
61+
'tracker/tracker_worker.cc',
62+
'utils/diffie_hellman.cc',
63+
'utils/instrumentation.cc',
64+
'utils/signal_interrupt.cc',
65+
)
66+
67+
subdir('torrent')
68+
69+
libtorrent_other = static_library(
70+
'torrent_other',
71+
libtorrent_files,
72+
gnu_symbol_visibility: 'hidden',
73+
link_with: libtorrent_torrent,
74+
dependencies: [zlib_dep, ssl_dep],
75+
include_directories: '..',
76+
)
77+
78+
depinc = include_directories('.')
79+
libtorrent_other_dep = declare_dependency(
80+
include_directories: depinc,
81+
link_with: [libtorrent_torrent, libtorrent_other],
82+
)
83+
84+
libtorrent = library(
85+
'libtorrent',
86+
'globals.cc',
87+
'manager.cc',
88+
'thread_main.cc',
89+
gnu_symbol_visibility: 'hidden',
90+
name_prefix: '',
91+
link_whole: [libtorrent_torrent, libtorrent_other],
92+
version: '24.0.0',
93+
dependencies: kqueue_dep,
94+
include_directories: '..',
95+
install: true,
96+
)
97+
98+
libtorrent_dep = declare_dependency(
99+
include_directories: depinc,
100+
link_with: libtorrent,
101+
)
102+
103+
pconf = import('pkgconfig')
104+
pconf.generate(
105+
libtorrent,
106+
description: 'A BitTorrent client',
107+
)

0 commit comments

Comments
 (0)