scikit-image
170 строк · 5.2 Кб
1# Platform detection
2is_windows = host_machine.system() == 'windows'
3is_mingw = is_windows and cc.get_id() == 'gcc'
4
5cython_c_args = []
6if is_windows
7# For mingw-w64, link statically against the UCRT.
8gcc_link_args = ['-lucrt', '-static']
9if is_mingw
10add_project_link_arguments(gcc_link_args, language: ['c', 'cpp'])
11# Force gcc to float64 long doubles for compatibility with MSVC
12# builds, for C only.
13add_project_arguments('-mlong-double-64', language: 'c')
14# Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118)
15add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
16# Manual add of MS_WIN64 macro when not using MSVC.
17# https://bugs.python.org/issue28267
18bitness = run_command(
19'_build_utils/gcc_build_bitness.py',
20check: true
21).stdout().strip()
22if bitness == '64'
23add_project_arguments('-DMS_WIN64', language: ['c', 'cpp'])
24endif
25# Silence warnings emitted by PyOS_snprintf for (%zd), see
26# https://github.com/rgommers/scipy/issues/118.
27# Use as c_args for extensions containing Cython code
28cython_c_args += ['-Wno-format-extra-args', '-Wno-format']
29endif
30endif
31
32# When cross-compiling skimage, the compiler needs access to NumPy and Pythran
33# headers for the host platform (where the package will actually run). These
34# headers may be incompatible with any corresponding headers that might be
35# installed on the build system (where the compilation is performed). To make
36# sure that the compiler finds the right headers, paths can be configured in
37# the 'properties' section of a Meson cross file:
38#
39# [properties]
40# numpy-include-dir = '/path/to/host/numpy/includes'
41# pythran-include-dir = '/path/to/host/pythran/includes'
42#
43# If a cross file is not provided or does not specify either of these
44# properties, fall back to running Python on the build system to query NumPy or
45# Pythran directly for the appropriate paths. This will detect appropriate
46# paths for native builds. (This might even work for certain build/host cross
47# combinations, but don't rely on that.)
48#
49# For more information about cross compilation in Meson, including a definition
50# of "build" and "host" in this context, refer to
51#
52# https://mesonbuild.com/Cross-compilation.html
53
54# NumPy include directory
55incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given')
56if incdir_numpy == 'not-given'
57# If not specified, try to query NumPy from the build python
58incdir_numpy = run_command(py3,
59[
60'-c',
61'import os; os.chdir(".."); import numpy; print(numpy.get_include())'
62],
63check: true
64).stdout().strip()
65endif
66
67inc_np = include_directories(incdir_numpy)
68
69cc = meson.get_compiler('c')
70
71# Pythran include directory
72incdir_pythran = meson.get_external_property('pythran-include-dir', 'not-given')
73if incdir_pythran == 'not-given'
74# If not specified, try to query Pythran from the build python
75incdir_pythran = run_command(py3,
76[
77'-c',
78'import os; os.chdir(".."); import pythran; print(os.path.dirname(pythran.__file__));'
79],
80check: true
81).stdout().strip()
82endif
83
84inc_pythran = include_directories(incdir_pythran)
85
86# Pythran build flags
87cpp_args_pythran = [
88'-DENABLE_PYTHON_MODULE',
89'-D__PYTHRAN__=3',
90'-DPYTHRAN_BLAS_NONE'
91]
92
93# Deal with M_PI & friends; add `use_math_defines` to c_args
94# Cython doesn't always get this correctly itself
95# explicitly add the define as a compiler flag for Cython-generated code.
96if is_windows
97use_math_defines = ['-D_USE_MATH_DEFINES']
98else
99use_math_defines = []
100endif
101
102# Don't use the deprecated NumPy C API. Define this to a fixed version instead of
103# NPY_API_VERSION in order not to break compilation for released SciPy versions
104# when NumPy introduces a new deprecation. Use in a meson.build file::
105#
106# py3.extension_module('_name',
107# 'source_fname',
108# numpy_nodepr_api)
109#
110numpy_nodepr_api = '-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION'
111
112python_sources = [
113'__init__.py',
114'__init__.pyi',
115'conftest.py',
116'py.typed'
117]
118
119py3.install_sources(
120python_sources,
121pure: false,
122subdir: 'skimage'
123)
124
125cython_cli = find_program('_build_utils/cythoner.py')
126cy = meson.get_compiler('cython')
127
128cython_args = ['@INPUT@', '@OUTPUT@']
129if cy.version().version_compare('>=3.1.0')
130cython_args += ['-Xfreethreading_compatible=True']
131endif
132
133cython_cpp_args = cython_args + ['--cplus']
134
135cython_gen = generator(cython_cli,
136arguments : cython_args,
137output : '@BASENAME@.c')
138
139cython_gen_cpp = generator(cython_cli,
140arguments : ['@INPUT@', '@OUTPUT@', '--cplus'],
141output : '@BASENAME@.cpp')
142
143c_undefined_ok = ['-Wno-maybe-uninitialized']
144
145# Suppress warning for deprecated Numpy API.
146# (Suppress warning messages emitted by #warning directives).
147# Replace with numpy_nodepr_api after Cython 3.0 is out
148_cpp_Wno_cpp = cpp.get_supported_arguments('-Wno-cpp')
149cython_c_args += [_cpp_Wno_cpp, use_math_defines]
150cython_cpp_args = cython_c_args
151
152subdir('_shared')
153subdir('_vendored')
154subdir('color')
155subdir('data')
156subdir('draw')
157subdir('exposure')
158subdir('feature')
159subdir('filters')
160subdir('future')
161subdir('graph')
162subdir('io')
163subdir('measure')
164subdir('metrics')
165subdir('morphology')
166subdir('registration')
167subdir('restoration')
168subdir('segmentation')
169subdir('transform')
170subdir('util')
171