From df873db5437a2252d32d20931bc3f01cabc4a5ac Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 11 Dec 2018 09:26:13 +0800 Subject: [PATCH] meson: Ensure things build with Windows We must link to ws2_32.lib for all Windows builds, and we need to use workarounds for alloca() and snprintf() since Visual Studio uses _alloca() for alloca() and provides snprintf() only on Visual Studio 2015 or later, meaning that we need to use _snprintf() here. Also fix the parts where we run the Python scripts to generate items, since those scripts already have shebang lines for Meson to pick up. --- meson.build | 16 ++++++++++++++++ src/meson.build | 4 ++-- tests/meson.build | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index fffc3bb..4c1e57d 100644 --- a/meson.build +++ b/meson.build @@ -12,6 +12,7 @@ libidn2_dep = notfound libicu_dep = notfound libidn_dep = notfound libunistring = notfound +networking_deps = notfound # FIXME: Cleanup this when Meson gets 'feature-combo': # https://github.com/mesonbuild/meson/issues/4566 @@ -73,6 +74,10 @@ if libidn2_dep.found() or libidn_dep.found() libunistring = cc.find_library('unistring') endif +if host_machine.system() == 'windows' + networking_deps = cc.find_library('ws2_32') +endif + if enable_runtime == 'auto' enable_runtime = 'no' endif @@ -114,6 +119,17 @@ endif python = import('python').find_installation() pkgconfig = import('pkgconfig') +if cc.get_id() == 'msvc' + if not cc.has_header_symbol('stdio.h', 'snprintf') + if cc.has_header_symbol('stdio.h', '_snprintf') + add_project_arguments('-Dsnprintf=_snprintf', language: 'c') + endif + endif + if cc.has_header_symbol('malloc.h', '_alloca') + add_project_arguments('-Dalloca=_alloca', language: 'c') + endif +endif + subdir('include') subdir('src') subdir('tools') diff --git a/src/meson.build b/src/meson.build index 6bb25b5..e8b55c2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -3,7 +3,7 @@ psl_make_dafsa = find_program('psl-make-dafsa') suffixes_dafsa_h = custom_target('suffixes_dafsa.h', input : psl_file, output : 'suffixes_dafsa.h', - command : [python, psl_make_dafsa, '--output-format=cxx+', '@INPUT@', '@OUTPUT@']) + command : [psl_make_dafsa, '--output-format=cxx+', '@INPUT@', '@OUTPUT@']) sources = [ 'lookup_string_in_fixed_set.c', @@ -19,7 +19,7 @@ cargs = [ libpsl = library('psl', sources, suffixes_dafsa_h, include_directories : [configinc, includedir], c_args : cargs, - dependencies : [libidn2_dep, libidn_dep, libicu_dep, libunistring], + dependencies : [libidn2_dep, libidn_dep, libicu_dep, libunistring, networking_deps], ) pkgconfig.generate(libpsl, diff --git a/tests/meson.build b/tests/meson.build index f37ce30..b0508a1 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,12 +1,12 @@ psl_dafsa = custom_target('psl.dafsa', input : psl_file, output : 'psl.dafsa', - command : [python, psl_make_dafsa, '--output-format=binary', '@INPUT@', '@OUTPUT@']) + command : [psl_make_dafsa, '--output-format=binary', '@INPUT@', '@OUTPUT@']) psl_ascii_dafsa = custom_target('psl_ascii.dafsa', input : psl_file, output : 'psl_ascii.dafsa', - command : [python, psl_make_dafsa, '--output-format=binary', '--encoding=ascii', '@INPUT@', '@OUTPUT@']) + command : [psl_make_dafsa, '--output-format=binary', '--encoding=ascii', '@INPUT@', '@OUTPUT@']) tests_cargs = [ '-DHAVE_CONFIG_H',