Repository navigation
Expand file tree
/
Copy pathmeson.build
More file actions
103 lines (93 loc) · 3.57 KB
/
Copy pathmeson.build
File metadata and controls
103 lines (93 loc) · 3.57 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
project(
'dimod',
'c', 'cpp', 'cython',
default_options: [
'cpp_std=c++11',
'buildtype=release',
'b_ndebug=if-release', # add -DNDEBUG when building for "release", which we do by default
'optimization=3',
'pkgconfig.relocatable=true',
'warning_level=1', # equivalent to -Wall. We should consider cranking it up to 3
'python.allow_limited_api=false', # Our build system can then opt-in for Python 3.12+
],
meson_version: '>= 1.10.0',
# As of July 2026, there is no nicer way that I know of to dynamically get the version
version: run_command(
['dimod/_build/_version.py'],
capture: true,
check: true,
).stdout(),
)
cpp = meson.get_compiler('cpp')
py = import('python').find_installation(pure: false)
if cpp.has_argument('-g1')
add_project_arguments('-g1', language: 'cpp')
endif
# We build the limited API when we have Python>=3.12, which is the lowest
# version that Cython makes use of vectorcall.
# See https://cython.readthedocs.io/en/stable/src/userguide/limited_api.html
# By default this will do nothing unless the user overrides the
# python.allow_limited_api=false we specify above, which we do when building
# with cibuildwheel
if py.version().version_compare('>=3.12')
limited_api = '3.12'
else
limited_api = '' # i.e. no limited api
endif
dimod_dep = declare_dependency(
include_directories: 'dimod/include/',
)
# Some packages that use dimod as a subproject do not need the extension modules
# and it speeds up the build a lot to be able to turn them off.
if get_option('build-python')
foreach path : [
'dimod/binary/cybqm/cybqm_float32.pyx',
'dimod/binary/cybqm/cybqm_float64.pyx',
'dimod/constrained/cyconstrained.pyx',
'dimod/constrained/cyexpression.pyx',
'dimod/cyqmbase/cyqmbase_float32.pyx',
'dimod/cyqmbase/cyqmbase_float64.pyx',
'dimod/discrete/cydiscrete_quadratic_model.pyx',
'dimod/quadratic/cyqm/cyqm_float32.pyx',
'dimod/quadratic/cyqm/cyqm_float64.pyx',
'dimod/cyutilities.pyx',
'dimod/cyvariables.pyx',
]
basename = path.split('/')[-1].split('.')[0]
directory = '/'.join(path.split('/').slice(0, -1))
py.extension_module(
basename,
path,
cython_args : ['-Xfreethreading_compatible=True'],
dependencies: dimod_dep,
install: true,
override_options : ['cython_language=cpp'],
subdir: directory,
limited_api: limited_api,
)
endforeach
py.extension_module(
'cylp',
'dimod/cylp.pyx',
cython_args : ['-Xfreethreading_compatible=True'],
dependencies: [
dimod_dep,
declare_dependency(
include_directories: 'dimod/_extern',
sources: 'dimod/_extern/filereaderlp/reader.cpp',
),
],
install: true,
override_options : ['cython_language=cpp'],
subdir: 'dimod/',
limited_api: limited_api,
)
# If we're not building the extensions, we shouldn't install the package
# because imports will fail.
install_subdir('dimod', install_dir: py.get_install_dir(pure: false))
endif # get_option('build-python')
# meson doesn't disable tests by default, so we let the user decide via the build-tests
# option. If set to 'auto', then we build the tests for non-release builds.
if get_option('build-tests').enabled() or (get_option('build-tests').auto() and get_option('buildtype') != 'release')
subdir('testscpp/')
endif