|
| 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') |
0 commit comments