project('libnaunet', 'c', version: '0.01', meson_version: '>=0.63.0', default_options: ['warning_level=2', 'c_std=c99'], license: 'GPL-3.0-only') compiler = meson.get_compiler('c') cmake = import('cmake') is_debug = get_option('debug') is_minsize = get_option('optimization') == 's' is_windows = host_machine.system() == 'windows' naunet_src = [ 'src/common.c', 'src/util/error.c', 'src/util/buffer.c', 'src/util/packet.c', 'src/util/file/util.c' ] naunet_inc = [include_directories('include')] naunet_deps = [] naunet_args = [] alabaster = subproject('libalabaster') naunet_deps += [alabaster.get_variable('alabaster')] math = compiler.find_library('m', required: false) if math.found() naunet_deps += [math] endif if get_option('event-loop').enabled() naunet_src += [ 'src/loop.c', 'src/poll.c', 'src/timer.c', 'src/signal.c', 'src/packet_pool.c', 'src/packet_cache.c', 'src/packet_stream.c', 'src/multiplex.c', 'src/rpc.c', 'src/line_processor.c' ] # libev gets embedded in ev_embed_compat.c. libev = subproject('libev').get_variable('ev') naunet_src += ['src/ev_embed_compat.c'] naunet_deps += [libev] naunet_has_curl = false if get_option('curl').enabled() libcurl_found = false if 'curl' not in get_option('force_fallback_for') and get_option('wrap_mode') != 'forcefallback' libcurl = dependency('libcurl', required: false, allow_fallback: false) libcurl_found = libcurl.found() endif if not libcurl_found curl_opts = cmake.subproject_options() reltype = is_minsize ? 'MinSizeRel' : 'Release' curl_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : reltype }) curl_opts.add_cmake_defines({ 'BUILD_CURL_EXE': false }) curl_opts.add_cmake_defines({ 'BUILD_SHARED_LIBS': false }) curl_opts.add_cmake_defines({ 'BUILD_STATIC_LIBS': true }) curl_opts.add_cmake_defines({ 'CURL_USE_LIBSSH2': false }) curl_opts.add_cmake_defines({ 'CURL_USE_LIBPSL': false }) curl_opts.add_cmake_defines({ 'CURL_DISABLE_LDAP': true }) curl_opts.add_cmake_defines({ 'CURL_USE_OPENSSL': true }) curl_opts.add_cmake_defines({ 'ENABLE_WEBSOCKETS': true }) libcurl = cmake.subproject('libcurl', options: curl_opts).dependency('libcurl_static') zlib = dependency('zlib') openssl = dependency('openssl') naunet_deps += [zlib, openssl] if is_windows curl_opts.add_cmake_defines({ 'USE_LIBIDN2': false }) curl_opts.add_cmake_defines({ 'USE_WIN32_IDN': true }) naunet_deps += [ compiler.find_library('bcrypt'), compiler.find_library('crypt32') ] else curl_opts.add_cmake_defines({ 'USE_LIBIDN2': true }) libidn2 = dependency('libidn2') naunet_deps += [libidn2] endif endif naunet_has_curl = libcurl.found() if naunet_has_curl naunet_src += [ 'src/curl/curl.c', 'src/curl/http.c', 'src/curl/websocket.c' ] naunet_deps += [libcurl] naunet_args += ['-DNAUNET_HAS_CURL'] endif endif endif if get_option('json').enabled() #jsmn = subproject('jsmn').get_variable('jsmn') #naunet_deps += [jsmn] #naunet_args += ['-DNAUNET_HAS_JSON'] jansson_found = false if 'jansson' not in get_option('force_fallback_for') and get_option('wrap_mode') != 'forcefallback' jansson = dependency('jansson', required: false, allow_fallback: false) jansson_found = jansson.found() endif if not jansson_found jansson_opts = cmake.subproject_options() reltype = is_minsize ? 'MinSizeRel' : 'Release' jansson_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : reltype }) jansson_opts.add_cmake_defines({ 'JANSSON_EXAMPLES': false }) jansson_opts.add_cmake_defines({ 'JANSSON_WITHOUT_TESTS': true }) jansson_opts.add_cmake_defines({ 'JANSSON_BUILD_DOCS': false }) jansson_opts.add_cmake_defines({ 'JANSSON_INSTALL': false }) jansson = cmake.subproject('jansson', options: jansson_opts).dependency('jansson') endif naunet_deps += [jansson] naunet_args += ['-DNAUNET_HAS_JSON'] endif if is_windows naunet_args += ['-DNAUNET_ON_WINDOWS'] if get_option('win32-compat') # https://learn.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers naunet_args += ['-DNAUNET_WIN32_COMPAT_MODE'] endif naunet_src += [ 'src/winwrap.c', 'src/util/timer/timer_windows.c', 'src/util/thread/thread_windows.c', 'src/util/file/file_stdio.c', 'src/socket/socket_windows.c' ] naunet_args += ['-DNAUNET_NEEDS_STDIO_ASSIST'] naunet_has_mmap = false naunet_deps += [ compiler.find_library('kernel32'), compiler.find_library('ws2_32') ] else naunet_src += [ 'src/util/timer/timer_linux.c', 'src/util/thread/thread_linux.c', 'src/util/file/file_linux.c', 'src/socket/socket_linux.c' ] if get_option('event-loop').enabled() naunet_src += ['src/fs_event/fs_event_inotify.c'] endif naunet_args += ['-D_GNU_SOURCE'] naunet_has_mmap = true pthreads = dependency('pthreads', required: false) if pthreads.found() naunet_deps += [pthreads] endif have_pthread_cancel = compiler.has_function('pthread_cancel', prefix: '#include ') if have_pthread_cancel naunet_args += ['-DNAUNET_HAS_THREAD_CANCEL'] endif endif naunet = declare_dependency(include_directories: naunet_inc, dependencies: naunet_deps, sources: naunet_src, compile_args: naunet_args) if get_option('tests').allowed() subdir('tests') endif