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.
This commit is contained in:
Chun-wei Fan 2018-12-11 09:26:13 +08:00
parent 6a47e7c527
commit df873db543
3 changed files with 20 additions and 4 deletions

View File

@ -12,6 +12,7 @@ libidn2_dep = notfound
libicu_dep = notfound libicu_dep = notfound
libidn_dep = notfound libidn_dep = notfound
libunistring = notfound libunistring = notfound
networking_deps = notfound
# FIXME: Cleanup this when Meson gets 'feature-combo': # FIXME: Cleanup this when Meson gets 'feature-combo':
# https://github.com/mesonbuild/meson/issues/4566 # https://github.com/mesonbuild/meson/issues/4566
@ -73,6 +74,10 @@ if libidn2_dep.found() or libidn_dep.found()
libunistring = cc.find_library('unistring') libunistring = cc.find_library('unistring')
endif endif
if host_machine.system() == 'windows'
networking_deps = cc.find_library('ws2_32')
endif
if enable_runtime == 'auto' if enable_runtime == 'auto'
enable_runtime = 'no' enable_runtime = 'no'
endif endif
@ -114,6 +119,17 @@ endif
python = import('python').find_installation() python = import('python').find_installation()
pkgconfig = import('pkgconfig') 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('include')
subdir('src') subdir('src')
subdir('tools') subdir('tools')

View File

@ -3,7 +3,7 @@ psl_make_dafsa = find_program('psl-make-dafsa')
suffixes_dafsa_h = custom_target('suffixes_dafsa.h', suffixes_dafsa_h = custom_target('suffixes_dafsa.h',
input : psl_file, input : psl_file,
output : 'suffixes_dafsa.h', output : 'suffixes_dafsa.h',
command : [python, psl_make_dafsa, '--output-format=cxx+', '@INPUT@', '@OUTPUT@']) command : [psl_make_dafsa, '--output-format=cxx+', '@INPUT@', '@OUTPUT@'])
sources = [ sources = [
'lookup_string_in_fixed_set.c', 'lookup_string_in_fixed_set.c',
@ -19,7 +19,7 @@ cargs = [
libpsl = library('psl', sources, suffixes_dafsa_h, libpsl = library('psl', sources, suffixes_dafsa_h,
include_directories : [configinc, includedir], include_directories : [configinc, includedir],
c_args : cargs, c_args : cargs,
dependencies : [libidn2_dep, libidn_dep, libicu_dep, libunistring], dependencies : [libidn2_dep, libidn_dep, libicu_dep, libunistring, networking_deps],
) )
pkgconfig.generate(libpsl, pkgconfig.generate(libpsl,

View File

@ -1,12 +1,12 @@
psl_dafsa = custom_target('psl.dafsa', psl_dafsa = custom_target('psl.dafsa',
input : psl_file, input : psl_file,
output : 'psl.dafsa', 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', psl_ascii_dafsa = custom_target('psl_ascii.dafsa',
input : psl_file, input : psl_file,
output : 'psl_ascii.dafsa', 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 = [ tests_cargs = [
'-DHAVE_CONFIG_H', '-DHAVE_CONFIG_H',