|
| 1 | +# Copyright © 2018 Dylan Baker |
| 2 | +# Copyright © 2018,2020 Intel Corporation |
| 3 | + |
| 4 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +# of this software and associated documentation files (the "Software"), to deal |
| 6 | +# in the Software without restriction, including without limitation the rights |
| 7 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +# copies of the Software, and to permit persons to whom the Software is |
| 9 | +# furnished to do so, subject to the following conditions: |
| 10 | + |
| 11 | +# The above copyright notice and this permission notice shall be included in |
| 12 | +# all copies or substantial portions of the Software. |
| 13 | + |
| 14 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | +# SOFTWARE. |
| 21 | + |
| 22 | +project( |
| 23 | + 'expat', |
| 24 | + 'c', |
| 25 | + license: 'MIT', |
| 26 | + version: '2.6.3', |
| 27 | + meson_version: '>= 0.54.1', |
| 28 | +) |
| 29 | + |
| 30 | +config = configuration_data() |
| 31 | +cc = meson.get_compiler('c') |
| 32 | + |
| 33 | +config.set('PACKAGE_NAME', meson.project_name()) |
| 34 | +config.set('PACKAGE_TARNAME', meson.project_name()) |
| 35 | +config.set('PACKAGE_VERSION', meson.project_version()) |
| 36 | +config.set( 'PACKAGE_BUGREPORT', '[email protected]') |
| 37 | +config.set('PACKAGE_STRING', '@0@ @1@'.format(meson.project_name(), meson.project_version())) |
| 38 | + |
| 39 | +# Define how much context to retain around the current parse point. |
| 40 | +config.set('XML_CONTEXT_BYTES', 1024) |
| 41 | + |
| 42 | +dep_libbsd = dependency('libbsd-overlay', required: get_option('use_libbsd')) |
| 43 | +if dep_libbsd.type_name() == 'internal' |
| 44 | + config.set('HAVE_ARC4RANDOM_BUF', dep_libbsd.found()) |
| 45 | + config.set('HAVE_ARC4RANDOM', dep_libbsd.found()) |
| 46 | +else |
| 47 | + config.set('HAVE_ARC4RANDOM_BUF', cc.has_function('arc4random_buf', dependencies: dep_libbsd)) |
| 48 | + config.set('HAVE_ARC4RANDOM', cc.has_function('arc4random', dependencies: dep_libbsd)) |
| 49 | +endif |
| 50 | + |
| 51 | +config.set('XML_DTD', get_option('xml_dtd')) |
| 52 | +config.set('XML_GE', get_option('xml_ge')) |
| 53 | +config.set('XML_NS', get_option('xml_ns')) |
| 54 | + |
| 55 | +foreach h : ['dlfcn', 'fcntl', 'inttypes', 'memory', 'stdint', 'stdlib', 'strings', 'string', 'sys/stat', 'sys/types', 'unistd'] |
| 56 | + config.set('HAVE_@0@_H'.format(h.underscorify().to_upper()), cc.has_header(h + '.h')) |
| 57 | +endforeach |
| 58 | + |
| 59 | +_stdc = true |
| 60 | +foreach h : ['stdlib', 'stdarg', 'string', 'float'] |
| 61 | + if not cc.has_header( '@[email protected]'.format(h)) |
| 62 | + _stdc = false |
| 63 | + break |
| 64 | + endif |
| 65 | +endforeach |
| 66 | +config.set('STDC_HEADERS', _stdc) |
| 67 | + |
| 68 | +foreach f : ['getpagesize', 'mmap', 'getrandom'] |
| 69 | + config.set('HAVE_@0@'.format(f.to_upper()), cc.has_function(f)) |
| 70 | +endforeach |
| 71 | + |
| 72 | +if host_machine.endian() == 'little' |
| 73 | + config.set('BYTEORDER', 1234) |
| 74 | +else |
| 75 | + config.set('BYTEORDER', 4321) |
| 76 | +endif |
| 77 | + |
| 78 | +if not cc.has_header_symbol('sys/types.h', 'off_t') |
| 79 | + config.set('off_t', 'long') |
| 80 | +endif |
| 81 | + |
| 82 | +config.set('HAVE_SYSCALL_GETRANDOM', cc.has_header_symbol('sys/syscall.h', 'SYS_getrandom')) |
| 83 | + |
| 84 | +# Install headers |
| 85 | +config_h = configure_file( |
| 86 | + input: 'expat_config.h.cmake', |
| 87 | + output: 'expat_config.h', |
| 88 | + format: 'cmake@', |
| 89 | + configuration: config, |
| 90 | +) |
| 91 | +install_headers('lib/expat.h', 'lib/expat_external.h', config_h) |
| 92 | + |
| 93 | +expat_static_args = [] |
| 94 | + |
| 95 | +add_project_arguments('-DXML_ENABLE_VISIBILITY=1', language: 'c') |
| 96 | +add_project_arguments('-DHAVE_EXPAT_CONFIG_H', language: 'c') |
| 97 | +add_project_arguments(cc.get_supported_arguments('-fno-strict-aliasing'), language: 'c') |
| 98 | +if cc.get_argument_syntax() == 'msvc' |
| 99 | + add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', '-wd4996', language: 'c') |
| 100 | +endif |
| 101 | + |
| 102 | +if host_machine.system() == 'windows' |
| 103 | + add_project_arguments('-DXMLCALL=WINAPIV', language: 'c') |
| 104 | + add_project_arguments('-DXMLIMPORT=__declspec(dllexport)', language: 'c') |
| 105 | + if get_option('default_library') == 'static' |
| 106 | + add_project_arguments('-DXML_STATIC', language: 'c') |
| 107 | + expat_static_args += '-DXML_STATIC' |
| 108 | + endif |
| 109 | +else |
| 110 | + add_project_arguments('-DXMLIMPORT=__attribute__ ((visibility("default")))', language: 'c') |
| 111 | + if get_option('use_dev_urandom') |
| 112 | + add_project_arguments('-DXML_DEV_URANDOM', language: 'c') |
| 113 | + endif |
| 114 | +endif |
| 115 | + |
| 116 | +incdir = include_directories('lib') |
| 117 | + |
| 118 | +libexpat = library( |
| 119 | + 'expat', |
| 120 | + 'lib/xmlparse.c', |
| 121 | + 'lib/xmlrole.c', |
| 122 | + 'lib/xmltok.c', |
| 123 | + include_directories: incdir, |
| 124 | + dependencies: dep_libbsd, |
| 125 | + version: '1.9.3', |
| 126 | + soversion: host_machine.system() != 'windows' ? '1' : '', |
| 127 | + install: true, |
| 128 | + gnu_symbol_visibility: 'hidden', |
| 129 | +) |
| 130 | + |
| 131 | +expat_dep = declare_dependency( |
| 132 | + link_with: libexpat, |
| 133 | + include_directories: incdir, |
| 134 | + compile_args: expat_static_args, |
| 135 | +) |
| 136 | + |
| 137 | +pkg = import('pkgconfig') |
| 138 | +pkg.generate(libexpat) |
| 139 | + |
| 140 | +if get_option('build_tests') |
| 141 | + add_languages('cpp') |
| 142 | + |
| 143 | + libtest = static_library( |
| 144 | + 'libtest', |
| 145 | + 'tests/chardata.c', |
| 146 | + 'tests/memcheck.c', |
| 147 | + 'tests/minicheck.c', |
| 148 | + 'tests/structdata.c', |
| 149 | + include_directories: incdir, |
| 150 | + ) |
| 151 | + |
| 152 | + test( |
| 153 | + 'runtests', |
| 154 | + executable( |
| 155 | + 'runtests', |
| 156 | + 'tests/runtests.c', |
| 157 | + include_directories: incdir, |
| 158 | + link_with: [libtest, libexpat], |
| 159 | + ), |
| 160 | + ) |
| 161 | + test( |
| 162 | + 'runtestspp', |
| 163 | + executable( |
| 164 | + 'runtestspp', |
| 165 | + 'tests/runtestspp.cpp', |
| 166 | + include_directories: incdir, |
| 167 | + link_with: [libtest, libexpat], |
| 168 | + ), |
| 169 | + ) |
| 170 | +endif |
| 171 | + |
| 172 | +# TODO: tools, examples, tests, docs |
| 173 | +# These are probably not necessary for a wrap, but someone might have use for |
| 174 | +# them |
0 commit comments