-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeson.build
145 lines (123 loc) · 3.62 KB
/
meson.build
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
# Copyright 2020-2023 David Robillard <d@drobilla.net>
# SPDX-License-Identifier: 0BSD OR ISC
project(
'rerex',
['c'],
default_options: [
'b_ndebug=if-release',
'buildtype=release',
'c_std=c99',
],
license: 'ISC',
meson_version: '>= 0.54.0',
version: '0.0.1',
)
rerex_src_root = meson.current_source_dir()
rerex_build_root = meson.current_build_dir()
major_version = meson.project_version().split('.')[0]
version_suffix = '-@0@'.format(major_version)
versioned_name = 'rerex' + version_suffix
#######################
# Compilers and Flags #
#######################
# Required tools
pkg = import('pkgconfig')
cc = meson.get_compiler('c')
# Set global warning suppressions
c_suppressions = []
warning_level = get_option('warning_level')
if cc.get_id() == 'clang'
if warning_level == 'everything'
c_suppressions += [
'-Wno-declaration-after-statement',
'-Wno-unsafe-buffer-usage',
]
if not meson.is_cross_build()
c_suppressions += [
'-Wno-poison-system-directories',
]
endif
endif
elif cc.get_id() == 'msvc'
if warning_level == 'everything'
c_suppressions += [
'/wd4711', # function selected for automatic inline expansion
'/wd4800', # implicit conversion to bool
'/wd5045', # will insert Spectre mitigation
]
endif
if warning_level in ['everything', '3']
c_suppressions += [
'/wd4706', # assignment within conditional expression
]
endif
endif
c_suppressions = cc.get_supported_arguments(c_suppressions)
##########################
# 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
###########
# Library #
###########
include_dirs = include_directories(['include'])
c_headers = files('include/rerex/rerex.h')
sources = files('src/rerex.c')
# Set appropriate arguments for building against the library type
extra_c_args = []
if get_option('default_library') == 'static'
extra_c_args = ['-DREREX_STATIC']
endif
# Build shared and/or static library
librerex = library(
versioned_name,
sources,
c_args: c_suppressions + extra_c_args + ['-DREREX_INTERNAL'],
gnu_symbol_visibility: 'hidden',
include_directories: include_dirs,
install: true,
soversion: soversion,
version: meson.project_version(),
)
# Declare dependency for internal meson dependants
rerex_dep = declare_dependency(
compile_args: extra_c_args,
include_directories: include_dirs,
link_with: librerex,
)
# Generage pkg-config file for external dependants
pkg.generate(
librerex,
description: 'A simple and efficient regular expression implementation',
extra_cflags: extra_c_args,
filebase: versioned_name,
name: 'Rerex',
subdirs: [versioned_name],
version: meson.project_version(),
)
# Override pkg-config dependency for internal meson dependants
meson.override_dependency(versioned_name, rerex_dep)
# Install header to a versioned include directory
install_headers(c_headers, subdir: versioned_name / 'rerex')
#########
# Tests #
#########
# Build and run tests
if not get_option('tests').disabled()
subdir('test')
endif
# Display configuration summary
if not meson.is_subproject()
summary('Tests', not get_option('tests').disabled(), bool_yn: true)
summary('Install prefix', get_option('prefix'))
summary('Headers', get_option('prefix') / get_option('includedir'))
summary('Libraries', get_option('prefix') / get_option('libdir'))
endif