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
|
# Copyright 2021-2024 David Robillard <d@drobilla.net>
# SPDX-License-Identifier: 0BSD OR ISC
project(
'serd',
['c'],
default_options: [
'b_ndebug=if-release',
'buildtype=release',
'c_std=c99',
'c_winlibs=[]',
],
license: 'ISC',
meson_version: '>= 0.56.0',
version: '0.32.4',
)
serd_src_root = meson.current_source_dir()
serd_build_root = meson.current_build_dir()
major_version = meson.project_version().split('.')[0]
version_suffix = '-@0@'.format(major_version)
versioned_name = 'serd' + version_suffix
#######################
# Compilers and Flags #
#######################
# Required tools
pkg = import('pkgconfig')
cc = meson.get_compiler('c')
# Set global warning suppressions
warning_level = get_option('warning_level')
c_suppressions = []
if cc.get_id() in ['clang', 'emscripten']
if warning_level == 'everything'
c_suppressions += [
'-Wno-cast-align',
'-Wno-cast-function-type-strict',
'-Wno-cast-qual',
'-Wno-declaration-after-statement',
'-Wno-double-promotion',
'-Wno-format-nonliteral',
'-Wno-padded',
'-Wno-switch-default',
'-Wno-unsafe-buffer-usage',
]
if host_machine.system() == 'windows'
c_suppressions += [
'-Wno-deprecated-declarations',
'-Wno-nonportable-system-include-path',
'-Wno-unused-macros',
]
endif
endif
if warning_level in ['everything', '3']
c_suppressions += ['-Wno-nullability-extension']
if host_machine.system() == 'freebsd'
c_suppressions += ['-Wno-c11-extensions']
endif
endif
if not meson.is_cross_build()
c_suppressions += ['-Wno-poison-system-directories']
endif
elif cc.get_id() == 'gcc'
if warning_level == 'everything'
c_suppressions += [
'-Wno-cast-align',
'-Wno-cast-qual',
'-Wno-format-nonliteral',
'-Wno-inline',
'-Wno-padded',
'-Wno-switch-default',
'-Wno-unsuffixed-float-constants',
'-Wno-unused-const-variable',
]
if host_machine.system() == 'windows'
c_suppressions += ['-Wno-float-conversion']
endif
endif
elif cc.get_id() == 'msvc'
c_suppressions += [
'/experimental:external',
'/external:W0',
'/external:anglebrackets',
]
if warning_level == 'everything'
c_suppressions += [
'/wd4061', # enumerator in switch is not explicitly handled
'/wd4514', # unreferenced inline function has been removed
'/wd4710', # function not inlined
'/wd4711', # function selected for automatic inline expansion
'/wd4800', # implicit conversion from int to bool
'/wd4820', # padding added after construct
'/wd5045', # will insert Spectre mitigation for memory load
]
endif
if warning_level in ['everything', '3']
c_suppressions += [
'/wd4706', # assignment within conditional expression
]
endif
if warning_level in ['everything', '3', '2']
c_suppressions += [
'/wd4996', # POSIX name for this item is deprecated
]
endif
endif
c_suppressions = cc.get_supported_arguments(c_suppressions)
################
# Dependencies #
################
m_dep = cc.find_library('m', required: false)
##########################
# Platform Configuration #
##########################
# Use versioned name everywhere to support parallel major version installations
if host_machine.system() == 'windows'
if get_option('default_library') == 'both'
error('default_library=both is not supported on Windows')
endif
soversion = ''
else
soversion = meson.project_version().split('.')[0]
endif
# Request POSIX APIs from standard headers if necessary
system_c_args = []
if host_machine.system() in ['cygwin', 'gnu', 'linux']
system_c_args += ['-D_POSIX_C_SOURCE=200809L']
endif
# Build platform-specific configuration arguments
platform_c_args = []
if get_option('checks').disabled()
# Generic build without platform-specific features
platform_c_args += ['-DSERD_NO_DEFAULT_CONFIG']
elif get_option('checks').auto()
# Statically detect configuration from the build environment
platform_c_args += system_c_args
else
# Only use the features detected by the build system
platform_c_args += ['-DSERD_NO_DEFAULT_CONFIG'] + system_c_args
# Feature checks have a header to include and code for the body of main()
template = '#include <@0@>\nint main(void) { @1@; }'
feature_tests = {
'fileno': [
'stdio.h',
'return fileno(stdin);',
],
'posix_fadvise': [
'fcntl.h',
'posix_fadvise(0, 0, 4096, POSIX_FADV_SEQUENTIAL);',
],
'posix_memalign': [
'stdlib.h',
'void* mem=NULL; posix_memalign(&mem, 8U, 8U);',
],
}
# Define HAVE_SOMETHING symbols for all detected features
foreach name, args : feature_tests
code = template.format(args[0], args[1])
if cc.links(code, args: system_c_args, name: name)
platform_c_args += ['-DHAVE_' + name.to_upper()]
endif
endforeach
endif
###########
# Library #
###########
include_dirs = include_directories('include')
c_headers = files(
'include/serd/serd.h',
)
sources = files(
'src/base64.c',
'src/byte_source.c',
'src/env.c',
'src/n3.c',
'src/node.c',
'src/reader.c',
'src/string.c',
'src/system.c',
'src/uri.c',
'src/writer.c',
)
# Set appropriate arguments for building against the library type
extra_c_args = []
if get_option('default_library') == 'static'
extra_c_args = ['-DSERD_STATIC']
endif
# Build shared and/or static library
libserd = library(
versioned_name,
sources,
c_args: [
'-DSERD_INTERNAL',
'-DSERD_VERSION="@0@"'.format(meson.project_version()),
] + c_suppressions + extra_c_args + platform_c_args,
darwin_versions: [major_version + '.0.0', meson.project_version()],
dependencies: m_dep,
gnu_symbol_visibility: 'hidden',
include_directories: include_dirs,
install: true,
soversion: soversion,
version: meson.project_version(),
)
# Declare dependency for internal meson dependants
serd_dep = declare_dependency(
compile_args: extra_c_args,
include_directories: include_dirs,
link_with: libserd,
)
# Generage pkg-config file for external dependants
pkg.generate(
libserd,
description: 'Lightweight C library for working with RDF data',
extra_cflags: extra_c_args,
filebase: versioned_name,
name: get_option('title'),
subdirs: [versioned_name],
version: meson.project_version(),
)
# Override pkg-config dependency for internal meson dependants
meson.override_dependency(versioned_name, serd_dep)
# Install header to a versioned include directory
install_headers(c_headers, subdir: versioned_name / 'serd')
#########
# Tools #
#########
# Build serdi command line utility
if not get_option('tools').disabled()
tool_link_args = []
if get_option('static')
tool_link_args += ['-static']
endif
serdi = executable(
'serdi',
files('src/serdi.c'),
c_args: c_suppressions + platform_c_args,
dependencies: serd_dep,
install: true,
link_args: tool_link_args,
)
meson.override_find_program('serdi', serdi)
endif
# Display top-level summary (before subdirectories to appear first)
if not meson.is_subproject()
summary(
{
'Tests': not get_option('tests').disabled(),
'Tools': not get_option('tools').disabled(),
},
bool_yn: true,
section: 'Components',
)
summary(
{
'Install prefix': get_option('prefix'),
'Headers': get_option('prefix') / get_option('includedir'),
'Libraries': get_option('prefix') / get_option('libdir'),
},
section: 'Directories',
)
if not get_option('tools').disabled()
summary(
{
'Executables': get_option('prefix') / get_option('bindir'),
},
section: 'Directories',
)
endif
endif
###########
# Support #
###########
subdir('scripts')
if not get_option('tests').disabled()
subdir('test')
endif
subdir('doc')
|