forked from JeffersonLab/iguana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
233 lines (218 loc) · 6.83 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
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
project(
'iguana',
'cpp',
license: ['LGPLv3'],
license_files: ['LICENSE'],
meson_version: '>=1.2',
default_options: {
'cpp_std': 'c++17',
'buildtype': 'release',
'libdir': 'lib',
'licensedir': 'share/licenses/iguana',
'pkgconfig.relocatable': 'true',
},
version: run_command(
meson.project_source_root() / 'meson' / 'detect-version.sh',
meson.project_source_root(),
check: true
).stdout().strip()
)
project_description = 'Implementation Guardian of Analysis Algorithms'
# initialize binding languanges
add_languages('fortran', native: false, required: get_option('bind_fortran'))
# meson modules
pkg = import('pkgconfig')
fs = import('fs')
# resolve dependencies
# NOTE: those that are typically installed by package managers should use `meson/minimum-version.sh`
fmt_dep = dependency(
'fmt',
method: 'pkg-config',
version: run_command('meson' / 'minimum-version.sh', 'fmt', check: true).stdout().strip()
)
yamlcpp_dep = dependency(
'yaml-cpp',
method: 'pkg-config',
version: run_command('meson' / 'minimum-version.sh', 'yaml-cpp', check: true).stdout().strip()
)
hipo_dep = dependency(
'hipo4',
method: 'pkg-config',
version: '>=4.1.0',
)
ROOT_dep = dependency(
'ROOT',
required: get_option('z_require_root'),
method: 'cmake',
version: run_command('meson' / 'minimum-version.sh', 'ROOT', check: true).stdout().strip()
)
# list of dependencies
# FIXME: for users which use LD_LIBRARY_PATH, we should try to keep this list
# ordered such that the ones users are *least likely* to try to build
# themselves are listed last (see FIXME in meson/this_iguana.sh.in)
dep_list = []
foreach dep : [ hipo_dep, fmt_dep, yamlcpp_dep, ROOT_dep ]
if dep.found()
dep_list += dep
endif
endforeach
# pkgconfig configuration: make a list of dependency library and include directories
dep_lib_dirs = []
dep_include_dirs = []
dep_pkgconfig_dirs = []
foreach dep : dep_list
### skip ROOT (handled differently, and most ROOT users already have it in their environment)
if dep.name() == 'ROOT'
continue
endif
### handle pkg-config deps
if dep.type_name() == 'pkgconfig'
libdirs = [ dep.get_variable(pkgconfig: 'libdir') ]
incdirs = [ dep.get_variable(pkgconfig: 'includedir') ]
### handle cmake deps
elif dep.type_name() == 'cmake'
libdirs = []
foreach lib : dep.get_variable(cmake: 'PACKAGE_LIBRARIES').split(';')
libdirs += run_command('dirname', lib, check: true).stdout().strip()
endforeach
incdirs = ROOT_dep.get_variable(cmake: 'PACKAGE_INCLUDE_DIRS').split(';')
### error, if unknown
else
error('Cannot determine how dependency "' + dep.name() + '" was found')
endif
### append to `dep_lib_dirs`
foreach libdir : libdirs
if not dep_lib_dirs.contains(libdir)
dep_lib_dirs += libdir
endif
### append to `dep_pkgconfig_dirs`
if dep.type_name() == 'pkgconfig'
pkgconfigdir = libdir / 'pkgconfig'
if not dep_pkgconfig_dirs.contains(pkgconfigdir)
dep_pkgconfig_dirs += pkgconfigdir
endif
endif
endforeach
### append to `dep_include_dirs`
foreach incdir : incdirs
if not dep_include_dirs.contains(incdir)
dep_include_dirs += incdir
endif
endforeach
endforeach
# handle HIPO dataframes
hipo_dep_dataframes_found = hipo_dep.get_variable(pkgconfig: 'with_dataframes', default_value: 'false').to_lower() == 'true'
# handle ROOT
ROOT_dep_inc_dirs = []
ROOT_dep_link_args = []
ROOT_dep_link_args_for_validators = []
ROOT_dep_rpath = ''
if ROOT_dep.found()
ROOT_dep_inc_dirs += include_directories(run_command('root-config', '--incdir', check: true).stdout().strip())
ROOT_libdir = run_command('root-config', '--libdir', check: true).stdout().strip()
ROOT_dep_link_args += [
# ROOT libraries that we need (safer than `root-config --libs`)
'-L' + ROOT_libdir,
'-lCore',
'-lGenVector',
'-lROOTDataFrame',
'-lROOTVecOps',
'-lTreePlayer',
]
ROOT_dep_link_args_for_validators = [
# additional ROOT libraries for validators (namely, graphics libraries)
'-L' + ROOT_libdir,
'-lRIO',
'-lHist',
'-lGpad',
]
ROOT_dep_rpath = ROOT_libdir
endif
# general project vars
project_inc = include_directories('src')
project_libs = []
project_deps = declare_dependency(dependencies: [ fmt_dep, yamlcpp_dep, hipo_dep ] ) # do NOT include ROOT here
project_etc = get_option('sysconfdir') / meson.project_name()
project_test_env = environment()
project_pkg_vars = [
'bindir=' + '${prefix}' / get_option('bindir'),
'dep_pkgconfigdirs=' + ':'.join(dep_pkgconfig_dirs),
'dep_libdirs=' + ':'.join(dep_lib_dirs),
'dep_includedirs=' + ':'.join(dep_include_dirs),
]
# sanitizer settings
project_test_env.set(
'UBSAN_OPTIONS',
'halt_on_error=1',
'abort_on_error=1',
'print_summary=1',
'print_stacktrace=1',
'suppressions=' + meson.project_source_root() / 'meson' / 'ubsan.supp',
)
project_test_env.set(
'ASAN_OPTIONS',
'halt_on_error=1',
'abort_on_error=1',
'print_summary=1',
)
project_test_env.set(
'LSAN_OPTIONS',
'suppressions=' + meson.project_source_root() / 'meson' / 'lsan.supp',
)
# set preprocessor macros
add_project_arguments(
'-DIGUANA_ETCDIR="' + get_option('prefix') / project_etc + '"',
language: ['cpp'],
)
# build and install shared libraries
subdir('src/iguana/services')
subdir('src/iguana/algorithms')
subdir('src/iguana/tests')
# build bindings
pythondir = 'python'
if get_option('bind_python')
subdir('bind/python')
endif
# generate pkg-config file
project_pkg_vars_nonempty = []
foreach var : project_pkg_vars
if not var.endswith('=') # remove empty variable values
project_pkg_vars_nonempty += var
endif
endforeach
pkg.generate(
name: meson.project_name(),
description: project_description,
libraries: project_libs,
requires: [ fmt_dep, yamlcpp_dep, hipo_dep ], # pkg-config dependencies only
variables: project_pkg_vars_nonempty,
)
# build examples
if get_option('install_examples')
subdir('examples')
endif
# install environment setup files
if get_option('z_install_envfile')
configure_file(
input: 'meson' / 'this_iguana.sh.in',
output: 'this_iguana.sh',
install: true,
install_dir: get_option('bindir'),
configuration: {
'ld_path': host_machine.system() != 'darwin' ? 'LD_LIBRARY_PATH' : 'DYLD_LIBRARY_PATH',
'python': get_option('bind_python') ? 'true' : 'false',
'libdir': get_option('libdir'),
'root': ROOT_dep.found() ? 'true' : 'false',
'etcdir': project_etc,
},
)
foreach shell : ['csh', 'tcsh']
configure_file(
input: 'meson' / 'this_iguana.csh.in',
output: 'this_iguana.' + shell,
install: true,
install_dir: get_option('bindir'),
configuration: {'shell': shell},
)
endforeach
endif