Hash :
b4b4162f
Author :
Date :
2024-06-15T19:41:08
meson: fix compilation on BSDs with icu+iconv on BSDs, icu is installed and included from /usr/local. When found, libiconv headers override the normal ones and thus result in a missing link. Work around this oddity and add the link. Signed-off-by: Rosen Penev <rosenp@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
project(
'libxml2',
'c',
version: '2.13.0',
license: 'MIT',
default_options: ['buildtype=debug', 'warning_level=3'],
meson_version: '>= 0.61',
)
v_array = meson.project_version().split('.')
v_maj = v_array[0]
v_min = v_array[1]
v_mic = v_array[2]
v_nbr = v_maj.to_int() * 10000 + v_min.to_int() * 100 + v_mic.to_int()
v_extra = ''
r = run_command('git', 'describe', check: false)
if (r.returncode() == 0)
v_extra = '-GIT' + r.stdout().strip()
endif
# install paths
dir_prefix = get_option('prefix')
dir_bin = dir_prefix / get_option('bindir')
dir_include = dir_prefix / get_option('includedir')
dir_pkginclude = dir_include / meson.project_name()
dir_lib = dir_prefix / get_option('libdir')
dir_data = dir_prefix / get_option('datadir')
dir_doc = dir_data / 'doc' / 'libxml2'
dir_locale = dir_prefix / get_option('localedir')
# host
host_os = host_machine.system()
bsd = ['freebsd', 'openbsd', 'dragonfly']
cygwin = 'cygwin'
windows = 'windows'
sys_bsd = bsd.contains(host_os)
sys_cygwin = cygwin.contains(host_os)
sys_windows = windows.contains(host_os)
libxml2_cflags = []
xml_cflags = ''
dep_args = []
if sys_cygwin or sys_windows
if get_option('default_library') == 'static'
xml_cflags = '-DLIBXML_STATIC'
libxml2_cflags += '-DLIBXML_STATIC'
dep_args += '-DLIBXML_STATIC'
endif
endif
# binaries
cc = meson.get_compiler('c')
# options
want_c14n = get_option('c14n')
want_catalog = get_option('catalog')
want_debug = get_option('debuging')
want_history = get_option('history')
want_html = get_option('html')
want_http = get_option('http')
want_ipv6 = get_option('ipv6')
want_iso8859x = get_option('iso8859x')
want_legacy = get_option('legacy')
want_output = get_option('output')
want_pattern = get_option('pattern')
want_push = get_option('push')
want_python = get_option('python')
want_reader = get_option('reader')
want_readline = get_option('readline')
want_regexps = get_option('regexps')
want_sax1 = get_option('sax1')
want_schemas = get_option('schemas')
want_schematron = get_option('schematron')
want_thread_alloc = get_option('thread-alloc')
want_tls = get_option('tls')
want_valid = get_option('valid')
want_writer = get_option('writer')
want_xinclude = get_option('xinclude')
want_xpath = get_option('xpath')
want_xptr = get_option('xptr')
# TODO: Options should be three-valued: "yes", "no", default
# TODO: Legacy defaults
# hard dependencies on options
if want_c14n == true
if want_output == false
message('-Dc14n=true overrides -Doutput')
endif
want_output = true
if want_xpath == false
message('-Dc14n=true overrides -Dxpath')
endif
want_xpath = true
endif
if want_schemas == true
if want_pattern == false
message('-Dschemas=true overrides -Dpattern')
endif
want_pattern = true
if want_regexps == false
message('-Dschemas=true overrides -Dregexps')
endif
want_regexps = true
endif
if want_schematron == true
if want_pattern == false
message('-Dschematron=true overrides -Dpattern')
endif
want_pattern = true
if want_xpath == false
message('-Dschematron=true overrides -Dxpath')
endif
want_xpath = true
endif
if want_reader == true
if want_push == false
message('-Dreader=true overrides -Dpush')
endif
want_push = true
endif
if want_writer == true
if want_output == false
message('-Dwriter=true overrides -Doutput')
endif
want_output = true
if want_push == false
message('-Dwriter=true overrides -Dpush')
endif
want_push = true
endif
if want_xinclude == true
if want_xpath == false
message('-Dxinclude=true overrides -Dxpath')
endif
want_xpath = true
endif
if want_xptr == true
if want_xpath == false
message('-Dxptr=true overrides -Dxpath')
endif
want_xpath = true
endif
# minimum dependencies
if get_option('minimum')
# TODO: This is should allow other options
want_c14n = false
want_catalog = false
want_debug = false
want_history = false
want_html = false
want_http = false
want_ipv6 = false
want_iso8859x = false
want_output = false
want_pattern = false
want_push = false
want_python = false
want_reader = false
want_readline = false
want_regexps = false
want_sax1 = false
want_schemas = false
want_schematron = false
want_thread_alloc = false
want_valid = false
want_writer = false
want_xinclude = false
want_xpath = false
want_xptr = false
else
# Disable dependent modules
if want_output == false
want_c14n = false
want_writer = false
endif
if want_pattern == false
want_schemas = false
want_schematron = false
endif
if want_push == false
want_reader = false
want_writer = false
endif
if want_regexps == false
want_schemas = false
endif
if want_xpath == false
want_c14n = false
want_schematron = false
want_xinclude = false
want_xptr = false
endif
endif
cflags_try = []
### workaround for native compilers, see configure.ac
if cc.get_argument_syntax() == 'gcc'
cflags_try += [
'-Wshadow',
'-Wpointer-arith',
'-Wcast-align',
'-Wwrite-strings',
'-Wstrict-prototypes',
'-Wmissing-prototypes',
'-Wno-long-long',
'-Wno-format-extra-args',
]
if host_machine.cpu_family() == 'alpha'
cflags_try += '-mieee'
endif
else
if host_machine.cpu_family() == 'alpha'
cflags_try += '-ieee'
elif host_machine.cpu_family() == 'parisc'
cflags_try += '-Wp,-H30000'
endif
endif
foreach cf : cflags_try
if cc.has_argument(cf)
libxml2_cflags += cf
endif
endforeach
# configuration
#
# X : done
# N : not done
#
# [X] config.h.in
# [X] include/libxml/xmlversion.h.in
# [N] libxml-2.0-uninstalled.pc.in
# [X] libxml-2.0.pc.in
# [X] libxml2-config.cmake.in
# [X] python/setup.py.in
# [N] xml2-config.in
## config.h
config_h = configuration_data()
config_h.set_quoted('PACKAGE_NAME', meson.project_name())
config_h.set_quoted('PACKAGE_VERSION', meson.project_version())
config_h.set_quoted('PACKAGE_BIN_DIR', dir_bin)
config_h.set_quoted('PACKAGE_LIB_DIR', dir_lib)
config_h.set_quoted('PACKAGE_DATA_DIR', dir_data)
config_h.set_quoted('LOCALEDIR', dir_locale)
# header files
xml_check_headers = [
'stdint.h',
'fcntl.h',
'unistd.h',
'sys/stat.h',
'sys/mman.h',
'sys/socket.h',
'netinet/in.h',
'arpa/inet.h',
'netdb.h',
'sys/select.h',
'poll.h',
'sys/time.h',
'sys/timeb.h',
'dl.h',
'dlfcn.h',
'glob.h',
]
foreach header : xml_check_headers
if cc.has_header(header)
config_h.set10('HAVE_' + header.underscorify().to_upper(), true)
endif
endforeach
# library functions
xml_check_functions = [
# fct | header
['gettimeofday', 'sys/time.h'],
['ftime', 'sys/timeb.h'],
['stat', 'sys/stat.h'],
['mmap', 'sys/mman.h'],
['munmap', 'sys/mman.h'],
]
foreach function : xml_check_functions
if cc.has_header_symbol(function[1], function[0])
config_h.set10('HAVE_' + function[0].to_upper(), true)
endif
endforeach
# library
config_dir = [include_directories('.'), include_directories('include')]
## dependencies
xml_deps = []
### math library
if sys_windows == false
m_dep = cc.find_library('m', required: false)
if m_dep.found()
xml_deps += m_dep
endif
endif
### thread local storage
if want_tls == true
tls_src = '''
#include <threads.h>
int main()
{
_Thread_local int v;
return 0;
}
'''
res = cc.compiles(tls_src, name: '_Thread_local')
if res == true
config_h.set('XML_THREAD_LOCAL', '_Thread_local')
else
tls_src = '''
int main()
{
__thread int v;
return 0;
}
'''
res = cc.compiles(tls_src, name: '__thread')
if res == true
config_h.set('XML_THREAD_LOCAL', '__thread')
else
tls_src = '''
int main()
{
__declspec(thread) int v;
return 0;
}
'''
res = cc.compiles(tls_src, name: '__declspec(thread)')
if res == true
config_h.set('XML_THREAD_LOCAL', '__declspec(thread)')
else
want_tls = false
endif
endif
endif
endif
### __attribute__((destructor))
if cc.has_function_attribute('destructor')
config_h.set10('HAVE_ATTRIBUTE_DESTRUCTOR', true)
config_h.set('ATTRIBUTE_DESTRUCTOR', '__attribute__((destructor))')
endif
### DSO support
if sys_cygwin == true
module_extension = '.dll'
elif sys_windows == true
module_extension = '.dll'
else
module_extension = '.so'
endif
dl_dep = dependency('', required: false)
if not get_option('minimum')
if host_machine.system() != 'windows'
if meson.version().version_compare('>=0.62')
dl_dep = dependency('dl', required: get_option('modules'))
else
dl_dep = cc.find_library('dl', required: get_option('modules'))
endif
if dl_dep.found()
config_h.set10('HAVE_DLOPEN', true)
xml_deps += dl_dep
endif
elif get_option('modules').allowed()
dl_dep = declare_dependency()
endif
endif
### threads
threads_dep = dependency('', required: false)
if not get_option('minimum')
if host_machine.system() != 'windows'
threads_dep = dependency('threads', required: get_option('threads'))
if threads_dep.found()
config_h.set10('HAVE_PTHREAD_H', true)
xml_deps += threads_dep
endif
elif get_option('threads').allowed()
threads_dep = declare_dependency()
endif
endif
want_thread_alloc = threads_dep.found()
### xmllint shell history
xmllint_deps = []
if want_readline == true
termlib_lib = ['ncurses', 'curses', 'termcap', 'terminfo', 'termlib']
foreach tl : termlib_lib
termlib_dep = cc.find_library(tl, required: false)
if (
termlib_dep.found()
and cc.has_function('tputs', dependencies: termlib_dep)
)
xmllint_deps += termlib_dep
config_h.set10('HAVE_LIB' + tl.underscorify().to_upper(), true)
break
endif
endforeach
readline_dep = dependency('readline', required: false)
if readline_dep.found()
xmllint_deps += readline_dep
config_h.set10('HAVE_LIBREADLINE', true)
endif
if want_history == true
history_dep = dependency('history', required: false)
if history_dep.found()
xmllint_deps += history_dep
config_h.set10('HAVE_LIBHISTORY', true)
endif
endif
endif
### crypto
if sys_windows == true
bcrypt_dep = cc.find_library('bcrypt', required: true)
xml_deps += bcrypt_dep
endif
### inet
if want_http == true
if sys_windows == true
ws2_dep = cc.find_library('ws2_32', required: true)
xml_deps += ws2_dep
else
has_in_libc = cc.has_function('gethostbyname')
if has_in_libc == false
nsl_dep = cc.find_library('nsl', required: true)
if nsl_dep.found()
has_in_nsl = cc.has_function(
'gethostbyname',
dependencies: nsl_dep,
required: false,
)
if has_in_nsl == true
xml_deps += nsl_dep
endif
endif
endif
endif
### socket length
socklen_src = '''
#include <stddef.h>
#ifdef _WIN32
#include <ws2tcpip.h>
#else
#include <sys/socket.h>
#endif
int main()
{
(void)getsockopt (1, 1, 1, NULL, (socklen_t *)NULL);
return 0;
}
'''
res = cc.compiles(socklen_src, name: 'socket length as socklen_t')
if res == true
config_h.set('XML_SOCKLEN_T', 'socklen_t')
else
socklen_src = '''
#include <stddef.h>
#include <sys/socket.h>
int main()
{
(void)getsockopt (1, 1, 1, NULL, (size_t *)NULL);
return 0;
}
'''
res = cc.compiles(socklen_src, name: 'socket length as size_t')
if res == true
config_h.set('XML_SOCKLEN_T', 'size_t')
else
socklen_src = '''
#include <stddef.h>
#include <sys/socket.h>
int main()
{
(void)getsockopt (1, 1, 1, NULL, (int *)NULL);
return 0;
}
'''
res = cc.compiles(socklen_src, name: 'socket length as int')
if res == false
message('could not determine socket length type, use int')
endif
config_h.set('XML_SOCKLEN_T', 'int')
endif
endif
if want_ipv6 == true
### IPV6 on Windows has been supported since Windows XP SP1 (around 2003)
### see:
### https://learn.microsoft.com/en-us/windows/win32/winsock/ipv6-support-2
### nevertheless, we check it like autotools
ipv6_src = '''
#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#endif
int main()
{
struct sockaddr_storage ss;
socket(AF_INET6, SOCK_STREAM, 0);
getaddrinfo(0, 0, 0, 0);
return 0;
}
'''
res = cc.compiles(ipv6_src, name: 'support for IPV6')
if res == true
config_h.set10('SUPPORT_IP6', true)
endif
endif
endif
### zlib
if not get_option('minimum')
zlib_dep = dependency('zlib', required: get_option('zlib'))
else
zlib_dep = dependency('', required: false)
endif
xml_deps += zlib_dep
### lzma
if not get_option('minimum')
lzma_dep = dependency('liblzma', required: get_option('lzma'))
else
lzma_dep = dependency('', required: false)
endif
xml_deps += lzma_dep
# icu
icu_dep = dependency('icu-i18n', method: 'pkg-config', required: get_option('icu'))
if icu_dep.found()
defs = icu_dep.get_variable(pkgconfig: 'DEFS')
if cc.has_argument(defs)
libxml2_cflags += defs
endif
endif
xml_deps += icu_dep
### iconv
if not get_option('minimum')
# this is a hack for the BSDs. The iconv dependency works as long as libiconv is not in the include path.
if sys_bsd and icu_dep.found()
iconv_dep = cc.find_library('iconv', dirs: icu_dep.get_variable(pkgconfig: 'includedir'), required: get_option('iconv'))
else
iconv_dep = dependency('iconv', required: get_option('iconv'))
endif
else
iconv_dep = dependency('', required: false)
endif
xml_deps += iconv_dep
if not iconv_dep.found() and want_iso8859x == false
want_iso8859x = false
else
want_iso8859x = true
endif
subdir('include/libxml')
# Set config_h after all subdirs and dependencies have set values
configure_file(output: 'config.h', configuration: config_h)
## libxml2 library
xml_src = [
'buf.c',
'chvalid.c',
'dict.c',
'entities.c',
'encoding.c',
'error.c',
'globals.c',
'hash.c',
'list.c',
'parser.c',
'parserInternals.c',
'SAX2.c',
'threads.c',
'tree.c',
'uri.c',
'valid.c',
'xmlIO.c',
'xmlmemory.c',
'xmlstring.c',
]
xml_opt_src = [
[want_c14n, ['c14n.c']],
[want_catalog, ['catalog.c']],
[want_debug, ['debugXML.c']],
[want_html, ['HTMLparser.c', 'HTMLtree.c']],
[want_http, ['nanohttp.c']],
[want_legacy, ['legacy.c']],
[lzma_dep.found(), ['xzlib.c']],
[dl_dep.found(), ['xmlmodule.c']],
[want_output, ['xmlsave.c']],
[want_pattern, ['pattern.c']],
[want_reader, ['xmlreader.c']],
[want_regexps, ['xmlregexp.c', 'xmlunicode.c']],
[want_schemas, ['relaxng.c', 'xmlschemas.c', 'xmlschemastypes.c']],
[want_schemas and not want_xpath, ['xpath.c']],
[want_schematron, ['schematron.c']],
[want_writer, ['xmlwriter.c']],
[want_xinclude, ['xinclude.c']],
[want_xpath, ['xpath.c']],
[want_xptr, ['xlink.c', 'xpointer.c']],
]
foreach file : xml_opt_src
want = file[0]
src = file[1]
if want == true
if src.length() > 1
foreach s : src
xml_src += s
endforeach
else
xml_src += src
endif
endif
endforeach
xml_lib = library(
'xml2',
files(xml_src),
c_args: libxml2_cflags,
dependencies: xml_deps,
include_directories: config_dir,
install: true,
version: meson.project_version(),
)
dep_inc = include_directories('include')
xml_dep = declare_dependency(include_directories: dep_inc, link_with: xml_lib, compile_args: dep_args)
meson.override_dependency('libxml-2.0', xml_dep)
## xmllint tool
executable(
'xmllint',
files('xmllint.c', 'shell.c'),
dependencies: [xml_dep, xmllint_deps],
include_directories: config_dir,
install: true,
)
## xmlcatalog tool
executable(
'xmlcatalog',
files('xmlcatalog.c'),
dependencies: [xml_dep, xmllint_deps],
include_directories: config_dir,
install: true,
)
## testdso module
testdso_mod = shared_module(
'testdso',
files('testdso.c'),
build_rpath: get_option('libdir'),
include_directories: config_dir,
name_prefix: '',
)
## tests
checks = [
'runsuite',
'runtest',
'runxmlconf',
# Disabled for now, see #694
# 'testModule',
'testapi',
'testchar',
'testdict',
'testlimits',
'testparser',
'testrecurse',
]
foreach check : checks
exe = executable(
check,
files(check + '.c'),
dependencies: [threads_dep, xml_dep],
include_directories: config_dir,
)
if check != 'testlimits'
test(check, exe, timeout: 0, workdir: meson.current_source_dir())
endif
endforeach
subdir('example')
subdir('doc')
if want_python == true
subdir('python')
endif
## pc files
pkgmod = import('pkgconfig')
pkgmod.generate(
xml_lib,
description: 'libXML library version2.',
filebase: 'libxml-2.0',
name: 'libXML',
variables: 'modules=' + dl_dep.found().to_string('1', '0'),
)
## libxml2-config.cmake file
config_cmake = configuration_data()
config_cmake.set('LIBXML_MAJOR_VERSION', v_maj)
config_cmake.set('LIBXML_MINOR_VERSION', v_min)
config_cmake.set('LIBXML_MICRO_VERSION', v_mic)
config_cmake.set('VERSION', meson.project_version())
config_cmake.set('WITH_ICONV', iconv_dep.found().to_int().to_string())
config_cmake.set('WITH_ICU', icu_dep.found().to_int().to_string())
config_cmake.set('WITH_LZMA', lzma_dep.found().to_int().to_string())
config_cmake.set('WITH_MODULES', dl_dep.found().to_int().to_string())
config_cmake.set('WITH_THREADS', threads_dep.found().to_int().to_string())
config_cmake.set('WITH_ZLIB', zlib_dep.found().to_int().to_string())
config_cmake.set('XML_CFLAGS', xml_cflags)
configure_file(
input: 'libxml2-config.cmake.in',
output: 'libxml2-config.cmake',
configuration: config_cmake,
install_dir: dir_lib / 'cmake' / 'libxml2',
)
# summary
summary(
{
'OS': host_os,
'c14n': want_c14n,
'catalog': want_catalog,
'debug': want_debug,
'history': want_history,
'html': want_html,
'http': want_http,
'iconv': iconv_dep.found(),
'icu': icu_dep.found(),
'ipv6': want_ipv6,
'iso8859x': want_iso8859x,
'legacy': want_legacy,
'lzma': lzma_dep.found(),
'modules': dl_dep.found(),
'output': want_output,
'pattern': want_pattern,
'push': want_push,
'python': want_python,
'reader': want_reader,
'readline': want_readline,
'regexps': want_regexps,
'sax1': want_sax1,
'schemas': want_schemas,
'schematron': want_schematron,
'threads': threads_dep.found(),
'thread-alloc': want_thread_alloc,
'tls': want_tls,
'valid': want_valid,
'writer': want_writer,
'xinclude': want_xinclude,
'xpath': want_xpath,
'xptr': want_xptr,
'zlib': zlib_dep.found(),
},
section: 'Configuration Options Summary:',
)