| 1 |
# Ref: https://github.com/scipy/scipy/blob/main/scipy/meson.build |
| 2 |
# commit: 053a3e8 |
| 3 |
# |
| 4 |
# NOTES: |
| 5 |
# - As scikit-misc does not use these librares/languages |
| 6 |
# - c++ |
| 7 |
# - f2py (https://numpy.org/doc/stable/f2py/), |
| 8 |
# - pythran |
| 9 |
# - pybind |
| 10 |
|
| 11 |
|
| 12 |
#### Setup NumPy |
| 13 |
# Include numpy directory - needed in all submodules |
| 14 |
# The chdir is needed because within numpy there's an `import signal` |
| 15 |
# statement, and we don't want that to pick up scipy's signal module rather |
| 16 |
# than the stdlib module. The try-except is needed because when things are |
| 17 |
# split across drives on Windows, there is no relative path and an exception |
| 18 |
# gets raised. There may be other such cases, so add a catch-all and switch to |
| 19 |
# an absolute path. Relative paths are needed when for example a virtualenv is |
| 20 |
# placed inside the source tree; Meson rejects absolute paths to places inside |
| 21 |
# the source tree. |
| 22 |
incdir_numpy = run_command(py, |
| 23 |
[ |
| 24 |
'-c', |
| 25 |
'''import os |
| 26 |
os.chdir(os.path.join("..", "tools")) |
| 27 |
import numpy as np |
| 28 |
try: |
| 29 |
incdir = os.path.relpath(np.get_include()) |
| 30 |
except Exception: |
| 31 |
incdir = np.get_include() |
| 32 |
print(incdir) |
| 33 |
''' |
| 34 |
], |
| 35 |
check: true |
| 36 |
).stdout().strip() |
| 37 |
inc_np = include_directories(incdir_numpy) |
| 38 |
np_dep = declare_dependency(include_directories: inc_np) |
| 39 |
|
| 40 |
# We do need an absolute path to feed to `cc.find_library` below |
| 41 |
_incdir_numpy_abs = run_command(py, |
| 42 |
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], |
| 43 |
check: true |
| 44 |
).stdout().strip() |
| 45 |
|
| 46 |
npymath_path = _incdir_numpy_abs / '..' / 'lib' |
| 47 |
npyrandom_path = _incdir_numpy_abs / '..' / '..' / 'random' / 'lib' |
| 48 |
npymath_lib = cc.find_library('npymath', dirs: npymath_path) |
| 49 |
npyrandom_lib = cc.find_library('npyrandom', dirs: npyrandom_path) |
| 50 |
|
| 51 |
# Don't use the deprecated NumPy C API. Define this to a fixed version instead of |
| 52 |
# NPY_API_VERSION in order not to break compilation for released SciPy versions |
| 53 |
# when NumPy introduces a new deprecation. Use in a meson.build file |
| 54 |
# |
| 55 |
# py.extension_module('_name', |
| 56 |
# 'source_fname', |
| 57 |
# numpy_nodepr_api) |
| 58 |
|
| 59 |
# numpy_nodepr_api = '-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION' |
| 60 |
numpy_nodepr_api = '-DNPY_NO_DEPRECATED_API=1' |
| 61 |
### |
| 62 |
|
| 63 |
#### Check Supported Compiler Flags |
| 64 |
# This is necessary to ensure that SciPy |
| 65 |
# can be built with any supported compiler. We need so many warning flags |
| 66 |
# because we want to be able to build with `-Werror` in CI; that ensures that |
| 67 |
# for new code we add, there are no unexpected new issues introduced. |
| 68 |
# |
| 69 |
# Cleaning up code so we no longer need some of these warning flags is useful, |
| 70 |
# but not a priority. |
| 71 |
# |
| 72 |
# The standard convention used here is: |
| 73 |
# - for C, drop the leading dash and turn remaining dashes into underscores |
| 74 |
# - for C++, prepend `_cpp` and turn remaining dashes into underscores |
| 75 |
# - for Fortran, prepend `_fflags` and turn remaining dashes into underscores |
| 76 |
|
| 77 |
# C warning flags |
| 78 |
Wno_maybe_uninitialized = cc.get_supported_arguments('-Wno-maybe-uninitialized') |
| 79 |
Wno_discarded_qualifiers = cc.get_supported_arguments('-Wno-discarded-qualifiers') |
| 80 |
Wno_empty_body = cc.get_supported_arguments('-Wno-empty-body') |
| 81 |
Wno_implicit_function_declaration = cc.get_supported_arguments('-Wno-implicit-function-declaration') |
| 82 |
Wno_parentheses = cc.get_supported_arguments('-Wno-parentheses') |
| 83 |
Wno_switch = cc.get_supported_arguments('-Wno-switch') |
| 84 |
Wno_unused_result = cc.get_supported_arguments('-Wno-unused-result') |
| 85 |
Wno_unused_label = cc.get_supported_arguments('-Wno-unused-label') |
| 86 |
Wno_unused_variable = cc.get_supported_arguments('-Wno-unused-variable') |
| 87 |
|
| 88 |
# Fortran warning flags |
| 89 |
_fflag_Wno_argument_mismatch = ff.get_supported_arguments('-Wno-argument-mismatch') |
| 90 |
_fflag_Wno_conversion = ff.get_supported_arguments('-Wno-conversion') |
| 91 |
_fflag_Wno_intrinsic_shadow = ff.get_supported_arguments('-Wno-intrinsic-shadow') |
| 92 |
_fflag_Wno_maybe_uninitialized = ff.get_supported_arguments('-Wno-maybe-uninitialized') |
| 93 |
_fflag_Wno_surprising = ff.get_supported_arguments('-Wno-surprising') |
| 94 |
_fflag_Wno_uninitialized = ff.get_supported_arguments('-Wno-uninitialized') |
| 95 |
_fflag_Wno_unused_dummy_argument = ff.get_supported_arguments('-Wno-unused-dummy-argument') |
| 96 |
_fflag_Wno_unused_label = ff.get_supported_arguments('-Wno-unused-label') |
| 97 |
_fflag_Wno_unused_variable = ff.get_supported_arguments('-Wno-unused-variable') |
| 98 |
_fflag_Wno_tabs = ff.get_supported_arguments('-Wno-tabs') |
| 99 |
|
| 100 |
# The default list of warnings to ignore from Fortran code. There is a lot of |
| 101 |
# old, vendored code that is very bad and we want to compile it silently (at |
| 102 |
# least with GCC and Clang) |
| 103 |
fortran_ignore_warnings = ff.get_supported_arguments( |
| 104 |
_fflag_Wno_argument_mismatch, |
| 105 |
_fflag_Wno_conversion, |
| 106 |
_fflag_Wno_maybe_uninitialized, |
| 107 |
_fflag_Wno_unused_dummy_argument, |
| 108 |
_fflag_Wno_unused_label, |
| 109 |
_fflag_Wno_unused_variable, |
| 110 |
_fflag_Wno_tabs, |
| 111 |
) |
| 112 |
|
| 113 |
### |
| 114 |
|
| 115 |
#### Check Supported Linker Flags |
| 116 |
|
| 117 |
## C |
| 118 |
Wlno_compact_unwind = cc.get_supported_link_arguments('-Wl,-no_compact_unwind') |
| 119 |
# TODO: This should not exist long term |
| 120 |
# Disable warning about undefined dynamic lookup of symbols. It is harmless. |
| 121 |
# https://github.com/python/cpython/issues/97524#issuecomment-1270616173 |
| 122 |
Wlno_fixup_chains = cc.get_supported_link_arguments('-Wl,-no_fixup_chains') |
| 123 |
### |
| 124 |
|
| 125 |
#### Setup on Operating System |
| 126 |
is_mingw = is_windows and cc.get_id() == 'gcc' |
| 127 |
|
| 128 |
if is_mingw and ff.get_id() != 'gcc' |
| 129 |
error('If you are using GCC on Windows, you must also use GFortran! Detected ' + ff.get_id()) |
| 130 |
endif |
| 131 |
|
| 132 |
if is_mingw |
| 133 |
# For mingw-w64, link statically against the UCRT. |
| 134 |
gcc_link_args = ['-lucrt', '-static'] |
| 135 |
add_project_link_arguments(gcc_link_args, language: ['c', 'cpp', 'fortran']) |
| 136 |
# Force gcc to float64 long doubles for compatibility with MSVC |
| 137 |
# builds, for C only. |
| 138 |
add_project_arguments('-mlong-double-64', language: 'c') |
| 139 |
# Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118) |
| 140 |
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp']) |
| 141 |
# Silence warnings emitted by PyOS_snprintf for (%zd), see |
| 142 |
# https://github.com/rgommers/scipy/issues/118. |
| 143 |
# Use as c_args for extensions containing Cython code |
| 144 |
cython_c_args += ['-Wno-format-extra-args', '-Wno-format'] |
| 145 |
# Flag needed to work around BLAS and LAPACK Gfortran dependence on |
| 146 |
# undocumented C feature when passing single character string arguments. See: |
| 147 |
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90329 |
| 148 |
# https://github.com/wch/r-source/blob/838f9d5a7be08f2a8c08e47bcd28756f5d0aac90/src/gnuwin32/MkRules.rules#L121 |
| 149 |
add_project_arguments('-fno-optimize-sibling-calls', language: ['fortran']) |
| 150 |
elif is_macos |
| 151 |
cython_c_link_args += [ |
| 152 |
Wlno_compact_unwind, |
| 153 |
Wlno_fixup_chains |
| 154 |
] |
| 155 |
endif |
| 156 |
### |
| 157 |
|
| 158 |
#### BLAS and LAPACK |
| 159 |
# TODO: 64-bit BLAS and LAPACK |
| 160 |
# |
| 161 |
# Note that this works as long as BLAS and LAPACK are detected properly via |
| 162 |
# pkg-config. By default we look for OpenBLAS, other libraries can be configured via |
| 163 |
# `meson configure -Dblas=blas -Dlapack=lapack` (example to build with Netlib |
| 164 |
# BLAS and LAPACK). |
| 165 |
# For MKL and for auto-detecting one of multiple libs, we'll need a custom |
| 166 |
# dependency in Meson (like is done for scalapack) - see |
| 167 |
# https://github.com/mesonbuild/meson/issues/2835 |
| •168 |
blas_name = 'blas' |
| 169 |
lapack_name = 'lapack' |
| 170 |
# pkg-config uses a lower-case name while CMake uses a capitalized name, so try |
| 171 |
# that too to make the fallback detection with CMake work |
| 172 |
if blas_name == 'openblas' |
| 173 |
blas = dependency(['openblas', 'OpenBLAS']) |
| 174 |
else |
| 175 |
blas = dependency(blas_name) |
| 176 |
endif |
| 177 |
if blas_name == 'blas' |
| 178 |
# Netlib BLAS has a separate `libcblas.so` which we use directly in the g77 |
| 179 |
# ABI wrappers, so detect it and error out if we cannot find it. |
| 180 |
# In the future, this should be done automatically for: |
| 181 |
# `dependency('blas', modules: cblas)` |
| 182 |
# see https://github.com/mesonbuild/meson/pull/10921. |
| •183 |
cblas = dependency('blas') |
| 184 |
else |
| 185 |
cblas = [] |
| 186 |
endif |
| 187 |
|
| 188 |
if lapack_name == 'openblas' |
| 189 |
lapack = dependency(['openblas', 'OpenBLAS']) |
| 190 |
else |
| 191 |
lapack = dependency(lapack_name) |
| 192 |
endif |
| 193 |
|
| 194 |
|
| 195 |
### |
| 196 |
|
| 197 |
#### Dependencies Information |
| 198 |
dependency_map = { |
| 199 |
'BLAS': blas, |
| 200 |
'LAPACK': lapack, |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
foreach name, dep : dependency_map |
| 205 |
conf_data.set(name + '_NAME', dep.name()) |
| 206 |
conf_data.set(name + '_FOUND', dep.found()) |
| 207 |
|
| 208 |
if dep.found() |
| 209 |
conf_data.set(name + '_VERSION', dep.version()) |
| 210 |
conf_data.set(name + '_TYPE_NAME', dep.type_name()) |
| 211 |
conf_data.set(name + '_INCLUDEDIR', dep.get_variable('includedir', default_value: 'unknown')) |
| 212 |
conf_data.set(name + '_LIBDIR', dep.get_variable('libdir', default_value: 'unknown')) |
| 213 |
conf_data.set(name + '_OPENBLAS_CONFIG', dep.get_variable('openblas_config', default_value: 'unknown')) |
| 214 |
conf_data.set(name + '_PCFILEDIR', dep.get_variable('pcfiledir', default_value: 'unknown')) |
| 215 |
endif |
| 216 |
|
| 217 |
endforeach |
| 218 |
|
| 219 |
### |
| 220 |
|
| 221 |
#### Include Python Sources in this Directory |
| 222 |
# Copy the main __init__ to the build dir |
| 223 |
python_sources = [ |
| 224 |
'__init__.py', |
| 225 |
'_distributor_init.py', |
| 226 |
] |
| 227 |
|
| 228 |
py.install_sources( |
| 229 |
python_sources, |
| 230 |
subdir: 'skmisc' |
| 231 |
) |
| 232 |
|
| 233 |
#### Build __config__.py |
| 234 |
configure_file( |
| 235 |
input: '__config__.py.in', |
| 236 |
output: '__config__.py', |
| 237 |
configuration : conf_data, |
| 238 |
install_dir: skmisc_dir, |
| 239 |
) |
| 240 |
### |
| 241 |
|
| 242 |
#### Build _version.py |
| 243 |
configure_file( |
| 244 |
input: '_version.py.in', |
| 245 |
output: '_version.py', |
| 246 |
configuration: conf_data, |
| 247 |
install_dir: skmisc_dir, |
| 248 |
) |
| 249 |
|
| 250 |
# Meson does not inculde any generated files in the source distribution |
| 251 |
# We want the generated _version.py so that a versioned build can be |
| 252 |
# created from the source dist. |
| 253 |
meson.add_dist_script('_build_utils/copy_version_to_dist.py') |
| 254 |
|
| 255 |
### |
| 256 |
|
| 257 |
#### Included sub-packages |
| 258 |
subdir('loess') |
| 259 |
### |