1project('libpsl', 'c', 2 version : '0.21.1', 3 meson_version : '>=0.49.0') 4 5# Derived from LIBPSL_SO_VERSION in configure.ac 6lt_version = '5.3.2' 7 8cc = meson.get_compiler('c') 9 10enable_runtime = get_option('runtime') 11enable_builtin = get_option('builtin') 12 13# We need to know the CRT being used to determine what .lib files we need on 14# Visual Studio for dependencies that don't normally come with pkg-config files 15vs_crt = 'release' 16vs_crt_opt = get_option('b_vscrt') 17if vs_crt_opt in ['mdd', 'mtd'] 18 vs_crt = 'debug' 19elif vs_crt_opt == 'from_buildtype' 20 if get_option('buildtype') == 'debug' 21 vs_crt = 'debug' 22 endif 23endif 24 25notfound = dependency('', required : false) 26libidn2_dep = notfound 27libicu_dep = notfound 28libidn_dep = notfound 29libunistring = notfound 30networking_deps = notfound 31 32# FIXME: Cleanup this when Meson gets 'feature-combo': 33# https://github.com/mesonbuild/meson/issues/4566 34# Dependency fallbacks would help too: 35# https://github.com/mesonbuild/meson/pull/4595 36if ['libidn2', 'auto'].contains(enable_runtime) or ['libidn2', 'auto'].contains(enable_builtin) 37 libidn2_dep = dependency('libidn2', required : false) 38 if not libidn2_dep.found() and cc.has_header('idn2.h') 39 libidn2_dep = cc.find_library('idn2', required : false) 40 endif 41 if libidn2_dep.found() 42 if enable_runtime == 'auto' 43 enable_runtime = 'libidn2' 44 endif 45 if enable_builtin == 'auto' 46 enable_builtin = 'libidn2' 47 endif 48 elif [enable_runtime, enable_builtin].contains('libidn2') 49 error('You requested libidn2 but it is not installed.') 50 endif 51endif 52 53if ['libicu', 'auto'].contains(enable_runtime) or ['libicu', 'auto'].contains(enable_builtin) 54 libicu_dep = dependency('icu-uc', required : false) 55 if not libicu_dep.found() and cc.has_header('unicode/ustring.h') 56 # MSVC: the debug configuration of ICU generated the libraries with d suffix 57 # we must handle this and search for the right library depending on the 58 # build type. Note debugoptimized is just a release build with .pdb files enabled 59 if cc.get_id() in ['msvc', 'clang-cl'] and vs_crt == 'debug' 60 libicu_dep = cc.find_library('icuucd', required : false) 61 else 62 libicu_dep = cc.find_library('icuuc', required : false) 63 endif 64 endif 65 if libicu_dep.found() 66 if enable_runtime == 'auto' 67 enable_runtime = 'libicu' 68 endif 69 if enable_builtin == 'auto' 70 enable_builtin = 'libicu' 71 endif 72 elif [enable_runtime, enable_builtin].contains('libicu') 73 error('You requested libicu but it is not installed.') 74 endif 75endif 76 77if ['libidn', 'auto'].contains(enable_runtime) or ['libidn', 'auto'].contains(enable_builtin) 78 libidn_dep = dependency('libidn', required : false) 79 if not libidn_dep.found() and cc.has_header('idna.h') 80 libidn_dep = cc.find_library('idn', required : false) 81 endif 82 if libidn_dep.found() 83 if enable_runtime == 'auto' 84 enable_runtime = 'libidn' 85 endif 86 if enable_builtin == 'auto' 87 enable_builtin = 'libidn' 88 endif 89 elif [enable_runtime, enable_builtin].contains('libidn') 90 error('You requested libidn but it is not installed.') 91 endif 92endif 93 94if libidn2_dep.found() or libidn_dep.found() 95 # Check for libunistring, we need it for psl_str_to_utf8lower() 96 libunistring = cc.find_library('unistring') 97endif 98 99if host_machine.system() == 'windows' 100 networking_deps = cc.find_library('ws2_32') 101endif 102 103if enable_runtime == 'auto' 104 enable_runtime = 'no' 105endif 106if enable_builtin == 'auto' 107 enable_builtin = 'no' 108endif 109 110config = configuration_data() 111config.set_quoted('PACKAGE_VERSION', meson.project_version()) 112config.set('WITH_LIBIDN2', enable_runtime == 'libidn2') 113config.set('WITH_LIBICU', enable_runtime == 'libicu') 114config.set('WITH_LIBIDN', enable_runtime == 'libidn') 115config.set('BUILTIN_GENERATOR_LIBIDN2', enable_builtin == 'libidn2') 116config.set('BUILTIN_GENERATOR_LIBICU', enable_builtin == 'libicu') 117config.set('BUILTIN_GENERATOR_LIBIDN', enable_builtin == 'libidn') 118config.set('HAVE_UNISTD_H', cc.check_header('unistd.h')) 119config.set('HAVE_STDINT_H', cc.check_header('stdint.h')) 120config.set('HAVE_ALLOCA_H', cc.check_header('alloca.h')) 121config.set('HAVE_DIRENT_H', cc.check_header('dirent.h')) 122config.set('HAVE_STRINGS_H', cc.check_header('strings.h')) 123config.set('HAVE_ALLOCA', cc.has_function('alloca')) 124config.set('HAVE_STRNDUP', cc.has_function('strndup')) 125config.set('HAVE_CLOCK_GETTIME', cc.has_function('clock_gettime')) 126config.set('HAVE_FMEMOPEN', cc.has_function('fmemopen')) 127config.set('HAVE_NL_LANGINFO', cc.has_function('nl_langinfo')) 128configure_file(output : 'config.h', configuration : config) 129 130configinc = include_directories('.') 131includedir = include_directories('include') 132 133psl_distfile = get_option('psl_distfile') 134psl_file = get_option('psl_file') 135if psl_file == '' 136 psl_file = join_paths(meson.current_source_dir(), 'list', 'public_suffix_list.dat') 137endif 138psl_test_file = get_option('psl_testfile') 139if psl_test_file == '' 140 psl_test_file = join_paths(meson.current_source_dir(), 'list', 'tests', 'tests.txt') 141endif 142 143python = import('python').find_installation() 144pkgconfig = import('pkgconfig') 145 146if cc.get_id() == 'msvc' 147 if not cc.has_header_symbol('stdio.h', 'snprintf') 148 if cc.has_header_symbol('stdio.h', '_snprintf') 149 add_project_arguments('-Dsnprintf=_snprintf', language: 'c') 150 endif 151 endif 152 if cc.has_header_symbol('malloc.h', '_alloca') 153 add_project_arguments('-Dalloca=_alloca', language: 'c') 154 endif 155endif 156 157subdir('include') 158subdir('src') 159subdir('tools') 160subdir('tests') 161subdir('fuzz') 162