Skip to content

Commit c972a6b

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 5414ca2 commit c972a6b

File tree

7 files changed

+537
-0
lines changed

7 files changed

+537
-0
lines changed

meson.build

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
project(
2+
'libtorrent',
3+
'cpp',
4+
version: '0.15.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', '-lt0F03-')
18+
cdata.set_quoted('PEER_VERSION', 'lt\\x0F\\x03')
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 get_option('posix_fallocate') and cc.has_function('posix_fallocate')
63+
cdata.set('USE_POSIX_FALLOCATE', 1)
64+
elif host_machine.system() == 'darwin'
65+
cdata.set('SYS_DARWIN', 1)
66+
elif cc.has_function('fallocate')
67+
cdata.set('USE_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 = declare_dependency()
113+
else
114+
execinfo_dep = dependency('execinfo')
115+
endif
116+
cdata.set('HAVE_BACKTRACE', 1)
117+
else
118+
execinfo_dep = dependency('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 get_option('kqueue').enabled()
125+
if cdata.has('USE_EPOLL')
126+
error('epoll and kqueue are mutually exclusive. Please enable only one')
127+
endif
128+
if cc.has_header('sys/event.h')
129+
kqueue_dep = declare_dependency()
130+
else
131+
kqueue_dep = dependency('libkqueue')
132+
endif
133+
cdata.set('USE_KQUEUE', 1)
134+
elif not cdata.has('USE_EPOLL')
135+
kqueue_dep = dependency('libkqueue', required: get_option('kqueue'))
136+
if cc.has_header('sys/event.h', required: get_option('kqueue')) or kqueue_dep.found()
137+
cdata.set('USE_KQUEUE', 1)
138+
endif
139+
else
140+
kqueue_dep = []
141+
endif
142+
143+
if cc.links('#include <atomic>\n#include <bitset>\nint main(){std::atomic<std::bitset<3>> b;std::atomic_is_lock_free(&b);}')
144+
atomic_dep = dependency('', required: false)
145+
else
146+
atomic_dep = cc.find_library('atomic')
147+
endif
148+
149+
if host_machine.system() != 'sunos'
150+
socket_dep = dependency('', required: false)
151+
else
152+
socket_dep = cc.find_library('socket')
153+
endif
154+
155+
ssl_dep = dependency('libcrypto')
156+
thread_dep = dependency('threads')
157+
zlib_dep = dependency('zlib')
158+
159+
cfile = configure_file(
160+
configuration: cdata,
161+
output: 'config.h',
162+
)
163+
164+
subdir('src')
165+
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: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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_library.cc',
40+
'net/udns_resolver.cc',
41+
'protocol/extensions.cc',
42+
'protocol/handshake.cc',
43+
'protocol/handshake_encryption.cc',
44+
'protocol/handshake_manager.cc',
45+
'protocol/initial_seed.cc',
46+
'protocol/peer_connection_base.cc',
47+
'protocol/peer_connection_leech.cc',
48+
'protocol/peer_connection_metadata.cc',
49+
'protocol/peer_factory.cc',
50+
'protocol/request_list.cc',
51+
'tracker/thread_tracker.cc',
52+
'tracker/tracker_dht.cc',
53+
'tracker/tracker_http.cc',
54+
'tracker/tracker_udp.cc',
55+
'tracker/tracker_worker.cc',
56+
'utils/diffie_hellman.cc',
57+
'utils/instrumentation.cc',
58+
'utils/signal_interrupt.cc',
59+
)
60+
61+
subdir('torrent')
62+
63+
libtorrent_other = static_library(
64+
'torrent_other',
65+
libtorrent_files,
66+
gnu_symbol_visibility: 'hidden',
67+
dependencies: [atomic_dep, ssl_dep],
68+
include_directories: '..',
69+
)
70+
71+
depinc = include_directories('.')
72+
libtorrent_other_dep = declare_dependency(
73+
include_directories: depinc,
74+
link_with: [libtorrent_torrent, libtorrent_other],
75+
)
76+
77+
libtorrent = library(
78+
'libtorrent',
79+
'globals.cc',
80+
'manager.cc',
81+
'thread_main.cc',
82+
gnu_symbol_visibility: 'hidden',
83+
name_prefix: '',
84+
link_whole: libtorrent_torrent,
85+
dependencies: [libtorrent_other_dep, ssl_dep],
86+
version: '24.0.0',
87+
include_directories: '..',
88+
install: true,
89+
)
90+
91+
libtorrent_dep = declare_dependency(
92+
include_directories: depinc,
93+
link_with: libtorrent,
94+
)
95+
96+
pconf = import('pkgconfig')
97+
pconf.generate(
98+
libtorrent,
99+
description: 'A BitTorrent client',
100+
)

0 commit comments

Comments
 (0)