-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmeson.build
204 lines (176 loc) · 6.52 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
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
project('haclog', 'c',
version: run_command('python', '-c', '''
with open("version.txt", "r") as f:
print("{}".format(f.readline().strip("\n")))
''', check: true).stdout().strip(),
license: 'MIT',
license_files: ['LICENSE'],
meson_version: '>= 1.1.0')
################################
# version
################################
haclog_version = meson.project_version()
haclog_version_without_ext = haclog_version.split('-')[0]
haclog_semver = haclog_version_without_ext.split('.')
haclog_version_major = haclog_semver[0]
haclog_version_minor = haclog_semver[1]
haclog_version_patch = haclog_semver[2]
haclog_soversion = haclog_version_major
message('--------------------------------')
message('# haclog version:', haclog_version)
message('# haclog soversion:', haclog_soversion)
message('# default_library:', get_option('default_library'))
message('# haclog HACLOG_BUILD_TESTING:', get_option('HACLOG_BUILD_TESTING'))
message('# haclog HACLOG_BUILD_EXAMPLE:', get_option('HACLOG_BUILD_EXAMPLE'))
message('# haclog HACLOG_BUILD_BENCHMARK:',
get_option('HACLOG_BUILD_BENCHMARK'))
message('# haclog HACLOG_BUILD_GBENCHMARK:',
get_option('HACLOG_BUILD_GBENCHMARK'))
message('--------------------------------')
################################
# configure
################################
conf_data = configuration_data()
conf_data.set('HACLOG_VERSION', haclog_version)
if get_option('default_library') == 'shared'
conf_data.set('HACLOG_USE_DLL', 1)
elif get_option('default_library') == 'static'
else
assert(false, '''
haclog not support build shared and static in the same time
setup --default-library=shared or --default-library=static
''')
endif
if build_machine.system() != 'windows'
compiler = meson.get_compiler('c')
if compiler.has_header('execinfo.h')
if compiler.has_function('backtrace', prefix: '#include <execinfo.h>')
conf_data.set('HACLOG_HAVE_BACKTRACE', 1)
conf_data.set('HACLOG_BACKTRACE_HEADER', 'execinfo.h')
endif
endif
endif
configure_file(
format: 'cmake@',
input: 'haclog/haclog_config.h.in',
output: 'haclog_config.h',
configuration: conf_data)
# NOTE:
# configure_file output can't contain a path segment, so need move gen
# file manually
run_command('python', '-c',
'''
import os;
build_dir = "@0@";
gen_dir = os.path.join(build_dir, "gen", "haclog");
os.makedirs(gen_dir, exist_ok=True);
src_file = os.path.join(build_dir, "haclog_config.h");
dst_file = os.path.join(gen_dir, "haclog_config.h");
os.replace(src_file, dst_file);
'''.format(meson.current_build_dir().replace('\\', '/')),
check: true)
################################
# functions
################################
func_glob ='''import glob;
files = glob.glob("@0@/**/*.@1@", recursive=@2@);
for f in files:
print("{}".format(f))
'''
func_listdir = '''import os;
dirs = os.listdir("@0@");
for filename in dirs:
filepath = os.path.join("@0@", filename)
if os.path.isdir(filepath):
print(filename)
'''
################################
# haclog
################################
cmd_src_c = run_command(
'python', '-c', func_glob.format('haclog', 'c', 'True'), check: true)
cmd_src_h = run_command(
'python', '-c', func_glob.format('haclog', 'h', 'True'), check: true)
haclog_src_c = cmd_src_c.stdout().strip().split('\n')
haclog_src_h = cmd_src_h.stdout().strip().split('\n')
haclog_gen_h = join_paths(
meson.current_build_dir(), 'gen', 'haclog', 'haclog_config.h')
incdir = include_directories('.', 'gen')
libhaclog = library('haclog', haclog_src_c,
include_directories: incdir,
c_args: '-DHACLOG_EXPORTS',
# NOTE: meson not support semver ext, e.g. 0.0.1-alpha.1
version: haclog_version_without_ext,
soversion: haclog_soversion,
install: true)
install_headers(haclog_gen_h, subdir: 'haclog')
install_headers(haclog_src_h, preserve_path: true)
# pkg-config
pkg = import('pkgconfig')
pkg.generate(libhaclog)
################################
# test
################################
if get_option('HACLOG_BUILD_TESTING')
unity_test_dep = dependency('unity', required: true)
cmd_listdir_test = run_command(
'python', '-c', func_listdir.format('test'), check: true)
test_dirs = cmd_listdir_test.stdout().strip().split('\n')
foreach test_dir : test_dirs
test_filepath = join_paths('test', test_dir).replace('\\', '/')
cmd_test_src_c = run_command(
'python', '-c', func_glob.format(test_filepath, 'c', 'True'),
check: true)
test_src_c = cmd_test_src_c.stdout().strip().split('\n')
test_incdir = include_directories(test_filepath, '.', 'gen')
test_exe = executable('test_' + test_dir, test_src_c,
include_directories: test_incdir,
link_with: libhaclog,
dependencies: unity_test_dep)
test('name of test', test_exe)
endforeach
endif
################################
# examples
################################
if get_option('HACLOG_BUILD_EXAMPLE')
cmd_listdir_example = run_command(
'python', '-c', func_listdir.format('example'), check: true)
example_dirs = cmd_listdir_example.stdout().strip().split('\n')
foreach example_dir : example_dirs
example_filepath = join_paths('example', example_dir).replace('\\', '/')
cmd_example_src_c = run_command(
'python', '-c', func_glob.format(example_filepath, 'c', 'True'),
check: true)
example_src_c = cmd_example_src_c.stdout().strip().split('\n')
example_incdir = include_directories(example_filepath, '.', 'gen')
executable('example_' + example_dir, example_src_c,
include_directories: example_incdir,
link_with: libhaclog)
endforeach
endif
################################
# benchmark
################################
if get_option('HACLOG_BUILD_BENCHMARK')
cmd_listdir_benchmark = run_command(
'python', '-c', func_listdir.format('benchmark'), check: true)
benchmark_dirs = cmd_listdir_benchmark.stdout().strip().split('\n')
foreach benchmark_dir : benchmark_dirs
benchmark_filepath = join_paths('benchmark', benchmark_dir).replace('\\', '/')
cmd_benchmark_src_c = run_command(
'python', '-c', func_glob.format(benchmark_filepath, 'c', 'True'),
check: true)
benchmark_src_c = cmd_benchmark_src_c.stdout().strip().split('\n')
benchmark_incdir = include_directories(benchmark_filepath, '.', 'gen')
executable('benchmark_' + benchmark_dir, benchmark_src_c,
include_directories: benchmark_incdir,
link_with: libhaclog)
endforeach
endif
################################
# gbenchmark
################################
if get_option('HACLOG_BUILD_GBENCHMARK')
message('google benchmark without meson.build, ignore HACLOG_BUILD_GBENCHMARK')
endif