Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
project(
'libtorrent',
'cpp',
version: '0.16.3',
meson_version: '>=1.3.0',
default_options: ['cpp_std=c++17', 'warning_level=1'],
)

if get_option('b_ndebug') not in ['true', 'if-release']
add_project_arguments('-DDEBUG', language: 'cpp')
endif

cdata = configuration_data()

cdata.set('HAVE_CONFIG_H', 1)
cdata.set_quoted('VERSION', meson.project_version())
cdata.set_quoted('PEER_NAME', '-lt1002-')
cdata.set_quoted('PEER_VERSION', 'lt\\x10\\x02')

cc = meson.get_compiler('cpp')
if cc.has_function_attribute('visibility:default')
cdata.set('SUPPORT_ATTRIBUTE_VISIBILITY', 1)
endif

cdata.set('IS_@0@_ENDIAN'.format(host_machine.endian().to_upper()), 1)

cdata.set('LT_INSTRUMENTATION', 1)

if cc.has_header_symbol('new', 'std::hardware_constructive_interference_size')
cdata.set('LT_SMP_CACHE_BYTES', 'std::hardware_constructive_interference_size')
else
cdata.set('LT_SMP_CACHE_BYTES', '128')
endif

cdata.set('lt_cacheline_aligned', 'alignas(LT_SMP_CACHE_BYTES)')
if cc.sizeof('void*') == 8
cdata.set('DEFAULT_ADDRESS_SPACE_SIZE', 4096)
else
cdata.set('DEFAULT_ADDRESS_SPACE_SIZE', 1024)
endif

foreach h : ['epoll', 'inotify']
if cc.has_header('sys/@0@.h'.format(h), required: get_option(h))
cdata.set('USE_@0@'.format(h.to_upper()), 1)
endif
endforeach

foreach f : ['madvise', 'mincore']
if cc.has_header_symbol('sys/mman.h', f, required: get_option(f))
cdata.set('USE_@0@'.format(f.to_upper()), 1)
endif
endforeach

if cc.has_function('__builtin_popcount')
cdata.set('USE_BUILTIN_POPCOUNT', 1)
endif

if cc.has_function('posix_fadvise')
cdata.set('USE_POSIX_FADVISE', 1)
endif

if cc.has_function('fallocate')
cdata.set('USE_FALLOCATE', 1)
elif host_machine.system() == 'darwin'
cdata.set('SYS_DARWIN', 1)
elif cc.has_function('posix_fallocate')
cdata.set('USE_POSIX_FALLOCATE', 1)
endif

if cdata.has('USE_MINCORE')
if cc.compiles('#include <sys/mman.h>\nint main(){mincore(0,0,(unsigned char*)0);}', werror: true)
cdata.set('USE_MINCORE_UNSIGNED', 1)
else
cdata.set('USE_MINCORE_UNSIGNED', 0)
endif
endif

if cc.compiles('#include <pthread.h>\nint main(){pthread_setname_np("foo");}')
cdata.set('HAS_PTHREAD_SETNAME_NP_DARWIN', 1)
elif cc.compiles('#include <pthread.h>\nint main(){pthread_t t;pthread_setname_np(t,"foo");}')
cdata.set('HAS_PTHREAD_SETNAME_NP_GENERIC', 1)
endif

if cc.has_header('sys/statvfs.h', required: get_option('statvfs'))
cdata.set('HAVE_SYS_STATVFS_H', 1)
cdata.set('FS_STAT_FD', 'fstatvfs(fd, &m_stat) == 0')
cdata.set('FS_STAT_FN', 'statvfs(fn, &m_stat) == 0')
cdata.set('FS_STAT_STRUCT', 'struct statvfs')
cdata.set('FS_STAT_SIZE_TYPE', 'unsigned long')
cdata.set('FS_STAT_COUNT_TYPE', 'fsblkcnt_t')
cdata.set('FS_STAT_BLOCK_SIZE', '(m_stat.f_frsize)')
elif cc.has_header('sys/statfs.h', required: get_option('statfs'))
cdata.set('HAVE_SYS_STATFS_H', 1)
cdata.set('HAVE_SYS_VFS_H', 1)
cdata.set('FS_STAT_FD', 'fstatfs(fd, &m_stat) == 0')
cdata.set('FS_STAT_FN', 'statfs(fn, &m_stat) == 0')
cdata.set('FS_STAT_STRUCT', 'struct statfs')
cdata.set('FS_STAT_SIZE_TYPE', 'long')
cdata.set('FS_STAT_COUNT_TYPE', 'long')
cdata.set('FS_STAT_BLOCK_SIZE', '(m_stat.f_bsize)')
else
cdata.set('FS_STAT_FD', '(errno = ENOSYS) == 0')
cdata.set('FS_STAT_FN', '(errno = ENOSYS) == 0')
cdata.set('FS_STAT_STRUCT', 'struct {blocksize_type f_bsize;blockcount_type f_bavail;}')
cdata.set('FS_STAT_SIZE_TYPE', 'int')
cdata.set('FS_STAT_COUNT_TYPE', 'int')
cdata.set('FS_STAT_BLOCK_SIZE', '(4096)')
endif

if get_option('execinfo').enabled()
if cc.has_function('backtrace')
execinfo_dep = dependency('', required: false)
else
execinfo_dep = cc.find_library('execinfo')
endif
cdata.set('HAVE_BACKTRACE', 1)
else
execinfo_dep = cc.find_library('execinfo', required: get_option('execinfo'))
if cc.has_function('backtrace', required: get_option('execinfo')) or execinfo_dep.found()
cdata.set('HAVE_BACKTRACE', 1)
endif
endif

if cdata.has('USE_EPOLL')
if get_option('kqueue').enabled()
error('epoll and kqueue are mutually exclusive. Please enable only one')
endif
elif get_option('kqueue').disabled()
error('One of epoll or kqueue must be enabled')
endif

kqueue_opt = get_option('kqueue').disable_auto_if(cdata.has('USE_EPOLL'))
if kqueue_opt.allowed()
if cc.has_header('sys/event.h', required: false)
kqueue_dep = dependency('', required: false)
else
kqueue_dep = dependency('libkqueue')
endif
cdata.set('USE_KQUEUE', 1)
else
kqueue_dep = dependency('', required: false)
endif

if host_machine.system() != 'sunos'
socket_dep = dependency('', required: false)
else
socket_dep = cc.find_library('socket')
endif

if cc.links('#include <atomic>\nint main(){std::atomic<long long> b;return b.fetch_add(5);}')
atomic_dep = dependency('', required: false)
else
atomic_dep = cc.find_library('atomic')
endif

curl_dep = dependency('libcurl')
ssl_dep = dependency('libcrypto')
thread_dep = dependency('threads')
zlib_dep = dependency('zlib')

cfile = configure_file(
configuration: cdata,
output: 'config.h',
)

subdir('src')
subdir('test')
9 changes: 9 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
option('epoll', type: 'feature')
option('execinfo', type: 'feature')
option('inotify', type: 'feature')
option('kqueue', type: 'feature')
option('madvise', type: 'feature')
option('mincore', type: 'feature')
option('statvfs', type: 'feature')
option('statfs', type: 'feature')
option('tests', type: 'feature')
103 changes: 103 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
incdirs = include_directories('..', '.')

libtorrent_files = files(
'data/chunk.cc',
'data/chunk_list.cc',
'data/chunk_part.cc',
'data/hash_check_queue.cc',
'data/hash_chunk.cc',
'data/hash_queue.cc',
'data/hash_queue_node.cc',
'data/hash_torrent.cc',
'data/memory_chunk.cc',
'data/socket_file.cc',
'data/thread_disk.cc',
'dht/dht_bucket.cc',
'dht/dht_node.cc',
'dht/dht_router.cc',
'dht/dht_server.cc',
'dht/dht_tracker.cc',
'dht/dht_transaction.cc',
'download/available_list.cc',
'download/chunk_selector.cc',
'download/chunk_statistics.cc',
'download/delegator.cc',
'download/download_constructor.cc',
'download/download_main.cc',
'download/download_wrapper.cc',
'net/address_list.cc',
'net/curl_get.cc',
'net/curl_socket.cc',
'net/curl_stack.cc',
'net/listen.cc',
'net/socket_base.cc',
'net/socket_datagram.cc',
'net/socket_fd.cc',
'net/socket_set.cc',
'net/socket_stream.cc',
'net/thread_net.cc',
'net/throttle_internal.cc',
'net/throttle_list.cc',
'net/udns_library.cc',
'net/udns_resolver.cc',
'protocol/extensions.cc',
'protocol/handshake.cc',
'protocol/handshake_encryption.cc',
'protocol/handshake_manager.cc',
'protocol/initial_seed.cc',
'protocol/peer_connection_base.cc',
'protocol/peer_connection_leech.cc',
'protocol/peer_connection_metadata.cc',
'protocol/peer_factory.cc',
'protocol/request_list.cc',
'tracker/thread_tracker.cc',
'tracker/tracker_controller.cc',
'tracker/tracker_dht.cc',
'tracker/tracker_http.cc',
'tracker/tracker_list.cc',
'tracker/tracker_udp.cc',
'tracker/tracker_worker.cc',
'utils/diffie_hellman.cc',
'utils/instrumentation.cc',
'utils/signal_interrupt.cc',
)

subdir('torrent')

libtorrent_other = static_library(
'torrent_other',
libtorrent_files,
gnu_symbol_visibility: 'hidden',
dependencies: [curl_dep, ssl_dep],
include_directories: '..',
)

depinc = include_directories('.')
libtorrent_other_dep = declare_dependency(
include_directories: depinc,
link_with: [libtorrent_torrent, libtorrent_other],
)

libtorrent = library(
'libtorrent',
'manager.cc',
'thread_main.cc',
gnu_symbol_visibility: 'hidden',
name_prefix: '',
link_whole: libtorrent_torrent,
dependencies: [atomic_dep, libtorrent_other_dep, ssl_dep],
version: '31.0.0',
include_directories: '..',
install: true,
)

libtorrent_dep = declare_dependency(
include_directories: depinc,
link_with: libtorrent,
)

pconf = import('pkgconfig')
pconf.generate(
libtorrent,
description: 'A BitTorrent client',
)
Loading
Loading