-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmeson.build
More file actions
155 lines (144 loc) · 4.39 KB
/
meson.build
File metadata and controls
155 lines (144 loc) · 4.39 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
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
project('cypari2',
['c', 'cython'],
version: files('VERSION'),
license: 'GPL v2+',
default_options: ['c_std=c17', 'python.install_env=auto'],
meson_version: '>=1.5.0',
)
# Python module
# https://mesonbuild.com/Python-module.html
py = import('python').find_installation(pure: false)
# Compilers
cc = meson.get_compiler('c')
cython = meson.get_compiler('cython')
# Workaround as described in https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html#arithmetic-methods
add_project_arguments('-X c_api_binop_methods=True', language: 'cython')
# Compiler debug output
run_command(cc, '-v', check:true)
# Dependencies
inc_cysignals = run_command(
py,
[
'-c',
'''
from os.path import relpath
import cysignals
path = cysignals.__file__.replace('__init__.py', '')
try:
print(relpath(path))
except Exception:
print(path)
'''.strip(),
],
check: true,
).stdout().strip()
cysignals = declare_dependency(include_directories: inc_cysignals)
# Find PARI
# GMP may be a dependency of Pari, but since Pari doesn't have a pkg-config file,
# we have to find it ourselves.
gmp = dependency('gmp', required: false)
# Cannot be found via pkg-config
# Also require shared library, since otherwise every Cython extension would include it's own copy of pari leading to hard-to-debug segmentation faults at runtime
pari_header_include_dirs = [] # additional dirs to search for PARI headers
pari_lib_dirs = [] # additional dirs to search for the PARI library
if host_machine.system() == 'darwin'
brew = find_program('brew', required: false)
if brew.found()
brew_prefix = run_command(brew, '--prefix', check: true).stdout().strip()
message('Homebrew prefix: ' + brew_prefix)
pari_header_include_dirs += include_directories(brew_prefix + '/include')
pari_lib_dirs += [brew_prefix + '/lib']
endif
endif
# Explicitly check for header to give better error message (using -v to show search paths)
cc.has_header(
'pari/pari.h',
required: true,
args: ['-v'],
include_directories: pari_header_include_dirs,
)
pari = cc.find_library(
'pari',
has_headers: ['pari/pari.h'],
required: true,
dirs: pari_lib_dirs,
header_include_directories: pari_header_include_dirs,
)
pari = declare_dependency(include_directories: pari_header_include_dirs,
dependencies: [pari, gmp])
if meson.can_run_host_binaries()
# Get PARI version (mostly as smoke test)
pari_version_code = '''
#include <pari/pari.h>
int main(void) {
pari_init(1000000, 2);
GEN v = pari_version();
const char *version = GENtostr(pari_version());
pari_printf("%s",version);
pari_close();
return 0;
}
'''
pari_version = cc.run(
pari_version_code,
args: ['-v'],
name: 'pari version',
dependencies: [pari],
required: true,
)
message('PARI Version: ' + pari_version.stdout())
endif
pari_datadir = get_option('pari_datadir')
if pari_datadir == ''
pari_datadir_code = '''
#include <pari/pari.h>
int main(void) {
pari_init(1000000, 2);
pari_printf("%s", pari_datadir);
pari_close();
return 0;
}
'''
pari_datadir = cc.run(
pari_datadir_code,
name: 'pari datadir',
dependencies: [pari],
required: true,
).stdout()
endif
message('PARI data dir: ' + pari_datadir)
# In MSYS, convert to Windows path
# (e.g /usr/share/pari -> C:\msys64\usr\share\pari)
if host_machine.system() == 'windows' and pari_datadir.startswith('/')
pari_datadir = run_command(
'cygpath', '-am', pari_datadir,
check: true,
).stdout().strip()
endif
message('PARI Datadir: ' + pari_datadir)
# Run code generation step
code_gen_result = run_command(
py.full_path(), '-c',
'''
import sys
sys.path.insert(0, ".")
from autogen import rebuild
rebuild(r"''' + pari_datadir + '''", force=True, output=r"''' + meson.current_build_dir() + '''/cypari2")
print("Code generation successful")
''',
check: true
)
py.install_sources(
meson.current_build_dir() + '/cypari2/auto_paridecl.pxd',
meson.current_build_dir() + '/cypari2/auto_gen.pxi',
meson.current_build_dir() + '/cypari2/auto_instance.pxi',
subdir: 'cypari2'
)
inc_root = include_directories('.')
# Meson currently ignores include_directories for Cython modules, so we
# have to add them manually.
# https://github.com/mesonbuild/meson/issues/9562
add_project_arguments('-I', meson.current_source_dir(), language: 'cython')
add_project_arguments('-I', meson.current_build_dir(), language: 'cython')
subdir('cypari2')
subdir('tests')