Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sage
Path: blob/develop/src/meson.build
7361 views
1
# Compilers
2
cc = meson.get_compiler('c')
3
cpp = meson.get_compiler('cpp')
4
cython = meson.get_compiler('cython')
5
6
# Setup dependencies that are needed by many modules
7
numpy = dependency('numpy', required: false, version: '>=2.2.4')
8
if not numpy.found()
9
# Older versions of numpy don't have a pkg-config file
10
inc_numpy = run_command(
11
py,
12
[
13
'-c',
14
'''
15
from os.path import relpath
16
import numpy
17
path = numpy.get_include()
18
try:
19
print(relpath(path))
20
except Exception:
21
print(path)
22
'''.strip(),
23
],
24
check: true,
25
).stdout().strip()
26
numpy = declare_dependency(include_directories: inc_numpy)
27
endif
28
29
inc_cysignals = run_command(
30
py,
31
[
32
'-c',
33
'''
34
from os.path import relpath
35
import cysignals
36
path = cysignals.__file__.replace('__init__.py', '')
37
try:
38
print(relpath(path))
39
except Exception:
40
print(path)
41
'''.strip(),
42
],
43
check: true,
44
).stdout().strip()
45
cysignals = declare_dependency(include_directories: inc_cysignals)
46
47
inc_gmpy2 = run_command(
48
py,
49
[
50
'-c',
51
'''
52
from os.path import relpath
53
import gmpy2
54
path = gmpy2.__file__.replace('__init__.py', '')
55
try:
56
print(relpath(path))
57
except Exception:
58
print(path)
59
'''.strip(),
60
],
61
check: true,
62
).stdout().strip()
63
gmpy2 = declare_dependency(include_directories: inc_gmpy2)
64
gmp = dependency('gmp')
65
66
if is_windows
67
# Not yet available on Windows
68
cypari2 = disabler()
69
else
70
inc_cypari2 = run_command(
71
py,
72
[
73
'-c',
74
'''
75
from os.path import relpath
76
import cypari2
77
path = cypari2.__file__.replace('__init__.py', '')
78
try:
79
print(relpath(path))
80
except Exception:
81
print(path)
82
'''.strip(),
83
],
84
check: true,
85
).stdout().strip()
86
# Cannot be found via pkg-config
87
# We need to link against libpari directly to avoid runtime issues, so use pari as dependency of cypari2
88
pari = cc.find_library('pari', required: not is_windows, disabler: true)
89
if pari.found() and not meson.is_cross_build()
90
# Verify PARI version
91
pari_version_code = '''
92
#include <stdio.h>
93
#include <pari/pari.h>
94
int main(void) {
95
pari_init(1000000, 2);
96
GEN v = pari_version(), M = gel(v,1), m = gel(v,2), p = gel(v,3);
97
printf("%ld.%ld.%ld", itos(M), itos(m), itos(p));
98
pari_close();
99
return 0;
100
}
101
'''
102
pari_version = cc.run(
103
pari_version_code,
104
args: ['-v'],
105
name: 'pari version',
106
dependencies: [pari],
107
required: true,
108
).stdout().strip()
109
if pari_version.version_compare('<=2.17.0')
110
message('PARI version > 2.17.0 required, found ' + pari_version)
111
pari = disabler()
112
endif
113
endif
114
cypari2 = declare_dependency(
115
include_directories: inc_cypari2,
116
dependencies: pari,
117
)
118
endif
119
120
121
mpfr = dependency('mpfr')
122
123
if is_windows
124
# TODO: Reenable the following once conda's python is fixed
125
# https://github.com/conda-forge/python-feedstock/pull/770
126
# # In its currently released version, flint is not working on Windows; thus always use subproject
127
# #flint = dependency('flint', version: '>=3.1.3')
128
# cmake = import('cmake')
129
# cmake_opts = cmake.subproject_options()
130
# cmake_opts.add_cmake_defines({'BUILD_SHARED_LIBS': 'OFF'})
131
# flint_proj = cmake.subproject('flint', options: cmake_opts)
132
# flint = flint_proj.dependency('flint')
133
# meson.override_dependency('flint', flint)
134
flint = disabler()
135
else
136
flint = dependency('flint', version: '>=3.0.0')
137
if flint.version().version_compare('<3.1')
138
# In older versions of flint, pkg-config file is broken, so we manually use find_library
139
# This has been fixed in flint v3.1: https://github.com/flintlib/flint/pull/1647
140
flint = cc.find_library('flint')
141
endif
142
endif
143
144
blas_order = []
145
if host_machine.system() == 'darwin'
146
blas_order += 'accelerate'
147
endif
148
if host_machine.cpu_family() == 'x86_64'
149
blas_order += 'mkl'
150
endif
151
# pkg-config uses a lower-case name while CMake uses a capitalized name, so try
152
# that too to make the fallback detection with CMake work
153
blas_order += ['cblas', 'openblas', 'OpenBLAS', 'flexiblas', 'blis', 'blas']
154
blas = dependency(blas_order)
155
if is_windows
156
# pkg-config file is wrong on Windows (https://github.com/conda-forge/gsl-feedstock/issues/63)
157
gsl = cc.find_library('gsl', required: false, disabler: true)
158
else
159
gsl = dependency('gsl', version: '>=2.5')
160
endif
161
gd = dependency('gdlib', required: false, version: '>=2.1')
162
if not gd.found()
163
# Doesn't have a pkg-config file on some systems (https://github.com/conda-forge/libgd-feedstock/issues/55)
164
gd = cc.find_library('gd', required: not is_windows, disabler: true)
165
endif
166
# Only some platforms have a standalone math library (https://mesonbuild.com/howtox.html#add-math-library-lm-portably)
167
m = cc.find_library('m', required: false)
168
m4ri = dependency('m4ri', version: '>=20250128', required: false)
169
if not m4ri.found()
170
# Older versions of m4ri are declaring "@SIMD_CFLAGS@" as compile_args
171
# which breaks the build. So we exclude these compile args.
172
# https://github.com/malb/m4ri/commit/3197be5f7d3c67e8f13e32516557f35cbf4ff6ce
173
m4ri = dependency('m4ri', version: '>=20140914').partial_dependency(
174
includes: true,
175
link_args: true,
176
links: true,
177
sources: true,
178
)
179
endif
180
m4rie = dependency('m4rie', required: false)
181
if not m4rie.found()
182
# For some reason, m4rie is not found via pkg-config on some systems (eg Conda)
183
m4rie = cc.find_library('m4rie', required: not is_windows, disabler: true)
184
endif
185
mtx = dependency('libmtx', required: false)
186
if not mtx.found()
187
# fallback for older versions without pkg-config
188
mtx = cc.find_library(
189
'mtx',
190
required: get_option('meataxe'),
191
disabler: true,
192
has_headers: ['meataxe.h'],
193
)
194
endif
195
png = dependency(['libpng', 'png', 'png16'], version: '>=1.2')
196
zlib = dependency('zlib', version: '>=1.2.11')
197
# We actually want >= 20250122, but the version number is not updated in the pkgconfig
198
# https://github.com/conda-forge/eclib-feedstock/issues/48
199
# To old versions of eclib don't ship a pkg-config file, so this should be rather safe
200
ec = dependency(
201
'eclib',
202
version: '>=20231211',
203
required: get_option('eclib'),
204
disabler: true,
205
)
206
ecm = cc.find_library('ecm', required: not is_windows, disabler: true)
207
gmpxx = dependency('gmpxx', required: not is_windows, disabler: true)
208
fflas = dependency(
209
'fflas-ffpack',
210
required: not is_windows,
211
disabler: true,
212
version: '>=2.5.0',
213
)
214
givaro = dependency(
215
'givaro',
216
required: not is_windows,
217
disabler: true,
218
version: '>=4.2.0',
219
)
220
linbox = dependency('linbox', required: false, version: '>=1.7.0')
221
if not linbox.found()
222
linbox = cc.find_library('linbox', required: not is_windows, disabler: true)
223
endif
224
mpc = cc.find_library('mpc', required: not is_windows, disabler: true)
225
mpfi = cc.find_library('mpfi', required: false)
226
if not mpfi.found()
227
mpfi_proj = subproject('mpfi')
228
mpfi = mpfi_proj.get_variable('mpfi_dep')
229
endif
230
231
gap = dependency('libgap', version: '>=4.13.0', required: false)
232
if not gap.found()
233
# Fallback in case pkg-config info is not available
234
# Test for common.h header that was added in 4.12 as a indirect version check
235
gap = cc.find_library(
236
'gap',
237
has_headers: ['gap/common.h'],
238
required: not is_windows,
239
disabler: true,
240
)
241
endif
242
singular = dependency('Singular', required: not is_windows, disabler: true)
243
singular_factory = disabler()
244
if singular.found()
245
singular_factory = singular
246
else
247
singular_proj = subproject('singular')
248
singular_factory = singular_proj.get_variable('factory_dep')
249
endif
250
# Cannot be found via pkg-config
251
ntl = cc.find_library('ntl', required: not is_windows, disabler: true)
252
253
boost_cpp17_compatible = false
254
boost = dependency(
255
'boost',
256
version: '>=1.83.0',
257
required: false,
258
modules: ['graph'],
259
)
260
if boost.found()
261
# Need at least v1.83.0 (https://github.com/boostorg/functional/commit/6a573e4b8333ee63ee62ce95558c3667348db233)
262
# for C++17 compatibility.
263
boost_cpp17_compatible = true
264
else
265
boost = dependency(
266
'boost',
267
version: '>=1.66.0',
268
required: false,
269
modules: ['graph'],
270
)
271
endif
272
273
274
# Meson currently ignores include_directories for Cython modules, so we
275
# have to add them manually.
276
# https://github.com/mesonbuild/meson/issues/9562
277
add_project_arguments('-I', meson.current_source_dir(), language: 'cython')
278
add_project_arguments('-I', meson.current_build_dir(), language: 'cython')
279
280
# Add global compiler flags
281
add_project_arguments('-X auto_pickle=False', language: 'cython')
282
add_project_arguments('-X autotestdict=False', language: 'cython')
283
add_project_arguments('-X binding=True', language: 'cython')
284
add_project_arguments('-X c_api_binop_methods=True', language: 'cython')
285
add_project_arguments('-X cdivision=True', language: 'cython')
286
add_project_arguments('-X cpow=True', language: 'cython')
287
add_project_arguments('-X embedsignature=True', language: 'cython')
288
add_project_arguments('--embed-positions', language: 'cython')
289
add_project_arguments('-X fast_getattr=True', language: 'cython')
290
#add_project_arguments('-X language_level="3"', language : 'cython')
291
add_project_arguments('-X legacy_implicit_noexcept=True', language: 'cython')
292
add_project_arguments(
293
'-X preliminary_late_includes_cy28=True',
294
language: 'cython',
295
)
296
297
inc_cpython = include_directories('sage/cpython')
298
inc_rings = include_directories('sage/rings')
299
inc_rings_finite = include_directories('sage/rings/finite_rings')
300
inc_flint = include_directories('sage/libs/flint')
301
inc_gsl = include_directories('sage/libs/gsl')
302
inc_ntl = include_directories('sage/libs/ntl')
303
inc_arb = include_directories('sage/libs/arb')
304
inc_data_structures = include_directories('sage/data_structures')
305
inc_ext = include_directories('sage/ext')
306
inc_partn_ref2 = include_directories('sage/groups/perm_gps/partn_ref2')
307
inc_src = include_directories('.')
308
309
src = meson.current_source_dir()
310
311
# Submodules
312
subdir('sage')
313
subdir('doc')
314
315