|
1 | | -# NumPy include directory - needed in all submodules |
2 | | -incdir_numpy = get_option('incdir_numpy') |
3 | | -if incdir_numpy == '' |
4 | | - incdir_numpy = run_command(py3_target, |
5 | | - [ |
6 | | - '-c', |
7 | | - 'import os; os.chdir(".."); import numpy; print(numpy.get_include())' |
8 | | - ], |
9 | | - check: true |
10 | | - ).stdout().strip() |
| 1 | +# <!-- from https://github.com/scipy/scipy/blob/4d9f5e65af06d4cc3f770407f1a66a185675eea9/scipy/meson.build |
| 2 | + |
| 3 | +incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given') |
| 4 | +if incdir_numpy == 'not-given' |
| 5 | + incdir_numpy = run_command(py3, |
| 6 | + [ |
| 7 | + '-c', |
| 8 | + '''import os |
| 9 | +import numpy as np |
| 10 | +try: |
| 11 | + incdir = os.path.relpath(np.get_include()) |
| 12 | +except Exception: |
| 13 | + incdir = np.get_include() |
| 14 | +print(incdir) |
| 15 | + ''' |
| 16 | + ], |
| 17 | + check: true |
| 18 | + ).stdout().strip() |
| 19 | + |
| 20 | + # We do need an absolute path to feed to `cc.find_library` below |
| 21 | + _incdir_numpy_abs = run_command(py3, |
| 22 | + ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], |
| 23 | + check: true |
| 24 | + ).stdout().strip() |
| 25 | +else |
| 26 | + _incdir_numpy_abs = incdir_numpy |
11 | 27 | endif |
12 | | -# this creates a raw string which is useful for Windows use of '\' for paths |
13 | | -incdir_numpy = '''@0@'''.format(incdir_numpy) |
14 | | - |
15 | | -# HACK: Meson prefixes filenames of intermediate compiled objects with their filepath. This poses a problem for conda builds |
16 | | -# since conda ensures the host environment directory has 255 characters so the meson object filenames then exceed 255 |
17 | | -# characters. To remedy this, the fortranobject.c file from numpy is copied into pyoptsparse so that the meson build |
18 | | -# uses a relative path, rather than an absolute path, thus reducing the auto generated object filename |
19 | | -# see for example https://github.com/mesonbuild/meson/issues/4226 |
20 | | -run_command(py3_command, |
21 | | - [ |
22 | | - '-c', |
23 | | - 'import os; os.chdir(".."); import shutil; shutil.copy(os.path.join(r"' + incdir_numpy + '", "..", "..", "f2py", "src", "fortranobject.c"), "pyoptsparse")' |
24 | | - ], |
25 | | - check: true |
26 | | -) |
27 | | - |
28 | 28 | inc_np = include_directories(incdir_numpy) |
29 | 29 |
|
| 30 | +# Don't use the deprecated NumPy C API. Define this to a fixed version instead of |
| 31 | +# NPY_API_VERSION in order not to break compilation for released SciPy versions |
| 32 | +# when NumPy introduces a new deprecation. |
| 33 | +numpy_nodepr_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION'] |
| 34 | +np_dep = declare_dependency(include_directories: inc_np, compile_args: numpy_nodepr_api) |
30 | 35 |
|
31 | | -# TODO: pyoptsparse supports numpy>=1.16 but numpy.f2py.get_include() wasnt added until later, raise numpy version? |
32 | | -#incdir_f2py = run_command(py3_target, |
33 | | -# [ |
34 | | -# '-c', |
35 | | -# 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())' |
36 | | -# ], |
37 | | -# check : true |
38 | | -#).stdout().strip() |
39 | 36 | incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src' |
40 | 37 | inc_f2py = include_directories(incdir_f2py) |
41 | | - |
42 | | - |
43 | | -# TODO: this is kept in here so that when meson becomes pep517-compliant |
44 | | -# we can uncomment these to have meson install the source files |
45 | | - |
46 | | -#python_sources = [ |
47 | | -# '__init__.py', |
48 | | -# 'pyOpt_MPI.py', |
49 | | -# 'pyOpt_constraint.py', |
50 | | -# 'pyOpt_error.py', |
51 | | -# 'pyOpt_gradient.py', |
52 | | -# 'pyOpt_history.py', |
53 | | -# 'pyOpt_objective.py', |
54 | | -# 'pyOpt_optimization.py', |
55 | | -# 'pyOpt_optimizer.py', |
56 | | -# 'pyOpt_solution.py', |
57 | | -# 'pyOpt_utils.py', |
58 | | -# 'pyOpt_variable.py', |
59 | | -# 'types.py' |
60 | | -#] |
61 | | - |
62 | | -#py3_target.install_sources( |
63 | | -# python_sources, |
64 | | -# pure: true, |
65 | | -# subdir: 'pyoptsparse' |
66 | | -#) |
| 38 | +fortranobject_c = incdir_f2py / 'fortranobject.c' |
| 39 | + |
| 40 | +# Share this object across multiple modules. |
| 41 | +fortranobject_lib = static_library('_fortranobject', |
| 42 | + fortranobject_c, |
| 43 | + c_args: numpy_nodepr_api, |
| 44 | + dependencies: py3_dep, |
| 45 | + include_directories: [inc_np, inc_f2py], |
| 46 | + gnu_symbol_visibility: 'hidden', |
| 47 | +) |
| 48 | +fortranobject_dep = declare_dependency( |
| 49 | + link_with: fortranobject_lib, |
| 50 | + include_directories: [inc_np, inc_f2py], |
| 51 | +) |
67 | 52 |
|
68 | 53 | subdir('pySNOPT') |
69 | 54 | subdir('pySLSQP') |
70 | 55 | subdir('pyCONMIN') |
71 | 56 | subdir('pyNLPQLP') |
72 | 57 | subdir('pyNSGA2') |
73 | 58 | subdir('pyPSQP') |
74 | | -#subdir('pyALPSO') |
75 | | -#subdir('pyParOpt') |
76 | | -#subdir('postprocessing') |
77 | | - |
78 | | -# test imports |
79 | | -# envdata = environment() |
80 | | -# python_paths = [join_paths(meson.current_build_dir(), '..')] |
81 | | -# envdata.prepend('PYTHONPATH', python_paths) |
82 | | - |
83 | | -# progs = [['SLSQP', 'pySLSQP', 'slsqp'], |
84 | | -# ['CONMIN', 'pyCONMIN', 'conmin'], |
85 | | -# ['PSQP', 'pyPSQP', 'psqp'], |
86 | | -# ['NSGA2', 'pyNSGA2', 'nsga2']] |
87 | | - |
88 | | - |
89 | | -# foreach p : progs |
90 | | -# import_command = 'from pyoptsparse.' + p[1] + ' import '+p[2]+'; print('+p[2]+'.__file__)' |
91 | | -# test( |
92 | | -# 'import test for '+p[0], |
93 | | -# py3_command, |
94 | | -# args: ['-c', import_command], |
95 | | -# env: envdata |
96 | | -# ) |
97 | | -# endforeach |
0 commit comments