-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmeson.build
More file actions
120 lines (107 loc) · 3.01 KB
/
Copy pathmeson.build
File metadata and controls
120 lines (107 loc) · 3.01 KB
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
project(
'canfigger',
'c',
version: '0.3.3',
meson_version: '>= 0.48.0',
license: 'MIT',
default_options: ['warning_level=3', 'c_std=c99'],
)
cc = meson.get_compiler('c')
extra_flags = [
'-fno-common',
'-Wshadow',
'-Wstrict-overflow=2',
'-Wformat-security',
'-Wformat-overflow=2',
'-Wunused-result',
'-Werror=odr',
'-Werror=lto-type-mismatch',
'-Werror=strict-aliasing',
]
add_project_arguments(cc.get_supported_arguments(extra_flags), language: 'c')
# Suppress MSVC C4996 deprecation warnings for standard C functions like strerror()
if cc.get_id() == 'msvc'
add_project_arguments('/D_CRT_SECURE_NO_WARNINGS', language: 'c')
endif
# Parse version components
version_components = meson.project_version().split('.')
major_version = version_components[0]
minor_version = version_components[1]
patch_version = version_components[2]
conf = configuration_data()
conf.set('CANFIGGER_VERSION_MAJOR', major_version)
conf.set('CANFIGGER_VERSION_MINOR', minor_version)
conf.set('CANFIGGER_VERSION_PATCH', patch_version)
config_h = configure_file(output: 'canfigger_version.h', configuration: conf)
src = ('canfigger.c')
buildtarget = library(
meson.project_name(),
src,
version: meson.project_version(),
install: not meson.is_subproject(),
)
# How to use in a superproject and other info
# https://mesonbuild.com/Subprojects.html
canfigger_dep = declare_dependency(
include_directories: include_directories('.'),
link_with: buildtarget,
)
if not meson.is_subproject()
if get_option('build_examples')
examples = ['example-01', 'example-02']
foreach ex : examples
example = executable(
ex,
ex + '.c',
dependencies: canfigger_dep,
c_args: '-DSOURCE_DIR="@0@"'.format(meson.current_source_dir()),
)
if get_option('build_tests')
test('test_' + ex, example)
endif
endforeach
subdir('examples')
endif
pkg = import('pkgconfig')
pkg.generate(
buildtarget,
description: 'Simple configuration file parser library',
subdirs: meson.project_name(),
)
install_headers('canfigger.h', config_h, subdir: meson.project_name())
if get_option('gen_docs')
doxygen = find_program('doxygen', required: true)
doxyfile = configure_file(
input: 'doxygen/Doxyfile.in',
output: 'Doxyfile',
configuration: {
'PROJECT_VERSION': meson.project_version(),
'SOURCE_ROOT': meson.current_source_dir(),
'BUILD_ROOT': meson.current_build_dir(),
},
)
docs_tgt = custom_target(
'doxygen-html',
input: [doxyfile, 'canfigger.h', 'canfigger.c', 'README.md'],
output: ['html'],
command: [doxygen, doxyfile],
build_by_default: false,
)
alias_target('docs', docs_tgt)
endif
install_data(
files(
'ChangeLog.txt',
'LICENSE',
'README.md',
'example-01.c',
'example-01.conf',
'example-02.c',
'example-02.conf',
),
install_dir: get_option('docdir'),
)
if get_option('build_tests')
subdir('tests')
endif
endif